-
Notifications
You must be signed in to change notification settings - Fork 12
DateRangePicker: add ability to use predefined ranges #608
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
ba013ae
mostly works, need to clean things up
hoorayimhelping 5756ae8
ability to go forward or backwards
hoorayimhelping 1392a4e
Add testids to prev and next month buttons
hoorayimhelping 5e435ed
Add tests
hoorayimhelping 1a68477
cleanup
hoorayimhelping 9f7bd4a
got styling kinda working i guess
hoorayimhelping c484cd0
DateRangePicker allows arbitrary dates; scrollable date list
hoorayimhelping 134b6d4
Add max range length
hoorayimhelping caf5df7
Add futureStartDatesDisabled
hoorayimhelping d27998e
Cleanup and tests
hoorayimhelping b58e2dc
review: use autodocs properly
hoorayimhelping b082866
review: no loafing
hoorayimhelping 07d369a
review: fix datesAreWithinMaxRange, add it to utils, add tests
hoorayimhelping 1995b3d
review: update shadow and border radius
hoorayimhelping aadb26e
review: update isDateRangeTheWholeMonth
hoorayimhelping 9051dcb
Review: export DateRangePicker properly
hoorayimhelping be605b8
Rename function
hoorayimhelping 8f9a533
prettify
hoorayimhelping ceb1089
Fix failing test (circular imports)
hoorayimhelping File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,182 @@ | ||
import { Args } from "@storybook/react"; | ||
import { Args, Meta, StoryObj } from "@storybook/react"; | ||
import { DateRangePicker } from "./DateRangePicker"; | ||
import { getPredefinedMonthsForDateRangePicker } from "./utils"; | ||
|
||
const defaultStory = { | ||
const meta: Meta<typeof DateRangePicker> = { | ||
component: DateRangePicker, | ||
args: { | ||
maxRangeLength: undefined, | ||
onSelectDateRange: (startDate: Date, endDate: Date) => { | ||
console.log("Date range selected: ", startDate, endDate); | ||
}, | ||
}, | ||
argTypes: { | ||
startDate: { | ||
control: "date", | ||
}, | ||
endDate: { | ||
control: "date", | ||
}, | ||
futureDatesDisabled: { | ||
control: "boolean", | ||
}, | ||
placeholder: { | ||
control: "text", | ||
}, | ||
onSelectDateRange: { | ||
control: "object", | ||
}, | ||
tags: ["autodocs"], | ||
title: "Display/DateRangePicker", | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
predefinedDatesList: [], | ||
}, | ||
component: DateRangePicker, | ||
render: (args: Args) => { | ||
const endDate = args.endDate ? new Date(args.endDate) : undefined; | ||
const startDate = args.startDate ? new Date(args.startDate) : undefined; | ||
|
||
return ( | ||
<DateRangePicker | ||
key="default" | ||
endDate={endDate} | ||
disabled={args.disabled} | ||
futureDatesDisabled={args.futureDatesDisabled} | ||
futureStartDatesDisabled={args.futureStartDatesDisabled} | ||
maxRangeLength={args.maxRangeLength} | ||
onSelectDateRange={args.onSelectDateRange} | ||
placeholder={args.placeholder} | ||
startDate={startDate} | ||
/> | ||
); | ||
}, | ||
title: "Display/DateRangePicker", | ||
tags: ["autodocs"], | ||
}; | ||
|
||
export default defaultStory; | ||
export const DateRangeWithMaxRange: Story = { | ||
args: { | ||
maxRangeLength: 15, | ||
predefinedDatesList: [], | ||
}, | ||
render: (args: Args) => { | ||
const endDate = args.endDate ? new Date(args.endDate) : undefined; | ||
const startDate = args.startDate ? new Date(args.startDate) : undefined; | ||
|
||
export const Playground = { | ||
...defaultStory, | ||
return ( | ||
<DateRangePicker | ||
key="default" | ||
endDate={endDate} | ||
disabled={args.disabled} | ||
futureDatesDisabled={args.futureDatesDisabled} | ||
futureStartDatesDisabled={args.futureStartDatesDisabled} | ||
maxRangeLength={args.maxRangeLength} | ||
onSelectDateRange={args.onSelectDateRange} | ||
placeholder={args.placeholder} | ||
startDate={startDate} | ||
/> | ||
); | ||
}, | ||
}; | ||
|
||
export const DateRangeFutureStartDatesDisabled: Story = { | ||
args: { | ||
futureStartDatesDisabled: true, | ||
predefinedDatesList: [], | ||
}, | ||
}; | ||
|
||
export const PredefinedDatesLastSixMonths: Story = { | ||
render: (args: Args) => { | ||
const endDate = args.endDate ? new Date(args.endDate) : undefined; | ||
const startDate = args.startDate ? new Date(args.startDate) : undefined; | ||
const predefinedDatesList = getPredefinedMonthsForDateRangePicker(-6); | ||
|
||
return ( | ||
<DateRangePicker | ||
key="default" | ||
endDate={endDate} | ||
disabled={args.disabled} | ||
futureDatesDisabled={args.futureDatesDisabled} | ||
futureStartDatesDisabled={args.futureStartDatesDisabled} | ||
maxRangeLength={args.maxRangeLength} | ||
onSelectDateRange={args.onSelectDateRange} | ||
placeholder={args.placeholder} | ||
predefinedDatesList={predefinedDatesList} | ||
startDate={startDate} | ||
/> | ||
); | ||
}, | ||
}; | ||
|
||
export const PredefinedDatesNextSixMonths: Story = { | ||
render: (args: Args) => { | ||
const endDate = args.endDate ? new Date(args.endDate) : undefined; | ||
const startDate = args.startDate ? new Date(args.startDate) : undefined; | ||
const predefinedDatesList = getPredefinedMonthsForDateRangePicker(6); | ||
|
||
return ( | ||
<DateRangePicker | ||
key="default" | ||
endDate={endDate} | ||
disabled={args.disabled} | ||
futureDatesDisabled={args.futureDatesDisabled} | ||
futureStartDatesDisabled={args.futureStartDatesDisabled} | ||
maxRangeLength={args.maxRangeLength} | ||
onSelectDateRange={args.onSelectDateRange} | ||
placeholder={args.placeholder} | ||
predefinedDatesList={predefinedDatesList} | ||
startDate={startDate} | ||
/> | ||
); | ||
}, | ||
}; | ||
|
||
export const PredefinedDatesArbitraryDates: Story = { | ||
render: (args: Args) => { | ||
const endDate = args.endDate ? new Date(args.endDate) : undefined; | ||
const startDate = args.startDate ? new Date(args.startDate) : undefined; | ||
const predefinedDatesList = [ | ||
{ startDate: new Date("04/14/2025"), endDate: new Date("05/14/2025") }, | ||
{ startDate: new Date("05/14/2025"), endDate: new Date("06/14/2025") }, | ||
{ startDate: new Date("06/14/2025"), endDate: new Date("07/14/2025") }, | ||
]; | ||
|
||
return ( | ||
<DateRangePicker | ||
key="default" | ||
endDate={endDate} | ||
disabled={args.disabled} | ||
futureDatesDisabled={args.futureDatesDisabled} | ||
futureStartDatesDisabled={args.futureStartDatesDisabled} | ||
maxRangeLength={args.maxRangeLength} | ||
onSelectDateRange={args.onSelectDateRange} | ||
placeholder={args.placeholder} | ||
predefinedDatesList={predefinedDatesList} | ||
startDate={startDate} | ||
/> | ||
); | ||
}, | ||
}; | ||
|
||
export const PredefinedDatesScrollable: Story = { | ||
render: (args: Args) => { | ||
const endDate = args.endDate ? new Date(args.endDate) : undefined; | ||
const startDate = args.startDate ? new Date(args.startDate) : undefined; | ||
const predefinedDatesList = [ | ||
{ startDate: new Date("09/14/2024"), endDate: new Date("10/14/2024") }, | ||
{ startDate: new Date("10/14/2024"), endDate: new Date("11/14/2024") }, | ||
{ startDate: new Date("11/14/2024"), endDate: new Date("12/14/2024") }, | ||
{ startDate: new Date("12/14/2024"), endDate: new Date("01/14/2025") }, | ||
{ startDate: new Date("01/14/2025"), endDate: new Date("02/14/2025") }, | ||
{ startDate: new Date("02/14/2025"), endDate: new Date("03/14/2025") }, | ||
{ startDate: new Date("03/14/2025"), endDate: new Date("04/14/2025") }, | ||
{ startDate: new Date("04/14/2025"), endDate: new Date("05/14/2025") }, | ||
{ startDate: new Date("05/14/2025"), endDate: new Date("06/14/2025") }, | ||
{ startDate: new Date("06/14/2025"), endDate: new Date("07/14/2025") }, | ||
]; | ||
|
||
return ( | ||
<DateRangePicker | ||
key="default" | ||
endDate={endDate} | ||
disabled={args.disabled} | ||
futureDatesDisabled={args.futureDatesDisabled} | ||
futureStartDatesDisabled={args.futureStartDatesDisabled} | ||
maxRangeLength={args.maxRangeLength} | ||
onSelectDateRange={args.onSelectDateRange} | ||
placeholder={args.placeholder} | ||
predefinedDatesList={predefinedDatesList} | ||
startDate={startDate} | ||
/> | ||
); | ||
}, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.