@wordpress/components
Version:
UI components for WordPress.
110 lines (109 loc) • 4.05 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
// \0rolldown/runtime.js
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: ((k) => from[k]).bind(null, key),
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
let clsx = require("clsx");
clsx = __toESM(clsx);
let _wordpress_element = require("@wordpress/element");
let ______button_index_tsx = require("../../button/index.cjs");
______button_index_tsx = __toESM(______button_index_tsx);
let ___toolbar_item_index_tsx = require("../toolbar-item/index.cjs");
___toolbar_item_index_tsx = __toESM(___toolbar_item_index_tsx);
let ___toolbar_context_index_ts = require("../toolbar-context/index.cjs");
___toolbar_context_index_ts = __toESM(___toolbar_context_index_ts);
let __toolbar_button_container_tsx = require("./toolbar-button-container.cjs");
__toolbar_button_container_tsx = __toESM(__toolbar_button_container_tsx);
let react_jsx_runtime = require("react/jsx-runtime");
// packages/components/src/toolbar/toolbar-button/index.tsx
function useDeprecatedProps({ isDisabled, ...otherProps }) {
return {
disabled: isDisabled,
...otherProps
};
}
function UnforwardedToolbarButton(props, ref) {
const { children, className, containerClassName, extraProps, isActive, title, ...restProps } = useDeprecatedProps(props);
if (!(0, _wordpress_element.useContext)(___toolbar_context_index_ts.default)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__toolbar_button_container_tsx.default, {
className: containerClassName,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(______button_index_tsx.default, {
ref,
icon: restProps.icon,
size: "compact",
label: title,
shortcut: restProps.shortcut,
"data-subscript": restProps.subscript,
onClick: (event) => {
event.stopPropagation();
if (restProps.onClick) restProps.onClick(event);
},
className: (0, clsx.default)("components-toolbar__control", className),
isPressed: isActive,
accessibleWhenDisabled: true,
"data-toolbar-item": true,
...extraProps,
...restProps,
children
})
});
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(___toolbar_item_index_tsx.default, {
className: (0, clsx.default)("components-toolbar-button", className),
...extraProps,
...restProps,
ref,
children: (toolbarItemProps) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(______button_index_tsx.default, {
size: "compact",
label: title,
isPressed: isActive,
...toolbarItemProps,
children
})
});
}
/**
* ToolbarButton can be used to add actions to a toolbar, usually inside a Toolbar
* or ToolbarGroup when used to create general interfaces.
*
* ```jsx
* import { Toolbar, ToolbarButton } from '@wordpress/components';
* import { pencil } from '@wordpress/icons';
*
* function MyToolbar() {
* return (
* <Toolbar label="Options">
* <ToolbarButton
* icon={ pencil }
* label="Edit"
* onClick={ () => alert( 'Editing' ) }
* />
* </Toolbar>
* );
* }
* ```
*/
const ToolbarButton = (0, _wordpress_element.forwardRef)(UnforwardedToolbarButton);
ToolbarButton.displayName = "ToolbarButton";
exports.ToolbarButton = ToolbarButton;
exports.default = ToolbarButton;
//# sourceMappingURL=index.cjs.map