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

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

5
import {css} from 'styled-components';
P
Peter Pan 已提交
6
import vdlIcon from '!!css-loader!~/public/style/vdl-icon.css';
7

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

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

// sizes
17 18 19 20
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`);
21
export const headerHeight = rem(60);
P
Peter Pan 已提交
22 23
export const contentMargin = rem(20);
export const contentHeight = `calc(100vh - ${math(`${contentMargin} * 2 + ${headerHeight}`)})`;
24 25 26 27 28 29
export const asideWidth = rem(260);
export const borderRadius = '4px';
export const progressSpinnerSize = '20px';

// colors
export const primaryColor = '#2932E1';
P
Peter Pan 已提交
30
export const dangerColor = '#FF3912';
31 32
export const primaryFocusedColor = lighten(0.08, primaryColor);
export const primaryActiveColor = lighten(0.12, primaryColor);
P
Peter Pan 已提交
33 34
export const dangerFocusedColor = lighten(0.08, dangerColor);
export const dangerActiveColor = lighten(0.12, dangerColor);
35 36 37 38 39 40 41 42 43 44 45 46 47
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);
48
export const borderActiveColor = darken(0.3, borderColor);
49 50 51
export const navbarBackgroundColor = '#1527C2';
export const navbarHoverBackgroundColor = lighten(0.05, navbarBackgroundColor);
export const navbarHighlightColor = '#596cd6';
52
export const progressBarColor = '#FFF';
P
Peter Pan 已提交
53
export const maskColor = 'rgba(255, 255, 255, 0.8)';
54 55
export const tooltipBackgroundColor = 'rgba(0, 0, 0, 0.6)';
export const tooltipTextColor = '#FFF';
56 57 58 59 60

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

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
// 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);
};
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
export const link = css`
    a {
        color: ${primaryColor};
        cursor: pointer;
        ${transitionProps('color')};

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

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

108 109 110 111 112 113 114 115 116 117 118 119 120
const spinner = keyframes`
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
`;

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

P
Peter Pan 已提交
121
// prettier-ignore
122 123 124
export const GlobalStyle = createGlobalStyle`
    ${normalize}

125 126 127 128 129 130 131 132
    ${fontFace({
        fontFamily: 'vdl-icon',
        fontFilePath: `${process.env.PUBLIC_PATH}/style/fonts/vdl-icon`,
        fileFormats: ['ttf', 'woff', 'svg'],
        fontWeight: 'normal',
        fontStyle: 'normal',
        fontDisplay: 'block'
    })}
P
Peter Pan 已提交
133 134 135

    ${vdlIcon.toString()}

136 137 138 139 140 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
    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;
170 171
        ${position('fixed', 0, null, null, 0)}
        ${size('2px', '100%')}
172 173 174 175
    }

    #nprogress .peg {
        display: block;
176 177
        ${position('absolute', null, 0, null, null)}
        ${size('100%', rem(100))}
178 179 180 181 182 183 184 185
        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;
186
        ${position('fixed', progressSpinnerSize, progressSpinnerSize, null, null)}
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
    }

    #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;
    }
`;