UNPKG

@wordpress/block-library

Version:
1 lines • 5.2 kB
{"version":3,"file":"ordered-list-settings.mjs","names":["ToolsPanel","ToolsPanelItem"],"sources":["../../src/list/ordered-list-settings.jsx"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport { InspectorControls } from '@wordpress/block-editor';\nimport {\n\tTextControl,\n\tToggleControl,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport { SelectControl } from '@wordpress/ui';\nimport { useToolsPanelDropdownMenuProps } from '../utils/hooks';\n\nconst LIST_STYLE_ITEMS = [\n\t{\n\t\tlabel: __( 'Numbers' ),\n\t\tvalue: 'decimal',\n\t},\n\t{\n\t\tlabel: __( 'Uppercase letters' ),\n\t\tvalue: 'upper-alpha',\n\t},\n\t{\n\t\tlabel: __( 'Lowercase letters' ),\n\t\tvalue: 'lower-alpha',\n\t},\n\t{\n\t\tlabel: __( 'Uppercase Roman numerals' ),\n\t\tvalue: 'upper-roman',\n\t},\n\t{\n\t\tlabel: __( 'Lowercase Roman numerals' ),\n\t\tvalue: 'lower-roman',\n\t},\n];\n\nconst OrderedListSettings = ( { setAttributes, reversed, start, type } ) => {\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\n\treturn (\n\t\t<InspectorControls>\n\t\t\t<ToolsPanel\n\t\t\t\tlabel={ __( 'Settings' ) }\n\t\t\t\tresetAll={ () => {\n\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\ttype: undefined,\n\t\t\t\t\t\tstart: undefined,\n\t\t\t\t\t\treversed: undefined,\n\t\t\t\t\t} );\n\t\t\t\t} }\n\t\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t\t>\n\t\t\t\t<ToolsPanelItem\n\t\t\t\t\tlabel={ __( 'List style' ) }\n\t\t\t\t\tisShownByDefault\n\t\t\t\t\thasValue={ () => !! type }\n\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\ttype: undefined,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<SelectControl\n\t\t\t\t\t\tlabel={ __( 'List style' ) }\n\t\t\t\t\t\titems={ LIST_STYLE_ITEMS }\n\t\t\t\t\t\tvalue={\n\t\t\t\t\t\t\tLIST_STYLE_ITEMS.find(\n\t\t\t\t\t\t\t\t( item ) => item.value === type\n\t\t\t\t\t\t\t) ?? LIST_STYLE_ITEMS[ 0 ]\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonValueChange={ ( item ) =>\n\t\t\t\t\t\t\titem && setAttributes( { type: item.value } )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</ToolsPanelItem>\n\t\t\t\t<ToolsPanelItem\n\t\t\t\t\tlabel={ __( 'Start value' ) }\n\t\t\t\t\tisShownByDefault\n\t\t\t\t\thasValue={ () => !! start }\n\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\tstart: undefined,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\tlabel={ __( 'Start value' ) }\n\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\tconst int = parseInt( value, 10 );\n\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t// It should be possible to unset the value,\n\t\t\t\t\t\t\t\t// e.g. with an empty string.\n\t\t\t\t\t\t\t\tstart: isNaN( int ) ? undefined : int,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tvalue={\n\t\t\t\t\t\t\tNumber.isInteger( start )\n\t\t\t\t\t\t\t\t? start.toString( 10 )\n\t\t\t\t\t\t\t\t: ''\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstep=\"1\"\n\t\t\t\t\t/>\n\t\t\t\t</ToolsPanelItem>\n\t\t\t\t<ToolsPanelItem\n\t\t\t\t\tlabel={ __( 'Reverse order' ) }\n\t\t\t\t\tisShownByDefault\n\t\t\t\t\thasValue={ () => !! reversed }\n\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\treversed: undefined,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Reverse order' ) }\n\t\t\t\t\t\tchecked={ reversed || false }\n\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t// Unset the attribute if not reversed.\n\t\t\t\t\t\t\t\treversed: value || undefined,\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</ToolsPanelItem>\n\t\t\t</ToolsPanel>\n\t\t</InspectorControls>\n\t);\n};\n\nexport default OrderedListSettings;\n"],"mappings":";;;;;;;AAWA,MAAM,mBAAmB;CACxB;EACC,OAAO,GAAI,SAAU;EACrB,OAAO;CACR;CACA;EACC,OAAO,GAAI,mBAAoB;EAC/B,OAAO;CACR;CACA;EACC,OAAO,GAAI,mBAAoB;EAC/B,OAAO;CACR;CACA;EACC,OAAO,GAAI,0BAA2B;EACtC,OAAO;CACR;CACA;EACC,OAAO,GAAI,0BAA2B;EACtC,OAAO;CACR;AACD;AAEA,MAAM,uBAAwB,EAAE,eAAe,UAAU,OAAO,WAAY;CAC3E,MAAM,oBAAoB,+BAA+B;CAEzD,OACC,oBAAC,mBAAD,EAAA,UACC,qBAACA,0BAAD;EACC,OAAQ,GAAI,UAAW;EACvB,gBAAiB;GAChB,cAAe;IACd,MAAM,KAAA;IACN,OAAO,KAAA;IACP,UAAU,KAAA;GACX,CAAE;EACH;EACoB;EATrB,UAAA;GAWC,oBAACC,8BAAD;IACC,OAAQ,GAAI,YAAa;IACzB,kBAAA;IACA,g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