aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/@next/components/layout.tsx
blob: 1a78f691c6c029750033d918d0bcecd175361dc1 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import styled from 'styled-components';

interface WrapWidths {
    default: string;
    full: string;
    medium: string;
    narrow: string;
    [key: string]: string;
}

interface ColumnWidths {
    [key: string]: string;
}

interface PaddingSizes {
    [key: string]: string;
}

interface SectionProps {
    noPadding?: any;
    padLarge?: any;
    noMargin?: any;
    bgColor?: string;
    fullWidth?: any;
}

interface WrapProps {
    width?: 'default' | 'full' | 'medium' | 'narrow';
    bgColor?: string;
    padding?: number | ('large' | 'default' | number)[];
}

interface ColumnProps {
    colWidth?: '1/4' | '1/3' | '1/2' | '2/3';
    noPadding?: any;
    padLarge?: any;
    bgColor?: string;
}

interface GetColWidthArgs {
    span?: number;
    columns: number;
}

const _getColumnWidth = (args: GetColWidthArgs): string => {
    const { span = 1, columns } = args;
    const percentWidth = (span / columns) * 100;
    const gutterDiff = (GUTTER * (columns - 1)) / columns;
    return `calc(${percentWidth}% - ${gutterDiff}px)`;
};

const _getPadding = (value: number | (string | number)[]): string => {
    if (Array.isArray(value)) {
        return value.map(val => PADDING_SIZES[val] || `${val}px`).join(' ');
    } else {
        return `${value}px`;
    }
}

const GUTTER = 30 as number;
const MAX_WIDTH = 1500;
const BREAKPOINTS = {
    mobile: '768px',
};
const WRAPPER_WIDTHS: WrapWidths = {
    default: `${MAX_WIDTH}px`, // tbd
    full: '100%',
    medium: '1136px',
    narrow: '930px',
};
const COLUMN_WIDTHS: ColumnWidths = {
    '1/4': _getColumnWidth({ columns: 4 }),
    '1/3': _getColumnWidth({ columns: 3 }),
    '1/2': _getColumnWidth({ columns: 2 }),
    '2/3': _getColumnWidth({ span: 2, columns: 3 }),
};
const PADDING_SIZES: PaddingSizes = {
    'default': '30px',
    'large': '60px',
};


export const Main = styled.main`
    border: 1px dotted rgba(0, 0, 255, 0.3);
    width: calc(100% - 60px);
    max-width: ${MAX_WIDTH}px;
    margin: 0 auto;
`;

export const Section = styled.section<SectionProps>`
    width: ${props => props.fullWidth ? `calc(100% + ${GUTTER * 2}px)` : '100%'};
    padding: ${props => !props.noPadding && (props.padLarge ? '60px 30px' : '30px')};
    margin-bottom: ${props => !props.noMargin && `${GUTTER}px`};
    margin-left: ${props => props.fullWidth && `-${GUTTER}px`};
    background-color: ${props => props.bgColor};
    border: 1px dotted rgba(0, 255, 0, 0.3);

    @media (min-width: 1560px) {
        width: ${props => props.fullWidth && '100vw'};
        margin-left: ${props => props.fullWidth && `calc(750px - 50vw)`};
    }

    @media (max-width: ${BREAKPOINTS.mobile}) {
        padding: 30px;
    }
`;

const WrapBase = styled.div<WrapProps>`
    max-width: ${props => WRAPPER_WIDTHS[props.width || 'default']};
    padding: ${props => props.padding && _getPadding(props.padding)};
    background-color: ${props => props.bgColor};
    margin: 0 auto;
`;

export const Wrap = styled(WrapBase)`
    @media (min-width: ${BREAKPOINTS.mobile}) {
        display: flex;
        justify-content: space-between;
    }
`;

export const WrapCentered = styled(WrapBase)`
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
`;

export const WrapGrid = styled(WrapBase)`
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
`;

export const Column = styled.div<ColumnProps>`
    padding: ${props => !props.noPadding && (props.padLarge ? '60px 30px' : '30px')};
    border: 1px dotted rgba(255, 0, 0, 0.3);
    background-color: ${props => props.bgColor};

    @media (min-width: ${BREAKPOINTS.mobile}) {
        width: ${props => props.colWidth ? COLUMN_WIDTHS[props.colWidth] : '100%'};
    }
`;