uikit-react-public 0.11.20 → 0.14.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Badge/Badge.d.ts +6 -0
- package/dist/components/Badge/Badge.stories.d.ts +15 -0
- package/dist/components/Badge/index.d.ts +2 -0
- package/dist/components/Button/Button.d.ts +2 -1
- package/dist/components/Calendar/Calendar.d.ts +3 -0
- package/dist/components/Calendar/Calendar.stories.d.ts +42 -0
- package/dist/components/Calendar/Calendar.types.d.ts +18 -0
- package/dist/components/Calendar/index.d.ts +2 -0
- package/dist/components/Calendar/subcomponents/AcademicWeeks.d.ts +7 -0
- package/dist/components/Calendar/subcomponents/ColumnHeading.d.ts +7 -0
- package/dist/components/Calendar/subcomponents/Controls.d.ts +6 -0
- package/dist/components/{Datepicker/subcomponents/Day → Calendar/subcomponents}/Day.d.ts +3 -3
- package/dist/components/{Datepicker → Calendar}/subcomponents/EventDot.d.ts +2 -2
- package/dist/components/Calendar/subcomponents/Grid.d.ts +11 -0
- package/dist/components/Calendar/subcomponents/index.d.ts +7 -0
- package/dist/components/{Datepicker → Calendar}/utils/getAcademicWeekNumbers/getAcademicWeekNumbers.d.ts +1 -1
- package/dist/components/Calendar/utils/index.d.ts +4 -0
- package/dist/components/Calendar/utils/normaliseMonth/normaliseMonth.d.ts +9 -0
- package/dist/components/Calendar/utils/parseDateFromString/parseDateFromString.d.ts +9 -0
- package/dist/components/Calendar/utils/parseDateFromString/parseDateFromString.test.d.ts +1 -0
- package/dist/components/CookieNotice/CookieNotice.d.ts +16 -0
- package/dist/components/CookieNotice/index.d.ts +2 -0
- package/dist/components/Datepicker/Datepicker.d.ts +3 -16
- package/dist/components/Datepicker/Datepicker.stories.d.ts +9 -3
- package/dist/components/Datepicker/Datepicker.types.d.ts +23 -7
- package/dist/components/Datepicker/index.d.ts +1 -2
- package/dist/components/Datepicker/subcomponents/CustomDatepicker.d.ts +17 -0
- package/dist/components/Datepicker/subcomponents/DatepickerInput.d.ts +10 -0
- package/dist/components/Datepicker/subcomponents/NativeDatepicker.d.ts +6 -0
- package/dist/components/Datepicker/subcomponents/Panel.d.ts +6 -0
- package/dist/components/Datepicker/subcomponents/VisibleField.d.ts +12 -0
- package/dist/components/Datepicker/subcomponents/index.d.ts +5 -7
- package/dist/components/Datepicker/utils/dateToLocaleISOString/dateToLocaleISOString.d.ts +17 -0
- package/dist/components/Datepicker/utils/dateToLocaleISOString/dateToLocaleISOString.test.d.ts +1 -0
- package/dist/components/Datepicker/utils/index.d.ts +2 -3
- package/dist/components/Datepicker/utils/parseInputValue/parseInputValue.d.ts +11 -0
- package/dist/components/Datepicker/utils/parseInputValue/parseInputValue.test.d.ts +1 -0
- package/dist/components/Dialog/BaseDialog.d.ts +7 -2
- package/dist/components/FileInput/FileInput.d.ts +8 -0
- package/dist/components/FileInput/FileInput.stories.d.ts +16 -0
- package/dist/components/FileInput/__tests__/FileInput.test.d.ts +1 -0
- package/dist/components/FileInput/index.d.ts +2 -0
- package/dist/components/Footer/Footer.d.ts +1 -1
- package/dist/components/Header/Header.d.ts +4 -1
- package/dist/components/Heading/Heading.d.ts +1 -1
- package/dist/components/Link/BaseLink.d.ts +10 -0
- package/dist/components/Link/Link.d.ts +5 -10
- package/dist/components/Link/Link.stories.d.ts +1 -1
- package/dist/components/Link/index.d.ts +1 -1
- package/dist/components/Menu/Menu.d.ts +2 -1
- package/dist/components/Menu/MenuContent.d.ts +2 -1
- package/dist/components/Menu/MenuItem.d.ts +2 -0
- package/dist/components/Menu/MenuSection.d.ts +1 -1
- package/dist/components/Search/Search.d.ts +16 -0
- package/dist/components/Search/Search.stories.d.ts +34 -0
- package/dist/components/Search/__tests__/Search.test.d.ts +1 -0
- package/dist/components/Search/index.d.ts +2 -0
- package/dist/components/Select/Select.d.ts +1 -1
- package/dist/components/Select/Select.stories.d.ts +3 -7
- package/dist/components/Select/Select.types.d.ts +19 -14
- package/dist/components/Select/subcomponents/CustomOption.d.ts +1 -1
- package/dist/components/Select/subcomponents/CustomSelect.d.ts +1 -2
- package/dist/components/Select/subcomponents/Panel.d.ts +1 -1
- package/dist/components/Select/subcomponents/VisibleField.d.ts +4 -4
- package/dist/components/StandaloneLink/StandaloneLink.d.ts +12 -0
- package/dist/components/StandaloneLink/StandaloneLink.stories.d.ts +13 -0
- package/dist/components/StandaloneLink/__tests__/StandaloneLink.test.d.ts +1 -0
- package/dist/components/StandaloneLink/index.d.ts +2 -0
- package/dist/components/Table/Table.d.ts +10 -8
- package/dist/components/Table/Table.stories.d.ts +21 -0
- package/dist/components/Table/Table.types.d.ts +11 -0
- package/dist/components/Table/__tests__/Table.test.d.ts +1 -0
- package/dist/components/Table/index.d.ts +2 -1
- package/dist/components/Table/subcomponents/Body.d.ts +4 -0
- package/dist/components/Table/subcomponents/Cell/Cell.d.ts +12 -0
- package/dist/components/Table/subcomponents/Cell/Cell.stories.d.ts +313 -0
- package/dist/components/Table/subcomponents/Cell/CellContent.d.ts +10 -0
- package/dist/components/Table/subcomponents/Cell/__tests__/Cell.test.d.ts +1 -0
- package/dist/components/Table/subcomponents/Head.d.ts +4 -0
- package/dist/components/Table/subcomponents/HeadCell/HeadCell.d.ts +13 -0
- package/dist/components/Table/subcomponents/HeadCell/HeadCell.stories.d.ts +312 -0
- package/dist/components/Table/subcomponents/HeadCell/HeadCellContent.d.ts +10 -0
- package/dist/components/Table/subcomponents/HeadCell/__tests__/HeadCell.test.d.ts +1 -0
- package/dist/components/Table/subcomponents/Row.d.ts +5 -0
- package/dist/components/Table/subcomponents/SortIcon.d.ts +7 -0
- package/dist/components/Table/subcomponents/index.d.ts +10 -0
- package/dist/components/Tabs/Tab.d.ts +1 -1
- package/dist/components/Tabs/TabContext.d.ts +1 -0
- package/dist/components/Tabs/Tabs.d.ts +3 -1
- package/dist/components/Tabs/Tabs.stories.d.ts +3 -0
- package/dist/components/Timepicker/Timepicker.d.ts +10 -0
- package/dist/components/Timepicker/Timepicker.stories.d.ts +7 -0
- package/dist/components/Timepicker/__tests__/Timepicker.test.d.ts +1 -0
- package/dist/components/Timepicker/index.d.ts +2 -0
- package/dist/components/Timepicker/utils/convertDateToTimeString.d.ts +2 -0
- package/dist/components/Timepicker/utils/convertDateToTimeString.test.d.ts +1 -0
- package/dist/components/Timepicker/utils/index.d.ts +1 -0
- package/dist/components/WeekPicker/WeekPicker.d.ts +3 -0
- package/dist/components/WeekPicker/index.d.ts +1 -0
- package/dist/components/WeekPicker/subcomponents/CustomDatepicker.d.ts +17 -0
- package/dist/components/WeekPicker/subcomponents/DatepickerInput.d.ts +13 -0
- package/dist/components/WeekPicker/subcomponents/VisibleField.d.ts +15 -0
- package/dist/components/WeekPicker/subcomponents/index.d.ts +3 -0
- package/dist/components/index.d.ts +13 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/useFocusTrap.d.ts +9 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6006 -4599
- package/dist/theme/defaultTheme.d.ts +7 -0
- package/dist/theme/useTheme.d.ts +14 -0
- package/dist/utils/__tests__/capitalise.test.d.ts +1 -0
- package/dist/utils/capitalise.d.ts +2 -0
- package/lib/components/Alert/Alert.tsx +7 -1
- package/lib/components/Alert/__tests__/__snapshots__/Alert.test.tsx.snap +4 -0
- package/lib/components/Badge/Badge.stories.tsx +19 -0
- package/lib/components/Badge/Badge.tsx +48 -0
- package/lib/components/Badge/index.ts +2 -0
- package/lib/components/Breadcrumbs/__tests__/__snapshots__/Breadcrumbs.test.tsx.snap +4 -4
- package/lib/components/Button/Button.tsx +5 -2
- package/lib/components/Calendar/Calendar.stories.tsx +209 -0
- package/lib/components/Calendar/Calendar.tsx +121 -0
- package/lib/components/Calendar/Calendar.types.ts +21 -0
- package/lib/components/Calendar/__tests__/Calendar.test.tsx +71 -0
- package/lib/components/Calendar/__tests__/__snapshots__/Calendar.test.tsx.snap +1218 -0
- package/lib/components/Calendar/index.ts +6 -0
- package/lib/components/{Datepicker → Calendar}/subcomponents/AcademicWeek.tsx +1 -1
- package/lib/components/{Datepicker → Calendar}/subcomponents/AcademicWeeks.tsx +9 -7
- package/lib/components/Calendar/subcomponents/ColumnHeading.tsx +40 -0
- package/lib/components/{Datepicker/subcomponents/MonthSelector/MonthSelector.tsx → Calendar/subcomponents/Controls.tsx} +17 -17
- package/lib/components/{Datepicker/subcomponents/Day → Calendar/subcomponents}/Day.stories.tsx +8 -8
- package/lib/components/{Datepicker/subcomponents/Day → Calendar/subcomponents}/Day.tsx +28 -16
- package/lib/components/{Datepicker → Calendar}/subcomponents/EventDot.tsx +3 -3
- package/lib/components/Calendar/subcomponents/Grid.tsx +116 -0
- package/lib/components/Calendar/subcomponents/index.ts +7 -0
- package/lib/components/{Datepicker → Calendar}/utils/getAcademicWeekNumbers/getAcademicWeekNumbers.test.ts +1 -1
- package/lib/components/{Datepicker → Calendar}/utils/getAcademicWeekNumbers/getAcademicWeekNumbers.ts +1 -1
- package/lib/components/{Datepicker → Calendar}/utils/getDatesForCalendarGrid/getDatesForCalendarGrid.test.ts +29 -65
- package/lib/components/{Datepicker → Calendar}/utils/getDatesForCalendarGrid/getDatesForCalendarGrid.ts +11 -43
- package/lib/components/Calendar/utils/index.ts +4 -0
- package/lib/components/Calendar/utils/normaliseMonth/normaliseMonth.test.ts +40 -0
- package/lib/components/Calendar/utils/normaliseMonth/normaliseMonth.ts +16 -0
- package/lib/components/Calendar/utils/parseDateFromString/parseDateFromString.test.ts +15 -0
- package/lib/components/Calendar/utils/parseDateFromString/parseDateFromString.ts +19 -0
- package/lib/components/CookieNotice/CookieNotice.tsx +114 -0
- package/lib/components/CookieNotice/index.ts +2 -0
- package/lib/components/Datepicker/Datepicker.stories.tsx +128 -64
- package/lib/components/Datepicker/Datepicker.tsx +34 -114
- package/lib/components/Datepicker/Datepicker.types.ts +38 -9
- package/lib/components/Datepicker/__tests__/Datepicker.test.tsx +53 -112
- package/lib/components/Datepicker/__tests__/__snapshots__/Datepicker.test.tsx.snap +92 -747
- package/lib/components/Datepicker/index.ts +1 -2
- package/lib/components/Datepicker/subcomponents/CustomDatepicker.tsx +209 -0
- package/lib/components/Datepicker/subcomponents/DatepickerInput.tsx +74 -0
- package/lib/components/Datepicker/subcomponents/NativeDatepicker.tsx +70 -0
- package/lib/components/Datepicker/subcomponents/Panel.tsx +32 -0
- package/lib/components/Datepicker/subcomponents/VisibleField.tsx +104 -0
- package/lib/components/Datepicker/subcomponents/index.ts +5 -7
- package/lib/components/Datepicker/utils/dateToLocaleISOString/dateToLocaleISOString.test.ts +32 -0
- package/lib/components/Datepicker/utils/dateToLocaleISOString/dateToLocaleISOString.ts +23 -0
- package/lib/components/Datepicker/utils/index.ts +2 -3
- package/lib/components/Datepicker/utils/parseInputValue/parseInputValue.test.ts +110 -0
- package/lib/components/Datepicker/utils/parseInputValue/parseInputValue.ts +57 -0
- package/lib/components/Dialog/BaseDialog.tsx +44 -4
- package/lib/components/Field/__tests__/Field.test.tsx +148 -148
- package/lib/components/FileInput/FileInput.stories.tsx +70 -0
- package/lib/components/FileInput/FileInput.tsx +68 -0
- package/lib/components/FileInput/__tests__/FileInput.test.tsx +99 -0
- package/lib/components/FileInput/__tests__/__snapshots__/FileInput.test.tsx.snap +91 -0
- package/lib/components/FileInput/index.ts +2 -0
- package/lib/components/Footer/Footer.tsx +3 -3
- package/lib/components/Footer/__tests__/__snapshots__/Footer.test.tsx.snap +31 -31
- package/lib/components/Header/Header.tsx +19 -2
- package/lib/components/Header/__tests__/__snapshots__/Header.test.tsx.snap +4 -4
- package/lib/components/Heading/Documentation.mdx +1 -1
- package/lib/components/Heading/Heading.tsx +1 -1
- package/lib/components/Heading/__tests__/Heading.test.tsx +7 -19
- package/lib/components/Heading/__tests__/__snapshots__/Heading.test.tsx.snap +7 -7
- package/lib/components/Label/Label.tsx +0 -2
- package/lib/components/Label/__tests__/__snapshots__/Label.test.tsx.snap +7 -7
- package/lib/components/Link/BaseLink.tsx +84 -0
- package/lib/components/Link/Link.tsx +72 -32
- package/lib/components/Link/__tests__/__snapshots__/link.test.tsx.snap +3 -3
- package/lib/components/Link/__tests__/link.test.tsx +6 -13
- package/lib/components/Link/index.ts +1 -1
- package/lib/components/Menu/Menu.context.tsx +3 -1
- package/lib/components/Menu/Menu.tsx +5 -2
- package/lib/components/Menu/MenuContent.tsx +9 -6
- package/lib/components/Menu/MenuItem.tsx +20 -3
- package/lib/components/Menu/MenuSection.tsx +4 -3
- package/lib/components/Pagination/PaginationControls.tsx +1 -3
- package/lib/components/Search/Search.stories.tsx +41 -0
- package/lib/components/Search/Search.tsx +167 -0
- package/lib/components/Search/__tests__/Search.test.tsx +94 -0
- package/lib/components/Search/__tests__/__snapshots__/Search.test.tsx.snap +179 -0
- package/lib/components/Search/index.ts +2 -0
- package/lib/components/Select/Select.stories.tsx +8 -35
- package/lib/components/Select/Select.tsx +2 -2
- package/lib/components/Select/Select.types.ts +20 -15
- package/lib/components/Select/__tests__/__snapshots__/Select.test.tsx.snap +3 -3
- package/lib/components/Select/subcomponents/CustomOption.tsx +22 -9
- package/lib/components/Select/subcomponents/CustomSelect.tsx +31 -20
- package/lib/components/Select/subcomponents/Panel.tsx +4 -5
- package/lib/components/Select/subcomponents/VisibleField.tsx +26 -22
- package/lib/components/StandaloneLink/StandaloneLink.stories.tsx +32 -0
- package/lib/components/StandaloneLink/StandaloneLink.tsx +183 -0
- package/lib/components/StandaloneLink/__tests__/StandaloneLink.test.tsx +57 -0
- package/lib/components/StandaloneLink/__tests__/__snapshots__/StandaloneLink.test.tsx.snap +19 -0
- package/lib/components/StandaloneLink/index.ts +2 -0
- package/lib/components/Table/Table.stories.tsx +337 -0
- package/lib/components/Table/Table.tsx +42 -67
- package/lib/components/Table/Table.types.ts +14 -0
- package/lib/components/Table/__tests__/Table.test.tsx +121 -0
- package/lib/components/Table/__tests__/__snapshots__/Table.test.tsx.snap +210 -0
- package/lib/components/Table/index.ts +8 -1
- package/lib/components/Table/subcomponents/Body.tsx +18 -0
- package/lib/components/Table/subcomponents/Cell/Cell.stories.tsx +151 -0
- package/lib/components/Table/subcomponents/Cell/Cell.tsx +72 -0
- package/lib/components/Table/subcomponents/Cell/CellContent.tsx +91 -0
- package/lib/components/Table/subcomponents/Cell/__tests__/Cell.test.tsx +115 -0
- package/lib/components/Table/subcomponents/Cell/__tests__/__snapshots__/Cell.test.tsx.snap +107 -0
- package/lib/components/Table/subcomponents/Head.tsx +34 -0
- package/lib/components/Table/subcomponents/HeadCell/HeadCell.stories.tsx +85 -0
- package/lib/components/Table/subcomponents/HeadCell/HeadCell.tsx +99 -0
- package/lib/components/Table/subcomponents/HeadCell/HeadCellContent.tsx +61 -0
- package/lib/components/Table/subcomponents/HeadCell/__tests__/HeadCell.test.tsx +137 -0
- package/lib/components/Table/subcomponents/HeadCell/__tests__/__snapshots__/HeadCell.test.tsx.snap +110 -0
- package/lib/components/Table/subcomponents/Row.tsx +49 -0
- package/lib/components/Table/subcomponents/SortIcon.tsx +63 -0
- package/lib/components/Table/subcomponents/index.ts +14 -0
- package/lib/components/Tabs/Tab.tsx +3 -3
- package/lib/components/Tabs/TabContext.tsx +1 -0
- package/lib/components/Tabs/Tabs.stories.tsx +9 -3
- package/lib/components/Tabs/Tabs.tsx +10 -32
- package/lib/components/Tabs/__tests__/Tabs.test.tsx +10 -4
- package/lib/components/Tabs/__tests__/__snapshots__/Tabs.test.tsx.snap +32 -32
- package/lib/components/Timepicker/Timepicker.stories.tsx +43 -0
- package/lib/components/Timepicker/Timepicker.tsx +96 -0
- package/lib/components/Timepicker/__tests__/Timepicker.test.tsx +55 -0
- package/lib/components/Timepicker/__tests__/__snapshots__/Timepicker.test.tsx.snap +19 -0
- package/lib/components/Timepicker/index.tsx +2 -0
- package/lib/components/Timepicker/utils/convertDateToTimeString.test.ts +54 -0
- package/lib/components/Timepicker/utils/convertDateToTimeString.ts +10 -0
- package/lib/components/Timepicker/utils/index.ts +1 -0
- package/lib/components/WeekPicker/WeekPicker.tsx +26 -0
- package/lib/components/WeekPicker/index.ts +1 -0
- package/lib/components/WeekPicker/subcomponents/CustomDatepicker.tsx +298 -0
- package/lib/components/WeekPicker/subcomponents/DatepickerInput.tsx +111 -0
- package/lib/components/WeekPicker/subcomponents/VisibleField.tsx +126 -0
- package/lib/components/WeekPicker/subcomponents/index.ts +3 -0
- package/lib/components/index.ts +20 -0
- package/lib/hooks/index.ts +2 -0
- package/lib/hooks/useFocusTrap.ts +123 -0
- package/lib/index.ts +1 -0
- package/lib/theme/defaultTheme.ts +7 -0
- package/lib/utils/__tests__/capitalise.test.ts +40 -0
- package/lib/utils/capitalise.ts +4 -0
- package/package.json +2 -2
- package/dist/components/Datepicker/subcomponents/AcademicWeeks.d.ts +0 -7
- package/dist/components/Datepicker/subcomponents/CalendarGrid/CalendarGrid.d.ts +0 -8
- package/dist/components/Datepicker/subcomponents/CalendarGrid/index.d.ts +0 -1
- package/dist/components/Datepicker/subcomponents/CalendarMenu/CalendarMenu.d.ts +0 -12
- package/dist/components/Datepicker/subcomponents/CalendarMenu/index.d.ts +0 -1
- package/dist/components/Datepicker/subcomponents/ColumnHeadings/ColumnHeadings.d.ts +0 -2
- package/dist/components/Datepicker/subcomponents/ColumnHeadings/index.d.ts +0 -1
- package/dist/components/Datepicker/subcomponents/DateField/DateField.d.ts +0 -7
- package/dist/components/Datepicker/subcomponents/DateField/index.d.ts +0 -1
- package/dist/components/Datepicker/subcomponents/Day/index.d.ts +0 -1
- package/dist/components/Datepicker/subcomponents/MonthSelector/MonthSelector.d.ts +0 -6
- package/dist/components/Datepicker/subcomponents/MonthSelector/index.d.ts +0 -1
- package/dist/components/Datepicker/subcomponents/Native/Native.d.ts +0 -9
- package/dist/components/Datepicker/subcomponents/Native/index.d.ts +0 -1
- package/dist/components/Datepicker/utils/parseDateForDateField/parseDateForDateField.d.ts +0 -20
- package/lib/components/Datepicker/subcomponents/CalendarGrid/CalendarGrid.tsx +0 -54
- package/lib/components/Datepicker/subcomponents/CalendarGrid/index.ts +0 -1
- package/lib/components/Datepicker/subcomponents/CalendarMenu/CalendarMenu.tsx +0 -90
- package/lib/components/Datepicker/subcomponents/CalendarMenu/index.ts +0 -1
- package/lib/components/Datepicker/subcomponents/ColumnHeadings/ColumnHeadings.tsx +0 -35
- package/lib/components/Datepicker/subcomponents/ColumnHeadings/index.ts +0 -1
- package/lib/components/Datepicker/subcomponents/DateField/DateField.tsx +0 -155
- package/lib/components/Datepicker/subcomponents/DateField/__tests__/DateField.test.tsx +0 -191
- package/lib/components/Datepicker/subcomponents/DateField/index.ts +0 -1
- package/lib/components/Datepicker/subcomponents/Day/index.ts +0 -1
- package/lib/components/Datepicker/subcomponents/MonthSelector/index.ts +0 -1
- package/lib/components/Datepicker/subcomponents/Native/Native.tsx +0 -59
- package/lib/components/Datepicker/subcomponents/Native/index.ts +0 -1
- package/lib/components/Datepicker/utils/parseDateForDateField/parseDateForDateField.test.ts +0 -41
- package/lib/components/Datepicker/utils/parseDateForDateField/parseDateForDateField.ts +0 -48
- package/lib/components/Field/__tests__/__snapshots__/Field.test.tsx.snap +0 -300
- /package/dist/components/{Datepicker/subcomponents/DateField/__tests__/DateField.test.d.ts → Calendar/__tests__/Calendar.test.d.ts} +0 -0
- /package/dist/components/{Datepicker → Calendar}/subcomponents/AcademicWeek.d.ts +0 -0
- /package/dist/components/{Datepicker/subcomponents/Day → Calendar/subcomponents}/Day.stories.d.ts +0 -0
- /package/dist/components/{Datepicker → Calendar}/utils/getAcademicWeekNumbers/getAcademicWeekNumbers.test.d.ts +0 -0
- /package/dist/components/{Datepicker → Calendar}/utils/getDatesForCalendarGrid/getDatesForCalendarGrid.d.ts +0 -0
- /package/dist/components/{Datepicker → Calendar}/utils/getDatesForCalendarGrid/getDatesForCalendarGrid.test.d.ts +0 -0
- /package/dist/components/{Datepicker/utils/parseDateForDateField/parseDateForDateField.test.d.ts → Calendar/utils/normaliseMonth/normaliseMonth.test.d.ts} +0 -0
|
@@ -17,24 +17,15 @@
|
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
19
|
const getDatesForCalendarGrid = (date: Date): Date[] => {
|
|
20
|
-
if (!date || !(date instanceof Date))
|
|
21
|
-
throw new Error('No date provided');
|
|
20
|
+
if (!date || !(date instanceof Date)) throw new Error('No date provided');
|
|
22
21
|
|
|
23
22
|
const month = date.getMonth();
|
|
24
|
-
const daysInMonth = new Date(
|
|
25
|
-
date.getFullYear(),
|
|
26
|
-
month + 1,
|
|
27
|
-
0
|
|
28
|
-
).getDate();
|
|
23
|
+
const daysInMonth = new Date(date.getFullYear(), month + 1, 0).getDate();
|
|
29
24
|
|
|
30
25
|
// Get all days in current month
|
|
31
26
|
const dates: Date[] = [];
|
|
32
27
|
for (let day = 1; day <= daysInMonth; day++) {
|
|
33
|
-
const newDate = new Date(
|
|
34
|
-
date.getFullYear(),
|
|
35
|
-
month,
|
|
36
|
-
day
|
|
37
|
-
);
|
|
28
|
+
const newDate = new Date(date.getFullYear(), month, day);
|
|
38
29
|
if (newDate.getMonth() !== month) break;
|
|
39
30
|
dates.push(newDate);
|
|
40
31
|
}
|
|
@@ -43,28 +34,14 @@ const getDatesForCalendarGrid = (date: Date): Date[] => {
|
|
|
43
34
|
// Sunday (0) should become 6
|
|
44
35
|
// Monday (1) should become 0
|
|
45
36
|
// Tuesday (2) should become 1, etc.
|
|
46
|
-
const adjustDay = (day: number): number =>
|
|
47
|
-
day === 0 ? 6 : day - 1;
|
|
37
|
+
const adjustDay = (day: number): number => (day === 0 ? 6 : day - 1);
|
|
48
38
|
|
|
49
39
|
// Calculate previous month's "grey days"
|
|
50
40
|
const prevMonthGreyDays = [];
|
|
51
|
-
const prevMonth = new Date(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
);
|
|
56
|
-
const firstDayOfMonth = new Date(
|
|
57
|
-
date.getFullYear(),
|
|
58
|
-
month,
|
|
59
|
-
1
|
|
60
|
-
).getDay();
|
|
61
|
-
const numberOfDaysFromPrevMonth =
|
|
62
|
-
adjustDay(firstDayOfMonth);
|
|
63
|
-
const totalDaysInPrevMonth = new Date(
|
|
64
|
-
date.getFullYear(),
|
|
65
|
-
month,
|
|
66
|
-
0
|
|
67
|
-
).getDate();
|
|
41
|
+
const prevMonth = new Date(date.getFullYear(), month - 1, 1);
|
|
42
|
+
const firstDayOfMonth = new Date(date.getFullYear(), month, 1).getDay();
|
|
43
|
+
const numberOfDaysFromPrevMonth = adjustDay(firstDayOfMonth);
|
|
44
|
+
const totalDaysInPrevMonth = new Date(date.getFullYear(), month, 0).getDate();
|
|
68
45
|
|
|
69
46
|
for (let i = numberOfDaysFromPrevMonth; i > 0; i--) {
|
|
70
47
|
prevMonthGreyDays.push(
|
|
@@ -78,26 +55,17 @@ const getDatesForCalendarGrid = (date: Date): Date[] => {
|
|
|
78
55
|
|
|
79
56
|
// Calculate next month's "grey days"
|
|
80
57
|
const nextMonthGreyDays = [];
|
|
81
|
-
const nextMonth = new Date(
|
|
82
|
-
date.getFullYear(),
|
|
83
|
-
month + 1,
|
|
84
|
-
1
|
|
85
|
-
);
|
|
58
|
+
const nextMonth = new Date(date.getFullYear(), month + 1, 1);
|
|
86
59
|
const lastDayOfMonth = new Date(
|
|
87
60
|
date.getFullYear(),
|
|
88
61
|
month,
|
|
89
62
|
daysInMonth
|
|
90
63
|
).getDay();
|
|
91
|
-
const numberOfDaysFromNextMonth =
|
|
92
|
-
6 - adjustDay(lastDayOfMonth);
|
|
64
|
+
const numberOfDaysFromNextMonth = 6 - adjustDay(lastDayOfMonth);
|
|
93
65
|
|
|
94
66
|
for (let i = 1; i <= numberOfDaysFromNextMonth; i++) {
|
|
95
67
|
nextMonthGreyDays.push(
|
|
96
|
-
new Date(
|
|
97
|
-
nextMonth.getFullYear(),
|
|
98
|
-
nextMonth.getMonth(),
|
|
99
|
-
i
|
|
100
|
-
)
|
|
68
|
+
new Date(nextMonth.getFullYear(), nextMonth.getMonth(), i)
|
|
101
69
|
);
|
|
102
70
|
}
|
|
103
71
|
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as normaliseMonth } from './normaliseMonth/normaliseMonth';
|
|
2
|
+
export { default as parseDateFromString } from './parseDateFromString/parseDateFromString';
|
|
3
|
+
export { default as getAcademicWeekNumbers } from './getAcademicWeekNumbers/getAcademicWeekNumbers';
|
|
4
|
+
export { default as getDatesForCalendarGrid } from './getDatesForCalendarGrid/getDatesForCalendarGrid';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import normaliseMonth from './normaliseMonth';
|
|
3
|
+
|
|
4
|
+
describe('Calendar: normaliseMonth', () => {
|
|
5
|
+
test('Should return null if given undefined', () => {
|
|
6
|
+
expect(normaliseMonth(undefined)).toBeNull();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
test('Should return null if given null', () => {
|
|
10
|
+
expect(normaliseMonth(null)).toBeNull();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('Returns a Date object set to the first of the month', () => {
|
|
14
|
+
const date = new Date('2025-03-10');
|
|
15
|
+
const normalisedDate = normaliseMonth(date);
|
|
16
|
+
expect(normalisedDate).toBeInstanceOf(Date);
|
|
17
|
+
expect(normalisedDate?.getFullYear()).toBe(2025);
|
|
18
|
+
expect(normalisedDate?.getMonth()).toBe(2); // March (0-indexed)
|
|
19
|
+
expect(normalisedDate?.getDate()).toBe(1);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('Works for a date within daylight saving time', () => {
|
|
23
|
+
const date = new Date('2025-06-15');
|
|
24
|
+
const normalisedDate = normaliseMonth(date);
|
|
25
|
+
expect(normalisedDate).toBeInstanceOf(Date);
|
|
26
|
+
expect(normalisedDate?.getFullYear()).toBe(2025);
|
|
27
|
+
expect(normalisedDate?.getMonth()).toBe(5); // June (0-indexed)
|
|
28
|
+
expect(normalisedDate?.getDate()).toBe(1);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('Returned date is normalised for midnight', () => {
|
|
32
|
+
const date = new Date('2025-01-01T12:34:56');
|
|
33
|
+
const normalisedDate = normaliseMonth(date);
|
|
34
|
+
expect(normalisedDate).toBeInstanceOf(Date);
|
|
35
|
+
expect(normalisedDate?.getFullYear()).toBe(2025);
|
|
36
|
+
expect(normalisedDate?.getMonth()).toBe(0); // January (0-indexed)
|
|
37
|
+
expect(normalisedDate?.getDate()).toBe(1);
|
|
38
|
+
expect(normalisedDate?.getHours()).toBe(0);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalises a given date to the first day of its month (with the time set to midnight).
|
|
3
|
+
* If the input date is undefined, it returns null.
|
|
4
|
+
* Used in <Calendar> to track the displayed month.
|
|
5
|
+
* @param date The date to normalise.
|
|
6
|
+
* @returns A new Date object set to the first day of the month with the time at midnight, or null if the input was null or undefined.
|
|
7
|
+
*/
|
|
8
|
+
const normaliseMonth = (date: Date | null | undefined) => {
|
|
9
|
+
if (!date) return null;
|
|
10
|
+
const newDate = new Date(date);
|
|
11
|
+
newDate.setDate(1);
|
|
12
|
+
newDate.setHours(0, 0, 0, 0);
|
|
13
|
+
return newDate;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default normaliseMonth;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import parseDateFromString from './parseDateFromString';
|
|
3
|
+
|
|
4
|
+
describe('Calendar: parseDateFromString', () => {
|
|
5
|
+
test('Should return null for an invalid date string', () => {
|
|
6
|
+
expect(parseDateFromString('invalid-date')).toBeNull();
|
|
7
|
+
expect(parseDateFromString('')).toBeNull();
|
|
8
|
+
expect(parseDateFromString(' ')).toBeNull();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test('Should return a valid date for a valid date string', () => {
|
|
12
|
+
expect(parseDateFromString('2023-03-15')).toEqual(new Date('2023-03-15'));
|
|
13
|
+
expect(parseDateFromString('2025-06-30')).toEqual(new Date('2025-06-30'));
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses a date string into a Date object.
|
|
3
|
+
* Returns null if the input is invalid.
|
|
4
|
+
*
|
|
5
|
+
* @param dateString - The date string to parse (can be in ISO format or UNIX timestamp).
|
|
6
|
+
* @returns A Date object, or null if invalid.
|
|
7
|
+
*/
|
|
8
|
+
const parseDateFromString = (dateString: string): Date | null => {
|
|
9
|
+
const date = new Date(dateString);
|
|
10
|
+
if (isNaN(date.getTime())) {
|
|
11
|
+
console.warn(
|
|
12
|
+
`Calendar: Invalid date string provided: "${dateString}". Expected format is ISO 8601 (YYYY-MM-DD)`
|
|
13
|
+
);
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return date;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default parseDateFromString;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { HTMLAttributes, useRef } from 'react';
|
|
2
|
+
import { css, cx } from '@emotion/css';
|
|
3
|
+
import useTheme from '../../theme/useTheme';
|
|
4
|
+
import marginsStyle, { MarginProps } from '../common/marginsStyle';
|
|
5
|
+
import Paragraph from '../Paragraph';
|
|
6
|
+
import { Button, Icon, Link } from '..';
|
|
7
|
+
import { useFocusTrap } from '../../hooks/useFocusTrap';
|
|
8
|
+
|
|
9
|
+
export const NAME = 'ucl-uikit-cookie-notice';
|
|
10
|
+
export const DEFAULT_POLICY_HREF =
|
|
11
|
+
'https://www.ucl.ac.uk/legal-services/privacy/cookie-policy';
|
|
12
|
+
export const DEFAULT_TEXT =
|
|
13
|
+
'We use necessary cookies to manage your session and essential site functions. We also use Google Analytics cookies to understand how our site is used. You can accept or reject non-essential cookies.';
|
|
14
|
+
|
|
15
|
+
export interface CookieNoticeBaseProps extends HTMLAttributes<HTMLDivElement> {
|
|
16
|
+
policyHref?: string;
|
|
17
|
+
text?: string;
|
|
18
|
+
onAccept?: () => void;
|
|
19
|
+
onReject?: () => void;
|
|
20
|
+
trapFocus?: boolean;
|
|
21
|
+
testId?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type CookieNoticeProps = CookieNoticeBaseProps & MarginProps;
|
|
25
|
+
|
|
26
|
+
const CookieNotice = ({
|
|
27
|
+
policyHref = DEFAULT_POLICY_HREF,
|
|
28
|
+
text = DEFAULT_TEXT,
|
|
29
|
+
onAccept,
|
|
30
|
+
onReject,
|
|
31
|
+
trapFocus = false,
|
|
32
|
+
testId = NAME,
|
|
33
|
+
className,
|
|
34
|
+
...props
|
|
35
|
+
}: CookieNoticeProps) => {
|
|
36
|
+
const [theme] = useTheme();
|
|
37
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
38
|
+
|
|
39
|
+
useFocusTrap({
|
|
40
|
+
isActive: trapFocus,
|
|
41
|
+
containerRef,
|
|
42
|
+
restoreFocus: true,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const baseStyle = css`
|
|
46
|
+
position: fixed;
|
|
47
|
+
left: 0;
|
|
48
|
+
right: 0;
|
|
49
|
+
bottom: 0;
|
|
50
|
+
height: auto;
|
|
51
|
+
background-color: ${theme.color.neutral.grey40};
|
|
52
|
+
padding: ${theme.padding.p20} ${theme.padding.p24};
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
const style = cx(NAME, baseStyle, marginsStyle(props, theme), className);
|
|
56
|
+
|
|
57
|
+
const buttonsStyle = css`
|
|
58
|
+
margin-top: ${theme.margin.m16};
|
|
59
|
+
display: flex;
|
|
60
|
+
align-items: center;
|
|
61
|
+
gap: ${theme.margin.m8};
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
const policyLinkStyle = css`
|
|
65
|
+
margin-left: ${theme.margin.m16};
|
|
66
|
+
display: inline-flex;
|
|
67
|
+
color: ${theme.color.text.primary};
|
|
68
|
+
&:visited {
|
|
69
|
+
color: ${theme.color.text.primary};
|
|
70
|
+
}
|
|
71
|
+
`;
|
|
72
|
+
|
|
73
|
+
const policyLinkIconStyle = css`
|
|
74
|
+
margin-top: -1px;
|
|
75
|
+
margin-left: ${theme.margin.m4};
|
|
76
|
+
`;
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<div
|
|
80
|
+
ref={containerRef}
|
|
81
|
+
className={style}
|
|
82
|
+
data-testid={testId}
|
|
83
|
+
{...props}
|
|
84
|
+
>
|
|
85
|
+
<Paragraph noMargins>{text}</Paragraph>
|
|
86
|
+
|
|
87
|
+
<div className={buttonsStyle}>
|
|
88
|
+
<Button
|
|
89
|
+
size='small'
|
|
90
|
+
onClick={onAccept}
|
|
91
|
+
>
|
|
92
|
+
Accept
|
|
93
|
+
</Button>
|
|
94
|
+
|
|
95
|
+
<Button
|
|
96
|
+
size='small'
|
|
97
|
+
onClick={onReject}
|
|
98
|
+
>
|
|
99
|
+
Reject
|
|
100
|
+
</Button>
|
|
101
|
+
<Link
|
|
102
|
+
className={policyLinkStyle}
|
|
103
|
+
noVisited
|
|
104
|
+
href={policyHref}
|
|
105
|
+
target='_blank'
|
|
106
|
+
>
|
|
107
|
+
Cookies policy <Icon.ExternalLink className={policyLinkIconStyle} />
|
|
108
|
+
</Link>
|
|
109
|
+
</div>
|
|
110
|
+
</div>
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export default CookieNotice;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
2
|
import { useArgs } from '@storybook/preview-api';
|
|
3
3
|
import Datepicker from './Datepicker';
|
|
4
|
-
import type { AcademicWeek } from './Datepicker.types';
|
|
5
4
|
|
|
6
5
|
const meta = {
|
|
7
|
-
title: 'Components/
|
|
6
|
+
title: 'Components/Ready to use/Datepicker',
|
|
8
7
|
component: Datepicker,
|
|
9
8
|
parameters: { layout: 'padded' },
|
|
10
9
|
argTypes: {
|
|
11
|
-
|
|
10
|
+
value: { control: { type: 'date' } },
|
|
12
11
|
minDate: { control: { type: 'date' } },
|
|
13
12
|
maxDate: { control: { type: 'date' } },
|
|
13
|
+
disabled: { control: { type: 'boolean' } },
|
|
14
14
|
native: { control: { type: 'boolean' } },
|
|
15
15
|
showAcademicWeeks: { control: { type: 'boolean' } },
|
|
16
16
|
},
|
|
@@ -20,66 +20,39 @@ const meta = {
|
|
|
20
20
|
export default meta;
|
|
21
21
|
type Story = StoryObj<typeof meta>;
|
|
22
22
|
|
|
23
|
+
const dateToISOString = (date: Date) => {
|
|
24
|
+
return date.toISOString().split('T')[0];
|
|
25
|
+
};
|
|
26
|
+
|
|
23
27
|
export const Default: Story = {
|
|
24
|
-
args: {
|
|
25
|
-
date: null,
|
|
26
|
-
onDateChange: () => {},
|
|
27
|
-
},
|
|
28
28
|
render: () => {
|
|
29
29
|
const [args, updateArgs] = useArgs();
|
|
30
30
|
|
|
31
|
-
//
|
|
31
|
+
// Storybook controls provide UNIX timestamps for dates, need to convert
|
|
32
32
|
// https://storybook.js.org/docs/essentials/controls#annotation
|
|
33
|
-
args.
|
|
34
|
-
args.minDate = args.minDate
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return (
|
|
41
|
-
<Datepicker
|
|
42
|
-
{...args}
|
|
43
|
-
date={args.date}
|
|
44
|
-
onDateChange={onDateChange}
|
|
45
|
-
/>
|
|
46
|
-
);
|
|
47
|
-
},
|
|
48
|
-
};
|
|
33
|
+
args.value = args.value ? new Date(args.value) : null;
|
|
34
|
+
args.minDate = args.minDate
|
|
35
|
+
? new Date(args.minDate).toLocaleDateString('sv-SE')
|
|
36
|
+
: null;
|
|
37
|
+
args.maxDate = args.maxDate
|
|
38
|
+
? new Date(args.maxDate).toLocaleDateString('sv-SE')
|
|
39
|
+
: null;
|
|
49
40
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
args: {
|
|
53
|
-
native: true,
|
|
54
|
-
date: null,
|
|
55
|
-
onDateChange: () => {},
|
|
56
|
-
},
|
|
57
|
-
render: () => {
|
|
58
|
-
const [args, updateArgs] = useArgs();
|
|
59
|
-
args.date = args.date ? new Date(args.date) : null;
|
|
60
|
-
args.minDate = args.minDate ? new Date(args.minDate) : null;
|
|
61
|
-
args.maxDate = args.maxDate ? new Date(args.maxDate) : null;
|
|
62
|
-
const onDateChange = (date: Date | null | undefined) =>
|
|
63
|
-
updateArgs({ date: date });
|
|
41
|
+
const onValueChange = (value: Date | null | undefined) =>
|
|
42
|
+
updateArgs({ value: value });
|
|
64
43
|
return (
|
|
65
44
|
<Datepicker
|
|
66
45
|
{...args}
|
|
67
|
-
|
|
68
|
-
onDateChange={onDateChange}
|
|
46
|
+
onValueChange={onValueChange}
|
|
69
47
|
/>
|
|
70
48
|
);
|
|
71
49
|
},
|
|
72
50
|
};
|
|
73
51
|
|
|
74
|
-
|
|
75
|
-
return date.toISOString().split('T')[0];
|
|
76
|
-
};
|
|
77
|
-
|
|
52
|
+
// Story repeated in Calendar.stories.tsx
|
|
78
53
|
export const WithEvents: Story = {
|
|
79
54
|
name: 'With events',
|
|
80
55
|
args: {
|
|
81
|
-
date: null,
|
|
82
|
-
onDateChange: () => {},
|
|
83
56
|
// IIFE gives us event dots for the current month
|
|
84
57
|
events: (() => {
|
|
85
58
|
const currentDate = new Date();
|
|
@@ -105,23 +78,29 @@ export const WithEvents: Story = {
|
|
|
105
78
|
},
|
|
106
79
|
render: () => {
|
|
107
80
|
const [args, updateArgs] = useArgs();
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
81
|
+
|
|
82
|
+
// Storybook controls provide UNIX timestamps for dates, need to convert
|
|
83
|
+
// https://storybook.js.org/docs/essentials/controls#annotation
|
|
84
|
+
args.value = args.value ? new Date(args.value) : null;
|
|
85
|
+
args.minDate = args.minDate
|
|
86
|
+
? new Date(args.minDate).toLocaleDateString('sv-SE')
|
|
87
|
+
: null;
|
|
88
|
+
args.maxDate = args.maxDate
|
|
89
|
+
? new Date(args.maxDate).toLocaleDateString('sv-SE')
|
|
90
|
+
: null;
|
|
91
|
+
|
|
92
|
+
const onValueChange = (value: Date | null | undefined) =>
|
|
93
|
+
updateArgs({ value: value });
|
|
113
94
|
return (
|
|
114
95
|
<Datepicker
|
|
115
96
|
{...args}
|
|
116
|
-
|
|
117
|
-
onDateChange={onDateChange}
|
|
118
|
-
events={args.events}
|
|
97
|
+
onValueChange={onValueChange}
|
|
119
98
|
/>
|
|
120
99
|
);
|
|
121
100
|
},
|
|
122
101
|
};
|
|
123
102
|
|
|
124
|
-
const academicWeeks
|
|
103
|
+
const academicWeeks = [
|
|
125
104
|
{ start: '2025-08-25', number: 1 },
|
|
126
105
|
{ start: '2025-09-01', number: 2 },
|
|
127
106
|
{ start: '2025-09-08', number: 3 },
|
|
@@ -177,26 +156,111 @@ const academicWeeks: AcademicWeek[] = [
|
|
|
177
156
|
{ start: '2026-08-24', number: 53 },
|
|
178
157
|
];
|
|
179
158
|
|
|
159
|
+
// Story repeated in Calendar.stories.tsx
|
|
180
160
|
export const WithAcademicWeeks: Story = {
|
|
181
161
|
name: 'With academic weeks',
|
|
182
162
|
args: {
|
|
183
|
-
date: null,
|
|
184
|
-
onDateChange: () => {},
|
|
185
163
|
showAcademicWeeks: true,
|
|
186
164
|
academicWeeks: academicWeeks,
|
|
165
|
+
value: new Date(academicWeeks[0].start), // So the week numbers appear on story mount
|
|
166
|
+
},
|
|
167
|
+
render: () => {
|
|
168
|
+
const [args, updateArgs] = useArgs();
|
|
169
|
+
|
|
170
|
+
// Storybook controls provide UNIX timestamps for dates, need to convert
|
|
171
|
+
// https://storybook.js.org/docs/essentials/controls#annotation
|
|
172
|
+
args.value = args.value ? new Date(args.value) : null;
|
|
173
|
+
args.minDate = args.minDate
|
|
174
|
+
? new Date(args.minDate).toLocaleDateString('sv-SE')
|
|
175
|
+
: null;
|
|
176
|
+
args.maxDate = args.maxDate
|
|
177
|
+
? new Date(args.maxDate).toLocaleDateString('sv-SE')
|
|
178
|
+
: null;
|
|
179
|
+
|
|
180
|
+
const onValueChange = (value: Date | null | undefined) =>
|
|
181
|
+
updateArgs({ value: value });
|
|
182
|
+
return (
|
|
183
|
+
<Datepicker
|
|
184
|
+
{...args}
|
|
185
|
+
onValueChange={onValueChange}
|
|
186
|
+
/>
|
|
187
|
+
);
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// Story repeated in Datepicker.stories.tsx
|
|
192
|
+
export const MinMaxDates: Story = {
|
|
193
|
+
name: 'With min and max dates',
|
|
194
|
+
args: {
|
|
195
|
+
// Initialise min date as 5 days into the current month
|
|
196
|
+
minDate: (() => {
|
|
197
|
+
const now = new Date();
|
|
198
|
+
return new Date(now.getFullYear(), now.getMonth(), 5)
|
|
199
|
+
.toISOString()
|
|
200
|
+
.split('T')[0];
|
|
201
|
+
})(),
|
|
202
|
+
// Initialise max date as 5 days before the last day of the current month
|
|
203
|
+
maxDate: (() => {
|
|
204
|
+
const now = new Date();
|
|
205
|
+
// Get last day of current month
|
|
206
|
+
const lastDay = new Date(
|
|
207
|
+
now.getFullYear(),
|
|
208
|
+
now.getMonth() + 1,
|
|
209
|
+
0
|
|
210
|
+
).getDate();
|
|
211
|
+
return new Date(now.getFullYear(), now.getMonth(), lastDay - 5)
|
|
212
|
+
.toISOString()
|
|
213
|
+
.split('T')[0];
|
|
214
|
+
})(),
|
|
215
|
+
},
|
|
216
|
+
render: () => {
|
|
217
|
+
const [args, updateArgs] = useArgs();
|
|
218
|
+
|
|
219
|
+
// Storybook controls provide UNIX timestamps for dates, need to convert
|
|
220
|
+
// https://storybook.js.org/docs/essentials/controls#annotation
|
|
221
|
+
args.value = args.value ? new Date(args.value) : null;
|
|
222
|
+
args.minDate = args.minDate
|
|
223
|
+
? new Date(args.minDate).toLocaleDateString('sv-SE')
|
|
224
|
+
: null;
|
|
225
|
+
args.maxDate = args.maxDate
|
|
226
|
+
? new Date(args.maxDate).toLocaleDateString('sv-SE')
|
|
227
|
+
: null;
|
|
228
|
+
|
|
229
|
+
const onValueChange = (value: Date | null | undefined) =>
|
|
230
|
+
updateArgs({ value: value });
|
|
231
|
+
return (
|
|
232
|
+
<Datepicker
|
|
233
|
+
{...args}
|
|
234
|
+
onValueChange={onValueChange}
|
|
235
|
+
/>
|
|
236
|
+
);
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
export const Native: Story = {
|
|
241
|
+
name: 'As native fallback',
|
|
242
|
+
args: {
|
|
243
|
+
native: true,
|
|
187
244
|
},
|
|
188
245
|
render: () => {
|
|
189
246
|
const [args, updateArgs] = useArgs();
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
247
|
+
|
|
248
|
+
// Storybook controls provide UNIX timestamps for dates, need to convert
|
|
249
|
+
// https://storybook.js.org/docs/essentials/controls#annotation
|
|
250
|
+
args.value = args.value ? new Date(args.value) : null;
|
|
251
|
+
args.minDate = args.minDate
|
|
252
|
+
? new Date(args.minDate).toLocaleDateString('sv-SE')
|
|
253
|
+
: null;
|
|
254
|
+
args.maxDate = args.maxDate
|
|
255
|
+
? new Date(args.maxDate).toLocaleDateString('sv-SE')
|
|
256
|
+
: null;
|
|
257
|
+
|
|
258
|
+
const onValueChange = (value: Date | null | undefined) =>
|
|
259
|
+
updateArgs({ value: value });
|
|
195
260
|
return (
|
|
196
261
|
<Datepicker
|
|
197
262
|
{...args}
|
|
198
|
-
|
|
199
|
-
onDateChange={onDateChange}
|
|
263
|
+
onValueChange={onValueChange}
|
|
200
264
|
/>
|
|
201
265
|
);
|
|
202
266
|
},
|