style.ts 7.2 KB
Newer Older
1
import * as polished from 'polished';
2

3
import {createGlobalStyle, keyframes} from 'styled-components';
4

5
import {css} from 'styled-components';
6 7
import tippy from '!!css-loader!tippy.js/dist/tippy.css';
import toast from '!!css-loader!react-toastify/dist/ReactToastify.css';
P
Peter Pan 已提交
8
import vdlIcon from '!!css-loader!~/public/style/vdl-icon.css';
9

10 11 12
export {default as styled} from 'styled-components';
export * from 'styled-components';
export * from 'polished';
13 14
// rename conflict shorthands
export {borderRadius as borderRadiusShortHand, borderColor as borderColorShortHand} from 'polished';
15

16
const {math, size, lighten, darken, normalize, fontFace, transitions, border, position} = polished;
17

18 19
export const iconFontPath = `${process.env.PUBLIC_PATH}/style/fonts/vdl-icon`;

20
// sizes
21 22 23 24
const fontSize = '14px';
export const rem = (pxval: string | number): string => polished.rem(pxval, fontSize);
export const em = (pxval: string | number, base?: string | number): string => polished.em(pxval, base || fontSize);
export const half = (value: string | number): string => math(`(${value}) / 2`);
25
export const headerHeight = rem(60);
P
Peter Pan 已提交
26 27
export const contentMargin = rem(20);
export const contentHeight = `calc(100vh - ${math(`${contentMargin} * 2 + ${headerHeight}`)})`;
28 29 30 31 32 33
export const asideWidth = rem(260);
export const borderRadius = '4px';
export const progressSpinnerSize = '20px';

// colors
export const primaryColor = '#2932E1';
P
Peter Pan 已提交
34
export const dangerColor = '#FF3912';
35 36
export const primaryFocusedColor = lighten(0.08, primaryColor);
export const primaryActiveColor = lighten(0.12, primaryColor);
P
Peter Pan 已提交
37 38
export const dangerFocusedColor = lighten(0.08, dangerColor);
export const dangerActiveColor = lighten(0.12, dangerColor);
39 40 41 42 43 44 45 46 47 48 49 50 51
export const selectedColor = '#1A73E8';
export const lightColor = '#F4F5FC';
export const lightFocusedColor = darken(0.03, lightColor);
export const lightActiveColor = darken(0.06, lightColor);
export const textColor = '#333';
export const textLightColor = '#666';
export const textLighterColor = '#999';
export const textInvertColor = '#FFF';
export const bodyBackgroundColor = '#F4F4F4';
export const backgroundColor = '#FFF';
export const backgroundFocusedColor = '#F6F6F6';
export const borderColor = '#DDD';
export const borderFocusedColor = darken(0.15, borderColor);
52
export const borderActiveColor = darken(0.3, borderColor);
53 54 55
export const navbarBackgroundColor = '#1527C2';
export const navbarHoverBackgroundColor = lighten(0.05, navbarBackgroundColor);
export const navbarHighlightColor = '#596cd6';
56
export const progressBarColor = '#FFF';
P
Peter Pan 已提交
57
export const maskColor = 'rgba(255, 255, 255, 0.8)';
58 59
export const tooltipBackgroundColor = 'rgba(0, 0, 0, 0.6)';
export const tooltipTextColor = '#FFF';
60 61 62 63 64

// transitions
export const duration = '75ms';
export const easing = 'ease-in';

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
// mixins
export const sameBorder = (
    width = '1px' as
        | string
        | number
        | {width?: string | number; type?: string; color?: string; radius?: string | boolean},
    type = 'solid',
    color = borderColor,
    radius?: string | boolean
) => {
    if ('object' === typeof width) {
        type = width.type ?? 'solid';
        color = width.color ?? borderColor;
        radius = width.radius === true ? borderRadius : width.radius;
        width = width.width ?? '1px';
    }
    return Object.assign(
        {},
        border(width, type, color),
        radius ? {borderRadius: radius === true ? borderRadius : radius} : undefined
    );
};
export const transitionProps = (props: string | string[], args?: string) => {
    if ('string' === typeof props) {
        props = [props];
    }
    if (!args) {
        args = `${duration} ${easing}`;
    }
    return transitions(props, args);
};
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
export const link = css`
    a {
        color: ${primaryColor};
        cursor: pointer;
        ${transitionProps('color')};

        &:hover {
            color: ${primaryFocusedColor};
        }

        &:active {
            color: ${primaryActiveColor};
        }
    }
`;
111

112 113 114 115 116 117 118 119 120 121 122 123 124
const spinner = keyframes`
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
`;

export type WithStyled = {
    className?: string;
};

P
Peter Pan 已提交
125
// prettier-ignore
126 127 128
export const GlobalStyle = createGlobalStyle`
    ${normalize}

129 130
    ${fontFace({
        fontFamily: 'vdl-icon',
131
        fontFilePath: iconFontPath,
132 133 134 135 136
        fileFormats: ['ttf', 'woff', 'svg'],
        fontWeight: 'normal',
        fontStyle: 'normal',
        fontDisplay: 'block'
    })}
P
Peter Pan 已提交
137 138

    ${vdlIcon.toString()}
139 140
    ${toast.toString()}
    ${tippy.toString()}
P
Peter Pan 已提交
141

142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
    html {
        font-size: ${fontSize};
        font-family: 'Merriweather Sans', Helvetica, Arial, sans-serif;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    html,
    body {
        height: 100%;
        background-color: ${bodyBackgroundColor};
        color: ${textColor};
    }

    a {
        text-decoration: none;
        color: inherit;

        &:visited {
            color: currentColor;
        }
    }

    * {
        box-sizing: border-box;
    }

    #nprogress {
        pointer-events: none;
    }

    #nprogress .bar {
        background: ${progressBarColor};
        z-index: 99999;
176 177
        ${position('fixed', 0, null, null, 0)}
        ${size('2px', '100%')}
178 179 180 181
    }

    #nprogress .peg {
        display: block;
182 183
        ${position('absolute', null, 0, null, null)}
        ${size('100%', rem(100))}
184 185 186 187 188 189 190 191
        box-shadow: 0 0 rem(10) ${progressBarColor}, 0 0 ${rem(5)} ${progressBarColor};
        opacity: 1;
        transform: rotate(3deg) translate(0px, -${rem(4)});
    }

    #nprogress .spinner {
        display: block;
        z-index: 99999;
192
        ${position('fixed', progressSpinnerSize, progressSpinnerSize, null, null)}
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
    }

    #nprogress .spinner-icon {
        ${size(`calc(${half(headerHeight)} - ${half(progressSpinnerSize)})`)}
        box-sizing: border-box;

        border: solid 2px transparent;
        border-top-color: ${progressBarColor};
        border-left-color: ${progressBarColor};
        border-radius: 50%;

        animation: ${spinner} 400ms linear infinite;
    }

    .nprogress-custom-parent {
        overflow: hidden;
        position: relative;
    }

    .nprogress-custom-parent #nprogress .spinner,
    .nprogress-custom-parent #nprogress .bar {
        position: absolute;
    }
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250

    .Toastify__toast-container {
        z-index: 10001;

        .Toastify__toast {
            border-radius: ${borderRadius};
        }

        .Toastify__toast--default {
            color: ${textColor};
        }

        .Toastify__toast-body {
            padding: 0 1.428571429em;
        }
    }

    .tippy-box {
        z-index: 10002;
        color: ${tooltipTextColor};
        background-color: ${tooltipBackgroundColor};

        &[data-placement^='top'] > .tippy-arrow::before {
            border-top-color: ${tooltipBackgroundColor};
        }
        &[data-placement^='bottom'] > .tippy-arrow::before {
            border-bottom-color: ${tooltipBackgroundColor};
        }
        &[data-placement^='left'] > .tippy-arrow::before {
            border-left-color: ${tooltipBackgroundColor};
        }
        &[data-placement^='right'] > .tippy-arrow::before {
            border-right-color: ${tooltipBackgroundColor};
        }
    }
251
`;