@wordpress/block-editor
Version:
8 lines (7 loc) • 3.08 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/components/block-heading-level-dropdown/index.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { ToolbarDropdownMenu } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport HeadingLevelIcon from './heading-level-icon';\n\nconst HEADING_LEVELS = [ 1, 2, 3, 4, 5, 6 ];\n\nconst POPOVER_PROPS = {\n\tclassName: 'block-library-heading-level-dropdown',\n};\n\n/** @typedef {import('react').ComponentType} ComponentType */\n\n/**\n * HeadingLevelDropdown props.\n *\n * @typedef WPHeadingLevelDropdownProps\n *\n * @property {number} value The chosen heading level.\n * @property {number[]} options An array of supported heading levels.\n * @property {()=>number} onChange Function called with\n * the selected value changes.\n */\n\n/**\n * Dropdown for selecting a heading level (1 through 6) or paragraph (0).\n *\n * @param {WPHeadingLevelDropdownProps} props Component props.\n *\n * @return {ComponentType} The toolbar.\n */\nexport default function HeadingLevelDropdown( {\n\toptions = HEADING_LEVELS,\n\tvalue,\n\tonChange,\n} ) {\n\tconst validOptions = options\n\t\t.filter(\n\t\t\t( option ) => option === 0 || HEADING_LEVELS.includes( option )\n\t\t)\n\t\t.sort( ( a, b ) => a - b ); // Sorts numerically in ascending order;\n\n\treturn (\n\t\t<ToolbarDropdownMenu\n\t\t\tpopoverProps={ POPOVER_PROPS }\n\t\t\ticon={ <HeadingLevelIcon level={ value } /> }\n\t\t\tlabel={ __( 'Change level' ) }\n\t\t\tcontrols={ validOptions.map( ( targetLevel ) => {\n\t\t\t\tconst isActive = targetLevel === value;\n\t\t\t\treturn {\n\t\t\t\t\ticon: <HeadingLevelIcon level={ targetLevel } />,\n\t\t\t\t\ttitle:\n\t\t\t\t\t\ttargetLevel === 0\n\t\t\t\t\t\t\t? __( 'Paragraph' )\n\t\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t\t// translators: %d: heading level e.g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