-
Notifications
You must be signed in to change notification settings - Fork 23
/
Headline.tsx
67 lines (60 loc) · 1.86 KB
/
Headline.tsx
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import * as React from 'react';
import { ComponentPropsWithoutRef } from 'react';
import styled from 'styled-components';
import { compose, margin, system, MarginProps, textAlign, TextAlignProps, ResponsiveValue } from 'styled-system';
import { theme } from '../../essentials/theme';
import { get } from '../../utils/themeGet';
import { getSemanticValue } from '../../utils/cssVariables';
interface HeadlineProps extends ComponentPropsWithoutRef<'h1'>, MarginProps, TextAlignProps {
/**
* Set the html tag for the headline including the appropriate styles
*/
as?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
/**
* Set the style of the headline
*/
size?: ResponsiveValue<'xxl' | 'xl' | 'l' | 'm' | 's' | 'xs'>;
}
export const DEFAULT_HEADLINE_SIZE = {
h1: 'xxl',
h2: 'xl',
h3: 'l',
h4: 'm',
h5: 's',
h6: 'xs'
} as const;
const parser = system({
fontSize: {
property: 'fontSize',
defaultScale: {
xs: '0.75rem',
s: '0.875rem',
m: '1rem',
l: '1.5rem',
xl: '2rem',
xxl: '3rem'
}
},
lh: {
property: 'lineHeight',
defaultScale: {
xs: '1.125rem',
s: '1.25rem',
m: '1.375rem',
l: '2rem',
xl: '2.5rem',
xxl: '3.75rem'
}
}
});
const getSize = ({ as = 'h1', size }: HeadlineProps): ResponsiveValue<'xxl' | 'xl' | 'l' | 'm' | 's' | 'xs'> =>
size || DEFAULT_HEADLINE_SIZE[as];
const Headline: React.FC<HeadlineProps> = styled.h1.attrs({ theme })<HeadlineProps>`
color: inherit;
font-family: ${get('fonts.normal')};
font-weight: ${get('fontWeights.bold')};
margin: 0;
${props => parser({ fontSize: getSize(props), lh: getSize(props), ...props })}
${compose(margin, textAlign)}
`;
export { Headline, HeadlineProps };