Skip to content

Commit

Permalink
💄 style: 优化组件背景色
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Feb 25, 2021
1 parent fa403f9 commit 95cedb7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
14 changes: 4 additions & 10 deletions packages/page-loading/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { CSSProperties } from 'react';
import React, { useEffect } from 'react';
import React from 'react';
import classNames from 'classnames';
import { insertCss } from 'insert-css';

import 'nprogress/nprogress.css';

import { useProgress, progressColor } from './useProgress';
import { useProgress } from './useProgress';
import './style.less';

const clsPrefix = 'avx-page-loading';
Expand Down Expand Up @@ -45,15 +44,10 @@ const PageLoading: React.FC<PageLoadingProps> = ({
fullscreen,
color = '#1890ff',
id = 'avx-page-loading-container',
backgroundColor = '#f3f4f6',
backgroundColor = '#f5f5f5',
}) => {
// 控制 progress 颜色
useEffect(() => {
insertCss(progressColor(color));
}, [color]);

// 控制 Progress 显示
useProgress(id, progress);
useProgress(id, color, progress);

const colorStyle: CSSProperties = { background: color };

Expand Down
38 changes: 21 additions & 17 deletions packages/page-loading/src/useProgress.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import { useEffect } from 'react';
import NProgress from 'nprogress';
import { insertCss } from 'insert-css';

export const useProgress = (container, enable = true) => {
const progressColor = (color) => `
#nprogress .bar {
background: ${color};
}
#nprogress .peg {
box-shadow: 0 0 10px ${color}, 0 0 5px ${color};
}
#nprogress .spinner-icon {
border-top-color: ${color};
border-left-color: ${color};
}`;

export const useProgress = (container, color, enable = true) => {
// 控制 Progress 显示
useEffect(() => {
// 如果传入 progress props 且为 false
Expand All @@ -19,20 +34,9 @@ export const useProgress = (container, enable = true) => {
NProgress.done();
};
}, [container, enable]);
};



export const progressColor = (color) => `
#nprogress .bar {
background: ${color};
}
#nprogress .peg {
box-shadow: 0 0 10px ${color}, 0 0 5px ${color};
}
#nprogress .spinner-icon {
border-top-color: ${color};
border-left-color: ${color};
}`;
// 控制 progress 颜色
useEffect(() => {
insertCss(progressColor(color));
}, [color]);
};

1 comment on commit 95cedb7

@vercel
Copy link

@vercel vercel bot commented on 95cedb7 Feb 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.