@wordpress/components
Version:
UI components for WordPress.
101 lines (100 loc) • 4.02 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_compose = require("@wordpress/compose");
let _wordpress_primitives = require("@wordpress/primitives");
let _wordpress_element = require("@wordpress/element");
let _wordpress_a11y = require("@wordpress/a11y");
let ___icon_index_tsx = require("../icon/index.cjs");
___icon_index_tsx = __toESM(___icon_index_tsx);
let react_jsx_runtime = require("react/jsx-runtime");
// packages/components/src/placeholder/index.tsx
const PlaceholderIllustration = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_primitives.SVG, {
className: "components-placeholder__illustration",
fill: "none",
xmlns: "http://www.w3.org/2000/svg",
viewBox: "0 0 60 60",
preserveAspectRatio: "none",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_primitives.Path, {
vectorEffect: "non-scaling-stroke",
d: "M60 60 0 0"
})
});
/**
* Renders a placeholder. Normally used by blocks to render their empty state.
*
* ```jsx
* import { Placeholder } from '@wordpress/components';
* import { more } from '@wordpress/icons';
*
* const MyPlaceholder = () => <Placeholder icon={ more } label="Placeholder" />;
* ```
*/
function Placeholder(props) {
const { icon, children, label, instructions, className, notices, preview, isColumnLayout, withIllustration, ...additionalProps } = props;
const [resizeListener, { width }] = (0, _wordpress_compose.useResizeObserver)();
let modifierClassNames;
if (typeof width === "number") modifierClassNames = {
"is-large": width >= 480,
"is-medium": width >= 160 && width < 480,
"is-small": width < 160
};
const classes = (0, clsx.default)("components-placeholder", className, modifierClassNames, withIllustration ? "has-illustration" : null);
const fieldsetClasses = (0, clsx.default)("components-placeholder__fieldset", { "is-column-layout": isColumnLayout });
(0, _wordpress_element.useEffect)(() => {
if (instructions) (0, _wordpress_a11y.speak)(instructions);
}, [instructions]);
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
...additionalProps,
className: classes,
children: [
withIllustration ? PlaceholderIllustration : null,
resizeListener,
notices,
preview && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
className: "components-placeholder__preview",
children: preview
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "components-placeholder__label",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(___icon_index_tsx.default, { icon }), label]
}),
!!instructions && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
className: "components-placeholder__instructions",
children: instructions
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
className: fieldsetClasses,
children
})
]
});
}
exports.Placeholder = Placeholder;
exports.default = Placeholder;
//# sourceMappingURL=index.cjs.map