Skip to content

Commit 8c8f020

Browse files
committed
feat: loading template theme support
1 parent 1f7d155 commit 8c8f020

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

packages/plots/src/components/base/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const BaseChart: ForwardRefExoticComponent<PropsWithoutRef<CommonConfig>
2828

2929
return (
3030
<ErrorBoundary errorTemplate={errorTemplate}>
31-
{loading && <ChartLoading loadingTemplate={loadingTemplate} />}
31+
{loading && <ChartLoading loadingTemplate={loadingTemplate} theme={config.theme} loading={loading} />}
3232
<div className={className} style={containerStyle} ref={container} {...containerAttributes} />
3333
</ErrorBoundary>
3434
);

packages/util/src/rc/chart-loading.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
import React from 'react';
2+
import { ContainerConfig } from '../types';
23

3-
export interface ChartLoadingConfig {
4+
interface ChartLoadingConfig extends Pick<ContainerConfig, 'loadingTemplate' | 'loading'> {
45
/**
56
* @title 主题
67
* @description 配置主题颜色
78
*/
8-
theme?: string | object;
9-
/**
10-
* @title 加载模板
11-
* @description 图表加载
12-
*/
13-
loadingTemplate?: React.ReactElement;
9+
theme?: string;
1410
}
1511

16-
const shadowLoading = (ele: HTMLElement) => {
12+
const shadowLoading = (ele: HTMLElement, style = {}) => {
1713
if (typeof document === 'undefined') {
1814
return 'loading';
1915
}
16+
let overStyle = "";
17+
if (style) {
18+
Object.keys(style).forEach((key) => {
19+
overStyle += `${key}: ${style[key]};\n`;
20+
});
21+
}
2022
const shadowRoot = ele.attachShadow({ mode: 'open' });
2123
const shadowDiv = document.createElement('div');
2224
const shadowStyle = document.createElement('style');
@@ -34,6 +36,7 @@ const shadowLoading = (ele: HTMLElement) => {
3436
border-radius: 50%;
3537
background: #ccc;
3638
animation-timing-function: cubic-bezier(0, 1, 1, 0);
39+
${overStyle}
3740
}
3841
.loading div:nth-child(1) {
3942
left: 8px;
@@ -82,12 +85,13 @@ const shadowLoading = (ele: HTMLElement) => {
8285
shadowRoot.appendChild(shadowDiv);
8386
};
8487

85-
export const ChartLoading = ({ loadingTemplate, theme = 'light' }: ChartLoadingConfig) => {
88+
export const ChartLoading = ({ loadingTemplate, theme = 'light', loading }: ChartLoadingConfig) => {
8689
const shadow = React.useRef<HTMLDivElement>(null);
90+
const { container = {}, icon = {} } = typeof loading === 'object' ? loading : {};
8791

8892
React.useEffect(() => {
8993
if (!loadingTemplate && shadow.current) {
90-
shadowLoading(shadow.current);
94+
shadowLoading(shadow.current, icon);
9195
}
9296
}, []);
9397
const renderLoading = () => {
@@ -108,7 +112,8 @@ export const ChartLoading = ({ loadingTemplate, theme = 'light' }: ChartLoadingC
108112
left: 0,
109113
top: 0,
110114
zIndex: 99,
111-
backgroundColor: theme === 'dark' ? 'rgb(20, 20, 20)' : 'rgb(255, 255, 255)',
115+
background: theme === 'dark' ? 'rgb(20, 20, 20)' : 'rgb(255, 255, 255)',
116+
...container
112117
}}
113118
>
114119
{renderLoading()}

packages/util/src/types.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
export type LoadingStyle = {
2+
/**
3+
* @title icon style
4+
*/
5+
icon?: React.CSSProperties;
6+
/**
7+
* @title container style
8+
*/
9+
container?: React.CSSProperties;
10+
}
111
export interface ContainerConfig {
212
/**
313
* @title 图表样式
@@ -28,7 +38,7 @@ export interface ContainerConfig {
2838
* @description.en_US Is it loading
2939
* @default.en_US false
3040
*/
31-
loading?: boolean;
41+
loading?: boolean | LoadingStyle;
3242
/**
3343
* @title 加载模板
3444
* @description 加载模板

site/examples/statistics/line/demo/basic.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const DemoLine = () => {
1818
data,
1919
xField: 'year',
2020
yField: 'value',
21+
loading: true,
2122
point: {
2223
shapeField: 'square',
2324
sizeField: 4,
@@ -30,8 +31,13 @@ const DemoLine = () => {
3031
style: {
3132
lineWidth: 2,
3233
},
34+
theme: 'dark',
3335
};
34-
return <Line {...config} />;
36+
return (
37+
<div style={{ padding: 100, background: '#000' }}>
38+
<Line {...config} />
39+
</div>
40+
);
3541
};
3642

3743
createRoot(document.getElementById('container')).render(<DemoLine />);

0 commit comments

Comments
 (0)