Skip to content

Commit eddfd4e

Browse files
authored
feat: generate color by tvision-color (#144)
* feat: generate color by tvision-color * chore: remove built-in theme
1 parent 895dd08 commit eddfd4e

22 files changed

Lines changed: 49 additions & 264 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tdesign-react-starter",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"private": true,
55
"scripts": {
66
"dev:mock": "vite --open --mode mock",
@@ -59,7 +59,7 @@
5959
"react-router-dom": "^6.3.0",
6060
"tdesign-icons-react": "^0.1.6",
6161
"tdesign-react": "^0.45.1",
62-
"tvision-color": "^1.4.0"
62+
"tvision-color": "^1.5.0"
6363
},
6464
"browserslist": {
6565
"production": [

src/components/Board/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const TrendIcon = ({ trend, trendNum }: { trend?: ETrend; trendNum?: stri
4949
</div>
5050
);
5151

52-
const Board = ({ title, count, desc, trend, trendNum, Icon, dark, border }: IBoardProps) => (
52+
const Board = ({ title, count, desc, trend, trendNum, Icon, dark, border = false }: IBoardProps) => (
5353
<Card
5454
title={<span className={Style.boardTitle}>{title}</span>}
5555
className={classnames({

src/configs/color.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,6 @@ export const defaultColor = ['#0052d9', '#0594fa', '#00a870', '#ebb105', '#ed7b2
44

55
export const darkColor = ['#4582e6', '#29a4fb', '#03a56f', '#ca8d03', '#ed7b2f', '#ea7b84', '#f172c5', '#ab87d5'];
66

7-
export const colorMap: {
8-
[key: string]: string;
9-
} = {
10-
'#0052d9': '',
11-
'#0594fa': 'cyan',
12-
'#00a870': 'green',
13-
'#ebb105': 'yellow',
14-
'#ed7b2f': 'orange',
15-
'#e34d59': 'red',
16-
'#ed49b4': 'pink',
17-
'#834ec2': 'purple',
18-
19-
'#4582e6': '',
20-
'#29a4fb': 'cyan',
21-
'#03a56f': 'green',
22-
'#ca8d03': 'yellow',
23-
'#ea7b84': 'red',
24-
'#f172c5': 'pink',
25-
'#ab87d5': 'purple',
26-
};
27-
287
export const CHART_COLORS = {
298
[ETheme.light]: {
309
textColor: 'rgba(0, 0, 0, 0.9)',

src/main.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import App from 'layouts/index';
77

88
import 'tdesign-react/es/style/index.css';
99

10-
import './styles/theme.less';
1110
import './styles/index.less';
1211

1312
const env = import.meta.env.MODE || 'development';

src/modules/global/index.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
22
import { ETheme } from 'types/index.d';
33
import { Color } from 'tvision-color';
4-
import { CHART_COLORS, defaultColor, colorMap } from 'configs/color';
4+
import { CHART_COLORS, defaultColor } from 'configs/color';
55
import { generateColorMap, insertThemeStylesheet } from 'utils/color';
66
import { RootState } from '../store';
77
import { version } from '../../../package.json';
@@ -108,18 +108,17 @@ const globalSlice = createSlice({
108108
state.color = action?.payload;
109109
const mode = state.theme;
110110

111-
let colorType = colorMap?.[action?.payload];
112-
if (!colorType) {
113-
colorType = action?.payload;
114-
const newPalette = Color.getPaletteByGradation({
115-
colors: [colorType],
116-
step: 10,
117-
})[0];
118-
const newColorMap = generateColorMap(colorType, newPalette, mode);
119-
insertThemeStylesheet(colorType, newColorMap, mode);
120-
}
111+
const hex = action?.payload;
121112

122-
document.documentElement.setAttribute('theme-color', colorType || '');
113+
const { colors: newPalette, primary: brandColorIndex } = Color.getColorGradations({
114+
colors: [hex],
115+
step: 10,
116+
remainInput: false, // 是否保留输入 不保留会矫正不合适的主题色
117+
})[0];
118+
const newColorMap = generateColorMap(hex, newPalette, mode, brandColorIndex);
119+
insertThemeStylesheet(hex, newColorMap, mode);
120+
121+
document.documentElement.setAttribute('theme-color', hex || '');
123122
}
124123
},
125124
switchLayout: (state, action) => {

src/pages/Dashboard/Base/components/MiddleChart.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ const MiddleChart = () => {
3131
return (
3232
<Row gutter={[16, 16]} className={Style.middleChartPanel}>
3333
<Col xs={12} xl={9}>
34-
<Card title='统计数据' subtitle='(万元)' actions={LastWeekDatePicker(onTimeChange)}>
34+
<Card title='统计数据' subtitle='(万元)' actions={LastWeekDatePicker(onTimeChange)} bordered={false}>
3535
<ReactEcharts option={dynamicLineChartOption} notMerge={true} lazyUpdate={false} />
3636
</Card>
3737
</Col>
3838
<Col xs={12} xl={3}>
39-
<Card title='销售渠道' subtitle='2021-12'>
39+
<Card title='销售渠道' subtitle='2021-12' bordered={false}>
4040
<ReactEcharts option={dynamicPieChartOption} notMerge={true} lazyUpdate={true} />
4141
</Card>
4242
</Col>

src/pages/Dashboard/Base/components/RankList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ const PURCHASE_COLUMNS: TdPrimaryTableProps['columns'] = [
118118
const RankList = () => (
119119
<Row gutter={[16, 16]} className={Style.rankListPanel}>
120120
<Col xs={12} xl={6} span={12}>
121-
<Card title='销售订单排名' actions={DateRadioGroup}>
121+
<Card title='销售订单排名' actions={DateRadioGroup} bordered={false}>
122122
<Table columns={SALE_COLUMNS} rowKey='productName' size='medium' data={SALE_TREND_LIST} />
123123
</Card>
124124
</Col>
125125
<Col xs={12} xl={6} span={12}>
126-
<Card title='采购订单排名' actions={DateRadioGroup}>
126+
<Card title='采购订单排名' actions={DateRadioGroup} bordered={false}>
127127
<Table columns={PURCHASE_COLUMNS} rowKey='productName' size='medium' data={PURCHASE_TREND_LIST} />
128128
</Card>
129129
</Col>

src/pages/Dashboard/Detail/components/MonthPurchase.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Board from 'components/Board';
44
import { PANE_LIST } from '../constant';
55

66
const MonthPurchase = () => (
7-
<Card title='本月采购申请情况'>
7+
<Card title='本月采购申请情况' bordered={false}>
88
<Row gutter={[16, 16]}>
99
{PANE_LIST.map((item) => (
1010
<Col key={item.title} xs={6} xl={3} span={12}>

src/pages/Dashboard/Detail/components/PurchaseTrend.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const PurchaseTrend = () => {
7070
return (
7171
<Row className={Style.purchaseTrendPanel} gutter={[16, 16]}>
7272
<Col xs={12} xl={9}>
73-
<Card title='采购商品申请趋势' subtitle='(件)' actions={LastWeekDatePicker(onTimeChange)}>
73+
<Card title='采购商品申请趋势' subtitle='(件)' actions={LastWeekDatePicker(onTimeChange)} bordered={false}>
7474
<ReactEcharts
7575
option={dynamicChartOptions} // option:图表配置项
7676
notMerge={true}

src/pages/Dashboard/Detail/components/Satisfaction.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const Satisfaction = () => {
2828
<Button className={Style.exportBtn}>导出数据</Button>
2929
</div>
3030
}
31+
bordered={false}
3132
>
3233
<ReactEcharts
3334
option={dynamicChartOption} // option:图表配置项

0 commit comments

Comments
 (0)