-
Notifications
You must be signed in to change notification settings - Fork 1k
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
chore: update design/functionality of copying highlighted code snippets #7570
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8a04b2b
chore: design updates to copy code functionality
hbuchel 0171c39
add hover
hbuchel f5904e0
add hover sibling style
hbuchel da1a846
updates to css highlight colors
hbuchel 20dd267
darkmode, cleanup
hbuchel e531b49
update file name
hbuchel 0beb304
use space token
hbuchel f39bf5f
fix css transition
hbuchel bb83f66
cleanup
hbuchel a70dbd3
Fix some dark mode interaction colors
hbuchel c229fd8
add icon
hbuchel 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 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,21 @@ | ||
import { Icon } from '@aws-amplify/ui-react'; | ||
|
||
export const IconClipboard = ({ ...rest }) => { | ||
return ( | ||
<Icon | ||
aria-hidden="true" | ||
{...rest} | ||
viewBox={{ | ||
minX: 0, | ||
minY: 0, | ||
width: 24, | ||
height: 24 | ||
}} | ||
> | ||
<path | ||
d="M18.75 3H15C15 1.34531 13.6547 0 12 0C10.3453 0 9 1.34531 9 3H5.25C4.00781 3 3 4.00781 3 5.25V21.75C3 22.9922 4.00781 24 5.25 24H18.75C19.9922 24 21 22.9922 21 21.75V5.25C21 4.00781 19.9922 3 18.75 3ZM12 1.875C12.6234 1.875 13.125 2.37656 13.125 3C13.125 3.62344 12.6234 4.125 12 4.125C11.3766 4.125 10.875 3.62344 10.875 3C10.875 2.37656 11.3766 1.875 12 1.875ZM18.75 21.4688C18.75 21.6234 18.6234 21.75 18.4688 21.75H5.53125C5.37656 21.75 5.25 21.6234 5.25 21.4688V5.53125C5.25 5.37656 5.37656 5.25 5.53125 5.25H7.5V6.9375C7.5 7.24687 7.75313 7.5 8.0625 7.5H15.9375C16.2469 7.5 16.5 7.24687 16.5 6.9375V5.25H18.4688C18.6234 5.25 18.75 5.37656 18.75 5.53125V21.4688Z" | ||
fill="currentColor" | ||
/> | ||
</Icon> | ||
); | ||
}; |
This file contains 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 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 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,53 @@ | ||
import { useState, useId } from 'react'; | ||
import { CopyToClipboard } from 'react-copy-to-clipboard'; | ||
import { Button, VisuallyHidden } from '@aws-amplify/ui-react'; | ||
import { trackCopyClicks } from '@/utils/track'; | ||
import { prepareCopyText } from './utils/copy-code'; | ||
import { IconClipboard } from '@/components/Icons'; | ||
interface MDXHighlightedCodeProps { | ||
codeString: string; | ||
testId?: string; | ||
children?: React.ReactNode; | ||
} | ||
|
||
export const MDXHighlightedCode = ({ | ||
codeString, | ||
children | ||
}: MDXHighlightedCodeProps) => { | ||
const [copied, setCopied] = useState(false); | ||
|
||
const copyText = prepareCopyText(codeString); | ||
const highlightCodeId = useId(); | ||
|
||
const copy = () => { | ||
trackCopyClicks(copyText); | ||
setCopied(true); | ||
setTimeout(() => { | ||
setCopied(false); | ||
}, 2000); | ||
}; | ||
return ( | ||
<> | ||
<CopyToClipboard text={copyText} onCopy={copy}> | ||
<Button | ||
aria-describedby={highlightCodeId} | ||
size="small" | ||
className="highlight-copy-button" | ||
> | ||
<IconClipboard /> | ||
{copied ? 'Copied' : 'Copy'} | ||
|
||
<VisuallyHidden> | ||
{` `} | ||
highlighted code example | ||
</VisuallyHidden> | ||
</Button> | ||
</CopyToClipboard> | ||
<CopyToClipboard text={copyText} onCopy={copy}> | ||
<div className="highlight-code" id={highlightCodeId}> | ||
{children} | ||
</div> | ||
</CopyToClipboard> | ||
</> | ||
); | ||
}; |
46 changes: 0 additions & 46 deletions
46
src/components/MDXComponents/MDXHighlightedCopyCodeButton.tsx
This file was deleted.
Oops, something went wrong.
This file contains 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!!