11import * as React from 'react' ;
22import { 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' ;
55import { Colors } from '../../essentials' ;
66import { theme } from '../../essentials/theme' ;
77import { get } from '../../utils/themeGet' ;
@@ -18,7 +18,7 @@ interface HeadlineProps extends ComponentPropsWithoutRef<'h1'>, MarginProps, Tex
1818 /**
1919 * Set the style of the headline
2020 */
21- size ?: 'xxl' | 'xl' | 'l' | 'm' | 's' | 'xs' ;
21+ size ?: ResponsiveValue < 'xxl' | 'xl' | 'l' | 'm' | 's' | 'xs' > ;
2222}
2323
2424const DEFAULT_HEADLINE_SIZE = {
@@ -30,54 +30,41 @@ const DEFAULT_HEADLINE_SIZE = {
3030 h6 : 'xs'
3131} as const ;
3232
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+ }
7055 }
71- }
56+ } ) ;
57+
58+ const getSize = ( { as = 'h1' , size } : HeadlineProps ) : ResponsiveValue < 'xxl' | 'xl' | 'l' | 'm' | 's' | 'xs' > =>
59+ size || DEFAULT_HEADLINE_SIZE [ as ] ;
7260
7361const Headline : React . FC < HeadlineProps > = styled . h1 . attrs ( { theme } ) < HeadlineProps > `
7462 color: ${ p => ( p . inverted ? Colors . WHITE : Colors . AUTHENTIC_BLUE_900 ) } ;
7563 font-family: ${ get ( 'fonts.normal' ) } ;
7664 font-weight: ${ get ( 'fontWeights.bold' ) } ;
7765 margin: 0;
7866
79- ${ determineFontSize }
80-
67+ ${ props => parser ( { fontSize : getSize ( props ) , lh : getSize ( props ) , ...props } ) }
8168 ${ compose ( margin , textAlign ) }
8269` ;
8370
0 commit comments