{"version":3,"file":"index.cjs","names":["Button","usePluginContext","useSelect","interfaceStore","useDispatch"],"sources":["../../../src/components/complementary-area-toggle/index.tsx"],"sourcesContent":["import type { AriaRole } from 'react';\nimport { Button } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { usePluginContext } from '@wordpress/plugins';\nimport { store as interfaceStore } from '../../store';\nimport type { ComplementaryAreaToggleProps } from './types';\n\n/**\n * Whether the role supports checked state.\n *\n * @see https://www.w3.org/TR/wai-aria-1.1/#aria-checked\n * @param role Role.\n * @return Whether the role supports checked state.\n */\nfunction roleSupportsCheckedState( role?: AriaRole ): boolean {\n\treturn [\n\t\t'checkbox',\n\t\t'option',\n\t\t'radio',\n\t\t'switch',\n\t\t'menuitemcheckbox',\n\t\t'menuitemradio',\n\t\t'treeitem',\n\t].includes( role as string );\n}\n\nexport default function ComplementaryAreaToggle( {\n\tas = Button,\n\tscope,\n\tidentifier: identifierProp,\n\ticon: iconProp,\n\tselectedIcon,\n\tname,\n\tshortcut,\n\t...props\n}: ComplementaryAreaToggleProps ) {\n\tconst ComponentToUse = as;\n\tconst context = usePluginContext();\n\tconst icon = iconProp || context.icon;\n\tconst identifier = identifierProp || `${ context.name }/${ name }`;\n\tconst isSelected = useSelect(\n\t\t( select ) =>\n\t\t\tselect( interfaceStore ).getActiveComplementaryArea( scope ) ===\n\t\t\tidentifier,\n\t\t[ identifier, scope ]\n\t);\n\n\tconst { enableComplementaryArea, disableComplementaryArea } =\n\t\tuseDispatch( interfaceStore );\n\n\treturn (\n\t\t<ComponentToUse\n\t\t\ticon={ selectedIcon && isSelected ? selectedIcon : icon }\n\t\t\taria-controls={ identifier.replace( '/', ':' ) }\n\t\t\t// Make sure aria-checked matches spec https://www.w3.org/TR/wai-aria-1.1/#aria-checked\n\t\t\taria-checked={\n\t\t\t\troleSupportsCheckedState( props.role ) ? isSelected : undefined\n\t\t\t}\n\t\t\tonClick={ () => {\n\t\t\t\tif ( isSelected ) {\n\t\t\t\t\tdisableComplementaryArea( scope );\n\t\t\t\t} else {\n\t\t\t\t\tenableComplementaryArea( scope, identifier );\n\t\t\t\t}\n\t\t\t} }\n\t\t\tshortcut={ shortcut }\n\t\t\t{ ...props }\n\t\t/>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAcA,SAAS,yBAA0B,MAA2B;CAC7D,OAAO;EACN;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CAAC,CAAC,SAAU,IAAe;AAC5B;AAEA,SAAwB,wBAAyB,EAChD,KAAKA,sBAAAA,QACL,OACA,YAAY,gBACZ,MAAM,UACN,cACA,MACA,UACA,GAAG,SAC8B;CACjC,MAAM,iBAAiB;CACvB,MAAM,WAAA,GAAUC,mBAAAA,iBAAAA,CAAiB;CACjC,MAAM,OAAO,YAAY,QAAQ;CACjC,MAAM,aAAa,kBAAkB,GAAI,QAAQ,KAAM,GAAI;CAC3D,MAAM,cAAA,GAAaC,gBAAAA,UAAAA,EAChB,WACD,OAAQC,qBAAAA,KAAe,CAAC,CAAC,2BAA4B,KAAM,MAC3D,YACD,CAAE,YAAY,KAAM,CACrB;CAEA,MAAM,EAAE,yBAAyB,8BAAA,GAChCC,gBAAAA,YAAAA,CAAaD,qBAAAA,KAAe;CAE7B,OACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,gBAAD;EACC,MAAO,gBAAgB,aAAa,eAAe;EACnD,iBAAgB,WAAW,QAAS,KAAK,GAAI;EAE7C,gBACC,yBAA0B,MAAM,IAAK,IAAI,aAAa,KAAA;EAEvD,eAAgB;GACf,IAAK,YACJ,yBAA0B,KAAM;QAEhC,wBAAyB,OAAO,UAAW;EAE7C;EACW;EACX,GAAK;CACL,CAAA;AAEH"}