Skip to content

Commit 38232ee

Browse files
authored
chore(wizard, date picker): update tags and examples from js to ts (#12208)
* chore(wizard, date picker): update tags and examples from js to ts * chore(wizard, date picker): update tags and examples from js to ts
1 parent 097dae1 commit 38232ee

File tree

3 files changed

+53
-53
lines changed

3 files changed

+53
-53
lines changed

packages/react-core/src/demos/DatePicker/DatePicker.md

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,53 +13,7 @@ import { Modal as ModalDeprecated, ModalVariant as ModalVariantDeprecated } from
1313

1414
This is intended to be used as a filter. After selecting a start date, the next date is automatically selected.
1515

16-
```js
17-
import { useState } from 'react';
18-
import { Split, SplitItem, DatePicker, isValidDate, yyyyMMddFormat } from '@patternfly/react-core';
19-
20-
DateRangePicker = () => {
21-
const [from, setFrom] = useState();
22-
const [to, setTo] = useState();
23-
24-
const toValidator = (date) =>
25-
isValidDate(from) && date >= from ? '' : 'The "to" date must be after the "from" date';
26-
27-
const onFromChange = (_event, _value, date) => {
28-
setFrom(new Date(date));
29-
if (isValidDate(date)) {
30-
date.setDate(date.getDate() + 1);
31-
setTo(yyyyMMddFormat(date));
32-
} else {
33-
setTo('');
34-
}
35-
};
36-
37-
const onToChange = (_event, _value, date) => {
38-
if (isValidDate(date)) {
39-
setTo(yyyyMMddFormat(date));
40-
}
41-
};
42-
43-
return (
44-
<Split>
45-
<SplitItem>
46-
<DatePicker onChange={onFromChange} aria-label="Start date" placeholder="YYYY-MM-DD" />
47-
</SplitItem>
48-
<SplitItem style={{ padding: '6px 12px 0 12px' }}>to</SplitItem>
49-
<SplitItem>
50-
<DatePicker
51-
value={to}
52-
onChange={onToChange}
53-
isDisabled={!isValidDate(from)}
54-
rangeStart={from}
55-
validators={[toValidator]}
56-
aria-label="End date"
57-
placeholder="YYYY-MM-DD"
58-
/>
59-
</SplitItem>
60-
</Split>
61-
);
62-
};
16+
```ts file="./examples/DatePickerRange.tsx"
6317
```
6418

6519
### Date and time pickers in modal
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { useState } from 'react';
2+
import { Split, SplitItem, DatePicker, isValidDate, yyyyMMddFormat } from '@patternfly/react-core';
3+
4+
export const DatePickerRange: React.FunctionComponent = () => {
5+
const [from, setFrom] = useState<Date | undefined>();
6+
const [to, setTo] = useState<string>('');
7+
8+
const toValidator = (date: Date) =>
9+
isValidDate(from) && date >= from ? '' : 'The "to" date must be after the "from" date';
10+
11+
const onFromChange = (_event: React.MouseEvent<HTMLElement>, _value: string, date: Date) => {
12+
setFrom(new Date(date));
13+
if (isValidDate(date)) {
14+
date.setDate(date.getDate() + 1);
15+
setTo(yyyyMMddFormat(date));
16+
} else {
17+
setTo('');
18+
}
19+
};
20+
21+
const onToChange = (_event: React.MouseEvent<HTMLElement>, _value: string, date: Date) => {
22+
if (isValidDate(date)) {
23+
setTo(yyyyMMddFormat(date));
24+
}
25+
};
26+
27+
return (
28+
<Split>
29+
<SplitItem>
30+
<DatePicker onChange={onFromChange} aria-label="Start date" placeholder="YYYY-MM-DD" />
31+
</SplitItem>
32+
<SplitItem style={{ padding: '6px 12px 0 12px' }}>to</SplitItem>
33+
<SplitItem>
34+
<DatePicker
35+
value={to}
36+
onChange={onToChange}
37+
isDisabled={!isValidDate(from)}
38+
rangeStart={from}
39+
validators={[toValidator]}
40+
aria-label="End date"
41+
placeholder="YYYY-MM-DD"
42+
/>
43+
</SplitItem>
44+
</Split>
45+
);
46+
};

packages/react-core/src/demos/Wizard/WizardDemo.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@ import { DashboardWrapper } from '@patternfly/react-core/dist/js/demos/Dashboard
1414

1515
### In modal
1616

17-
```js file="../examples/Wizard/InModal.tsx" isFullscreen
17+
```ts file="../examples/Wizard/InModal.tsx" isFullscreen
1818
```
1919

2020
### In modal, with drawer
2121

22-
```js file="../examples/Wizard/InModalWithDrawer.tsx" isFullscreen
22+
```ts file="../examples/Wizard/InModalWithDrawer.tsx" isFullscreen
2323
```
2424

2525
### In modal, with drawer and informational step
2626

27-
```js file="../examples/Wizard/InModalWithDrawerInformationalStep.tsx" isFullscreen
27+
```ts file="../examples/Wizard/InModalWithDrawerInformationalStep.tsx" isFullscreen
2828
```
2929

3030
### In page
3131

32-
```js file="../examples/Wizard/InPage.tsx" isFullscreen
32+
```ts file="../examples/Wizard/InPage.tsx" isFullscreen
3333
```
3434

3535
### In page, with drawer
3636

37-
```js file="../examples/Wizard/InPageWithDrawer.tsx" isFullscreen
37+
```ts file="../examples/Wizard/InPageWithDrawer.tsx" isFullscreen
3838
```
3939

4040
### In page, with drawer and informational step
4141

42-
```js file="../examples/Wizard/InPageWithDrawerInformationalStep.tsx" isFullscreen
42+
```ts file="../examples/Wizard/InPageWithDrawerInformationalStep.tsx" isFullscreen
4343
```

0 commit comments

Comments
 (0)