@wordpress/block-library
Version:
Block library for the WordPress editor.
1 lines • 4.24 kB
Source Map (JSON)
{"version":3,"file":"edit.cjs","names":["__","SelectControl","useColorProps","getColorClassName","InspectorControls","HorizontalRule","useBlockProps"],"sources":["../../src/separator/edit.jsx"],"sourcesContent":["import clsx from 'clsx';\nimport {\n\tgetColorClassName,\n\tInspectorControls,\n\tuseBlockProps,\n\t__experimentalUseColorProps as useColorProps,\n} from '@wordpress/block-editor';\nimport { HorizontalRule } from '@wordpress/components';\nimport { SelectControl } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport useDeprecatedOpacity from './use-deprecated-opacity';\n\nconst HTML_ELEMENT_ITEMS = [\n\t{ label: __( 'Default (<hr>)' ), value: 'hr' },\n\t{ label: '<div>', value: 'div' },\n];\n\nconst HtmlElementControl = ( { tagName = 'hr', setAttributes } ) => {\n\tconst selectedItem =\n\t\tHTML_ELEMENT_ITEMS.find( ( item ) => item.value === tagName ) ??\n\t\tHTML_ELEMENT_ITEMS[ 0 ];\n\n\treturn (\n\t\t<SelectControl\n\t\t\tlabel={ __( 'HTML element' ) }\n\t\t\tvalue={ selectedItem }\n\t\t\tonValueChange={ ( item ) =>\n\t\t\t\tsetAttributes( { tagName: item?.value ?? 'hr' } )\n\t\t\t}\n\t\t\titems={ HTML_ELEMENT_ITEMS }\n\t\t\tdescription={\n\t\t\t\ttagName === 'hr'\n\t\t\t\t\t? __(\n\t\t\t\t\t\t\t'Only select <hr> if the separator conveys important information and should be announced by screen readers.'\n\t\t\t\t\t\t)\n\t\t\t\t\t: __(\n\t\t\t\t\t\t\t'The <div> element should only be used if the block is a design element with no semantic meaning.'\n\t\t\t\t\t\t)\n\t\t\t}\n\t\t/>\n\t);\n};\n\nexport default function SeparatorEdit( { attributes, setAttributes } ) {\n\tconst { backgroundColor, opacity, style, tagName } = attributes;\n\tconst colorProps = useColorProps( attributes );\n\tconst currentColor = colorProps?.style?.backgroundColor;\n\tconst hasCustomColor = !! style?.color?.background;\n\n\tuseDeprecatedOpacity( opacity, currentColor, setAttributes );\n\n\t// The dots styles uses text for the dots, to change those dots color is\n\t// using color, not backgroundColor.\n\tconst colorClass = getColorClassName( 'color', backgroundColor );\n\n\tconst className = clsx(\n\t\t{\n\t\t\t'has-text-color': backgroundColor || currentColor,\n\t\t\t[ colorClass ]: colorClass,\n\t\t\t'has-css-opacity': opacity === 'css',\n\t\t\t'has-alpha-channel-opacity': opacity === 'alpha-channel',\n\t\t},\n\t\tcolorProps.className\n\t);\n\n\tconst styles = {\n\t\tcolor: currentColor,\n\t\tbackgroundColor: currentColor,\n\t};\n\tconst Wrapper = tagName === 'hr' ? HorizontalRule : tagName;\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t<HtmlElementControl\n\t\t\t\t\ttagName={ tagName }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<Wrapper\n\t\t\t\t{ ...useBlockProps( {\n\t\t\t\t\tclassName,\n\t\t\t\t\tstyle: hasCustomColor ? styles : undefined,\n\t\t\t\t} ) }\n\t\t\t/>\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,MAAM,qBAAqB,CAC1B;CAAE,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,gBAAiB;CAAG,OAAO;AAAK,GAC7C;CAAE,OAAO;CAAS,OAAO;AAAM,CAChC;AAEA,MAAM,sBAAuB,EAAE,UAAU,MAAM,oBAAqB;CACnE,MAAM,eACL,mBAAmB,MAAQ,SAAU,KAAK,UAAU,OAAQ,KAC5D,mBAAoB;CAErB,OACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,cAAAA,eAAD;EACC,QAAA,GAAQD,gBAAAA,GAAAA,CAAI,cAAe;EAC3B,OAAQ;EACR,gBAAkB,SACjB,cAAe,EAAE,SAAS,MAAM,SAAS,KAAK,CAAE;EAEjD,OAAQ;EACR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