@wordpress/block-library
Version:
Block library for the WordPress editor.
8 lines (7 loc) • 4.38 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/accordion-heading/edit.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useEffect } from '@wordpress/element';\nimport {\n\tuseBlockProps,\n\t__experimentalGetSpacingClassesAndStyles as useSpacingProps,\n\tRichText,\n\tgetTypographyClassesAndStyles as useTypographyProps,\n\tuseSettings,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useDispatch } from '@wordpress/data';\n\nexport default function Edit( { attributes, setAttributes, context } ) {\n\tconst { title } = attributes;\n\tconst {\n\t\t'core/accordion-icon-position': iconPosition,\n\t\t'core/accordion-show-icon': showIcon,\n\t\t'core/accordion-heading-level': headingLevel,\n\t} = context;\n\tconst TagName = 'h' + headingLevel;\n\tconst { __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\n\t// Set icon attributes.\n\tuseEffect( () => {\n\t\tif ( iconPosition !== undefined && showIcon !== undefined ) {\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tsetAttributes( {\n\t\t\t\ticonPosition,\n\t\t\t\tshowIcon,\n\t\t\t} );\n\t\t}\n\t}, [\n\t\ticonPosition,\n\t\tshowIcon,\n\t\tsetAttributes,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t] );\n\n\tconst [ fluidTypographySettings, layout ] = useSettings(\n\t\t'typography.fluid',\n\t\t'layout'\n\t);\n\tconst typographyProps = useTypographyProps( attributes, {\n\t\ttypography: {\n\t\t\tfluid: fluidTypographySettings,\n\t\t},\n\t\tlayout: {\n\t\t\twideSize: layout?.wideSize,\n\t\t},\n\t} );\n\n\tconst blockProps = useBlockProps();\n\tconst spacingProps = useSpacingProps( attributes );\n\n\treturn (\n\t\t<TagName { ...blockProps }>\n\t\t\t<button\n\t\t\t\tclassName=\"wp-block-accordion-heading__toggle\"\n\t\t\t\tstyle={ spacingProps.style }\n\t\t\t\ttabIndex=\"-1\"\n\t\t\t>\n\t\t\t\t{ showIcon && iconPosition === 'left' && (\n\t\t\t\t\t<span\n\t\t\t\t\t\tclassName=\"wp-block-accordion-heading__toggle-icon\"\n\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t>\n\t\t\t\t\t\t+\n\t\t\t\t\t</span>\n\t\t\t\t) }\n\t\t\t\t<RichText\n\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\tdisableLineBreaks\n\t\t\t\t\ttagName=\"span\"\n\t\t\t\t\tvalue={ title }\n\t\t\t\t\tonChange={ ( newTitle ) =>\n\t\t\t\t\t\tsetAttributes( { title: newTitle } )\n\t\t\t\t\t}\n\t\t\t\t\tplaceholder={ __( 'Accordion title' ) }\n\t\t\t\t\tclassName=\"wp-block-accordion-heading__toggle-title\"\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\tletterSpacing: typographyProps.style.letterSpacing,\n\t\t\t\t\t\ttextDecoration: typographyProps.style.textDecoration,\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t\t{ showIcon && iconPosition === 'right' && (\n\t\t\t\t\t<span\n\t\t\t\t\t\tclassName=\"wp-block-accordion-heading__toggle-icon\"\n\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t>\n\t\t\t\t\t\t+\n\t\t\t\t\t</span>\n\t\t\t\t) }\n\t\t\t</button>\n\t\t</TagName>\n\t);\n}\n"],
"mappings": ";AAGA,SAAS,UAAU;AACnB,SAAS,iBAAiB;AAC1B;AAAA,EACC;AAAA,EACA,4CAA4C;AAAA,EAC5C;AAAA,EACA,iCAAiC;AAAA,EACjC;AAAA,EACA,SAAS;AAAA,OACH;AACP,SAAS,mBAAmB;AA+CzB,SAME,KANF;AA7CY,SAAR,KAAuB,EAAE,YAAY,eAAe,QAAQ,GAAI;AACtE,QAAM,EAAE,MAAM,IAAI;AAClB,QAAM;AAAA,IACL,gCAAgC;AAAA,IAChC,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