index.js
56 lines
| 1 | import { __ } from '@wordpress/i18n'; |
| 2 | import PanelArea from '../../../../components/panel-area'; |
| 3 | import { useContext } from '@wordpress/element'; |
| 4 | import ControlsContext from '../../../../block-context'; |
| 5 | import getAttribute from '../../../../utils/get-attribute'; |
| 6 | import getResponsivePlaceholder from '../../../../utils/get-responsive-placeholder'; |
| 7 | import FlexControls from './components/FlexControls'; |
| 8 | import hasNumericValue from '../../../../utils/has-numeric-value'; |
| 9 | import { TextControl } from '@wordpress/components'; |
| 10 | import getDeviceType from '../../../../utils/get-device-type'; |
| 11 | |
| 12 | export default function FlexChild( { attributes, setAttributes } ) { |
| 13 | const device = getDeviceType(); |
| 14 | const { id, supports: { flexChildPanel } } = useContext( ControlsContext ); |
| 15 | |
| 16 | const componentProps = { |
| 17 | attributes, |
| 18 | deviceType: device, |
| 19 | }; |
| 20 | |
| 21 | const { |
| 22 | useInnerContainer, |
| 23 | isGrid, |
| 24 | } = attributes; |
| 25 | |
| 26 | return ( |
| 27 | <PanelArea |
| 28 | title={ __( 'Flex Child', 'generateblocks' ) } |
| 29 | initialOpen={ false } |
| 30 | className="gblocks-panel-label" |
| 31 | id={ `${ id }FlexChild` } |
| 32 | > |
| 33 | { flexChildPanel.flex && ( ! useInnerContainer || ( useInnerContainer && isGrid ) ) && |
| 34 | <FlexControls |
| 35 | attributes={ attributes } |
| 36 | setAttributes={ setAttributes } |
| 37 | /> |
| 38 | } |
| 39 | |
| 40 | { flexChildPanel.order && ( ! useInnerContainer || ( useInnerContainer && isGrid ) ) && |
| 41 | <TextControl |
| 42 | type={ 'number' } |
| 43 | label={ __( 'Order', 'generateblocks' ) } |
| 44 | value={ hasNumericValue( getAttribute( 'order', componentProps ) ) ? getAttribute( 'order', componentProps ) : '' } |
| 45 | placeholder={ getResponsivePlaceholder( 'order', attributes, device ) } |
| 46 | onChange={ ( value ) => { |
| 47 | setAttributes( { |
| 48 | [ getAttribute( 'order', componentProps, true ) ]: parseFloat( value ), |
| 49 | } ); |
| 50 | } } |
| 51 | /> |
| 52 | } |
| 53 | </PanelArea> |
| 54 | ); |
| 55 | } |
| 56 |