UNPKG

@wordpress/global-styles-ui

Version:
8 lines (7 loc) • 4.54 kB
{ "version": 3, "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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA4B;AAC5B,gBAAsB;AACtB,2BAA6B;AAC7B,yBAA2B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