-
Notifications
You must be signed in to change notification settings - Fork 377
chore(wizard, date picker): update tags and examples from js to ts #12208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,46 @@ | ||||||||||||||||||||||||||||||||||||||||
| import { useState } from 'react'; | ||||||||||||||||||||||||||||||||||||||||
| import { Split, SplitItem, DatePicker, isValidDate, yyyyMMddFormat } from '@patternfly/react-core'; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| export const DatePickerRange: React.FunctionComponent = () => { | ||||||||||||||||||||||||||||||||||||||||
| const [from, setFrom] = useState<Date | undefined>(); | ||||||||||||||||||||||||||||||||||||||||
| const [to, setTo] = useState<string>(''); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| const toValidator = (date: Date) => | ||||||||||||||||||||||||||||||||||||||||
| isValidDate(from) && date >= from ? '' : 'The "to" date must be after the "from" date'; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| const onFromChange = (_event: React.MouseEvent<HTMLElement>, _value: string, date: Date) => { | ||||||||||||||||||||||||||||||||||||||||
| setFrom(new Date(date)); | ||||||||||||||||||||||||||||||||||||||||
| if (isValidDate(date)) { | ||||||||||||||||||||||||||||||||||||||||
| date.setDate(date.getDate() + 1); | ||||||||||||||||||||||||||||||||||||||||
| setTo(yyyyMMddFormat(date)); | ||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||
| setTo(''); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+11
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid mutating the input Line 14 mutates the 🔧 Proposed fix const onFromChange = (_event: React.MouseEvent<HTMLElement>, _value: string, date: Date) => {
setFrom(new Date(date));
if (isValidDate(date)) {
- date.setDate(date.getDate() + 1);
- setTo(yyyyMMddFormat(date));
+ const nextDay = new Date(date);
+ nextDay.setDate(nextDay.getDate() + 1);
+ setTo(yyyyMMddFormat(nextDay));
} else {
setTo('');
}
};📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| const onToChange = (_event: React.MouseEvent<HTMLElement>, _value: string, date: Date) => { | ||||||||||||||||||||||||||||||||||||||||
| if (isValidDate(date)) { | ||||||||||||||||||||||||||||||||||||||||
| setTo(yyyyMMddFormat(date)); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||
| <Split> | ||||||||||||||||||||||||||||||||||||||||
| <SplitItem> | ||||||||||||||||||||||||||||||||||||||||
| <DatePicker onChange={onFromChange} aria-label="Start date" placeholder="YYYY-MM-DD" /> | ||||||||||||||||||||||||||||||||||||||||
| </SplitItem> | ||||||||||||||||||||||||||||||||||||||||
| <SplitItem style={{ padding: '6px 12px 0 12px' }}>to</SplitItem> | ||||||||||||||||||||||||||||||||||||||||
| <SplitItem> | ||||||||||||||||||||||||||||||||||||||||
| <DatePicker | ||||||||||||||||||||||||||||||||||||||||
| value={to} | ||||||||||||||||||||||||||||||||||||||||
| onChange={onToChange} | ||||||||||||||||||||||||||||||||||||||||
| isDisabled={!isValidDate(from)} | ||||||||||||||||||||||||||||||||||||||||
| rangeStart={from} | ||||||||||||||||||||||||||||||||||||||||
| validators={[toValidator]} | ||||||||||||||||||||||||||||||||||||||||
| aria-label="End date" | ||||||||||||||||||||||||||||||||||||||||
| placeholder="YYYY-MM-DD" | ||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||
| </SplitItem> | ||||||||||||||||||||||||||||||||||||||||
| </Split> | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.