UNPKG

@wordpress/components

Version:
8 lines (7 loc) 1.67 kB
{ "version": 3, "sources": ["../../src/heading/hook.ts"], "sourcesContent": ["/**\n * Internal dependencies\n */\n\nimport { useContextSystem } from '../context';\nimport { useText } from '../text';\nimport { getHeadingFontSize } from '../utils/font-size';\nimport { CONFIG, COLORS } from '../utils';\nexport function useHeading(props) {\n const {\n as: asProp,\n level = 2,\n color = COLORS.theme.foreground,\n isBlock = true,\n weight = CONFIG.fontWeightHeading,\n ...otherProps\n } = useContextSystem(props, 'Heading');\n const as = asProp || `h${level}`;\n const a11yProps = {};\n if (typeof as === 'string' && as[0] !== 'h') {\n // If not a semantic `h` element, add a11y props:\n a11yProps.role = 'heading';\n a11yProps['aria-level'] = typeof level === 'string' ? parseInt(level) : level;\n }\n const textProps = useText({\n color,\n isBlock,\n weight,\n size: getHeadingFontSize(level),\n ...otherProps\n });\n return {\n ...textProps,\n ...a11yProps,\n as\n };\n}"], "mappings": ";AAIA,SAAS,wBAAwB;AACjC,SAAS,eAAe;AACxB,SAAS,0BAA0B;AACnC,SAAS,QAAQ,cAAc;AACxB,SAAS,WAAW,OAAO;AAChC,QAAM;AAAA,IACJ,IAAI;AAAA,IACJ,QAAQ;AAAA,IACR,QAAQ,OAAO,MAAM;AAAA,IACrB,UAAU;AAAA,IACV,SAAS,OAAO;AAAA,IAChB,GAAG;AAAA,EACL,IAAI,iBAAiB,OAAO,SAAS;AACrC,QAAM,KAAK,UAAU,IAAI,KAAK;AAC9B,QAAM,YAAY,CAAC;AACnB,MAAI,OAAO,OAAO,YAAY,GAAG,CAAC,MAAM,KAAK;AAE3C,cAAU,OAAO;AACjB,cAAU,YAAY,IAAI,OAAO,UAAU,WAAW,SAAS,KAAK,IAAI;AAAA,EAC1E;AACA,QAAM,YAAY,QAAQ;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,mBAAmB,KAAK;AAAA,IAC9B,GAAG;AAAA,EACL,CAAC;AACD,SAAO;AAAA,IACL,GAAG;AAAA,IACH,GAAG;AAAA,IACH;AAAA,EACF;AACF;", "names": [] }