UNPKG

@wordpress/components

Version:
107 lines (101 loc) 3.28 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.Placeholder = Placeholder; exports.default = void 0; var _clsx = _interopRequireDefault(require("clsx")); var _compose = require("@wordpress/compose"); var _primitives = require("@wordpress/primitives"); var _element = require("@wordpress/element"); var _a11y = require("@wordpress/a11y"); var _icon = _interopRequireDefault(require("../icon")); var _jsxRuntime = require("react/jsx-runtime"); /** * External dependencies */ /** * WordPress dependencies */ /** * Internal dependencies */ const PlaceholderIllustration = /*#__PURE__*/(0, _jsxRuntime.jsx)(_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, _jsxRuntime.jsx)(_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, _compose.useResizeObserver)(); // Since `useResizeObserver` will report a width of `null` until after the // first render, avoid applying any modifier classes until width is known. 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, _element.useEffect)(() => { if (instructions) { (0, _a11y.speak)(instructions); } }, [instructions]); return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", { ...additionalProps, className: classes, children: [withIllustration ? PlaceholderIllustration : null, resizeListener, notices, preview && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { className: "components-placeholder__preview", children: preview }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", { className: "components-placeholder__label", children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_icon.default, { icon: icon }), label] }), !!instructions && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { className: "components-placeholder__instructions", children: instructions }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { className: fieldsetClasses, children: children })] }); } var _default = exports.default = Placeholder; //# sourceMappingURL=index.js.map