import { Button, ToggleControl, TextControl } from '@wordpress/components'; import data from '../../utils/data'; import { useState } from '@wordpress/element'; import Select, { components } from 'react-select'; export const SETTINGS_BLOCK_TYPE_EMPTY = 'empty'; export const SETTINGS_BLOCK_TYPE_TOGGLE = 'toggle'; export const SETTINGS_BLOCK_TYPE_TOGGLE_CONTENT = 'toggle-content'; export const SETTINGS_BLOCK_TYPE_INPUT = 'input'; export const SETTINGS_BLOCK_TYPE_BUTTON = 'button'; export const SETTINGS_BLOCK_TYPE_SELECT = 'select'; export const SETTINGS_BLOCK_STYLING_TYPE_PRIMARY = 'primary'; export const SETTINGS_BLOCK_STYLING_TYPE_SECONDARY = 'secondary'; export const SETTINGS_BLOCK_STYLING_TYPE_TERTIARY = 'tertiary'; const SettingsBlock = ( { className, title, description, children, style, actionProps, tag, } ) => { const [ toggleContentVisible, setToggleContentVisible ] = useState( actionProps?.type !== SETTINGS_BLOCK_TYPE_TOGGLE_CONTENT ); const toggleContent = () => { if ( actionProps?.type !== SETTINGS_BLOCK_TYPE_TOGGLE_CONTENT ) { return; } setToggleContentVisible( ! toggleContentVisible ); }; const blockClassName = [ 'ppcp-r-settings-block' ]; blockClassName.push( 'ppcp-r-settings-block--' + style ); blockClassName.push( 'ppcp-r-settings-block--' + actionProps?.type ); if ( className ) { blockClassName.push( className ); } if ( toggleContentVisible && actionProps?.type === SETTINGS_BLOCK_TYPE_TOGGLE_CONTENT ) { blockClassName.push( 'ppcp-r-settings-block--content-visible' ); } return (
toggleContent() } >
{ title } { tag && tag }

{ actionProps?.type !== SETTINGS_BLOCK_TYPE_EMPTY && (
{ actionProps?.type === SETTINGS_BLOCK_TYPE_TOGGLE && ( actionProps?.callback( actionProps?.key, newValue ) } /> ) } { actionProps?.type === SETTINGS_BLOCK_TYPE_INPUT && ( <> actionProps?.callback( actionProps?.key, newValue ) } /> ) } { actionProps?.type === SETTINGS_BLOCK_TYPE_BUTTON && ( ) } { actionProps?.type === SETTINGS_BLOCK_TYPE_TOGGLE_CONTENT && (
{ data().getImage( 'icon-arrow-down.svg' ) }
) } { actionProps?.type === SETTINGS_BLOCK_TYPE_SELECT && (