diff options
Diffstat (limited to 'src/components/ui/headline')
-rw-r--r-- | src/components/ui/headline/index.tsx | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/components/ui/headline/index.tsx b/src/components/ui/headline/index.tsx new file mode 100644 index 000000000..3a3654f02 --- /dev/null +++ b/src/components/ui/headline/index.tsx | |||
@@ -0,0 +1,70 @@ | |||
1 | import classnames from 'classnames'; | ||
2 | import { Component, createElement, ReactNode } from 'react'; | ||
3 | import injectStyle from 'react-jss'; | ||
4 | |||
5 | import { Theme } from '@meetfranz/theme'; | ||
6 | import { IWithStyle, Omit } from '../typings/generic'; | ||
7 | |||
8 | interface IProps extends IWithStyle { | ||
9 | level?: number; | ||
10 | className?: string; | ||
11 | children: string | ReactNode; | ||
12 | id?: string; | ||
13 | } | ||
14 | |||
15 | const styles = (theme: Theme) => ({ | ||
16 | headline: { | ||
17 | fontWeight: 'lighter', | ||
18 | color: theme.colorText, | ||
19 | marginTop: 0, | ||
20 | marginBottom: 10, | ||
21 | textAlign: 'left', | ||
22 | }, | ||
23 | h1: { | ||
24 | fontSize: 30, | ||
25 | marginTop: 0, | ||
26 | }, | ||
27 | h2: { | ||
28 | fontSize: 20, | ||
29 | }, | ||
30 | h3: { | ||
31 | fontSize: 18, | ||
32 | }, | ||
33 | h4: { | ||
34 | fontSize: theme.uiFontSize, | ||
35 | }, | ||
36 | }); | ||
37 | |||
38 | class HeadlineComponent extends Component<IProps> { | ||
39 | render() { | ||
40 | const { classes, level, className, children, id } = this.props; | ||
41 | |||
42 | return createElement( | ||
43 | `h${level}`, | ||
44 | { | ||
45 | id, | ||
46 | className: classnames({ | ||
47 | [classes.headline]: true, | ||
48 | [classes[level ? `h${level}` : 'h1']]: true, | ||
49 | [`${className}`]: className, | ||
50 | }), | ||
51 | 'data-type': 'franz-headline', | ||
52 | }, | ||
53 | children, | ||
54 | ); | ||
55 | } | ||
56 | } | ||
57 | |||
58 | const Headline = injectStyle(styles)(HeadlineComponent); | ||
59 | |||
60 | const createH = (level: number) => (props: Omit<IProps, 'classes' | 'theme'>) => | ||
61 | ( | ||
62 | <Headline level={level} {...props}> | ||
63 | {props.children} | ||
64 | </Headline> | ||
65 | ); | ||
66 | |||
67 | export const H1 = createH(1); | ||
68 | export const H2 = createH(2); | ||
69 | export const H3 = createH(3); | ||
70 | export const H4 = createH(4); | ||