Skip to content

Commit c749f32

Browse files
authored
docs(DynamicDateRange): add story (#7417)
1 parent 94ca592 commit c749f32

File tree

3 files changed

+138
-2
lines changed

3 files changed

+138
-2
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { ControlsWithNote, DocsHeader, Footer } from '@sb/components';
2+
import { Canvas, Meta } from '@storybook/blocks';
3+
import * as ComponentStories from './DynamicDateRange.stories';
4+
5+
<Meta of={ComponentStories} />
6+
7+
<DocsHeader />
8+
9+
<br />
10+
11+
## Example
12+
13+
<Canvas of={ComponentStories.Default} />
14+
15+
## Properties
16+
17+
<ControlsWithNote of={ComponentStories.Default} />
18+
19+
## More examples
20+
21+
### Value Change
22+
23+
<Canvas of={ComponentStories.ValueChange} />
24+
25+
#### Code
26+
27+
```tsx
28+
function DynamicDateRangeComponent() {
29+
const [selValue, setSelValue] = useState("");
30+
const [convertedDates, setConvertedDates] = useState("");
31+
return (
32+
<>
33+
<DynamicDateRange
34+
onChange={(e) => {
35+
const selectedValue = e.detail.value;
36+
setSelValue(JSON.stringify(selectedValue));
37+
38+
const dates = e.currentTarget.toDates(selectedValue);
39+
setConvertedDates(
40+
dates.map((date) => date.toLocaleString()).join(" - "),
41+
);
42+
}}
43+
/>
44+
<hr />
45+
<FlexBox alignItems="Center" gap="0.5rem">
46+
<Label for="sel-val" showColon>
47+
Selected Value
48+
</Label>
49+
<Input
50+
id="sel-val"
51+
readonly
52+
value={selValue}
53+
style={{ width: "100%", maxWidth: "400px" }}
54+
/>
55+
</FlexBox>
56+
<FlexBox alignItems="Center" gap="0.5rem">
57+
<Label for="conv-val" showColon>
58+
Converted Dates
59+
</Label>
60+
<Input
61+
id="conv-val"
62+
readonly
63+
value={convertedDates}
64+
style={{ width: "100%", maxWidth: "400px" }}
65+
/>
66+
</FlexBox>
67+
</>
68+
);
69+
}
70+
```
71+
72+
<Footer />
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import '@ui5/webcomponents/dist/dynamic-date-range-options/Today.js';
2+
import '@ui5/webcomponents/dist/dynamic-date-range-options/Yesterday.js';
3+
import '@ui5/webcomponents/dist/dynamic-date-range-options/Tomorrow.js';
4+
import '@ui5/webcomponents/dist/dynamic-date-range-options/SingleDate.js';
5+
import '@ui5/webcomponents/dist/dynamic-date-range-options/DateRange.js';
6+
import type { Meta, StoryObj } from '@storybook/react';
7+
import { useState } from 'react';
8+
import { FlexBox } from '../../components/FlexBox/index.js';
9+
import { Input } from '../Input/index.js';
10+
import { Label } from '../Label/index.js';
11+
import { DynamicDateRange } from './index.js';
12+
13+
const meta = {
14+
title: 'Inputs / DynamicDateRange',
15+
component: DynamicDateRange,
16+
argTypes: {},
17+
args: {
18+
options: 'TODAY, TOMORROW, YESTERDAY, DATE, DATERANGE',
19+
},
20+
tags: ['package:@ui5/webcomponents'],
21+
} satisfies Meta<typeof DynamicDateRange>;
22+
23+
export default meta;
24+
type Story = StoryObj<typeof meta>;
25+
26+
export const Default: Story = {};
27+
28+
export const ValueChange: Story = {
29+
render(args) {
30+
const [selValue, setSelValue] = useState('');
31+
const [convertedDates, setConvertedDates] = useState('');
32+
return (
33+
<>
34+
<DynamicDateRange
35+
{...args}
36+
onChange={(e) => {
37+
const selectedValue = e.detail.value;
38+
setSelValue(JSON.stringify(selectedValue));
39+
40+
//@ts-expect-error: `toDates` is available
41+
const dates = e.currentTarget.toDates(selectedValue);
42+
setConvertedDates(dates.map((date) => date.toLocaleString()).join(' - '));
43+
}}
44+
/>
45+
<hr />
46+
<FlexBox alignItems="Center" gap="0.5rem">
47+
<Label for="sel-val" showColon>
48+
Selected Value
49+
</Label>
50+
<Input id="sel-val" readonly value={selValue} style={{ width: '100%', maxWidth: '400px' }} />
51+
</FlexBox>
52+
<FlexBox alignItems="Center" gap="0.5rem">
53+
<Label for="conv-val" showColon>
54+
Converted Dates
55+
</Label>
56+
<Input id="conv-val" readonly value={convertedDates} style={{ width: '100%', maxWidth: '400px' }} />
57+
</FlexBox>
58+
</>
59+
);
60+
},
61+
};

packages/main/src/webComponents/DynamicDateRange/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
'use client';
22

33
import '@ui5/webcomponents/dist/DynamicDateRange.js';
4-
import type { DynamicDateRangeValue } from '@ui5/webcomponents/dist/DynamicDateRange.js';
4+
import type {
5+
DynamicDateRangeChangeEventDetail,
6+
DynamicDateRangeValue,
7+
} from '@ui5/webcomponents/dist/DynamicDateRange.js';
58
import { withWebComponent } from '@ui5/webcomponents-react-base';
69
import type { CommonProps, Ui5CustomEvent, Ui5DomRef } from '@ui5/webcomponents-react-base';
710

@@ -33,7 +36,7 @@ interface DynamicDateRangePropTypes
3336
* | :--------: | :-----: |
3437
* | ✅|✅|
3538
*/
36-
onChange?: (event: Ui5CustomEvent<DynamicDateRangeDomRef>) => void;
39+
onChange?: (event: Ui5CustomEvent<DynamicDateRangeDomRef, DynamicDateRangeChangeEventDetail>) => void;
3740
}
3841

3942
/**

0 commit comments

Comments
 (0)