-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add slot for custom controls in absolute range date picker
- Loading branch information
1 parent
1095cef
commit fd1e578
Showing
12 changed files
with
301 additions
and
80 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import React, { useState } from 'react'; | ||
import startOfWeek from 'date-fns/startOfWeek'; | ||
import endOfWeek from 'date-fns/endOfWeek'; | ||
import startOfMonth from 'date-fns/startOfMonth'; | ||
import endOfMonth from 'date-fns/endOfMonth'; | ||
import enLocale from 'date-fns/locale/en-GB'; | ||
import { Box, DateRangePicker, DateRangePickerProps, Link, FormField } from '~components'; | ||
import { i18nStrings, isValid } from './common'; | ||
import { formatDate } from '~components/internal/utils/date-time'; | ||
|
||
export default function DatePickerScenario() { | ||
const [value, setValue] = useState<DateRangePickerProps['value']>(null); | ||
|
||
return ( | ||
<Box padding="s"> | ||
<h1>Date range picker with custom control</h1> | ||
<FormField label="Date Range Picker field"> | ||
<DateRangePicker | ||
value={value} | ||
onChange={e => setValue(e.detail.value)} | ||
locale={enLocale.code} | ||
i18nStrings={i18nStrings} | ||
relativeOptions={[]} | ||
placeholder="Filter by a date and time range" | ||
isValidRange={isValid} | ||
rangeSelectorMode="absolute-only" | ||
customAbsoluteRangeControl={(selectedDate, setSelectedDate) => ( | ||
<> | ||
Auto-select:{' '} | ||
<Link | ||
onFollow={() => { | ||
const today = formatDate(new Date()); | ||
return setSelectedDate({ | ||
start: { date: today, time: '' }, | ||
end: { date: today, time: '' }, | ||
}); | ||
}} | ||
> | ||
1D | ||
</Link>{' '} | ||
<Link | ||
variant="secondary" | ||
onFollow={() => | ||
setSelectedDate({ | ||
start: { | ||
date: formatDate(startOfWeek(new Date(), { locale: enLocale })), | ||
time: '', | ||
}, | ||
end: { | ||
date: formatDate(endOfWeek(new Date(), { locale: enLocale })), | ||
time: '', | ||
}, | ||
}) | ||
} | ||
> | ||
7D | ||
</Link>{' '} | ||
<Link | ||
onFollow={() => | ||
setSelectedDate({ | ||
start: { date: formatDate(startOfMonth(new Date())), time: '' }, | ||
end: { date: formatDate(endOfMonth(new Date())), time: '' }, | ||
}) | ||
} | ||
> | ||
1M | ||
</Link>{' '} | ||
<Link | ||
onFollow={() => | ||
setSelectedDate({ | ||
start: { date: '', time: '' }, | ||
end: { date: '', time: '' }, | ||
}) | ||
} | ||
> | ||
None | ||
</Link> | ||
</> | ||
)} | ||
/> | ||
</FormField> | ||
</Box> | ||
); | ||
} |
This file contains 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 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 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
Oops, something went wrong.