@primer/react
Version:
An implementation of GitHub's Primer Design System using React
53 lines (50 loc) • 2.1 kB
JavaScript
import { clsx } from 'clsx';
import React, { forwardRef, useEffect } from 'react';
import '@primer/behaviors/utils';
import '@primer/behaviors';
import { useRefObjectAsForwardedRef } from '../hooks/useRefObjectAsForwardedRef.js';
import classes from './Heading.module.css.js';
import Box from '../Box/Box.js';
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
const Heading = /*#__PURE__*/forwardRef(({
as: Component = 'h2',
className,
variant,
...props
}, forwardedRef) => {
const innerRef = React.useRef(null);
useRefObjectAsForwardedRef(forwardedRef, innerRef);
if (process.env.NODE_ENV !== "production") {
/**
* The Linter yells because it thinks this conditionally calls an effect,
* but since this is a compile-time flag and not a runtime conditional
* this is safe, and ensures the entire effect is kept out of prod builds
* shaving precious bytes from the output, and avoiding mounting a noop effect
*/
// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
if (innerRef.current && !(innerRef.current instanceof HTMLHeadingElement)) {
// eslint-disable-next-line no-console
console.warn('This Heading component should be an instanceof of h1-h6');
}
}, [innerRef]);
}
if (props.sx) {
return /*#__PURE__*/React.createElement(Box, _extends({
as: Component,
className: clsx(className, classes.Heading),
"data-variant": variant
}, props, {
// @ts-ignore temporary disable as we migrate to css modules, until we remove PolymorphicForwardRefComponent
ref: innerRef
}));
}
return /*#__PURE__*/React.createElement(Component, _extends({
className: clsx(className, classes.Heading),
"data-variant": variant
}, props, {
ref: innerRef
}));
});
Heading.displayName = 'Heading';
export { Heading as default };