@atlaskit/heading
Version:
A heading is a typography component used to display text in different sizes and formats.
103 lines (97 loc) • 3.18 kB
JavaScript
/* heading.tsx generated by @compiled/babel-plugin v3.0.2 */
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import "./heading.compiled.css";
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
/* eslint-disable @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors */
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';
var 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.
*/
var 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.
*/
var 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.
*/
var headingSizeStyles = {
xxlarge: "_fqox1iff",
xlarge: "_fqox12ln",
large: "_fqox10sd",
medium: "_fqox1af2",
small: "_fqox1e3o",
xsmall: "_fqox1qyo",
xxsmall: "_fqoxi4vh"
};
/**
* @codegenEnd
*/
var useColor = function useColor(colorProp) {
var 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>
* ```
*/
var Heading = /*#__PURE__*/forwardRef(function (props, ref) {
var children = props.children,
size = props.size,
id = props.id,
testId = props.testId,
as = props.as,
colorProp = props.color;
if (typeof process !== 'undefined' && process.env.NODE_ENV !== 'production' && as && typeof as !== 'string') {
throw new Error('`as` prop should be a string.');
}
var _useHeading = useHeading(sizeTagMap[size]),
_useHeading2 = _slicedToArray(_useHeading, 2),
hLevel = _useHeading2[0],
inferredElement = _useHeading2[1];
var Component = as || inferredElement;
var needsAriaRole = Component === 'div' && hLevel;
var 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;