@wordpress/components
Version:
UI components for WordPress.
1 lines • 2.46 kB
Source Map (JSON)
{"version":3,"file":"index.cjs","names":["useContext","ToolbarContext","Ariakit","forwardRef"],"sources":["../../../src/toolbar/toolbar-item/index.tsx"],"sourcesContent":["import * as Ariakit from '@ariakit/react';\nimport type { ForwardedRef } from 'react';\nimport { forwardRef, useContext } from '@wordpress/element';\nimport warning from '@wordpress/warning';\nimport ToolbarContext from '../toolbar-context';\nimport type { ToolbarItemProps } from './types';\n\nfunction UnforwardedToolbarItem(\n\t{ children, as: Component, ...props }: ToolbarItemProps,\n\tref: ForwardedRef< any >\n) {\n\tconst accessibleToolbarStore = useContext( ToolbarContext );\n\tconst isRenderProp = typeof children === 'function';\n\n\tif ( ! isRenderProp && ! Component ) {\n\t\twarning(\n\t\t\t'`ToolbarItem` is a generic headless component. You must pass either a `children` prop as a function or an `as` prop as a component. ' +\n\t\t\t\t'See https://developer.wordpress.org/block-editor/components/toolbar-item/'\n\t\t);\n\t\treturn null;\n\t}\n\n\tconst allProps = { ...props, ref, 'data-toolbar-item': true };\n\n\tif ( ! accessibleToolbarStore ) {\n\t\tif ( Component ) {\n\t\t\treturn <Component { ...allProps }>{ children }</Component>;\n\t\t}\n\t\tif ( ! isRenderProp ) {\n\t\t\treturn null;\n\t\t}\n\t\treturn children( allProps );\n\t}\n\n\tconst render = isRenderProp\n\t\t? children\n\t\t: Component && <Component>{ children }</Component>;\n\n\treturn (\n\t\t<Ariakit.ToolbarItem\n\t\t\taccessibleWhenDisabled\n\t\t\t{ ...allProps }\n\t\t\tstore={ accessibleToolbarStore }\n\t\t\trender={ render }\n\t\t/>\n\t);\n}\n\nexport const ToolbarItem = forwardRef( UnforwardedToolbarItem );\nToolbarItem.displayName = 'ToolbarItem';\nexport default ToolbarItem;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,SAAS,uBACR,EAAE,UAAU,IAAI,WAAW,GAAG,SAC9B,KACC;CACD,MAAM,0BAAA,GAAyBA,mBAAAA,WAAAA,CAAYC,4BAAAA,OAAe;CAC1D,MAAM,eAAe,OAAO,aAAa;CAEzC,IAAK,CAAE,gBAAgB,CAAE,WAAY;EACpC,CAAA,GAAA,mBAAA,QAAA,CACC,+MAED;EACA,OAAO;CACR;CAEA,MAAM,WAAW;EAAE,GAAG;EAAO;EAAK,qBAAqB;CAAK;CAE5D,IAAK,CAAE,wBAAyB;EAC/B,IAAK,WACJ,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,WAAD;GAAW,GAAK;GAAa;EAAqB,CAAA;EAE1D,IAAK,CAAE,cACN,OAAO;EAER,OAAO,SAAU,QAAS;CAC3B;CAEA,MAAM,SAAS,eACZ,WACA,aAAa,iBAAA,GAAA,kBAAA,IAAA,CAAC,WAAD,EAAa,SAAqB,CAAA;CAElD,OACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,eAAQ,aAAT;EACC,wBAAA;EACA,GAAK;EACL,OAAQ;EACC;CACT,CAAA;AAEH;AAEA,MAAa,eAAA,GAAcC,mBAAAA,WAAAA,CAAY,sBAAuB;AAC9D,YAAY,cAAc"}