UNPKG

@wordpress/block-editor

Version:
8 lines (7 loc) 2.3 kB
{ "version": 3, "sources": ["../../../src/hooks/block-fields/fields-dropdown-menu.js"], "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';\nimport { moreVertical, check } from '@wordpress/icons';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { useInspectorPopoverPlacement } from './use-inspector-popover-placement';\n\nexport default function FieldsDropdownMenu( {\n\tfields,\n\tvisibleFields,\n\tonToggleField,\n} ) {\n\tconst { popoverProps } = useInspectorPopoverPlacement();\n\n\tif ( ! fields || fields.length === 0 ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<DropdownMenu\n\t\t\ticon={ moreVertical }\n\t\t\tlabel={ __( 'Options' ) }\n\t\t\tpopoverProps={ popoverProps }\n\t\t\ttoggleProps={ { size: 'small' } }\n\t\t>\n\t\t\t{ ( { onClose } ) => (\n\t\t\t\t<MenuGroup label={ __( 'Show / Hide' ) }>\n\t\t\t\t\t{ fields.map( ( field ) => {\n\t\t\t\t\t\tconst isVisible = visibleFields.includes( field.id );\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\tkey={ field.id }\n\t\t\t\t\t\t\t\tisSelected={ isVisible }\n\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\tonToggleField( field.id );\n\t\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\trole=\"menuitemcheckbox\"\n\t\t\t\t\t\t\t\ticon={ isVisible ? check : null }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ field.label }\n\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t);\n\t\t\t\t\t} ) }\n\t\t\t\t</MenuGroup>\n\t\t\t) }\n\t\t</DropdownMenu>\n\t);\n}\n"], "mappings": ";AAGA,SAAS,cAAc,WAAW,gBAAgB;AAClD,SAAS,cAAc,aAAa;AACpC,SAAS,UAAU;AAKnB,SAAS,oCAAoC;AAyBtC;AAvBQ,SAAR,mBAAqC;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AACD,GAAI;AACH,QAAM,EAAE,aAAa,IAAI,6BAA6B;AAEtD,MAAK,CAAE,UAAU,OAAO,WAAW,GAAI;AACtC,WAAO;AAAA,EACR;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA,MAAO;AAAA,MACP,OAAQ,GAAI,SAAU;AAAA,MACtB;AAAA,MACA,aAAc,EAAE,MAAM,QAAQ;AAAA,MAE5B,WAAE,EAAE,QAAQ,MACb,oBAAC,aAAU,OAAQ,GAAI,aAAc,GAClC,iBAAO,IAAK,CAAE,UAAW;AAC1B,cAAM,YAAY,cAAc,SAAU,MAAM,EAAG;AACnD,eACC;AAAA,UAAC;AAAA;AAAA,YAEA,YAAa;AAAA,YACb,SAAU,MAAM;AACf,4BAAe,MAAM,EAAG;AACxB,sBAAQ;AAAA,YACT;AAAA,YACA,MAAK;AAAA,YACL,MAAO,YAAY,QAAQ;AAAA,YAEzB,gBAAM;AAAA;AAAA,UATF,MAAM;AAAA,QAUb;AAAA,MAEF,CAAE,GACH;AAAA;AAAA,EAEF;AAEF;", "names": [] }