import { useSelect } from '@wordpress/data'; /** * BlockSettings * * Bundles the used for several blocks * * * @param {object} props * @param {number} props.attributes the data * @param {string} props.setAttributes the state * @returns {*} React JSX */ import { __ } from '@wordpress/i18n'; import { useState, useEffect } from '@wordpress/element'; import apiFetch from '@wordpress/api-fetch'; import { Panel, PanelBody, PanelRow, SelectControl, ToggleControl, RangeControl, ColorPalette, Button, Spinner, } from '@wordpress/components'; import { InspectorControls, BlockControls, AlignmentToolbar, MediaUpload, MediaUploadCheck, } from '@wordpress/block-editor'; export default function BlockSettings({ attributes, setAttributes }) { const [ configOptions, setConfigOptions ] = useState([]); const [ isLoading, setIsLoading ] = useState(true); useEffect( () => { let isMounted = true; apiFetch( { path: '/badegg/v1/blocks/config' } ) .then( ( data ) => { if ( isMounted ) { setConfigOptions( data ); setIsLoading( false ); } } ) .catch( () => { if ( isMounted ) { setConfigOptions( null ); setIsLoading( false ); } } ); return () => { isMounted = false; }; }, [] ); if ( isLoading ) { return ( ); } if ( ! configOptions ) { return null; } const { alignment, container_width, padding_top, padding_bottom, background_hex, background_tint, background_image, background_url, background_opacity, background_contrast, background_fixed, } = attributes; return ( <> setAttributes({alignment: value})} /> setAttributes({ container_width: value }) } __next40pxDefaultSize={ true } __nextHasNoMarginBottom={ true } /> setAttributes({ padding_top: value }) } __nextHasNoMarginBottom /> setAttributes({ padding_bottom: value }) } __nextHasNoMarginBottom />

{ __('Colour', 'badegg') }

{ let slug, hex, selected = ''; if(value) { selected = configOptions.colours.find( ( c ) => c.color === value ); hex = value; } if(selected) { slug = selected.slug; } setAttributes( { background_colour: slug, background_hex: hex, }); } } /> { 'background_colour' in attributes && attributes.background_colour && ![0, '0', 'white', 'black'].includes(attributes.background_colour) ? ( <> setAttributes({ background_tint: value }) } __next40pxDefaultSize={ true } __nextHasNoMarginBottom={ true } /> setAttributes({ background_contrast: value }) } __nextHasNoMarginBottom /> ) : null } { background_image != 0 && ( <> setAttributes({ background_fixed: value }) } __nextHasNoMarginBottom /> setAttributes({ background_opacity: value }) } min={ 5 } max={ 100 } /> )} { setAttributes({ background_image: media.id, background_url: media.url, }); }} allowedTypes={ ['image'] } value={ background_image } render={ ({ open }) => ( )} /> { background_image != 0 && ( )}
); }