aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/@next/components/text.tsx
blob: 9058fc7c988c0699ff0ccbbc216c0dbe498c2389 (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
import * as React from 'react';
import styled from 'styled-components';
import {getCSSPadding, PaddingInterface} from 'ts/@next/constants/utilities';

interface BaseTextInterface extends PaddingInterface {
    size?: 'default' | 'medium' | 'large' | 'small';
    isCentered?: boolean;
}

interface HeadingProps extends BaseTextInterface {
    asElement?: 'h1'| 'h2'| 'h3'| 'h4';
    isCentered?: boolean;
    isNoMargin?: boolean;
    color?: string;
}

interface ParagraphProps extends BaseTextInterface {
    isNoMargin?: boolean;
    isMuted?: boolean | number;
}

const StyledHeading = styled.h1<HeadingProps>`
    color: ${props => props.color || props.theme.textColor};
    font-size: ${props => `var(--${props.size || 'default'}Heading)`};
    padding: ${props => props.padding && getCSSPadding(props.padding)};
    line-height: ${props => `var(--${props.size || 'default'}HeadingHeight)`};
    margin-bottom: ${props => !props.isNoMargin && '30px'};
    text-align: ${props => props.isCentered && 'center'};
    font-weight: 300;
    max-width: var(--desktopMaxWidth, none);
    margin-left: ${props => props.isCentered && 'auto'};
    margin-right: ${props => props.isCentered && 'auto'};

    @media (max-width: 768px) {
        text-align: center;
        max-width: var(--mobileMaxWidth, none);
    }
`;

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

    return (
        <Component
            style={{...style}}
            {...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 => `var(--${props.size || 'default'}Paragraph)`};
    margin-bottom: ${props => !props.isNoMargin && '30px'};
    padding: ${props => props.padding && getCSSPadding(props.padding)};
    color: ${props => props.color || props.theme.textColor};
    opacity: ${props => typeof props.isMuted === 'boolean' ? 0.75 : props.isMuted};
    text-align: ${props => props.isCentered && 'center'};
    line-height: 1.4;
`;