aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/@next/components/text.tsx
blob: 4bc21f0fc7716eae33c9f8262da52bdff3823413 (plain) (blame)
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
68
69
70
71
72
73
74
75
76
77
import * as React from 'react';
import styled, { withTheme } from 'styled-components';
import { colors } from 'ts/style/colors';

interface HeadingProps {
    asElement?: 'h1'| 'h2'| 'h3'| 'h4';
    size?: 'default' | 'medium' | 'large' | 'small';
    center?: boolean;
    children: Node | string;
    noMargin?: any;
}

interface ParagraphProps {
    noMargin?: any;
    size?: 'default' | 'small' | 'medium' | 'large';
    muted?: any;
    center?: any;
}

interface HeadingSizes {
    large: string;
    medium: string;
    default: string;
    small: string;
    [key: string]: string;
}

interface ParagraphSizes {
    default: string;
    medium: string;
    large: string;
    [key: string]: string;
}

const HEADING_SIZES: HeadingSizes = {
    large: '80px',
    medium: '50px',
    default: '28px',
    small: '20px',
};

const PARAGRAPH_SIZES: ParagraphSizes = {
    default: '18px',
    small: '14px',
    medium: '22px',
    large: '28px',
};

const StyledHeading = styled.h1<HeadingProps>`
    color: ${props => props.color || props.theme.textColor};
    font-size: ${props => HEADING_SIZES[props.size || 'default']};
    font-weight: 300;
    margin-bottom: ${props => !props.noMargin && '30px'};
    text-align: ${props => props.center && 'center'};
`;

export const Heading: React.StatelessComponent<HeadingProps> = props => {
    const {
        asElement = 'h1',
        children,
    } = props;
    const Component = StyledHeading.withComponent(asElement);
    return <Component {...props}>{children}</Component>;
};

// No need to declare it twice as Styled then rewrap as a stateless comp
// Note: this would be useful to be implemented the same way was "Heading"
// and be more generic. e.g. <Text /> with a props asElement so we can use it
// for literally anything =
export const Paragraph = styled.p<ParagraphProps>`
    font-size: ${props => PARAGRAPH_SIZES[props.size || 'default']};
    margin-bottom: ${props => !props.noMargin && '30px'};
    line-height: 1.4;
    color: ${props => props.color || props.theme.textColor};
    opacity: ${props => props.muted || 0.75};
    text-align: ${props => props.center && 'center'};
`;