BlockSettings.jsx
108 lines
| 1 | import { __ } from '@wordpress/i18n'; |
| 2 | import { BaseControl, Notice } from '@wordpress/components'; |
| 3 | |
| 4 | import { OpenPanel } from '@edge22/components'; |
| 5 | |
| 6 | import { |
| 7 | ApplyFilters, |
| 8 | URLControls, |
| 9 | TagNameControl, |
| 10 | } from '@components/index.js'; |
| 11 | import { useBlockStyles } from '@hooks/useBlockStyles'; |
| 12 | import { InlineBackgroundImage } from '../../element/components/InlineBackgroundImage'; |
| 13 | |
| 14 | export function BlockSettings( { |
| 15 | getStyleValue, |
| 16 | onStyleChange, |
| 17 | name, |
| 18 | attributes, |
| 19 | setAttributes, |
| 20 | htmlAttributes, |
| 21 | styles, |
| 22 | context, |
| 23 | } ) { |
| 24 | const { |
| 25 | tagName, |
| 26 | } = attributes; |
| 27 | |
| 28 | const { |
| 29 | currentAtRule, |
| 30 | } = useBlockStyles(); |
| 31 | |
| 32 | const panelProps = { |
| 33 | name, |
| 34 | attributes, |
| 35 | setAttributes, |
| 36 | }; |
| 37 | |
| 38 | return ( |
| 39 | <ApplyFilters |
| 40 | name="generateblocks.editor.blockControls" |
| 41 | blockName={ name } |
| 42 | getStyleValue={ getStyleValue } |
| 43 | onStyleChange={ onStyleChange } |
| 44 | currentAtRule={ currentAtRule } |
| 45 | attributes={ attributes } |
| 46 | setAttributes={ setAttributes } |
| 47 | > |
| 48 | <OpenPanel |
| 49 | { ...panelProps } |
| 50 | shouldRender={ 'a' === tagName && '' === currentAtRule } |
| 51 | panelId="link-destination" |
| 52 | > |
| 53 | <URLControls |
| 54 | label={ __( 'Link Destination', 'generateblocks' ) } |
| 55 | setAttributes={ setAttributes } |
| 56 | htmlAttributes={ htmlAttributes } |
| 57 | context={ context } |
| 58 | tagName={ tagName } |
| 59 | /> |
| 60 | </OpenPanel> |
| 61 | |
| 62 | <OpenPanel |
| 63 | { ...panelProps } |
| 64 | shouldRender={ '' === currentAtRule } |
| 65 | panelId="inline-background-image" |
| 66 | > |
| 67 | <InlineBackgroundImage |
| 68 | label={ __( 'Inline Background Image', 'generateblocks' ) } |
| 69 | htmlAttributes={ htmlAttributes } |
| 70 | setAttributes={ setAttributes } |
| 71 | styles={ styles } |
| 72 | onStyleChange={ onStyleChange } |
| 73 | context={ context } |
| 74 | /> |
| 75 | </OpenPanel> |
| 76 | |
| 77 | <OpenPanel |
| 78 | { ...panelProps } |
| 79 | shouldRender={ '' === currentAtRule } |
| 80 | panelId="settings" |
| 81 | > |
| 82 | <TagNameControl |
| 83 | blockName="generateblocks/loop-item" |
| 84 | value={ tagName } |
| 85 | onChange={ ( value ) => { |
| 86 | setAttributes( { tagName: value } ); |
| 87 | |
| 88 | if ( 'a' === value && ! styles?.display ) { |
| 89 | onStyleChange( 'display', 'block' ); |
| 90 | } |
| 91 | } } |
| 92 | /> |
| 93 | |
| 94 | { 'a' === tagName && ( |
| 95 | <BaseControl> |
| 96 | <Notice |
| 97 | status="warning" |
| 98 | isDismissible={ false } |
| 99 | > |
| 100 | { __( 'This container is now a link element. Be sure not to add any interactive elements inside of it, like buttons or other links.', 'generateblocks' ) } |
| 101 | </Notice> |
| 102 | </BaseControl> |
| 103 | ) } |
| 104 | </OpenPanel> |
| 105 | </ApplyFilters> |
| 106 | ); |
| 107 | } |
| 108 |