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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
import React from 'react';
import styles from './typo.module.scss';
import clsx from 'clsx';
type Variant = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'body';
type Align = 'inherit' | 'left' | 'center' | 'right';
interface TypographyProps extends React.HTMLAttributes<HTMLElement> {
variant?: Variant;
align?: Align;
gutter?: boolean;
}
const variantTagMap: Record<Variant, keyof JSX.IntrinsicElements> = {
h1: 'h1',
h2: 'h2',
h3: 'h3',
h4: 'h4',
h5: 'h5',
h6: 'h6',
body: 'p'
};
const Typography: React.FC<TypographyProps> = ({
variant = 'body',
align = 'inherit',
gutter = false,
className,
...props
}) => {
const Tag = variantTagMap[variant] as keyof React.ReactHTML;
const typographyClassName = clsx(
styles[`typo-${variant}`],
{
[`align-${align}`]: align !== 'inherit',
[styles['typo-gutter']]: gutter
},
className
);
return <Tag className={typographyClassName} {...props} />;
};
export default Typography;
|