UNPKG

@wordpress/components

Version:
8 lines (7 loc) 1.4 kB
{ "version": 3, "sources": ["../../src/base-control/hooks.ts"], "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useInstanceId } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport BaseControl from '.';\n/**\n * Generate props for the `BaseControl` and the inner control itself.\n *\n * Namely, it takes care of generating a unique `id`, properly associating it with the `label` and `help` elements.\n *\n * @param props\n */\nexport function useBaseControlProps(props) {\n const {\n help,\n id: preferredId,\n ...restProps\n } = props;\n const uniqueId = useInstanceId(BaseControl, 'wp-components-base-control', preferredId);\n return {\n baseControlProps: {\n id: uniqueId,\n help,\n ...restProps\n },\n controlProps: {\n id: uniqueId,\n ...(!!help ? {\n 'aria-describedby': `${uniqueId}__help`\n } : {})\n }\n };\n}"], "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA8B;AAK9B,eAAwB;AAQjB,SAAS,oBAAoB,OAAO;AACzC,QAAM;AAAA,IACJ;AAAA,IACA,IAAI;AAAA,IACJ,GAAG;AAAA,EACL,IAAI;AACJ,QAAM,eAAW,8BAAc,SAAAA,SAAa,8BAA8B,WAAW;AACrF,SAAO;AAAA,IACL,kBAAkB;AAAA,MAChB,IAAI;AAAA,MACJ;AAAA,MACA,GAAG;AAAA,IACL;AAAA,IACA,cAAc;AAAA,MACZ,IAAI;AAAA,MACJ,GAAI,CAAC,CAAC,OAAO;AAAA,QACX,oBAAoB,GAAG,QAAQ;AAAA,MACjC,IAAI,CAAC;AAAA,IACP;AAAA,EACF;AACF;", "names": ["BaseControl"] }