/** * External dependencies */ import clsx from 'clsx'; import type { Property } from 'csstype'; import type { ReactElement } from 'react'; /** * WordPress dependencies */ import { __ } from '@wordpress/i18n'; import { useSelect } from '@wordpress/data'; import { useState } from '@wordpress/element'; import { BaseControl, Popover, ColorPalette, __experimentalVStack as VStack, __experimentalSpacer as Spacer, __experimentalText as Text, } from '@wordpress/components'; import { store as blockEditorStore } from '@wordpress/block-editor'; import { useInstanceId } from '@wordpress/compose'; /** * Internal dependencies */ import ColorIndicatorButton from './color-indicator-button'; type Props = { label: string | ReactElement; help?: string; onChange: ( event: any ) => void; colors?: { name: string; slug: string; color: Property.Color; }[]; value: Property.Color | undefined; className?: string; }; export default function ColorControl( { label = __( 'Color', 'flexible-table-block' ), help, onChange, colors: colorsProp = [], value, className, }: Props ) { const instanceId = useInstanceId( ColorControl, 'ftb-color-control' ); const headingId = `${ instanceId }-heading`; const colors = useSelect( ( select ) => { const settings = select( blockEditorStore // @ts-ignore ).getSettings(); return settings?.colors ?? []; }, [] ); const [ isPickerOpen, setIsPickerOpen ] = useState< boolean >( false ); const handleOnChange = ( inputValue: Property.Color | undefined ) => onChange( inputValue ); const handleOnPickerOpen = () => setIsPickerOpen( true ); const handleOnPickerClose = () => setIsPickerOpen( false ); return ( { label } { isPickerOpen && ( ) } ); }