Skip to content

Commit 7cfa0c8

Browse files
committed
refactor(charts): remove @ui5/webcomponents-react peer dep
1 parent afff6de commit 7cfa0c8

4 files changed

Lines changed: 96 additions & 26 deletions

File tree

packages/charts/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@
131131
"recharts": "2.15.4"
132132
},
133133
"peerDependencies": {
134-
"@ui5/webcomponents-react": "~2.21.0",
135134
"@ui5/webcomponents-react-base": "~2.21.0",
136135
"react": "^18 || ^19"
137136
},
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { useEffect, useState } from 'react';
2+
import { classNames } from './ChartContainer.module.css.js';
3+
4+
interface ChartBusyIndicatorProps {
5+
delay: number;
6+
className?: string;
7+
}
8+
9+
function ChartBusyIndicator({ delay, className }: ChartBusyIndicatorProps) {
10+
const [visible, setVisible] = useState(delay <= 0);
11+
12+
useEffect(() => {
13+
if (delay <= 0) {
14+
return;
15+
}
16+
const id = setTimeout(() => setVisible(true), delay);
17+
return () => clearTimeout(id);
18+
}, [delay]);
19+
20+
if (!visible) {
21+
return null;
22+
}
23+
24+
return (
25+
<div
26+
className={className}
27+
role="progressbar"
28+
aria-label="Please wait"
29+
aria-valuemin={0}
30+
aria-valuemax={100}
31+
aria-valuetext="Busy"
32+
>
33+
<div className={classNames.busyIndicatorCircles}>
34+
<span className={`${classNames.busyIndicatorCircle} ${classNames.circleAnimation0}`} />
35+
<span className={`${classNames.busyIndicatorCircle} ${classNames.circleAnimation1}`} />
36+
<span className={`${classNames.busyIndicatorCircle} ${classNames.circleAnimation2}`} />
37+
</div>
38+
</div>
39+
);
40+
}
41+
42+
export { ChartBusyIndicator };

packages/charts/src/internal/ChartContainer.module.css

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,62 @@
88
position: relative;
99
}
1010

11+
.errorMessage {
12+
font-family: var(--sapFontFamily);
13+
font-size: var(--sapFontSize);
14+
color: var(--sapContent_LabelColor);
15+
}
16+
1117
.busyIndicator {
1218
background-color: color-mix(in srgb, var(--sapBackgroundColor) 45%, transparent);
1319
position: absolute;
1420
inset: 0;
1521
height: 100%;
1622
z-index: 1;
23+
display: flex;
24+
justify-content: center;
25+
align-items: center;
26+
}
27+
28+
.busyIndicatorCircles {
29+
line-height: 0;
30+
}
31+
32+
.busyIndicatorCircle {
33+
display: inline-block;
34+
width: 1rem;
35+
height: 1rem;
36+
border-radius: 50%;
37+
background-color: var(--sapContent_BusyColor);
38+
}
39+
40+
.busyIndicatorCircle:not(:last-child) {
41+
margin-inline-end: 0.1875rem;
42+
}
43+
44+
.circleAnimation0 {
45+
animation: grow 1.6s infinite cubic-bezier(0.32, 0.06, 0.85, 1.11);
46+
}
47+
48+
.circleAnimation1 {
49+
animation: grow 1.6s infinite cubic-bezier(0.32, 0.06, 0.85, 1.11);
50+
animation-delay: 0.2s;
51+
}
52+
53+
.circleAnimation2 {
54+
animation: grow 1.6s infinite cubic-bezier(0.32, 0.06, 0.85, 1.11);
55+
animation-delay: 0.4s;
56+
}
57+
58+
@keyframes grow {
59+
0%,
60+
50%,
61+
100% {
62+
transform: scale(0.5);
63+
}
64+
25% {
65+
transform: scale(1);
66+
}
1767
}
1868

1969
:global(.has-click-handler) {

packages/charts/src/internal/ChartContainer.tsx

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
1-
import { BusyIndicator } from '@ui5/webcomponents-react/BusyIndicator';
2-
import { Label } from '@ui5/webcomponents-react/Label';
31
import { useStylesheet } from '@ui5/webcomponents-react-base/internal/hooks';
42
import type { CommonProps } from '@ui5/webcomponents-react-base/internal/types';
5-
import { addCustomCSSWithScoping } from '@ui5/webcomponents-react-base/internal/utils';
63
import { clsx } from 'clsx';
74
import type { ComponentType, ReactElement, ReactNode } from 'react';
85
import { Component, forwardRef } from 'react';
96
import { ResponsiveContainer } from 'recharts';
7+
import { ChartBusyIndicator } from './ChartBusyIndicator.js';
108
import { classNames, styleData } from './ChartContainer.module.css.js';
119

12-
addCustomCSSWithScoping(
13-
'ui5-busy-indicator',
14-
`
15-
:host([data-component-name="ChartContainerBusyIndicator"]) .ui5-busy-indicator-busy-area{
16-
background:unset;
17-
},
18-
:host([data-component-name="ChartContainerBusyIndicator"]) .ui5-busy-indicator-busy-area:focus {
19-
border-radius: 0;
20-
}
21-
`,
22-
);
23-
2410
export interface ContainerProps extends CommonProps {
2511
children: ReactElement;
2612
Placeholder: ComponentType;
@@ -43,7 +29,7 @@ class ErrorBoundary extends Component<{ children: ReactNode }, { errorCount: num
4329

4430
render() {
4531
if (this.state.errorCount >= 3) {
46-
return <Label>Sorry, something went wrong while rendering this chart!</Label>;
32+
return <span className={classNames.errorMessage}>Sorry, something went wrong while rendering this chart!</span>;
4733
}
4834
return this.props.children;
4935
}
@@ -58,7 +44,7 @@ const ChartContainer = forwardRef<HTMLDivElement, ContainerProps>((props, ref) =
5844
slot,
5945
children,
6046
resizeDebounce,
61-
loadingDelay,
47+
loadingDelay = 1000,
6248
...rest
6349
} = props;
6450

@@ -68,14 +54,7 @@ const ChartContainer = forwardRef<HTMLDivElement, ContainerProps>((props, ref) =
6854
<div ref={ref} className={clsx(classNames.container, className)} slot={slot} {...rest}>
6955
{dataset?.length > 0 ? (
7056
<>
71-
{loading && (
72-
<BusyIndicator
73-
active
74-
delay={loadingDelay}
75-
className={classNames.busyIndicator}
76-
data-component-name="ChartContainerBusyIndicator"
77-
/>
78-
)}
57+
{loading && <ChartBusyIndicator delay={loadingDelay} className={classNames.busyIndicator} />}
7958
<ErrorBoundary>
8059
<ResponsiveContainer debounce={resizeDebounce}>{children}</ResponsiveContainer>
8160
</ErrorBoundary>

0 commit comments

Comments
 (0)