Skip to content

Commit 8934936

Browse files
authored
docs(charts): improve documentation (React19, ReadMe) (SAP#6756)
1 parent 381e0bc commit 8934936

File tree

7 files changed

+112
-9
lines changed

7 files changed

+112
-9
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import type { CarouselDomRef, CarouselPropTypes } from '@ui5/webcomponents-react';
2+
import { Carousel } from '@ui5/webcomponents-react';
3+
import type { ReactNode } from 'react';
4+
import { useEffect, useRef } from 'react';
5+
6+
export function StoryCarousel(props: Omit<CarouselPropTypes, 'children'> & { children: ReactNode[] }) {
7+
const { children } = props;
8+
const carouselRef = useRef<CarouselDomRef>(null);
9+
const counter = useRef(0);
10+
const intervalRef = useRef<NodeJS.Timeout | null>(null);
11+
12+
const cleanUpInterval = () => {
13+
if (intervalRef.current) {
14+
clearInterval(intervalRef.current);
15+
intervalRef.current = null;
16+
}
17+
};
18+
19+
useEffect(() => {
20+
const carousel = carouselRef.current;
21+
if (carousel && children.length) {
22+
intervalRef.current = setInterval(() => {
23+
counter.current++;
24+
carousel.navigateTo(counter.current % children.length);
25+
}, 5000);
26+
}
27+
28+
return () => {
29+
cleanUpInterval();
30+
};
31+
}, [children]);
32+
33+
return (
34+
<Carousel
35+
style={{ height: '500px' }}
36+
arrowsPlacement="Navigation"
37+
cyclic
38+
ref={carouselRef}
39+
onNavigate={() => {
40+
cleanUpInterval();
41+
}}
42+
{...props}
43+
/>
44+
);
45+
}

.storybook/preview-head.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
}
3131

3232
.sbdocs-wrapper {
33+
background-color: var(--sapBackgroundColor);
3334
padding-top: 2rem !important;
3435
}
3536

.storybook/preview.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import '@ui5/webcomponents-icons/dist/AllIcons.js';
22
import '@ui5/webcomponents-base/dist/features/F6Navigation.js';
3-
import { Preview } from '@storybook/react';
3+
import type { Preview } from '@storybook/react';
44
import { setLanguage } from '@ui5/webcomponents-base/dist/config/Language.js';
55
import { setTheme } from '@ui5/webcomponents-base/dist/config/Theme.js';
66
import applyDirection from '@ui5/webcomponents-base/dist/locale/applyDirection.js';
@@ -143,6 +143,7 @@ const preview: Preview = {
143143
'Testing with Cypress',
144144
['Setup', 'Commands', 'Queries'],
145145
'Charts',
146+
['Docs'],
146147
'Data Display',
147148
'Inputs',
148149
'Layouts & Floorplans',

docs/ReadMeCharts.mdx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { Footer, TableOfContent } from '@sb/components';
2+
import { Markdown, Meta, Story } from '@storybook/blocks';
3+
import ReadMe from '../packages/charts/README.md?raw';
4+
import { StoryCarousel } from '@sb/components/StoryCarousel.tsx';
5+
import { Default as BarDefault } from '../packages/charts/src/components/BarChart/BarChart.stories.tsx';
6+
import { Default as BulletDefault } from '../packages/charts/src/components/BulletChart/BulletChart.stories.tsx';
7+
import { Default as ColumnDefault } from '../packages/charts/src/components/ColumnChart/ColumnChart.stories.tsx';
8+
import { Default as ColumnTrendDefault } from '../packages/charts/src/components/ColumnChartWithTrend/ColumnChartWithTrend.stories.tsx';
9+
import { Default as ComposedDefault } from '../packages/charts/src/components/ComposedChart/ComposedChart.stories.tsx';
10+
import { Default as DonutDefault } from '../packages/charts/src/components/DonutChart/DonutChart.stories.tsx';
11+
import { Default as LineDefault } from '../packages/charts/src/components/LineChart/LineChart.stories.tsx';
12+
import { Default as PieDefault } from '../packages/charts/src/components/PieChart/PieChart.stories.tsx';
13+
import { Default as RadarDefault } from '../packages/charts/src/components/RadarChart/RadarChart.stories.tsx';
14+
import { Default as RadialDefault } from '../packages/charts/src/components/RadialChart/RadialChart.stories.tsx';
15+
import { Default as ScatterDefault } from '../packages/charts/src/components/ScatterChart/ScatterChart.stories.tsx';
16+
import { Title } from '@ui5/webcomponents-react';
17+
18+
<Meta title="Charts / Docs" />
19+
20+
<TableOfContent />
21+
22+
<Markdown>{ReadMe.split('## Documentation')[0].trim()}</Markdown>
23+
24+
## Charts
25+
26+
<StoryCarousel>
27+
{[
28+
{ name: 'BarChart', component: BarDefault },
29+
{ name: 'BulletChart', component: BulletDefault },
30+
{ name: 'ColumnChart', component: ColumnDefault },
31+
{ name: 'ColumnChartWithTrend', component: ColumnTrendDefault },
32+
{ name: 'ComposedChart', component: ComposedDefault },
33+
{ name: 'DonutChart', component: DonutDefault },
34+
{ name: 'LineChart', component: LineDefault },
35+
{ name: 'PieChart', component: PieDefault },
36+
{ name: 'RadarChart', component: RadarDefault },
37+
{ name: 'RadialChart', component: RadialDefault },
38+
{ name: 'ScatterChart', component: ScatterDefault }
39+
//TimelineChart doesn't render in `Story` here
40+
].map((chart) => {
41+
return (
42+
<div style={{ width: '100%' }} key={chart.name}>
43+
<Title>{chart.name}</Title>
44+
<Story of={chart.component} />
45+
</div>
46+
);
47+
})}
48+
</StoryCarousel>
49+
50+
<Footer />

packages/charts/README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
# @ui5/webcomponents-react-charts
22

3-
Chart library for ui5-webcomponents-react.
3+
Chart library built on top of [recharts](https://recharts.org/) for ui5-webcomponents-react.
44

5-
## Usage
6-
7-
### Installation
5+
## Installation
86

97
```bash
108
npm install @ui5/webcomponents-react-charts
119
```
1210

13-
### Documentation
11+
## Accessibility
12+
13+
Charts only offer limited accessibility support with only basic built-in features, so it’s essential to ensure your implementation meets the accessibility standards of your application.
14+
15+
## React 19 support
16+
17+
To use this library with React 19 you have to override your `react-is` version to match your React version!
18+
19+
## Documentation
1420

1521
You can find an interactive documentation in our [Storybook](https://sap.github.io/ui5-webcomponents-react/).
1622

packages/charts/src/components/TimelineChart/TimeLineChart.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ const meta = {
1212
dataset: {
1313
control: { disable: true }
1414
}
15-
}
15+
},
16+
args: { dataset: dummyDiscreteDataSet }
1617
} satisfies Meta<typeof TimelineChart>;
1718

1819
export default meta;
1920
type Story = StoryObj<typeof meta>;
2021

2122
export const Default: Story = {
2223
args: {
23-
dataset: dummyDiscreteDataSet,
2424
totalDuration: 36,
2525
isDiscrete: true,
2626
start: 1,

packages/charts/src/components/TimelineChart/TimelineChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
import { IllegalConnectionError, InvalidDiscreteLabelError } from './util/error.js';
2121
import { classNames, styleData } from './util/TimelineChart.module.css.js';
2222

23-
interface TimelineChartProps extends CommonProps {
23+
export interface TimelineChartProps extends CommonProps {
2424
/**
2525
* The data is an array of objects that is displayed on the chart.
2626
*/

0 commit comments

Comments
 (0)