UNPKG

@wordpress/components

Version:
8 lines (7 loc) 4.36 kB
{ "version": 3, "sources": ["../../src/placeholder/index.tsx"], "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useResizeObserver } from '@wordpress/compose';\nimport { SVG, Path } from '@wordpress/primitives';\nimport { useEffect } from '@wordpress/element';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport Icon from '../icon';\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nconst PlaceholderIllustration = /*#__PURE__*/_jsx(SVG, {\n className: \"components-placeholder__illustration\",\n fill: \"none\",\n xmlns: \"http://www.w3.org/2000/svg\",\n viewBox: \"0 0 60 60\",\n preserveAspectRatio: \"none\",\n children: /*#__PURE__*/_jsx(Path, {\n vectorEffect: \"non-scaling-stroke\",\n d: \"M60 60 0 0\"\n })\n});\n\n/**\n * Renders a placeholder. Normally used by blocks to render their empty state.\n *\n * ```jsx\n * import { Placeholder } from '@wordpress/components';\n * import { more } from '@wordpress/icons';\n *\n * const MyPlaceholder = () => <Placeholder icon={ more } label=\"Placeholder\" />;\n * ```\n */\nexport function Placeholder(props) {\n const {\n icon,\n children,\n label,\n instructions,\n className,\n notices,\n preview,\n isColumnLayout,\n withIllustration,\n ...additionalProps\n } = props;\n const [resizeListener, {\n width\n }] = useResizeObserver();\n\n // Since `useResizeObserver` will report a width of `null` until after the\n // first render, avoid applying any modifier classes until width is known.\n let modifierClassNames;\n if (typeof width === 'number') {\n modifierClassNames = {\n 'is-large': width >= 480,\n 'is-medium': width >= 160 && width < 480,\n 'is-small': width < 160\n };\n }\n const classes = clsx('components-placeholder', className, modifierClassNames, withIllustration ? 'has-illustration' : null);\n const fieldsetClasses = clsx('components-placeholder__fieldset', {\n 'is-column-layout': isColumnLayout\n });\n useEffect(() => {\n if (instructions) {\n speak(instructions);\n }\n }, [instructions]);\n return /*#__PURE__*/_jsxs(\"div\", {\n ...additionalProps,\n className: classes,\n children: [withIllustration ? PlaceholderIllustration : null, resizeListener, notices, preview && /*#__PURE__*/_jsx(\"div\", {\n className: \"components-placeholder__preview\",\n children: preview\n }), /*#__PURE__*/_jsxs(\"div\", {\n className: \"components-placeholder__label\",\n children: [/*#__PURE__*/_jsx(Icon, {\n icon: icon\n }), label]\n }), !!instructions && /*#__PURE__*/_jsx(\"div\", {\n className: \"components-placeholder__instructions\",\n children: instructions\n }), /*#__PURE__*/_jsx(\"div\", {\n className: fieldsetClasses,\n children: children\n })]\n });\n}\nexport default Placeholder;"], "mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,yBAAyB;AAClC,SAAS,KAAK,YAAY;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,aAAa;AAKtB,OAAO,UAAU;AACjB,SAAS,OAAO,MAAM,QAAQ,aAAa;AAC3C,IAAM,0BAAuC,qBAAK,KAAK;AAAA,EACrD,WAAW;AAAA,EACX,MAAM;AAAA,EACN,OAAO;AAAA,EACP,SAAS;AAAA,EACT,qBAAqB;AAAA,EACrB,UAAuB,qBAAK,MAAM;AAAA,IAChC,cAAc;AAAA,IACd,GAAG;AAAA,EACL,CAAC;AACH,CAAC;AAYM,SAAS,YAAY,OAAO;AACjC,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL,IAAI;AACJ,QAAM,CAAC,gBAAgB;AAAA,IACrB;AAAA,EACF,CAAC,IAAI,kBAAkB;AAIvB,MAAI;AACJ,MAAI,OAAO,UAAU,UAAU;AAC7B,yBAAqB;AAAA,MACnB,YAAY,SAAS;AAAA,MACrB,aAAa,SAAS,OAAO,QAAQ;AAAA,MACrC,YAAY,QAAQ;AAAA,IACtB;AAAA,EACF;AACA,QAAM,UAAU,KAAK,0BAA0B,WAAW,oBAAoB,mBAAmB,qBAAqB,IAAI;AAC1H,QAAM,kBAA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