AdvancedFields.js
2 years ago
AttributeHelp.js
2 years ago
BlockAddPrevButton.js
2 years ago
BlockAdvancedValue.js
2 years ago
BlockClassName.js
2 years ago
BlockDefaultValue.js
2 years ago
BlockDescription.js
2 years ago
BlockLabel.js
2 years ago
BlockName.js
2 years ago
BlockPlaceholder.js
2 years ago
BlockPrevButtonLabel.js
2 years ago
BlockRequired.js
2 years ago
BlockVisibility.js
2 years ago
FieldControl.js
2 years ago
FieldSettingsWrapper.js
2 years ago
FieldWrapper.js
2 years ago
GeneralFields.js
2 years ago
SelectVariations.js
2 years ago
ToggleGroupVariations.js
2 years ago
ToolBarDefault.js
2 years ago
ToolBarFields.js
2 years ago
ToolBarDefault.js
62 lines
| 1 | import useUniqKey from '../hooks/useUniqKey'; |
| 2 | import useBlockAttributes from '../hooks/useBlockAttributes'; |
| 3 | import useSuccessNotice from '../../hooks/useSuccessNotice'; |
| 4 | |
| 5 | const { |
| 6 | BlockControls, |
| 7 | } = wp.blockEditor; |
| 8 | |
| 9 | const { |
| 10 | useCopyToClipboard, |
| 11 | } = wp.compose; |
| 12 | |
| 13 | const { |
| 14 | TextControl, |
| 15 | ToolbarGroup, |
| 16 | ToolbarItem, |
| 17 | ToolbarButton, |
| 18 | Button, |
| 19 | } = wp.components; |
| 20 | |
| 21 | function ToolBarDefault( { children = null } ) { |
| 22 | const uniqKey = useUniqKey(); |
| 23 | |
| 24 | const [ |
| 25 | attributes, |
| 26 | setAttributes, |
| 27 | ] = useBlockAttributes(); |
| 28 | |
| 29 | const displayNotice = useSuccessNotice( |
| 30 | `Copied "${ attributes.name }" to clipboard.`, |
| 31 | ); |
| 32 | |
| 33 | const copyRef = useCopyToClipboard( |
| 34 | attributes.name, |
| 35 | () => displayNotice( true ), |
| 36 | ); |
| 37 | |
| 38 | return <BlockControls |
| 39 | key={ uniqKey( 'ToolBarFields-BlockControls' ) } |
| 40 | > |
| 41 | <ToolbarGroup |
| 42 | key={ uniqKey( 'ToolBarFields-ToolbarGroup' ) } |
| 43 | className="jet-fb-block-toolbar" |
| 44 | > |
| 45 | <ToolbarButton |
| 46 | isSmall |
| 47 | icon="admin-page" |
| 48 | showTooltip |
| 49 | shortcut="Copy name" |
| 50 | ref={ copyRef } |
| 51 | /> |
| 52 | <ToolbarItem |
| 53 | as={ TextControl } |
| 54 | value={ attributes.name } |
| 55 | onChange={ name => setAttributes( { name } ) } |
| 56 | /> |
| 57 | { children } |
| 58 | </ToolbarGroup> |
| 59 | </BlockControls>; |
| 60 | } |
| 61 | |
| 62 | export default ToolBarDefault; |