UNPKG

@atlaskit/heading

Version:

A heading is a typography component used to display text in different sizes and formats.

100 lines (95 loc) 2.95 kB
/* heading.tsx generated by @compiled/babel-plugin v3.0.2 */ /* eslint-disable @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors */ import "./heading.compiled.css"; import * as React from 'react'; import { ax, ix } from "@compiled/react/runtime"; import { forwardRef } from 'react'; // eslint-disable-next-line @atlaskit/design-system/no-emotion-primitives -- to be migrated to @atlaskit/primitives/compiled – go/akcss import { UNSAFE_inverseColorMap } from '@atlaskit/primitives'; import { UNSAFE_useSurface } from '@atlaskit/primitives/compiled'; import { useHeading } from './use-heading'; const sizeTagMap = { xxlarge: 'h1', xlarge: 'h1', large: 'h2', medium: 'h3', small: 'h4', xsmall: 'h5', xxsmall: 'h6' }; /** * Using '&&' here to increase specificity of Heading styles such that app styles like ".wiki-content h4" cannot override this component. */ const styles = { reset: "_dxsyidpf _1i144jg8 _nmk4glyw" }; /** * Using '&&' here to increase specificity of Heading styles such that app styles like ".wiki-content h4" cannot override this component. */ const headingColorStyles = { 'color.text': "_1w90i7uo", 'color.text.inverse': "_1w9015cr", 'color.text.warning.inverse': "_1w901yd3" }; /** * Using '&&' here to increase specificity of Heading styles such that app styles like ".wiki-content h4" cannot override this component. */ const headingSizeStyles = { xxlarge: "_fqox1iff", xlarge: "_fqox12ln", large: "_fqox10sd", medium: "_fqox1af2", small: "_fqox1e3o", xsmall: "_fqox1qyo", xxsmall: "_fqoxi4vh" }; /** * @codegenEnd */ const useColor = colorProp => { const surface = UNSAFE_useSurface(); if (colorProp) { return colorProp; } if (UNSAFE_inverseColorMap.hasOwnProperty(surface)) { return UNSAFE_inverseColorMap[surface]; } return 'color.text'; }; /** * __Heading__ * * Heading is a typography component used to display text in defined sizes and styles. * * @example * * ```jsx * <Heading size="xxlarge">Page title</Heading> * ``` */ const Heading = /*#__PURE__*/forwardRef((props, ref) => { const { children, size, id, testId, as, color: colorProp } = props; if (typeof process !== 'undefined' && process.env.NODE_ENV !== 'production' && as && typeof as !== 'string') { throw new Error('`as` prop should be a string.'); } const [hLevel, inferredElement] = useHeading(sizeTagMap[size]); const Component = as || inferredElement; const needsAriaRole = Component === 'div' && hLevel; const color = useColor(colorProp); return /*#__PURE__*/React.createElement(Component, { id: id, ref: ref, "data-testid": testId, role: needsAriaRole ? 'heading' : undefined, "aria-level": needsAriaRole ? hLevel : undefined, className: ax([styles.reset, headingSizeStyles[size], headingColorStyles[color]]) }, children); }); export default Heading;