@wordpress/components
Version:
UI components for WordPress.
39 lines (38 loc) • 1.46 kB
JavaScript
import * as Ariakit from "@ariakit/react";
import { forwardRef, useContext } from "@wordpress/element";
import warning from "@wordpress/warning";
import ToolbarContext from "../toolbar-context/index.mjs";
import { jsx } from "react/jsx-runtime";
// packages/components/src/toolbar/toolbar-item/index.tsx
function UnforwardedToolbarItem({ children, as: Component, ...props }, ref) {
const accessibleToolbarStore = useContext(ToolbarContext);
const isRenderProp = typeof children === "function";
if (!isRenderProp && !Component) {
warning("`ToolbarItem` is a generic headless component. You must pass either a `children` prop as a function or an `as` prop as a component. See https://developer.wordpress.org/block-editor/components/toolbar-item/");
return null;
}
const allProps = {
...props,
ref,
"data-toolbar-item": true
};
if (!accessibleToolbarStore) {
if (Component) return /* @__PURE__ */ jsx(Component, {
...allProps,
children
});
if (!isRenderProp) return null;
return children(allProps);
}
const render = isRenderProp ? children : Component && /* @__PURE__ */ jsx(Component, { children });
return /* @__PURE__ */ jsx(Ariakit.ToolbarItem, {
accessibleWhenDisabled: true,
...allProps,
store: accessibleToolbarStore,
render
});
}
const ToolbarItem = forwardRef(UnforwardedToolbarItem);
ToolbarItem.displayName = "ToolbarItem";
export { ToolbarItem, ToolbarItem as default };
//# sourceMappingURL=index.mjs.map