UNPKG

@wordpress/block-editor

Version:
8 lines (7 loc) 4.33 kB
{ "version": 3, "sources": ["../../../src/components/block-toolbar/pattern-overrides-dropdown.js"], "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tPopover,\n\tToolbarButton,\n\t__experimentalText as Text,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useState, useRef } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Renders the content of the pattern overrides popover.\n * Only mounts when the popover is opened.\n *\n * @param {Object} props Component props.\n * @param {Array} props.clientIds The client IDs of selected blocks.\n * @param {string} props.blockTitle The display title of the block.\n * @return {JSX.Element} The popover content.\n */\nfunction PatternOverridesPopoverContent( { clientIds, blockTitle } ) {\n\tconst blockMetaName = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockAttributes } = select( blockEditorStore );\n\t\t\treturn getBlockAttributes( clientIds?.[ 0 ] )?.metadata?.name;\n\t\t},\n\t\t[ clientIds ]\n\t);\n\n\tconst isSingleBlock = clientIds.length === 1;\n\n\t// Pattern overrides description\n\tlet description;\n\tif ( isSingleBlock && blockMetaName ) {\n\t\tdescription = sprintf(\n\t\t\t/* translators: 1: The block type's name. 2: The block's user-provided name (the same as the override name). */\n\t\t\t__( 'This %1$s is editable using the \"%2$s\" override.' ),\n\t\t\tblockTitle.toLowerCase(),\n\t\t\tblockMetaName\n\t\t);\n\t} else {\n\t\tdescription = __( 'These blocks are editable using overrides.' );\n\t}\n\n\treturn <Text>{ description }</Text>;\n}\n\n/**\n * Renders a toolbar button that displays information about pattern overrides in a popover.\n *\n * @param {Object} props Component props.\n * @param {JSX.Element} props.icon The icon element to display.\n * @param {Array} props.clientIds The client IDs of selected blocks.\n * @param {string} props.blockTitle The display title of the block.\n * @param {string} props.label The label for the button.\n * @return {JSX.Element} The pattern overrides button component.\n */\nexport default function PatternOverridesDropdown( {\n\ticon,\n\tclientIds,\n\tblockTitle,\n\tlabel,\n} ) {\n\tconst [ isOpen, setIsOpen ] = useState( false );\n\tconst anchorRef = useRef();\n\n\treturn (\n\t\t<>\n\t\t\t<ToolbarButton\n\t\t\t\tref={ anchorRef }\n\t\t\t\tclassName=\"block-editor-block-toolbar__pattern-overrides-indicator\"\n\t\t\t\ticon={ icon }\n\t\t\t\tlabel={ label }\n\t\t\t\tonClick={ () => setIsOpen( ! isOpen ) }\n\t\t\t\taria-expanded={ isOpen }\n\t\t\t/>\n\t\t\t{ isOpen && (\n\t\t\t\t<Popover\n\t\t\t\t\tanchor={ anchorRef.current }\n\t\t\t\t\tonClose={ () => setIsOpen( false ) }\n\t\t\t\t\tplacement=\"bottom-start\"\n\t\t\t\t\toffset={ 16 }\n\t\t\t\t\tclassName=\"block-editor-block-toolbar__pattern-overrides-popover\"\n\t\t\t\t>\n\t\t\t\t\t<PatternOverridesPopoverContent\n\t\t\t\t\t\tclientIds={ clientIds }\n\t\t\t\t\t\tblockTitle={ blockTitle }\n\t\t\t\t\t/>\n\t\t\t\t</Popover>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"], "mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA,sBAAsB;AAAA,OAChB;AACP,SAAS,IAAI,eAAe;AAC5B,SAAS,UAAU,cAAc;AACjC,SAAS,iBAAiB;AAK1B,SAAS,SAAS,wBAAwB;AAmClC,SAuBN,UAvBM,KAuBN,YAvBM;AAxBR,SAAS,+BAAgC,EAAE,WAAW,WAAW,GAAI;AACpE,QAAM,gBAAgB;AAAA,IACrB,CAAE,WAAY;AACb,YAAM,EAAE,mBAAmB,IAAI,OAAQ,gBAAiB;AACxD,aAAO,mBAAoB,YAAa,CAAE,CAAE,GAAG,UAAU;AAAA,IAC1D;AAAA,IACA,CAAE,SAAU;AAAA,EACb;AAEA,QAAM,gBAAgB,UAAU,WAAW;AAG3C,MAAI;AACJ,MAAK,iBAAiB,eAAgB;AACrC,kBAAc;AAAA;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