Skip to content

Commit b5fbe34

Browse files
authored
docs(Loader): add JSDoc comments, enhance story (#930)
1 parent 47365ce commit b5fbe34

File tree

3 files changed

+141
-25
lines changed

3 files changed

+141
-25
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs/blocks';
2+
import { Loader } from '@ui5/webcomponents-react/lib/Loader';
3+
import { LoaderType } from '@ui5/webcomponents-react/lib/LoaderType';
4+
import { Card } from '@ui5/webcomponents-react/lib/Card';
5+
import { Text } from '@ui5/webcomponents-react/lib/Text';
6+
import { Icon } from '@ui5/webcomponents-react/lib/Icon';
7+
import { FlexBox } from '@ui5/webcomponents-react/lib/FlexBox';
8+
import { FlexBoxDirection } from '@ui5/webcomponents-react/lib/FlexBoxDirection';
9+
import { createSelectArgTypes } from '@shared/stories/createSelectArgTypes';
10+
import { DocsHeader } from '@shared/stories/DocsHeader';
11+
import { DocsCommonProps } from '@shared/stories/DocsCommonProps';
12+
import { spacing } from '@ui5/webcomponents-react-base';
13+
import '@ui5/webcomponents-icons/dist/icons/activate.js';
14+
import { useEffect, useRef, useState } from 'react';
15+
16+
<Meta
17+
title="Components / Loader"
18+
component={Loader}
19+
argTypes={{
20+
...createSelectArgTypes({ type: LoaderType }),
21+
...DocsCommonProps
22+
}}
23+
args={{
24+
type: LoaderType.Indeterminate,
25+
progress: '60%',
26+
style: {},
27+
className: '',
28+
tooltip: '',
29+
slot: '',
30+
ref: null
31+
}}
32+
/>
33+
34+
<DocsHeader />
35+
36+
<Canvas>
37+
<Story name="Default">
38+
{(args) => {
39+
return <Loader {...args} />;
40+
}}
41+
</Story>
42+
</Canvas>
43+
44+
<ArgsTable story="." />
45+
46+
<br />
47+
48+
# Stories
49+
50+
<br />
51+
52+
## Card with Loader
53+
54+
<Canvas>
55+
<Story name="with Card">
56+
{(args) => {
57+
const initialText =
58+
'This is a text that will be updated 5 seconds after the header is clicked. The text will be visible until the new text has been fetched. To let the user know that the text is updating, the Loader will be displayed.';
59+
const [text, setText] = useState(initialText);
60+
const [loading, setLoading] = useState(false);
61+
const counter = useRef(0);
62+
const onHeaderClick = () => {
63+
setLoading(true);
64+
};
65+
useEffect(() => {
66+
if (loading) {
67+
setTimeout(() => {
68+
if (counter.current < 10) {
69+
setText((prev) => (prev === initialText ? 'Updated (⌐■_■)' : initialText));
70+
} else {
71+
setText('You really must be bored ಠ_ಠ');
72+
}
73+
counter.current++;
74+
setLoading(false);
75+
}, 5000);
76+
}
77+
}, [loading]);
78+
return (
79+
<Card
80+
avatar={<Icon name="activate" />}
81+
heading="Click the header to update the text below."
82+
headerInteractive
83+
style={{ width: '400px' }}
84+
onHeaderClick={onHeaderClick}
85+
>
86+
<FlexBox direction={FlexBoxDirection.Column}>
87+
{loading && <Loader {...args} />}
88+
<Text style={spacing.sapUiContentPadding}>{text}</Text>
89+
</FlexBox>
90+
</Card>
91+
);
92+
}}
93+
</Story>
94+
</Canvas>
95+
96+
```jsx
97+
const LoaderComponent = () => {
98+
const initialText =
99+
'This is a text that will be updated 5 seconds after the header is clicked. The text will be visible until the new text has been fetched. To let the user know that the text is updating, the Loader will be displayed.';
100+
const [text, setText] = useState(initialText);
101+
const [loading, setLoading] = useState(false);
102+
const onHeaderClick = () => {
103+
setLoading(true);
104+
};
105+
useEffect(() => {
106+
if (loading) {
107+
setTimeout(() => {
108+
setText((prev) => (prev === initialText ? 'Updated (⌐■_■)' : initialText));
109+
setLoading(false);
110+
}, 5000);
111+
}
112+
}, [loading]);
113+
return (
114+
<Card
115+
avatar={<Icon name="activate" />}
116+
heading="Click the header to update the text below."
117+
headerInteractive
118+
style={{ width: '400px' }}
119+
onHeaderClick={onHeaderClick}
120+
>
121+
<FlexBox direction={FlexBoxDirection.Column}>
122+
{loading && <Loader />}
123+
<Text style={spacing.sapUiContentPadding}>{text}</Text>
124+
</FlexBox>
125+
</Card>
126+
);
127+
};
128+
```

packages/main/src/components/Loader/demo.stories.tsx

Lines changed: 0 additions & 23 deletions
This file was deleted.

packages/main/src/components/Loader/index.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,27 @@ import { CommonProps } from '../../interfaces/CommonProps';
99
import { styles } from './Loader.jss';
1010

1111
export interface LoaderProps extends CommonProps {
12-
/*
12+
/**
1313
* Delay in ms until the Loader will be displayed
1414
*/
1515
delay?: number;
16+
/**
17+
* Defines the type of the `Loader`.
18+
* __Note:__ If the process completion rate can be detected the `Determinate` type should be used.
19+
*/
1620
type?: LoaderType;
21+
/**
22+
* Defines the progress of the Loader Bar. <br />
23+
* __Note:__ This prop has no effect if used with type `Indeterminate`.
24+
*/
1725
progress?: CSSProperties['width'];
1826
}
1927

2028
const useStyles = createComponentStyles(styles, { name: 'Loader' });
21-
29+
/**
30+
* The `Loader` signals that an operation is currently being executed. It uses as little space as possible to allow the user to interact with the UI.<br />
31+
* It can be used to signal a data update on an already existing dataset, or where an expansion will happen.
32+
*/
2233
const Loader: FC<LoaderProps> = forwardRef((props: LoaderProps, ref: RefObject<HTMLDivElement>) => {
2334
const { className, type, progress, tooltip, slot, style, delay } = props;
2435
const classes = useStyles(props);

0 commit comments

Comments
 (0)