{"version":3,"file":"index.mjs","names":[],"sources":["../../src/placeholder/index.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { useResizeObserver } from '@wordpress/compose';\nimport { SVG, Path } from '@wordpress/primitives';\nimport { useEffect } from '@wordpress/element';\nimport { speak } from '@wordpress/a11y';\nimport Icon from '../icon';\nimport type { PlaceholderProps } from './types';\nimport type { WordPressComponentProps } from '../context';\n\nconst PlaceholderIllustration = (\n\t<SVG\n\t\tclassName=\"components-placeholder__illustration\"\n\t\tfill=\"none\"\n\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t\tviewBox=\"0 0 60 60\"\n\t\tpreserveAspectRatio=\"none\"\n\t>\n\t\t<Path vectorEffect=\"non-scaling-stroke\" d=\"M60 60 0 0\" />\n\t</SVG>\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(\n\tprops: WordPressComponentProps< PlaceholderProps, 'div', false >\n) {\n\tconst {\n\t\ticon,\n\t\tchildren,\n\t\tlabel,\n\t\tinstructions,\n\t\tclassName,\n\t\tnotices,\n\t\tpreview,\n\t\tisColumnLayout,\n\t\twithIllustration,\n\t\t...additionalProps\n\t} = props;\n\tconst [ resizeListener, { width } ] = useResizeObserver();\n\n\t// Since `useResizeObserver` will report a width of `null` until after the\n\t// first render, avoid applying any modifier classes until width is known.\n\tlet modifierClassNames;\n\tif ( typeof width === 'number' ) {\n\t\tmodifierClassNames = {\n\t\t\t'is-large': width >= 480,\n\t\t\t'is-medium': width >= 160 && width < 480,\n\t\t\t'is-small': width < 160,\n\t\t};\n\t}\n\n\tconst classes = clsx(\n\t\t'components-placeholder',\n\t\tclassName,\n\t\tmodifierClassNames,\n\t\twithIllustration ? 'has-illustration' : null\n\t);\n\n\tconst fieldsetClasses = clsx( 'components-placeholder__fieldset', {\n\t\t'is-column-layout': isColumnLayout,\n\t} );\n\n\tuseEffect( () => {\n\t\tif ( instructions ) {\n\t\t\tspeak( instructions );\n\t\t}\n\t}, [ instructions ] );\n\n\treturn (\n\t\t<div { ...additionalProps } className={ classes }>\n\t\t\t{ withIllustration ? PlaceholderIllustration : null }\n\t\t\t{ resizeListener }\n\t\t\t{ notices }\n\t\t\t{ preview && (\n\t\t\t\t<div className=\"components-placeholder__preview\">\n\t\t\t\t\t{ preview }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<div className=\"components-placeholder__label\">\n\t\t\t\t<Icon icon={ icon } />\n\t\t\t\t{ label }\n\t\t\t</div>\n\t\t\t{ !! instructions && (\n\t\t\t\t<div className=\"components-placeholder__instructions\">\n\t\t\t\t\t{ instructions }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<div className={ fieldsetClasses }>{ children }</div>\n\t\t</div>\n\t);\n}\n\nexport default Placeholder;\n"],"mappings":";;;;;;;;AASA,MAAM,0BACL,oBAAC,KAAD;CACC,WAAU;CACV,MAAK;CACL,OAAM;CACN,SAAQ;CACR,qBAAoB;CAEpB,UAAA,oBAAC,MAAD;EAAM,cAAa;EAAqB,GAAE;CAAc,CAAA;AACpD,CAAA;;;;;;;;;;;AAaN,SAAgB,YACf,OACC;CACD,MAAM,EACL,MACA,UACA,OACA,cACA,WACA,SACA,SACA,gBACA,kBACA,GAAG,oBACA;CACJ,MAAM,CAAE,gBAAgB,EAAE,WAAY,kBAAkB;CAIxD,IAAI;CACJ,IAAK,OAAO,UAAU,UACrB,qBAAqB;EACpB,YAAY,SAAS;EACrB,aAAa,SAAS,OAAO,QAAQ;EACrC,YAAY,QAAQ;CACrB;CAGD,MAAM,UAAU,KACf,0BACA,WACA,oBACA,mBAAmB,qBAAqB,IACzC;CAEA,MAAM,kBAAkB,KAAM,oCAAoC,EACjE,oBAAoB,eACrB,CAAE;CAEF,gBAAiB;EAChB,IAAK,cACJ,MAAO,YAAa;CAEtB,GAAG,CAAE,YAAa,CAAE;CAEpB,OACC,qBAAC,OAAD;EAAK,GAAK;EAAkB,WAAY;EAAxC,UAAA;GACG,mBAAmB,0BAA0B;GAC7C;GACA;GACA,WACD,oBAAC,OAAD;IAAK,WAAU;IACZ,UAAA;GACE,CAAA;GAEN,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA,CACC,oBAAC,MAAD,EAAa,KAAQ,CAAA,GACnB,KACE;;GACH,CAAC,CAAE,gBACJ,oBAAC,OAAD;IAAK,WAAU;IACZ,UAAA;GACE,CAAA;GAEN,oBAAC,OAAD;IAAK,WAAY;IAAoB;GAAe,CAAA;EAChD;;AAEP"}