1
1
import * as React from 'react' ;
2
2
import { ComponentPropsWithoutRef } from 'react' ;
3
- import styled , { css } from 'styled-components' ;
4
- import { compose , margin , MarginProps , textAlign , TextAlignProps } from 'styled-system' ;
3
+ import styled from 'styled-components' ;
4
+ import { compose , margin , system , MarginProps , textAlign , TextAlignProps , ResponsiveValue } from 'styled-system' ;
5
5
import { Colors } from '../../essentials' ;
6
6
import { theme } from '../../essentials/theme' ;
7
7
import { get } from '../../utils/themeGet' ;
@@ -18,7 +18,7 @@ interface HeadlineProps extends ComponentPropsWithoutRef<'h1'>, MarginProps, Tex
18
18
/**
19
19
* Set the style of the headline
20
20
*/
21
- size ?: 'xxl' | 'xl' | 'l' | 'm' | 's' | 'xs' ;
21
+ size ?: ResponsiveValue < 'xxl' | 'xl' | 'l' | 'm' | 's' | 'xs' > ;
22
22
}
23
23
24
24
const DEFAULT_HEADLINE_SIZE = {
@@ -30,54 +30,41 @@ const DEFAULT_HEADLINE_SIZE = {
30
30
h6 : 'xs'
31
31
} as const ;
32
32
33
- function determineFontSize ( props : HeadlineProps ) {
34
- const h1Styles = css `
35
- font-size : ${ get ( 'fontSizes.7' ) } ;
36
- line-height : 3.75rem ;
37
- ` ;
38
-
39
- const size = props . size ?? DEFAULT_HEADLINE_SIZE [ props . as ] ;
40
- switch ( size ) {
41
- case 'xxl' :
42
- return h1Styles ;
43
- case 'xl' :
44
- return css `
45
- font-size : ${ get ( 'fontSizes.5' ) } ;
46
- line-height : 2.5rem ;
47
- ` ;
48
- case 'l' :
49
- return css `
50
- font-size : ${ get ( 'fontSizes.4' ) } ;
51
- line-height : 2rem ;
52
- ` ;
53
- case 'm' :
54
- return css `
55
- font-size : ${ get ( 'fontSizes.2' ) } ;
56
- line-height : 1.375rem ;
57
- ` ;
58
- case 's' :
59
- return css `
60
- font-size : ${ get ( 'fontSizes.1' ) } ;
61
- line-height : 1.25rem ;
62
- ` ;
63
- case 'xs' :
64
- return css `
65
- font-size : ${ get ( 'fontSizes.0' ) } ;
66
- line-height : 1.125rem ;
67
- ` ;
68
- default :
69
- return h1Styles ;
33
+ const parser = system ( {
34
+ fontSize : {
35
+ property : 'fontSize' ,
36
+ defaultScale : {
37
+ xs : '0.75rem' ,
38
+ s : '0.875rem' ,
39
+ m : '1rem' ,
40
+ l : '1.5rem' ,
41
+ xl : '2rem' ,
42
+ xxl : '3rem'
43
+ }
44
+ } ,
45
+ lh : {
46
+ property : 'lineHeight' ,
47
+ defaultScale : {
48
+ xs : '1.125rem' ,
49
+ s : '1.25rem' ,
50
+ m : '1.375rem' ,
51
+ l : '2rem' ,
52
+ xl : '2.5rem' ,
53
+ xxl : '3.75rem'
54
+ }
70
55
}
71
- }
56
+ } ) ;
57
+
58
+ const getSize = ( { as = 'h1' , size } : HeadlineProps ) : ResponsiveValue < 'xxl' | 'xl' | 'l' | 'm' | 's' | 'xs' > =>
59
+ size || DEFAULT_HEADLINE_SIZE [ as ] ;
72
60
73
61
const Headline : React . FC < HeadlineProps > = styled . h1 . attrs ( { theme } ) < HeadlineProps > `
74
62
color: ${ p => ( p . inverted ? Colors . WHITE : Colors . AUTHENTIC_BLUE_900 ) } ;
75
63
font-family: ${ get ( 'fonts.normal' ) } ;
76
64
font-weight: ${ get ( 'fontWeights.bold' ) } ;
77
65
margin: 0;
78
66
79
- ${ determineFontSize }
80
-
67
+ ${ props => parser ( { fontSize : getSize ( props ) , lh : getSize ( props ) , ...props } ) }
81
68
${ compose ( margin , textAlign ) }
82
69
` ;
83
70
0 commit comments