-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UI] Data source code snippets (#321)
* Export snackbar and move to match designs Signed-off-by: brookewp <[email protected]> * Create code snippet component Signed-off-by: brookewp <[email protected]> * Add to settings page Signed-off-by: brookewp <[email protected]> * Add method to fetch snippets Signed-off-by: brookewp <[email protected]> * Replace duplicate snackbar function Signed-off-by: brookewp <[email protected]> * Update logic and replace modal for working esc Signed-off-by: brookewp <[email protected]> * Add TabPanel to handle array of snippets Signed-off-by: brookewp <[email protected]> * Add title and icon to code snippet modal Signed-off-by: brookewp <[email protected]> * Switch to light build Signed-off-by: brookewp <[email protected]> --------- Signed-off-by: brookewp <[email protected]>
- Loading branch information
Showing
9 changed files
with
486 additions
and
33 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,55 @@ | ||
import { Button } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { copy } from '@wordpress/icons'; | ||
import { PrismLight as SyntaxHighlighter } from 'react-syntax-highlighter'; | ||
import php from 'react-syntax-highlighter/dist/esm/languages/prism/php'; | ||
import coy from 'react-syntax-highlighter/dist/esm/styles/prism/coy'; | ||
|
||
import { useDataSources } from '../hooks/useDataSources'; | ||
|
||
SyntaxHighlighter.registerLanguage( 'php', php ); | ||
|
||
const CodeSnippet = ( { code }: { code: string } ) => { | ||
const { showSnackbar } = useDataSources(); | ||
|
||
const handleCopy = () => { | ||
navigator.clipboard | ||
.writeText( code ) | ||
.then( () => { | ||
showSnackbar( 'success', __( 'Code copied to clipboard!', 'remote-data-blocks' ) ); | ||
} ) | ||
.catch( () => { | ||
showSnackbar( 'error', __( 'Failed to copy code', 'remote-data-blocks' ) ); | ||
} ); | ||
}; | ||
|
||
return ( | ||
<div | ||
style={ { | ||
position: 'relative', | ||
marginBottom: '1rem', | ||
padding: '16px', | ||
} } | ||
> | ||
<Button | ||
onClick={ handleCopy } | ||
icon={ copy } | ||
variant="tertiary" | ||
style={ { | ||
position: 'absolute', | ||
top: '8px', | ||
right: '8px', | ||
zIndex: '11', | ||
background: '#fff', | ||
} } | ||
> | ||
{ __( 'Copy' ) } | ||
</Button> | ||
<SyntaxHighlighter language="php" style={ coy } showLineNumbers> | ||
{ code } | ||
</SyntaxHighlighter> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CodeSnippet; |
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