-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathheading.tsx
More file actions
33 lines (28 loc) · 954 Bytes
/
heading.tsx
File metadata and controls
33 lines (28 loc) · 954 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import React, { useContext } from 'react';
import classNames from 'classnames';
import { ConfigContext } from '../config-provider/config-context';
import { getPrefixCls } from '../_utils/general';
import { HeadingProps } from './types';
const Heading = React.forwardRef<HTMLHeadingElement, HeadingProps>(
(props, ref) => {
const { level = 1, prefixCls: customisedCls, className, children, ...otherProps } = props;
const configContext = useContext(ConfigContext);
const prefixCls = getPrefixCls('typography', configContext.prefixCls, customisedCls);
if (level < 1 || level > 6) {
console.warn('The heading level parameter is invalid.');
return null;
}
const cls = classNames(prefixCls, className);
return React.createElement(
`h${level}`,
{
...otherProps,
ref,
className: cls,
},
children
);
}
);
Heading.displayName = 'Heading';
export default Heading;