UNPKG

@wordpress/global-styles-ui

Version:
1 lines • 4.73 kB
{"version":3,"file":"shadows-panel.cjs","names":["useSetting","usePresets","getNewIndexFromPresets","sprintf","__","ScreenHeader","ScreenBody","Stack","PresetGroup"],"sources":["../src/shadows-panel.tsx"],"sourcesContent":["import { __, sprintf } from '@wordpress/i18n';\nimport { Stack } from '@wordpress/ui';\nimport { ScreenHeader } from './screen-header';\nimport { ScreenBody } from './screen-body';\nimport PresetGroup from './presets/preset-group';\nimport { usePresets } from './presets/use-presets';\nimport { useSetting } from './hooks';\nimport { getNewIndexFromPresets } from './utils';\n\nexport const defaultShadow = '6px 6px 9px rgba(0, 0, 0, 0.2)';\n\ninterface ShadowPreset {\n\tname: string;\n\tslug: string;\n\tshadow: string;\n}\n\nexport default function ShadowsPanel() {\n\tconst [ defaultEnabled ] = useSetting< boolean >( 'shadow.defaultPresets' );\n\tconst def = usePresets< ShadowPreset >( 'shadow.presets', 'default' );\n\tconst theme = usePresets< ShadowPreset >( 'shadow.presets', 'theme' );\n\tconst custom = usePresets< ShadowPreset >( 'shadow.presets', 'custom' );\n\n\tconst addCustomShadow = () => {\n\t\tconst index = getNewIndexFromPresets( custom.presets, 'shadow-' );\n\t\tcustom.setPresets( [\n\t\t\t...custom.presets,\n\t\t\t{\n\t\t\t\t/* translators: %d: is an index for a preset */\n\t\t\t\tname: sprintf( __( 'Shadow %d' ), index ),\n\t\t\t\tshadow: defaultShadow,\n\t\t\t\tslug: `shadow-${ index }`,\n\t\t\t},\n\t\t] );\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<ScreenHeader\n\t\t\t\ttitle={ __( 'Shadows' ) }\n\t\t\t\tdescription={ __(\n\t\t\t\t\t'Manage and create shadow styles for use across the site.'\n\t\t\t\t) }\n\t\t\t/>\n\t\t\t<ScreenBody>\n\t\t\t\t<Stack\n\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\tclassName=\"global-styles-ui__shadows-panel\"\n\t\t\t\t\tgap=\"xl\"\n\t\t\t\t>\n\t\t\t\t\t{ defaultEnabled && (\n\t\t\t\t\t\t<PresetGroup\n\t\t\t\t\t\t\tlabel={ __( 'Default' ) }\n\t\t\t\t\t\t\titems={ def.presets }\n\t\t\t\t\t\t\tgetEditPath={ ( slug ) =>\n\t\t\t\t\t\t\t\t`/shadows/edit/default/${ slug }`\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t{ theme.presets.length > 0 && (\n\t\t\t\t\t\t<PresetGroup\n\t\t\t\t\t\t\tlabel={ __( 'Theme' ) }\n\t\t\t\t\t\t\titems={ theme.presets }\n\t\t\t\t\t\t\tgetEditPath={ ( slug ) =>\n\t\t\t\t\t\t\t\t`/shadows/edit/theme/${ slug }`\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t<PresetGroup\n\t\t\t\t\t\tlabel={ __( 'Custom' ) }\n\t\t\t\t\t\titems={ custom.presets }\n\t\t\t\t\t\tgetEditPath={ ( slug ) =>\n\t\t\t\t\t\t\t`/shadows/edit/custom/${ slug }`\n\t\t\t\t\t\t}\n\t\t\t\t\t\taddLabel={ __( 'Add shadow' ) }\n\t\t\t\t\t\tonAdd={ addCustomShadow }\n\t\t\t\t\t\tmenuAction={ {\n\t\t\t\t\t\t\tlabel: __( 'Remove all custom shadows' ),\n\t\t\t\t\t\t\toptionsLabel: __( 'Shadow options' ),\n\t\t\t\t\t\t\tconfirmText: __(\n\t\t\t\t\t\t\t\t'Are you sure you want to remove all custom shadows?'\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tconfirmButtonText: __( 'Remove' ),\n\t\t\t\t\t\t\tonConfirm: () => custom.setPresets( [] ),\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t</Stack>\n\t\t\t</ScreenBody>\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAa,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