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
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { css, cx } from '@emotion/css';
|
|
2
|
-
import AcademicWeek from './
|
|
3
|
-
import { getAcademicWeekNumbers } from '
|
|
2
|
+
import { AcademicWeek } from './';
|
|
3
|
+
import { getAcademicWeekNumbers } from '../utils';
|
|
4
4
|
import { useTheme } from '../../../theme';
|
|
5
|
-
import type { AcademicWeek as AcademicWeekType } from '../Datepicker.types';
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
import type { AcademicWeek as AcademicWeekType } from '../Calendar.types';
|
|
7
|
+
|
|
8
|
+
const NAME = 'ucl-uikit-calendar__academic-weeks';
|
|
8
9
|
|
|
9
10
|
interface AcademicWeeksProps {
|
|
10
11
|
date: Date;
|
|
11
|
-
|
|
12
|
+
weeks: AcademicWeekType[];
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
const AcademicWeeks = ({ date,
|
|
15
|
+
const AcademicWeeks = ({ date, weeks }: AcademicWeeksProps) => {
|
|
15
16
|
const [theme] = useTheme();
|
|
16
17
|
|
|
17
|
-
const academicWeekNumbers = getAcademicWeekNumbers(
|
|
18
|
+
const academicWeekNumbers = getAcademicWeekNumbers(weeks, date);
|
|
18
19
|
|
|
19
20
|
const baseStyle = css`
|
|
20
21
|
display: flex;
|
|
@@ -22,6 +23,7 @@ const AcademicWeeks = ({ date, academicWeeks }: AcademicWeeksProps) => {
|
|
|
22
23
|
padding-top: 32px;
|
|
23
24
|
width: 50px;
|
|
24
25
|
background-color: ${theme.color.interaction.blue5};
|
|
26
|
+
user-select: none;
|
|
25
27
|
`;
|
|
26
28
|
|
|
27
29
|
const style = cx(NAME, baseStyle);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { css, cx } from '@emotion/css';
|
|
2
|
+
import { useTheme } from '../../../theme';
|
|
3
|
+
|
|
4
|
+
interface ColumnHeadingProps {
|
|
5
|
+
index: number;
|
|
6
|
+
day: string; // 'M', 'T', 'W', 'T', 'F', 'S', 'S'
|
|
7
|
+
isWeekend: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const NAME = 'ucl-uikit-calendar__column-heading';
|
|
11
|
+
|
|
12
|
+
const ColumnHeading = ({ index, day, isWeekend }: ColumnHeadingProps) => {
|
|
13
|
+
const [theme] = useTheme();
|
|
14
|
+
|
|
15
|
+
const baseStyle = css`
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
justify-content: center;
|
|
19
|
+
width: 40px;
|
|
20
|
+
height: 32px;
|
|
21
|
+
color: ${isWeekend
|
|
22
|
+
? theme.color.system.orange100
|
|
23
|
+
: theme.color.neutral.grey60};
|
|
24
|
+
font-weight: 700;
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
const style = cx(NAME, baseStyle);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div
|
|
31
|
+
className={style}
|
|
32
|
+
data-testid={NAME}
|
|
33
|
+
key={index}
|
|
34
|
+
>
|
|
35
|
+
{day}
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default ColumnHeading;
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { css } from '@emotion/css';
|
|
1
|
+
import { css, cx } from '@emotion/css';
|
|
2
2
|
import { Icon } from '../../..';
|
|
3
|
-
import { useTheme } from '
|
|
3
|
+
import { useTheme } from '../../../theme';
|
|
4
4
|
|
|
5
|
-
interface
|
|
6
|
-
|
|
5
|
+
interface ControlsProps {
|
|
6
|
+
month: Date;
|
|
7
7
|
changeMonth: (change: number) => void;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}: MonthSelectorProps) => {
|
|
10
|
+
const NAME = 'ucl-uikit-calendar__controls';
|
|
11
|
+
|
|
12
|
+
const Controls = ({ month, changeMonth }: ControlsProps) => {
|
|
14
13
|
const [theme] = useTheme();
|
|
15
14
|
|
|
16
15
|
const baseStyle = css`
|
|
@@ -37,27 +36,28 @@ const MonthSelector = ({
|
|
|
37
36
|
}
|
|
38
37
|
`;
|
|
39
38
|
|
|
39
|
+
const style = cx(NAME, baseStyle);
|
|
40
|
+
|
|
40
41
|
return (
|
|
41
|
-
<div
|
|
42
|
+
<div
|
|
43
|
+
className={style}
|
|
44
|
+
data-testid={NAME}
|
|
45
|
+
>
|
|
42
46
|
<Icon.ChevronLeft
|
|
43
47
|
className={chevronIconStyle}
|
|
44
48
|
onClick={() => changeMonth(-1)}
|
|
45
49
|
/>
|
|
46
50
|
<span className={monthAndYearStyle}>
|
|
47
51
|
<span>
|
|
48
|
-
{
|
|
49
|
-
?
|
|
52
|
+
{month
|
|
53
|
+
? month.toLocaleDateString('default', {
|
|
50
54
|
month: 'long',
|
|
51
55
|
})
|
|
52
56
|
: new Date().toLocaleDateString('default', {
|
|
53
57
|
month: 'long',
|
|
54
58
|
})}
|
|
55
59
|
</span>
|
|
56
|
-
<span>
|
|
57
|
-
{date
|
|
58
|
-
? date.getFullYear()
|
|
59
|
-
: new Date().getFullYear()}
|
|
60
|
-
</span>
|
|
60
|
+
<span>{month ? month.getFullYear() : new Date().getFullYear()}</span>
|
|
61
61
|
</span>
|
|
62
62
|
<Icon.ChevronRight
|
|
63
63
|
className={chevronIconStyle}
|
|
@@ -67,4 +67,4 @@ const MonthSelector = ({
|
|
|
67
67
|
);
|
|
68
68
|
};
|
|
69
69
|
|
|
70
|
-
export default
|
|
70
|
+
export default Controls;
|
package/lib/components/{Datepicker/subcomponents/Day → Calendar/subcomponents}/Day.stories.tsx
RENAMED
|
@@ -2,7 +2,7 @@ import type { Meta, StoryObj } from '@storybook/react';
|
|
|
2
2
|
import Day from './Day';
|
|
3
3
|
|
|
4
4
|
const meta = {
|
|
5
|
-
title: 'Components/Work in progress/
|
|
5
|
+
title: 'Components/Work in progress/Calendar/Day',
|
|
6
6
|
component: Day,
|
|
7
7
|
argTypes: {
|
|
8
8
|
events: {
|
|
@@ -22,7 +22,7 @@ export const Default: Story = {
|
|
|
22
22
|
date: new Date(),
|
|
23
23
|
},
|
|
24
24
|
render: (args) => {
|
|
25
|
-
args.date =
|
|
25
|
+
args.date = new Date(args.date);
|
|
26
26
|
return <Day {...args} />;
|
|
27
27
|
},
|
|
28
28
|
};
|
|
@@ -33,7 +33,7 @@ export const Selected: Story = {
|
|
|
33
33
|
isSelected: true,
|
|
34
34
|
},
|
|
35
35
|
render: (args) => {
|
|
36
|
-
args.date =
|
|
36
|
+
args.date = new Date(args.date);
|
|
37
37
|
return <Day {...args} />;
|
|
38
38
|
},
|
|
39
39
|
};
|
|
@@ -44,7 +44,7 @@ export const Today: Story = {
|
|
|
44
44
|
isToday: true,
|
|
45
45
|
},
|
|
46
46
|
render: (args) => {
|
|
47
|
-
args.date =
|
|
47
|
+
args.date = new Date(args.date);
|
|
48
48
|
return <Day {...args} />;
|
|
49
49
|
},
|
|
50
50
|
};
|
|
@@ -55,7 +55,7 @@ export const Disabled: Story = {
|
|
|
55
55
|
isDisabled: true,
|
|
56
56
|
},
|
|
57
57
|
render: (args) => {
|
|
58
|
-
args.date =
|
|
58
|
+
args.date = new Date(args.date);
|
|
59
59
|
return <Day {...args} />;
|
|
60
60
|
},
|
|
61
61
|
};
|
|
@@ -66,7 +66,7 @@ export const NotInCurrentMonth: Story = {
|
|
|
66
66
|
isInCurrentMonth: false,
|
|
67
67
|
},
|
|
68
68
|
render: (args) => {
|
|
69
|
-
args.date =
|
|
69
|
+
args.date = new Date(args.date);
|
|
70
70
|
return <Day {...args} />;
|
|
71
71
|
},
|
|
72
72
|
};
|
|
@@ -81,7 +81,7 @@ export const WithEventDots: Story = {
|
|
|
81
81
|
],
|
|
82
82
|
},
|
|
83
83
|
render: (args) => {
|
|
84
|
-
args.date =
|
|
84
|
+
args.date = new Date(args.date);
|
|
85
85
|
return <Day {...args} />;
|
|
86
86
|
},
|
|
87
87
|
};
|
|
@@ -92,7 +92,7 @@ export const AlertOnPick: Story = {
|
|
|
92
92
|
date: new Date(),
|
|
93
93
|
},
|
|
94
94
|
render: (args) => {
|
|
95
|
-
args.date =
|
|
95
|
+
args.date = new Date(args.date);
|
|
96
96
|
const onPick = (date: Date) => alert(`Picked date: ${date.toDateString()}`);
|
|
97
97
|
return (
|
|
98
98
|
<Day
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { css } from '@emotion/css';
|
|
2
|
-
import EventDot from '
|
|
3
|
-
import { useTheme } from '
|
|
4
|
-
import { CalendarEvent } from '
|
|
1
|
+
import { css, cx } from '@emotion/css';
|
|
2
|
+
import { EventDot } from './';
|
|
3
|
+
import { useTheme } from '../../../theme';
|
|
4
|
+
import type { CalendarEvent } from '../Calendar.types';
|
|
5
5
|
|
|
6
6
|
export interface DayProps {
|
|
7
|
-
date: Date
|
|
8
|
-
onPick?: (date: Date) => void;
|
|
7
|
+
date: Date;
|
|
8
|
+
onPick?: (date: Date, event: React.SyntheticEvent) => void;
|
|
9
9
|
isSelected?: boolean;
|
|
10
10
|
isToday?: boolean;
|
|
11
11
|
isInCurrentMonth?: boolean;
|
|
@@ -13,6 +13,8 @@ export interface DayProps {
|
|
|
13
13
|
events?: CalendarEvent[]; // Max 3 events are displayed as dots
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
const NAME = 'ucl-uikit-calendar__day';
|
|
17
|
+
|
|
16
18
|
const Day = ({
|
|
17
19
|
date,
|
|
18
20
|
onPick,
|
|
@@ -27,8 +29,10 @@ const Day = ({
|
|
|
27
29
|
// More than 3 dots displayed breaks the layout
|
|
28
30
|
const displayedEvents = events.slice(0, 3);
|
|
29
31
|
|
|
30
|
-
const
|
|
31
|
-
if (date && onPick)
|
|
32
|
+
const handlePick = (event: React.MouseEvent) => {
|
|
33
|
+
if (date && !isDisabled && onPick) {
|
|
34
|
+
onPick(date, event);
|
|
35
|
+
}
|
|
32
36
|
};
|
|
33
37
|
|
|
34
38
|
const backgroundStyle = css`
|
|
@@ -48,7 +52,11 @@ const Day = ({
|
|
|
48
52
|
|
|
49
53
|
${isSelected &&
|
|
50
54
|
css`
|
|
51
|
-
background-color: ${theme.color.interaction.blue70};
|
|
55
|
+
/* background-color: ${theme.color.interaction.blue70}; */
|
|
56
|
+
background-color: ${isDisabled
|
|
57
|
+
? theme.color.neutral.grey10
|
|
58
|
+
: theme.color.interaction.blue70};
|
|
59
|
+
|
|
52
60
|
color: ${theme.color.text.inverted};
|
|
53
61
|
|
|
54
62
|
&:hover {
|
|
@@ -60,7 +68,10 @@ const Day = ({
|
|
|
60
68
|
cursor: not-allowed;
|
|
61
69
|
|
|
62
70
|
&:hover {
|
|
63
|
-
background-color: ${theme.color.neutral.white};
|
|
71
|
+
/* background-color: ${theme.color.neutral.white}; */
|
|
72
|
+
background-color: ${isSelected
|
|
73
|
+
? theme.color.neutral.grey10
|
|
74
|
+
: theme.color.neutral.white};
|
|
64
75
|
}
|
|
65
76
|
`}
|
|
66
77
|
`;
|
|
@@ -80,7 +91,7 @@ const Day = ({
|
|
|
80
91
|
`}
|
|
81
92
|
${isDisabled &&
|
|
82
93
|
css`
|
|
83
|
-
color: ${theme.color.neutral.
|
|
94
|
+
color: ${theme.color.neutral.grey20};
|
|
84
95
|
`}
|
|
85
96
|
`;
|
|
86
97
|
|
|
@@ -94,14 +105,15 @@ const Day = ({
|
|
|
94
105
|
width: 100%;
|
|
95
106
|
`;
|
|
96
107
|
|
|
108
|
+
const style = cx(NAME, backgroundStyle);
|
|
109
|
+
|
|
97
110
|
return (
|
|
98
111
|
<div
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
onClick={onClick}
|
|
112
|
+
onClick={handlePick}
|
|
113
|
+
className={style}
|
|
114
|
+
data-testid={NAME}
|
|
103
115
|
>
|
|
104
|
-
<div className={foregroundStyle}>{date
|
|
116
|
+
<div className={foregroundStyle}>{date.getDate()}</div>
|
|
105
117
|
<div className={eventDotsContainerStyle}>
|
|
106
118
|
{displayedEvents.map((_event, index) => (
|
|
107
119
|
<EventDot
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { css, cx } from '@emotion/css';
|
|
2
2
|
import { useTheme } from '../../../theme';
|
|
3
3
|
|
|
4
|
-
const NAME = 'ucl-uikit-
|
|
4
|
+
const NAME = 'ucl-uikit-calendar__event-dot';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
interface EventDotProps {
|
|
7
7
|
inverted: boolean;
|
|
8
8
|
inCurrentMonth: boolean;
|
|
9
|
-
}
|
|
9
|
+
}
|
|
10
10
|
|
|
11
11
|
const EventDot = ({ inverted, inCurrentMonth }: EventDotProps) => {
|
|
12
12
|
const [theme] = useTheme();
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { css, cx } from '@emotion/css';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { ColumnHeading, Day } from './';
|
|
4
|
+
import { getDatesForCalendarGrid } from '../utils';
|
|
5
|
+
import { useTheme } from '../../../theme';
|
|
6
|
+
import type { CalendarEvent } from '../Calendar.types';
|
|
7
|
+
|
|
8
|
+
interface GridProps {
|
|
9
|
+
month: Date; // 1st day of the month
|
|
10
|
+
pickedDate: Date | null;
|
|
11
|
+
onDatePick?: (date: Date, event: React.SyntheticEvent) => void;
|
|
12
|
+
minDate: Date | null;
|
|
13
|
+
maxDate: Date | null;
|
|
14
|
+
events: CalendarEvent[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const NAME = 'ucl-uikit-calendar__grid';
|
|
18
|
+
|
|
19
|
+
// Helper function: Convert ISO string 'yyyy-mm-dd' to local Date without timezone shift
|
|
20
|
+
function toLocalDate(dateStr: string): Date {
|
|
21
|
+
const [year, month, day] = dateStr.split('-').map(Number);
|
|
22
|
+
return new Date(year, month - 1, day);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getDateKey(date: Date): string {
|
|
26
|
+
return date.toISOString().split('T')[0];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Create events map grouped by date
|
|
30
|
+
function createEventsMap(
|
|
31
|
+
events: CalendarEvent[]
|
|
32
|
+
): Map<string, CalendarEvent[]> {
|
|
33
|
+
const eventsMap = new Map<string, CalendarEvent[]>();
|
|
34
|
+
|
|
35
|
+
events.forEach((event) => {
|
|
36
|
+
const eventDate = toLocalDate(event.date);
|
|
37
|
+
const dateKey = getDateKey(eventDate);
|
|
38
|
+
|
|
39
|
+
if (!eventsMap.has(dateKey)) {
|
|
40
|
+
eventsMap.set(dateKey, []);
|
|
41
|
+
}
|
|
42
|
+
eventsMap.get(dateKey)!.push(event);
|
|
43
|
+
});
|
|
44
|
+
return eventsMap;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const Grid = ({
|
|
48
|
+
month,
|
|
49
|
+
pickedDate,
|
|
50
|
+
onDatePick = () => {},
|
|
51
|
+
minDate,
|
|
52
|
+
maxDate,
|
|
53
|
+
events,
|
|
54
|
+
}: GridProps) => {
|
|
55
|
+
// Fix minDate timezone issues by zeroing time if valid
|
|
56
|
+
if (minDate && !isNaN(minDate.getTime())) minDate.setHours(0, 0, 0, 0);
|
|
57
|
+
|
|
58
|
+
const [theme] = useTheme();
|
|
59
|
+
|
|
60
|
+
const daysOfTheWeek = ['M', 'T', 'W', 'T', 'F', 'S', 'S'];
|
|
61
|
+
const dates = getDatesForCalendarGrid(month);
|
|
62
|
+
|
|
63
|
+
const eventsMap = useMemo(() => createEventsMap(events), [events]);
|
|
64
|
+
|
|
65
|
+
const baseStyle = css`
|
|
66
|
+
display: grid;
|
|
67
|
+
grid-template-columns: repeat(7, 1fr);
|
|
68
|
+
gap: 0;
|
|
69
|
+
text-align: center;
|
|
70
|
+
font-family: ${theme.font.family.primary};
|
|
71
|
+
font-weight: 400;
|
|
72
|
+
user-select: none;
|
|
73
|
+
`;
|
|
74
|
+
|
|
75
|
+
const style = cx(NAME, baseStyle);
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<div
|
|
79
|
+
className={style}
|
|
80
|
+
data-testid={NAME}
|
|
81
|
+
>
|
|
82
|
+
{daysOfTheWeek.map((day, index) => (
|
|
83
|
+
<ColumnHeading
|
|
84
|
+
key={index}
|
|
85
|
+
index={index}
|
|
86
|
+
day={day}
|
|
87
|
+
isWeekend={index >= 5}
|
|
88
|
+
/>
|
|
89
|
+
))}
|
|
90
|
+
{dates.map((mappedDate) => {
|
|
91
|
+
const dateKey = getDateKey(mappedDate);
|
|
92
|
+
const dateEvents = eventsMap.get(dateKey) || [];
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<Day
|
|
96
|
+
key={mappedDate.toISOString()}
|
|
97
|
+
date={mappedDate}
|
|
98
|
+
isSelected={
|
|
99
|
+
pickedDate?.toDateString() === mappedDate.toDateString()
|
|
100
|
+
}
|
|
101
|
+
isToday={mappedDate.toDateString() === new Date().toDateString()}
|
|
102
|
+
isInCurrentMonth={month.getMonth() === mappedDate.getMonth()}
|
|
103
|
+
isDisabled={
|
|
104
|
+
(minDate !== null && mappedDate < minDate) ||
|
|
105
|
+
(maxDate !== null && mappedDate > maxDate)
|
|
106
|
+
}
|
|
107
|
+
onPick={onDatePick}
|
|
108
|
+
events={dateEvents}
|
|
109
|
+
/>
|
|
110
|
+
);
|
|
111
|
+
})}
|
|
112
|
+
</div>
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export default Grid;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as Controls } from './Controls';
|
|
2
|
+
export { default as AcademicWeeks } from './AcademicWeeks';
|
|
3
|
+
export { default as AcademicWeek } from './AcademicWeek';
|
|
4
|
+
export { default as Grid } from './Grid';
|
|
5
|
+
export { default as ColumnHeading } from './ColumnHeading';
|
|
6
|
+
export { default as Day } from './Day';
|
|
7
|
+
export { default as EventDot } from './EventDot';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, test, vi } from 'vitest';
|
|
2
2
|
import getAcademicWeekNumbers, { getMonday } from './getAcademicWeekNumbers';
|
|
3
|
-
import type { AcademicWeek } from '../../
|
|
3
|
+
import type { AcademicWeek } from '../../';
|
|
4
4
|
|
|
5
5
|
describe('getMonday', () => {
|
|
6
6
|
test('Returns the Monday for the week of the given date', () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AcademicWeek } from '../../
|
|
1
|
+
import type { AcademicWeek } from '../../';
|
|
2
2
|
|
|
3
3
|
// The 'calendar period' is defined here as all the dates the calendar displays,
|
|
4
4
|
// which may include some dates in the previous month and some dates in the next month.
|
|
@@ -1,78 +1,51 @@
|
|
|
1
1
|
import { describe, expect, test } from 'vitest';
|
|
2
2
|
import getDatesForCalendarGrid from './getDatesForCalendarGrid';
|
|
3
3
|
|
|
4
|
+
// Note by Alex HF (2025-07-04): Some of these tests seem a bit excessive.
|
|
5
|
+
// I pasted them in from my orginal <Datepicker> work.
|
|
6
|
+
|
|
4
7
|
describe('getDatesForCalendarGrid', () => {
|
|
5
8
|
test('Returns an array of Date objects', () => {
|
|
6
9
|
const result = getDatesForCalendarGrid(new Date());
|
|
7
|
-
expect(
|
|
8
|
-
result.every((date) => date instanceof Date)
|
|
9
|
-
).toBe(true);
|
|
10
|
+
expect(result.every((date) => date instanceof Date)).toBe(true);
|
|
10
11
|
});
|
|
11
12
|
|
|
12
13
|
test('Throws an error if no date is provided', () => {
|
|
13
14
|
// @ts-expect-error - Expected behaviour is an error to be thrown
|
|
14
|
-
expect(() => getDatesForCalendarGrid()).toThrowError(
|
|
15
|
+
expect(() => getDatesForCalendarGrid()).toThrowError('No date provided');
|
|
16
|
+
// @ts-expect-error - Expected behaviour is an error to be thrown
|
|
17
|
+
expect(() => getDatesForCalendarGrid(null)).toThrowError(
|
|
15
18
|
'No date provided'
|
|
16
19
|
);
|
|
17
|
-
expect(() =>
|
|
18
|
-
// @ts-expect-error - Expected behaviour is an error to be thrown
|
|
19
|
-
getDatesForCalendarGrid(null)
|
|
20
|
-
).toThrowError('No date provided');
|
|
21
|
-
expect(() =>
|
|
22
|
-
// @ts-expect-error - Expected behaviour is an error to be thrown
|
|
23
|
-
getDatesForCalendarGrid(undefined)
|
|
24
|
-
).toThrowError('No date provided');
|
|
25
20
|
// @ts-expect-error - Expected behaviour is an error to be thrown
|
|
26
|
-
expect(() => getDatesForCalendarGrid(
|
|
21
|
+
expect(() => getDatesForCalendarGrid(undefined)).toThrowError(
|
|
27
22
|
'No date provided'
|
|
28
23
|
);
|
|
29
24
|
// @ts-expect-error - Expected behaviour is an error to be thrown
|
|
30
|
-
expect(() => getDatesForCalendarGrid(
|
|
25
|
+
expect(() => getDatesForCalendarGrid('')).toThrowError('No date provided');
|
|
26
|
+
// @ts-expect-error - Expected behaviour is an error to be thrown
|
|
27
|
+
expect(() => getDatesForCalendarGrid(0)).toThrowError('No date provided');
|
|
28
|
+
// @ts-expect-error - Expected behaviour is an error to be thrown
|
|
29
|
+
expect(() => getDatesForCalendarGrid('1st of March')).toThrowError(
|
|
31
30
|
'No date provided'
|
|
32
31
|
);
|
|
33
|
-
expect(() =>
|
|
34
|
-
// @ts-expect-error - Expected behaviour is an error to be thrown
|
|
35
|
-
getDatesForCalendarGrid('1st of March')
|
|
36
|
-
).toThrowError('No date provided');
|
|
37
32
|
});
|
|
38
33
|
|
|
39
34
|
test('Total dates returned are always divisible by 7', () => {
|
|
40
|
-
expect(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
).toBe(0);
|
|
44
|
-
expect(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
).toBe(0);
|
|
48
|
-
expect(
|
|
49
|
-
getDatesForCalendarGrid(new Date(2025, 3, 15))
|
|
50
|
-
.length % 7
|
|
51
|
-
).toBe(0);
|
|
52
|
-
expect(
|
|
53
|
-
getDatesForCalendarGrid(new Date(2025, 4, 20))
|
|
54
|
-
.length % 7
|
|
55
|
-
).toBe(0);
|
|
56
|
-
expect(
|
|
57
|
-
getDatesForCalendarGrid(new Date(2025, 5, 25))
|
|
58
|
-
.length % 7
|
|
59
|
-
).toBe(0);
|
|
60
|
-
expect(
|
|
61
|
-
getDatesForCalendarGrid(new Date(2025, 6, 30))
|
|
62
|
-
.length % 7
|
|
63
|
-
).toBe(0);
|
|
64
|
-
expect(
|
|
65
|
-
getDatesForCalendarGrid(new Date(2025, 12, 0))
|
|
66
|
-
.length % 7
|
|
67
|
-
).toBe(0);
|
|
35
|
+
expect(getDatesForCalendarGrid(new Date(2025, 1, 1)).length % 7).toBe(0);
|
|
36
|
+
expect(getDatesForCalendarGrid(new Date(2025, 2, 5)).length % 7).toBe(0);
|
|
37
|
+
expect(getDatesForCalendarGrid(new Date(2025, 3, 15)).length % 7).toBe(0);
|
|
38
|
+
expect(getDatesForCalendarGrid(new Date(2025, 4, 20)).length % 7).toBe(0);
|
|
39
|
+
expect(getDatesForCalendarGrid(new Date(2025, 5, 25)).length % 7).toBe(0);
|
|
40
|
+
expect(getDatesForCalendarGrid(new Date(2025, 6, 30)).length % 7).toBe(0);
|
|
41
|
+
expect(getDatesForCalendarGrid(new Date(2025, 12, 0)).length % 7).toBe(0);
|
|
68
42
|
});
|
|
69
43
|
|
|
70
|
-
test('If date is in Jan 2025, returns all dates in January
|
|
44
|
+
test('If date is in Jan 2025, returns all dates in January 2025', () => {
|
|
71
45
|
const date = new Date(2025, 0, 1);
|
|
72
46
|
const result = getDatesForCalendarGrid(date);
|
|
73
47
|
const janDates = [];
|
|
74
|
-
for (let i = 1; i <= 31; i++)
|
|
75
|
-
janDates.push(new Date(2025, 0, i));
|
|
48
|
+
for (let i = 1; i <= 31; i++) janDates.push(new Date(2025, 0, i));
|
|
76
49
|
janDates.forEach((dateInJan) => {
|
|
77
50
|
expect(result).toContainEqual(dateInJan);
|
|
78
51
|
});
|
|
@@ -88,12 +61,8 @@ describe('getDatesForCalendarGrid', () => {
|
|
|
88
61
|
test('If date is in Jan 2025, returns 1st & 2nd Feb 2025 at the end', () => {
|
|
89
62
|
const date = new Date(2025, 0, 1);
|
|
90
63
|
const result = getDatesForCalendarGrid(date);
|
|
91
|
-
expect(result[result.length - 2]).toEqual(
|
|
92
|
-
|
|
93
|
-
);
|
|
94
|
-
expect(result[result.length - 1]).toEqual(
|
|
95
|
-
new Date(2025, 1, 2)
|
|
96
|
-
);
|
|
64
|
+
expect(result[result.length - 2]).toEqual(new Date(2025, 1, 1));
|
|
65
|
+
expect(result[result.length - 1]).toEqual(new Date(2025, 1, 2));
|
|
97
66
|
});
|
|
98
67
|
|
|
99
68
|
test('If month starts on a Sunday, the total dates returned are divisible by 7', () => {
|
|
@@ -101,12 +70,12 @@ describe('getDatesForCalendarGrid', () => {
|
|
|
101
70
|
const result = getDatesForCalendarGrid(date);
|
|
102
71
|
expect(result.length % 7).toBe(0);
|
|
103
72
|
});
|
|
73
|
+
|
|
104
74
|
test('handles February in leap year correctly', () => {
|
|
105
75
|
const leapYear = new Date(2024, 1, 1); // February 2024
|
|
106
76
|
const result = getDatesForCalendarGrid(leapYear);
|
|
107
77
|
const febDates = [];
|
|
108
|
-
for (let i = 1; i <= 29; i++)
|
|
109
|
-
febDates.push(new Date(2024, 1, i));
|
|
78
|
+
for (let i = 1; i <= 29; i++) febDates.push(new Date(2024, 1, i));
|
|
110
79
|
febDates.forEach((date) => {
|
|
111
80
|
expect(result).toContainEqual(date);
|
|
112
81
|
});
|
|
@@ -116,8 +85,7 @@ describe('getDatesForCalendarGrid', () => {
|
|
|
116
85
|
const nonLeapYear = new Date(2025, 1, 1); // February 2025
|
|
117
86
|
const result = getDatesForCalendarGrid(nonLeapYear);
|
|
118
87
|
const febDates = [];
|
|
119
|
-
for (let i = 1; i <= 28; i++)
|
|
120
|
-
febDates.push(new Date(2025, 1, i));
|
|
88
|
+
for (let i = 1; i <= 28; i++) febDates.push(new Date(2025, 1, i));
|
|
121
89
|
febDates.forEach((date) => {
|
|
122
90
|
expect(result).toContainEqual(date);
|
|
123
91
|
});
|
|
@@ -127,18 +95,14 @@ describe('getDatesForCalendarGrid', () => {
|
|
|
127
95
|
const date = new Date(2025, 3, 1); // April 2025
|
|
128
96
|
const result = getDatesForCalendarGrid(date);
|
|
129
97
|
for (let i = 1; i < result.length; i++) {
|
|
130
|
-
expect(result[i].getTime()).toBeGreaterThan(
|
|
131
|
-
result[i - 1].getTime()
|
|
132
|
-
);
|
|
98
|
+
expect(result[i].getTime()).toBeGreaterThan(result[i - 1].getTime());
|
|
133
99
|
}
|
|
134
100
|
});
|
|
135
101
|
|
|
136
102
|
test('correctly handles months with 31 days', () => {
|
|
137
103
|
const date = new Date(2025, 0, 1); // January 2025
|
|
138
104
|
const result = getDatesForCalendarGrid(date);
|
|
139
|
-
expect(
|
|
140
|
-
result.filter((d) => d.getMonth() === 0).length
|
|
141
|
-
).toBe(31);
|
|
105
|
+
expect(result.filter((d) => d.getMonth() === 0).length).toBe(31);
|
|
142
106
|
});
|
|
143
107
|
|
|
144
108
|
test('week always starts with Monday', () => {
|