2019-02-19 11:42:05 +08:00
|
|
|
import * as React from 'react';
|
|
|
|
import classNames from 'classnames';
|
2020-11-21 15:40:06 +08:00
|
|
|
import { composeRef } from 'rc-util/lib/ref';
|
2019-02-19 11:42:05 +08:00
|
|
|
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
|
2020-05-14 15:57:04 +08:00
|
|
|
import devWarning from '../_util/devWarning';
|
2019-02-19 11:42:05 +08:00
|
|
|
|
|
|
|
export interface TypographyProps {
|
|
|
|
id?: string;
|
|
|
|
prefixCls?: string;
|
|
|
|
className?: string;
|
|
|
|
style?: React.CSSProperties;
|
|
|
|
children?: React.ReactNode;
|
|
|
|
['aria-label']?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface InternalTypographyProps extends TypographyProps {
|
|
|
|
component?: string;
|
2019-10-01 14:06:09 +08:00
|
|
|
/** @deprecated Use `ref` directly if using React 16 */
|
2019-03-05 13:48:38 +08:00
|
|
|
setContentRef?: (node: HTMLElement) => void;
|
2019-02-19 11:42:05 +08:00
|
|
|
}
|
|
|
|
|
2020-06-10 11:12:31 +08:00
|
|
|
const Typography: React.ForwardRefRenderFunction<{}, InternalTypographyProps> = (
|
2019-10-01 14:06:09 +08:00
|
|
|
{
|
|
|
|
prefixCls: customizePrefixCls,
|
|
|
|
component = 'article',
|
|
|
|
className,
|
|
|
|
'aria-label': ariaLabel,
|
|
|
|
setContentRef,
|
|
|
|
children,
|
|
|
|
...restProps
|
|
|
|
},
|
|
|
|
ref,
|
|
|
|
) => {
|
|
|
|
let mergedRef = ref;
|
|
|
|
|
|
|
|
if (setContentRef) {
|
2020-05-14 15:57:04 +08:00
|
|
|
devWarning(false, 'Typography', '`setContentRef` is deprecated. Please use `ref` instead.');
|
2019-10-01 14:06:09 +08:00
|
|
|
mergedRef = composeRef(ref, setContentRef);
|
2019-09-30 19:37:42 +08:00
|
|
|
}
|
2019-10-01 14:06:09 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<ConfigConsumer>
|
2020-01-02 19:10:16 +08:00
|
|
|
{({ getPrefixCls, direction }: ConfigConsumerProps) => {
|
2019-10-01 14:06:09 +08:00
|
|
|
const Component = component as any;
|
|
|
|
const prefixCls = getPrefixCls('typography', customizePrefixCls);
|
2020-09-06 13:07:39 +08:00
|
|
|
const componentClassName = classNames(
|
|
|
|
prefixCls,
|
|
|
|
{
|
|
|
|
[`${prefixCls}-rtl`]: direction === 'rtl',
|
|
|
|
},
|
|
|
|
className,
|
|
|
|
);
|
2019-10-01 14:06:09 +08:00
|
|
|
return (
|
|
|
|
<Component
|
2020-01-02 19:10:16 +08:00
|
|
|
className={componentClassName}
|
2019-10-01 14:06:09 +08:00
|
|
|
aria-label={ariaLabel}
|
|
|
|
ref={mergedRef}
|
|
|
|
{...restProps}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</Component>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</ConfigConsumer>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-04-20 19:18:53 +08:00
|
|
|
const RefTypography = React.forwardRef(Typography);
|
2019-10-01 14:06:09 +08:00
|
|
|
|
2020-04-20 19:18:53 +08:00
|
|
|
RefTypography.displayName = 'Typography';
|
2019-02-19 11:42:05 +08:00
|
|
|
|
2019-10-01 14:06:09 +08:00
|
|
|
// es default export should use const instead of let
|
|
|
|
const ExportTypography = (RefTypography as unknown) as React.FC<TypographyProps>;
|
|
|
|
|
|
|
|
export default ExportTypography;
|