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