/** * WordPress dependencies */ import { __experimentalHStack as HStack, __experimentalVStack as VStack, __experimentalItemGroup as ItemGroup, Button, FlexItem, privateApis as componentsPrivateApis, } from '@wordpress/components'; import { __, sprintf, isRTL } from '@wordpress/i18n'; import { plus, Icon, chevronLeft, chevronRight, moreVertical, } from '@wordpress/icons'; import { useState } from '@wordpress/element'; /** * Internal dependencies */ import { Subtitle } from './subtitle'; import { NavigationButtonAsItem } from './navigation-button'; import { ScreenHeader } from './screen-header'; import { ScreenBody } from './screen-body'; import { getNewIndexFromPresets } from './utils'; import ConfirmResetShadowDialog from './confirm-reset-shadow-dialog'; import { useSetting } from './hooks'; import { unlock } from './lock-unlock'; const { Menu } = unlock( componentsPrivateApis ); export const defaultShadow = '6px 6px 9px rgba(0, 0, 0, 0.2)'; export default function ShadowsPanel() { const [ defaultShadows ] = useSetting( 'shadow.presets.default' ); const [ defaultShadowsEnabled ] = useSetting( 'shadow.defaultPresets' ); const [ themeShadows ] = useSetting( 'shadow.presets.theme' ); const [ customShadows, setCustomShadows ] = useSetting( 'shadow.presets.custom' ); const onCreateShadow = ( shadow: any ) => { setCustomShadows( [ ...( customShadows || [] ), shadow ] ); }; const handleResetShadows = () => { setCustomShadows( [] ); }; const [ isResetDialogOpen, setIsResetDialogOpen ] = useState( false ); const toggleResetDialog = () => setIsResetDialogOpen( ! isResetDialogOpen ); return ( <> { isResetDialogOpen && ( ) } { defaultShadowsEnabled && ( ) } { themeShadows && themeShadows.length > 0 && ( ) } ); } interface ShadowListProps { label: string; shadows: any[]; category: string; canCreate?: boolean; onCreate?: ( shadow: any ) => void; onReset?: () => void; } function ShadowList( { label, shadows, category, canCreate, onCreate, onReset, }: ShadowListProps ) { const handleAddShadow = () => { const newIndex = getNewIndexFromPresets( shadows, 'shadow-' ); onCreate?.( { name: sprintf( /* translators: %d: is an index for a preset */ __( 'Shadow %d' ), newIndex ), shadow: defaultShadow, slug: `shadow-${ newIndex }`, } ); }; return ( { label } { canCreate && (