ant-design/components/typography/Typography.tsx
2019-08-06 15:36:12 +08:00

48 lines
1.1 KiB
TypeScript

import * as React from 'react';
import classNames from 'classnames';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
export interface TypographyProps {
id?: string;
prefixCls?: string;
className?: string;
style?: React.CSSProperties;
children?: React.ReactNode;
['aria-label']?: string;
}
interface InternalTypographyProps extends TypographyProps {
component?: string;
setContentRef?: (node: HTMLElement) => void;
}
const Typography: React.SFC<InternalTypographyProps> = ({
prefixCls: customizePrefixCls,
component = 'article',
className,
'aria-label': ariaLabel,
setContentRef,
children,
...restProps
}) => (
<ConfigConsumer>
{({ getPrefixCls }: ConfigConsumerProps) => {
const Component = component as any;
const prefixCls = getPrefixCls('typography', customizePrefixCls);
return (
<Component
className={classNames(prefixCls, className)}
aria-label={ariaLabel}
ref={setContentRef}
{...restProps}
>
{children}
</Component>
);
}}
</ConfigConsumer>
);
export default Typography;