components
4 years ago
css
4 years ago
attributes.js
4 years ago
block.js
4 years ago
deprecated.js
5 years ago
edit.js
4 years ago
editor.scss
4 years ago
save.js
4 years ago
edit.js
84 lines
| 1 | import BlockControls from './components/BlockControls'; |
| 2 | import InspectorControls from './components/InspectorControls'; |
| 3 | import InspectorAdvancedControls from './components/InspectorAdvancedControls'; |
| 4 | import ComponentCSS from './components/ComponentCSS'; |
| 5 | import GoogleFontLink from '../../components/google-font-link'; |
| 6 | import { Fragment, useRef, useState, useEffect } from '@wordpress/element'; |
| 7 | import { useDeviceType } from '../../hooks'; |
| 8 | import { compose } from '@wordpress/compose'; |
| 9 | import { withButtonLegacyMigration, withUniqueId } from '../../hoc'; |
| 10 | import withDynamicContent from '../../extend/dynamic-content/hoc/withDynamicContent'; |
| 11 | import ButtonContentRenderer from './components/ButtonContentRenderer'; |
| 12 | |
| 13 | const ButtonEdit = ( props ) => { |
| 14 | const { |
| 15 | attributes, |
| 16 | setAttributes, |
| 17 | clientId, |
| 18 | ContentRenderer = ButtonContentRenderer, |
| 19 | } = props; |
| 20 | |
| 21 | const { |
| 22 | anchor, |
| 23 | ariaLabel, |
| 24 | fontFamily, |
| 25 | googleFont, |
| 26 | googleFontVariants, |
| 27 | isBlockPreview = false, |
| 28 | } = attributes; |
| 29 | |
| 30 | const ref = useRef( null ); |
| 31 | const [ computedStyles, setComputedStyles ] = useState( {} ); |
| 32 | const [ deviceType, setDeviceType ] = useDeviceType( 'Desktop' ); |
| 33 | |
| 34 | useEffect( () => { |
| 35 | const computedButtonStyles = getComputedStyle( ref.current ); |
| 36 | |
| 37 | setComputedStyles( { |
| 38 | fontSize: parseInt( computedButtonStyles.fontSize ) || '', |
| 39 | } ); |
| 40 | }, [] ); |
| 41 | |
| 42 | return ( |
| 43 | <Fragment> |
| 44 | <BlockControls |
| 45 | clientId={ clientId } |
| 46 | attributes={ attributes } |
| 47 | setAttributes={ setAttributes } |
| 48 | /> |
| 49 | |
| 50 | <InspectorControls |
| 51 | { ...props } |
| 52 | deviceType={ deviceType } |
| 53 | setDeviceType={ setDeviceType } |
| 54 | state={ { deviceType } } |
| 55 | blockDefaults={ generateBlocksDefaults.button } |
| 56 | computedStyles={ computedStyles } |
| 57 | /> |
| 58 | |
| 59 | <InspectorAdvancedControls |
| 60 | anchor={ anchor } |
| 61 | ariaLabel={ ariaLabel } |
| 62 | setAttributes={ setAttributes } |
| 63 | /> |
| 64 | |
| 65 | <ComponentCSS { ...props } deviceType={ deviceType } /> |
| 66 | |
| 67 | <GoogleFontLink |
| 68 | fontFamily={ fontFamily } |
| 69 | googleFont={ googleFont } |
| 70 | googleFontVariants={ googleFontVariants } |
| 71 | isBlockPreview={ isBlockPreview } |
| 72 | /> |
| 73 | |
| 74 | <ContentRenderer { ...props } buttonRef={ ref } /> |
| 75 | </Fragment> |
| 76 | ); |
| 77 | }; |
| 78 | |
| 79 | export default compose( |
| 80 | withDynamicContent, |
| 81 | withUniqueId, |
| 82 | withButtonLegacyMigration |
| 83 | )( ButtonEdit ); |
| 84 |