{"version":3,"file":"index.cjs","names":["useContext","ToolbarContext","ToolbarGroupCollapsed","ToolbarGroupContainer","ToolbarButton"],"sources":["../../../src/toolbar/toolbar-group/index.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { useContext } from '@wordpress/element';\nimport ToolbarButton from '../toolbar-button';\nimport ToolbarGroupContainer from './toolbar-group-container';\nimport ToolbarGroupCollapsed from './toolbar-group-collapsed';\nimport ToolbarContext from '../toolbar-context';\nimport type { ToolbarGroupProps, ToolbarGroupControls } from './types';\n\nfunction isNestedArray< T >( arr: T | T[] ): arr is T[] {\n\treturn Array.isArray( arr ) && Array.isArray( arr[ 0 ] );\n}\n\n/**\n * Renders a collapsible group of controls\n *\n * The `controls` prop accepts an array of sets. A set is an array of controls.\n * Controls have the following shape:\n *\n * ```\n * {\n *   icon: string,\n *   title: string,\n *   subscript: string,\n *   onClick: Function,\n *   isActive: boolean,\n *   isDisabled: boolean\n * }\n * ```\n *\n * For convenience it is also possible to pass only an array of controls. It is\n * then assumed this is the only set.\n *\n * Either `controls` or `children` is required, otherwise this components\n * renders nothing.\n *\n * @param props               Component props.\n * @param [props.controls]    The controls to render in this toolbar.\n * @param [props.children]    Any other things to render inside the toolbar besides the controls.\n * @param [props.className]   Class to set on the container div.\n * @param [props.isCollapsed] Turns ToolbarGroup into a dropdown menu.\n * @param [props.title]       ARIA label for dropdown menu if is collapsed.\n */\nfunction ToolbarGroup( {\n\tcontrols = [],\n\tchildren,\n\tclassName,\n\tisCollapsed,\n\ttitle,\n\t...props\n}: ToolbarGroupProps ) {\n\t// It'll contain state if `ToolbarGroup` is being used within\n\t// `<Toolbar label=\"label\" />`\n\tconst accessibleToolbarState = useContext( ToolbarContext );\n\n\tif ( ( ! controls || ! controls.length ) && ! children ) {\n\t\treturn null;\n\t}\n\n\tconst finalClassName = clsx(\n\t\t// Unfortunately, there's legacy code referencing to `.components-toolbar`\n\t\t// So we can't get rid of it\n\t\taccessibleToolbarState\n\t\t\t? 'components-toolbar-group'\n\t\t\t: 'components-toolbar',\n\t\tclassName\n\t);\n\n\t// Normalize controls to nested array of objects (sets of controls)\n\tlet controlSets: ToolbarGroupControls[][];\n\tif ( isNestedArray< ToolbarGroupControls[] >( controls ) ) {\n\t\tcontrolSets = controls;\n\t} else {\n\t\tcontrolSets = [ controls ];\n\t}\n\n\tif ( isCollapsed ) {\n\t\treturn (\n\t\t\t<ToolbarGroupCollapsed\n\t\t\t\tlabel={ title }\n\t\t\t\tcontrols={ controlSets }\n\t\t\t\tclassName={ finalClassName }\n\t\t\t\tchildren={ children }\n\t\t\t\t{ ...props }\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn (\n\t\t<ToolbarGroupContainer className={ finalClassName } { ...props }>\n\t\t\t{ controlSets?.flatMap( ( controlSet, indexOfSet ) =>\n\t\t\t\tcontrolSet.map( ( control, indexOfControl: number ) => (\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tkey={ [ indexOfSet, indexOfControl ].join() }\n\t\t\t\t\t\tcontainerClassName={\n\t\t\t\t\t\t\tindexOfSet > 0 && indexOfControl === 0\n\t\t\t\t\t\t\t\t? 'has-left-divider'\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t\t{ ...control }\n\t\t\t\t\t/>\n\t\t\t\t) )\n\t\t\t) }\n\t\t\t{ children }\n\t\t</ToolbarGroupContainer>\n\t);\n}\n\nexport default ToolbarGroup;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,SAAS,cAAoB,KAA2B;CACvD,OAAO,MAAM,QAAS,GAAI,KAAK,MAAM,QAAS,IAAK,EAAI;AACxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAS,aAAc,EACtB,WAAW,CAAC,GACZ,UACA,WACA,aACA,OACA,GAAG,SACmB;CAGtB,MAAM,0BAAA,GAAyBA,mBAAAA,WAAAA,CAAYC,4BAAAA,OAAe;CAE1D,KAAO,CAAE,YAAY,CAAE,SAAS,WAAY,CAAE,UAC7C,OAAO;CAGR,MAAM,kBAAA,GAAiB,KAAA,QAAA,CAGtB,yBACG,6BACA,sBACH,SACD;CAGA,IAAI;CACJ,IAAK,cAAyC,QAAS,GACtD,cAAc;MAEd,cAAc,CAAE,QAAS;CAG1B,IAAK,aACJ,OACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,8BAAAA,SAAD;EACC,OAAQ;EACR,UAAW;EACX,WAAY;EACD;EACX,GAAK;CACL,CAAA;CAIH,OACC,iBAAA,GAAA,kBAAA,KAAA,CAACC,8BAAAA,SAAD;EAAuB,WAAY;EAAiB,GAAK;EAAzD,UAAA,CACG,aAAa,SAAW,YAAY,eACrC,WAAW,KAAO,SAAS,mBAC1B,iBAAA,GAAA,kBAAA,IAAA,CAACC,4BAAAA,SAAD;GAEC,oBACC,aAAa,KAAK,mBAAmB,IAClC,qBACA,KAAA;GAEJ,GAAK;EACL,GAPM,CAAE,YAAY,cAAe,CAAC,CAAC,KAAK,CAO1C,CACA,CACH,GACE,QACoB;;AAEzB"}