UNPKG

@wordpress/block-editor

Version:
8 lines (7 loc) 4.46 kB
{ "version": 3, "sources": ["../../../src/components/button-block-appender/index.js"], "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { Button } from '@wordpress/components';\nimport { forwardRef } from '@wordpress/element';\nimport { _x, sprintf } from '@wordpress/i18n';\nimport { Icon, plus } from '@wordpress/icons';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport Inserter from '../inserter';\n\nfunction ButtonBlockAppender(\n\t{ rootClientId, className, onFocus, tabIndex, onSelect },\n\tref\n) {\n\treturn (\n\t\t<Inserter\n\t\t\tposition=\"bottom center\"\n\t\t\trootClientId={ rootClientId }\n\t\t\t__experimentalIsQuick\n\t\t\tonSelectOrClose={ ( ...args ) => {\n\t\t\t\tif ( onSelect && typeof onSelect === 'function' ) {\n\t\t\t\t\tonSelect( ...args );\n\t\t\t\t}\n\t\t\t} }\n\t\t\trenderToggle={ ( {\n\t\t\t\tonToggle,\n\t\t\t\tdisabled,\n\t\t\t\tisOpen,\n\t\t\t\tblockTitle,\n\t\t\t\thasSingleBlockType,\n\t\t\t\tappenderLabel,\n\t\t\t} ) => {\n\t\t\t\tconst isToggleButton = ! hasSingleBlockType;\n\n\t\t\t\tlet label;\n\t\t\t\tif ( appenderLabel ) {\n\t\t\t\t\t// Block returns the full label; use directly (consistent with getBlockLabel).\n\t\t\t\t\tlabel = appenderLabel;\n\t\t\t\t} else if ( hasSingleBlockType ) {\n\t\t\t\t\tlabel = sprintf(\n\t\t\t\t\t\t// translators: %s: the name of the block when there is only one\n\t\t\t\t\t\t_x( 'Add %s', 'directly add the only allowed block' ),\n\t\t\t\t\t\tblockTitle.toLowerCase()\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tlabel = _x(\n\t\t\t\t\t\t'Add block',\n\t\t\t\t\t\t'Generic label for block inserter button'\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn (\n\t\t\t\t\t// Disable reason: There shouldn't be a case where this button is disabled but not visually hidden.\n\t\t\t\t\t// eslint-disable-next-line @wordpress/components-no-unsafe-button-disabled\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\tonFocus={ onFocus }\n\t\t\t\t\t\ttabIndex={ tabIndex }\n\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\tclassName,\n\t\t\t\t\t\t\t'block-editor-button-block-appender'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t\taria-haspopup={ isToggleButton ? 'true' : undefined }\n\t\t\t\t\t\taria-expanded={ isToggleButton ? isOpen : undefined }\n\t\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t\t\tlabel={ label }\n\t\t\t\t\t\tshowTooltip\n\t\t\t\t\t>\n\t\t\t\t\t\t<Icon icon={ plus } />\n\t\t\t\t\t</Button>\n\t\t\t\t);\n\t\t\t} }\n\t\t\tisAppender\n\t\t/>\n\t);\n}\n\n/**\n * Use `ButtonBlockAppender` instead.\n *\n * @deprecated\n */\nexport const ButtonBlockerAppender = forwardRef( ( props, ref ) => {\n\tdeprecated( `wp.blockEditor.ButtonBlockerAppender`, {\n\t\talternative: 'wp.blockEditor.ButtonBlockAppender',\n\t\tsince: '5.9',\n\t} );\n\n\treturn ButtonBlockAppender( props, ref );\n} );\n\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/button-block-appender/README.md\n */\nexport default forwardRef( ButtonBlockAppender );\n"], "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,wBAAuB;AACvB,qBAA2B;AAC3B,kBAA4B;AAC5B,mBAA2B;AAC3B,wBAAuB;AAKvB,sBAAqB;AA8Df;AA5DN,SAAS,oBACR,EAAE,cA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