-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: custom date selector component (#417)
* Add custome date selector * Ensure the same border-radius for both selected and highlighted calendar grid cell when selecting date. * Remove minValue property, as there is no limit to how far back in time a user can go back to report an incident.
- Loading branch information
1 parent
73c2a52
commit a13ee5f
Showing
12 changed files
with
249 additions
and
50 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
src/page-modules/contact/components/form/date-selector.tsx
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,83 @@ | ||
import style from './form.module.css'; | ||
import { MonoIcon } from '@atb/components/icon'; | ||
import { TranslatedString, useTranslation } from '@atb/translations'; | ||
import { fromDate, parseDate } from '@internationalized/date'; | ||
import { | ||
Button, | ||
Calendar, | ||
CalendarCell, | ||
CalendarGrid, | ||
DateInput, | ||
DatePicker, | ||
DateSegment, | ||
Dialog, | ||
Group, | ||
Heading, | ||
Label, | ||
Popover, | ||
} from 'react-aria-components'; | ||
|
||
export type DateSelectorProps = { | ||
label: TranslatedString; | ||
value?: string; | ||
onChange: (value: string) => void; | ||
}; | ||
|
||
export default function DateSelector({ | ||
label, | ||
value, | ||
onChange, | ||
}: DateSelectorProps) { | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<div className={style.dateSelectorContainer}> | ||
<Label>{t(label)}</Label> | ||
<DatePicker | ||
granularity="day" | ||
value={fromDate(new Date(value || ''), 'Europe/Oslo')} | ||
onChange={(e) => onChange(e.toString().slice(0, 10))} | ||
className={style.dateSelector} | ||
shouldForceLeadingZeros | ||
> | ||
<Group className={style.calendarSelectorGroup}> | ||
<DateInput className={style.dateSelectorInput}> | ||
{(segment) => <DateSegment segment={segment} />} | ||
</DateInput> | ||
<Button className={style.calendarButton}> | ||
<MonoIcon icon="time/Date" /> | ||
</Button> | ||
</Group> | ||
<Popover className={style.calendarDialog} placement="bottom right"> | ||
<Dialog> | ||
<Calendar> | ||
<header className={style.calendarDialog__header}> | ||
<Button | ||
slot="previous" | ||
className={style.calendarDialog__headerButtons} | ||
> | ||
<MonoIcon icon="navigation/ArrowLeft" /> | ||
</Button> | ||
<Heading className={style.calendarDialog__title} /> | ||
<Button | ||
slot="next" | ||
className={style.calendarDialog__headerButtons} | ||
> | ||
<MonoIcon icon="navigation/ArrowRight" /> | ||
</Button> | ||
</header> | ||
<CalendarGrid className={style.calendarGrid}> | ||
{(date) => ( | ||
<CalendarCell | ||
date={date} | ||
className={style.calendarGrid__cell} | ||
/> | ||
)} | ||
</CalendarGrid> | ||
</Calendar> | ||
</Dialog> | ||
</Popover> | ||
</DatePicker> | ||
</div> | ||
); | ||
} |
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
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
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.