-
Notifications
You must be signed in to change notification settings - Fork 0
Add prominent Edit on GitHub buttons to doc pages #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
80d76dc
Add prominent Edit on GitHub buttons to doc pages
justin808 adfc098
Fix CI: use main branch instead of master for react_on_rails repo
justin808 6227cdd
Fix build failure: guard useDoc() on category index pages
justin808 21c5477
Simplify Edit button: remove big button, add GitHub logo to breadcrumb
justin808 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import type {ReactNode} from 'react'; | ||
| import DocBreadcrumbs from '@theme-original/DocBreadcrumbs'; | ||
| import type DocBreadcrumbsType from '@theme/DocBreadcrumbs'; | ||
| import type {WrapperProps} from '@docusaurus/types'; | ||
| import {useDoc} from '@docusaurus/plugin-content-docs/client'; | ||
|
|
||
| import styles from './styles.module.css'; | ||
|
|
||
| type Props = WrapperProps<typeof DocBreadcrumbsType>; | ||
|
|
||
| function GitHubIcon(): ReactNode { | ||
| return ( | ||
| <svg | ||
| viewBox="0 0 16 16" | ||
| width="14" | ||
| height="14" | ||
| fill="currentColor" | ||
| aria-hidden="true"> | ||
| <path d="M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z" /> | ||
| </svg> | ||
| ); | ||
| } | ||
|
|
||
| function useDocSafe(): {editUrl: string | undefined} | null { | ||
| try { | ||
| const {metadata} = useDoc(); | ||
| return {editUrl: metadata.editUrl}; | ||
| } catch { | ||
| // useDoc() throws on category index pages where DocProvider is absent | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| export default function DocBreadcrumbsWrapper(props: Props): ReactNode { | ||
| const doc = useDocSafe(); | ||
| const editUrl = doc?.editUrl; | ||
|
|
||
| return ( | ||
| <div className={styles.breadcrumbRow}> | ||
| <DocBreadcrumbs {...props} /> | ||
| {editUrl && ( | ||
| <a | ||
| href={editUrl} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className={styles.editButton} | ||
| title="Edit this page on GitHub"> | ||
| <GitHubIcon /> | ||
| <span>Edit</span> | ||
| </a> | ||
| )} | ||
justin808 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </div> | ||
| ); | ||
| } | ||
31 changes: 31 additions & 0 deletions
31
prototypes/docusaurus/src/theme/DocBreadcrumbs/styles.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| .breadcrumbRow { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: space-between; | ||
| gap: 1rem; | ||
justin808 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| .editButton { | ||
| display: inline-flex; | ||
| align-items: center; | ||
| gap: 0.35rem; | ||
| flex-shrink: 0; | ||
| padding: 0.25rem 0.65rem; | ||
| border: 1px solid var(--site-border); | ||
| border-radius: 6px; | ||
| background: var(--site-soft-surface); | ||
| color: var(--ifm-color-content-secondary); | ||
| font-size: 0.8rem; | ||
| font-weight: 500; | ||
| line-height: 1; | ||
| text-decoration: none; | ||
| transition: background 0.15s, color 0.15s, border-color 0.15s; | ||
| white-space: nowrap; | ||
| } | ||
|
|
||
| .editButton:hover { | ||
| background: var(--ifm-color-primary); | ||
| border-color: var(--ifm-color-primary); | ||
| color: #ffffff; | ||
| text-decoration: none; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import type {ReactNode} from 'react'; | ||
| import Content from '@theme-original/DocItem/Content'; | ||
| import type ContentType from '@theme/DocItem/Content'; | ||
| import type {WrapperProps} from '@docusaurus/types'; | ||
|
|
||
| type Props = WrapperProps<typeof ContentType>; | ||
|
|
||
| export default function ContentWrapper(props: Props): ReactNode { | ||
| return <Content {...props} />; | ||
| } | ||
justin808 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
1 change: 1 addition & 0 deletions
1
prototypes/docusaurus/src/theme/DocItem/Content/styles.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /* Intentionally empty — big Edit on GitHub button removed */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.