@navikt/ds-react 5.5.0 → 5.6.0
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/_docs.json +507 -106
- package/cjs/accordion/Accordion.js +1 -0
- package/cjs/accordion/AccordionContext.js +1 -1
- package/cjs/accordion/AccordionHeader.js +2 -2
- package/cjs/accordion/AccordionItem.js +6 -2
- package/cjs/date/datepicker/DatePicker.js +30 -34
- package/cjs/date/datepicker/DatePickerStandalone.js +23 -26
- package/cjs/date/datepicker/parts/Caption.js +28 -0
- package/cjs/date/datepicker/{DayButton.js → parts/DayButton.js} +1 -2
- package/cjs/date/datepicker/{caption → parts}/DropdownCaption.js +13 -7
- package/cjs/date/datepicker/parts/HeadRow.js +36 -0
- package/cjs/date/datepicker/parts/Row.js +23 -0
- package/cjs/date/datepicker/{TableHead.js → parts/TableHead.js} +4 -3
- package/cjs/date/datepicker/parts/WeekNumber.js +35 -0
- package/cjs/date/datepicker/parts/WeekRow.js +34 -0
- package/cjs/date/hooks/useDatepicker.js +2 -2
- package/cjs/date/hooks/useMonthPicker.js +2 -2
- package/cjs/date/hooks/useRangeDatepicker.js +3 -3
- package/cjs/date/monthpicker/MonthSelector.js +1 -1
- package/cjs/date/utils/get-month-weeks.js +46 -0
- package/cjs/date/utils/labels.js +40 -1
- package/cjs/dropdown/Toggle.js +2 -2
- package/cjs/dropdown/index.js +0 -15
- package/cjs/form/Select.js +1 -1
- package/cjs/form/checkbox/useCheckbox.js +3 -4
- package/cjs/form/combobox/Combobox.js +1 -1
- package/cjs/form/combobox/Input/Input.js +1 -1
- package/cjs/form/search/Search.js +3 -1
- package/cjs/index.js +1 -0
- package/cjs/layout/bleed/Bleed.js +69 -0
- package/cjs/layout/bleed/index.js +5 -0
- package/cjs/layout/bleed/package.json +6 -0
- package/cjs/layout/box/Box.js +1 -1
- package/cjs/layout/responsive/Responsive.js +8 -6
- package/cjs/layout/sidemal-test/AvatarPanel.js +18 -0
- package/cjs/layout/sidemal-test/Content.js +66 -0
- package/cjs/layout/sidemal-test/Filter.js +48 -0
- package/cjs/layout/sidemal-test/Header.js +48 -0
- package/cjs/layout/sidemal-test/Intro.js +36 -0
- package/cjs/layout/sidemal-test/Sidebar.js +49 -0
- package/cjs/layout/sidemal-test/content-box/ContentBox.js +65 -0
- package/cjs/layout/sidemal-test/content-box/index.js +8 -0
- package/cjs/layout/sidemal-test/content-box/package.json +6 -0
- package/cjs/layout/stack/Stack.js +2 -2
- package/cjs/layout/stack/index.js +3 -1
- package/cjs/layout/utilities/css.js +37 -14
- package/cjs/loader/Loader.js +2 -2
- package/cjs/modal/dialog-polyfill.js +2 -0
- package/cjs/popover/Popover.js +3 -2
- package/cjs/tabs/TabList.js +6 -7
- package/cjs/timeline/Pin.js +20 -20
- package/cjs/timeline/Timeline.js +4 -4
- package/cjs/timeline/period/ClickablePeriod.js +19 -19
- package/cjs/timeline/period/index.js +1 -1
- package/cjs/timeline/utils/timeline.js +3 -3
- package/cjs/toggle-group/ToggleGroup.js +1 -1
- package/cjs/tooltip/Tooltip.js +1 -1
- package/cjs/typography/Heading.js +1 -1
- package/cjs/util/RandomIcon.js +1 -0
- package/cjs/util/Slot.js +88 -0
- package/cjs/util/useId.js +2 -4
- package/esm/accordion/Accordion.js +1 -0
- package/esm/accordion/Accordion.js.map +1 -1
- package/esm/accordion/AccordionContext.d.ts +1 -0
- package/esm/accordion/AccordionContext.js +1 -1
- package/esm/accordion/AccordionContext.js.map +1 -1
- package/esm/accordion/AccordionHeader.js +2 -2
- package/esm/accordion/AccordionHeader.js.map +1 -1
- package/esm/accordion/AccordionItem.js +6 -2
- package/esm/accordion/AccordionItem.js.map +1 -1
- package/esm/date/datepicker/DatePicker.d.ts +14 -5
- package/esm/date/datepicker/DatePicker.js +29 -33
- package/esm/date/datepicker/DatePicker.js.map +1 -1
- package/esm/date/datepicker/DatePickerStandalone.d.ts +3 -2
- package/esm/date/datepicker/DatePickerStandalone.js +22 -25
- package/esm/date/datepicker/DatePickerStandalone.js.map +1 -1
- package/esm/date/datepicker/{caption → parts}/Caption.d.ts +3 -0
- package/esm/date/datepicker/parts/Caption.js +22 -0
- package/esm/date/datepicker/parts/Caption.js.map +1 -0
- package/esm/date/datepicker/parts/DayButton.d.ts +4 -0
- package/esm/date/datepicker/{DayButton.js → parts/DayButton.js} +2 -1
- package/esm/date/datepicker/parts/DayButton.js.map +1 -0
- package/esm/date/datepicker/{caption → parts}/DropdownCaption.d.ts +3 -0
- package/esm/date/datepicker/parts/DropdownCaption.js +44 -0
- package/esm/date/datepicker/parts/DropdownCaption.js.map +1 -0
- package/esm/date/datepicker/parts/HeadRow.d.ts +11 -0
- package/esm/date/datepicker/parts/HeadRow.js +29 -0
- package/esm/date/datepicker/parts/HeadRow.js.map +1 -0
- package/esm/date/datepicker/parts/Row.d.ts +17 -0
- package/esm/date/datepicker/parts/Row.js +19 -0
- package/esm/date/datepicker/parts/Row.js.map +1 -0
- package/esm/date/datepicker/parts/TableHead.d.ts +6 -0
- package/esm/date/datepicker/{TableHead.js → parts/TableHead.js} +5 -2
- package/esm/date/datepicker/parts/TableHead.js.map +1 -0
- package/esm/date/datepicker/parts/WeekNumber.d.ts +13 -0
- package/esm/date/datepicker/parts/WeekNumber.js +31 -0
- package/esm/date/datepicker/parts/WeekNumber.js.map +1 -0
- package/esm/date/datepicker/parts/WeekRow.d.ts +5 -0
- package/esm/date/datepicker/parts/WeekRow.js +30 -0
- package/esm/date/datepicker/parts/WeekRow.js.map +1 -0
- package/esm/date/hooks/useDatepicker.js +2 -2
- package/esm/date/hooks/useDatepicker.js.map +1 -1
- package/esm/date/hooks/useMonthPicker.js +2 -2
- package/esm/date/hooks/useMonthPicker.js.map +1 -1
- package/esm/date/hooks/useRangeDatepicker.js +3 -3
- package/esm/date/hooks/useRangeDatepicker.js.map +1 -1
- package/esm/date/monthpicker/MonthButton.d.ts +2 -2
- package/esm/date/monthpicker/MonthPicker.d.ts +1 -1
- package/esm/date/monthpicker/MonthSelector.js +1 -1
- package/esm/date/monthpicker/MonthSelector.js.map +1 -1
- package/esm/date/utils/get-month-weeks.d.ts +16 -0
- package/esm/date/utils/get-month-weeks.js +42 -0
- package/esm/date/utils/get-month-weeks.js.map +1 -0
- package/esm/date/utils/labels.d.ts +9 -0
- package/esm/date/utils/labels.js +36 -0
- package/esm/date/utils/labels.js.map +1 -1
- package/esm/date/utils/navigation.d.ts +1 -1
- package/esm/date/utils/navigation.js.map +1 -1
- package/esm/dropdown/Toggle.js +1 -1
- package/esm/dropdown/Toggle.js.map +1 -1
- package/esm/dropdown/index.d.ts +1 -2
- package/esm/dropdown/index.js +0 -1
- package/esm/dropdown/index.js.map +1 -1
- package/esm/form/Select.js +1 -1
- package/esm/form/Select.js.map +1 -1
- package/esm/form/checkbox/useCheckbox.d.ts +1 -1
- package/esm/form/checkbox/useCheckbox.js +3 -4
- package/esm/form/checkbox/useCheckbox.js.map +1 -1
- package/esm/form/combobox/Combobox.d.ts +1 -1
- package/esm/form/combobox/Combobox.js +1 -1
- package/esm/form/combobox/Combobox.js.map +1 -1
- package/esm/form/combobox/Input/Input.d.ts +0 -2
- package/esm/form/combobox/Input/Input.js +1 -1
- package/esm/form/combobox/Input/Input.js.map +1 -1
- package/esm/form/search/Search.js +3 -1
- package/esm/form/search/Search.js.map +1 -1
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/layout/bleed/Bleed.d.ts +47 -0
- package/esm/layout/bleed/Bleed.js +41 -0
- package/esm/layout/bleed/Bleed.js.map +1 -0
- package/esm/layout/bleed/index.d.ts +1 -0
- package/esm/layout/bleed/index.js +2 -0
- package/esm/layout/bleed/index.js.map +1 -0
- package/esm/layout/box/Box.d.ts +1 -2
- package/esm/layout/box/Box.js +1 -1
- package/esm/layout/box/Box.js.map +1 -1
- package/esm/layout/responsive/Responsive.d.ts +8 -4
- package/esm/layout/responsive/Responsive.js +8 -6
- package/esm/layout/responsive/Responsive.js.map +1 -1
- package/esm/layout/sidemal-test/AvatarPanel.d.ts +4 -0
- package/esm/layout/sidemal-test/AvatarPanel.js +12 -0
- package/esm/layout/sidemal-test/AvatarPanel.js.map +1 -0
- package/esm/layout/sidemal-test/Content.d.ts +2 -0
- package/esm/layout/sidemal-test/Content.js +60 -0
- package/esm/layout/sidemal-test/Content.js.map +1 -0
- package/esm/layout/sidemal-test/Filter.d.ts +2 -0
- package/esm/layout/sidemal-test/Filter.js +22 -0
- package/esm/layout/sidemal-test/Filter.js.map +1 -0
- package/esm/layout/sidemal-test/Header.d.ts +2 -0
- package/esm/layout/sidemal-test/Header.js +42 -0
- package/esm/layout/sidemal-test/Header.js.map +1 -0
- package/esm/layout/sidemal-test/Intro.d.ts +2 -0
- package/esm/layout/sidemal-test/Intro.js +30 -0
- package/esm/layout/sidemal-test/Intro.js.map +1 -0
- package/esm/layout/sidemal-test/Sidebar.d.ts +4 -0
- package/esm/layout/sidemal-test/Sidebar.js +41 -0
- package/esm/layout/sidemal-test/Sidebar.js.map +1 -0
- package/esm/layout/sidemal-test/content-box/ContentBox.d.ts +8 -0
- package/esm/layout/sidemal-test/content-box/ContentBox.js +37 -0
- package/esm/layout/sidemal-test/content-box/ContentBox.js.map +1 -0
- package/esm/layout/sidemal-test/content-box/index.d.ts +1 -0
- package/esm/layout/sidemal-test/content-box/index.js +2 -0
- package/esm/layout/sidemal-test/content-box/index.js.map +1 -0
- package/esm/layout/stack/Stack.d.ts +7 -3
- package/esm/layout/stack/Stack.js +3 -3
- package/esm/layout/stack/Stack.js.map +1 -1
- package/esm/layout/stack/index.d.ts +1 -0
- package/esm/layout/stack/index.js +1 -0
- package/esm/layout/stack/index.js.map +1 -1
- package/esm/layout/utilities/css.d.ts +1 -1
- package/esm/layout/utilities/css.js +37 -14
- package/esm/layout/utilities/css.js.map +1 -1
- package/esm/loader/Loader.js +3 -3
- package/esm/loader/Loader.js.map +1 -1
- package/esm/modal/dialog-polyfill.js +2 -0
- package/esm/modal/dialog-polyfill.js.map +1 -1
- package/esm/popover/Popover.js +3 -2
- package/esm/popover/Popover.js.map +1 -1
- package/esm/tabs/TabList.js +6 -7
- package/esm/tabs/TabList.js.map +1 -1
- package/esm/timeline/Pin.js +21 -21
- package/esm/timeline/Pin.js.map +1 -1
- package/esm/timeline/Timeline.js +4 -4
- package/esm/timeline/Timeline.js.map +1 -1
- package/esm/timeline/TimelineRow.js.map +1 -1
- package/esm/timeline/hooks/usePeriodContext.d.ts +1 -1
- package/esm/timeline/period/ClickablePeriod.js +20 -20
- package/esm/timeline/period/ClickablePeriod.js.map +1 -1
- package/esm/timeline/period/index.d.ts +2 -2
- package/esm/timeline/period/index.js +1 -1
- package/esm/timeline/period/index.js.map +1 -1
- package/esm/timeline/utils/timeline.js +3 -3
- package/esm/timeline/utils/timeline.js.map +1 -1
- package/esm/toggle-group/ToggleGroup.js +1 -1
- package/esm/toggle-group/ToggleGroup.js.map +1 -1
- package/esm/tooltip/Tooltip.js +1 -1
- package/esm/tooltip/Tooltip.js.map +1 -1
- package/esm/typography/Heading.js +1 -1
- package/esm/typography/Heading.js.map +1 -1
- package/esm/util/RandomIcon.js +1 -0
- package/esm/util/RandomIcon.js.map +1 -1
- package/esm/util/Slot.d.ts +6 -0
- package/esm/util/Slot.js +60 -0
- package/esm/util/Slot.js.map +1 -0
- package/esm/util/mergeRefs.d.ts +1 -1
- package/esm/util/useId.js +2 -4
- package/esm/util/useId.js.map +1 -1
- package/package.json +4 -4
- package/src/accordion/Accordion.tsx +1 -0
- package/src/accordion/AccordionContext.tsx +2 -1
- package/src/accordion/AccordionHeader.tsx +2 -2
- package/src/accordion/AccordionItem.tsx +7 -5
- package/src/accordion/accordion.stories.tsx +21 -34
- package/src/alert/alert.stories.tsx +2 -2
- package/src/chips/chips.stories.tsx +29 -32
- package/src/date/datepicker/DatePicker.tsx +63 -58
- package/src/date/datepicker/DatePickerStandalone.tsx +36 -39
- package/src/date/datepicker/datepicker.stories.tsx +67 -2
- package/src/date/datepicker/datepicker.test.tsx +5 -4
- package/src/date/datepicker/{caption → parts}/Caption.tsx +19 -17
- package/src/date/datepicker/{DayButton.tsx → parts/DayButton.tsx} +3 -1
- package/src/date/datepicker/parts/DropdownCaption.tsx +113 -0
- package/src/date/datepicker/parts/HeadRow.tsx +56 -0
- package/src/date/datepicker/parts/Row.tsx +47 -0
- package/src/date/datepicker/{TableHead.tsx → parts/TableHead.tsx} +6 -2
- package/src/date/datepicker/parts/WeekNumber.tsx +79 -0
- package/src/date/datepicker/parts/WeekRow.tsx +60 -0
- package/src/date/hooks/useDatepicker.tsx +2 -2
- package/src/date/hooks/useMonthPicker.tsx +2 -2
- package/src/date/hooks/useRangeDatepicker.test.tsx +11 -11
- package/src/date/hooks/useRangeDatepicker.tsx +3 -3
- package/src/date/monthpicker/MonthButton.tsx +2 -2
- package/src/date/monthpicker/MonthPicker.tsx +1 -1
- package/src/date/monthpicker/MonthSelector.tsx +3 -3
- package/src/date/monthpicker/monthpicker.stories.tsx +1 -1
- package/src/date/utils/__tests__/get-initial-year.test.ts +0 -12
- package/src/date/utils/__tests__/get-month-weeks.test.ts +113 -0
- package/src/date/utils/__tests__/is-match.test.ts +3 -3
- package/src/date/utils/__tests__/parse-dates.test.ts +4 -2
- package/src/date/utils/get-month-weeks.ts +93 -0
- package/src/date/utils/labels.ts +51 -0
- package/src/date/utils/navigation.ts +3 -3
- package/src/dropdown/Toggle.tsx +1 -1
- package/src/dropdown/dropdown.stories.tsx +25 -28
- package/src/dropdown/index.ts +1 -2
- package/src/expansion-card/expansion-card.stories.tsx +143 -161
- package/src/form/ConfirmationPanel.test.tsx +5 -5
- package/src/form/Select.tsx +1 -1
- package/src/form/checkbox/Checkbox.test.tsx +14 -26
- package/src/form/checkbox/checkbox.stories.tsx +66 -71
- package/src/form/checkbox/useCheckbox.ts +3 -4
- package/src/form/combobox/Combobox.tsx +2 -3
- package/src/form/combobox/Input/Input.tsx +1 -3
- package/src/form/combobox/combobox.stories.tsx +20 -23
- package/src/form/combobox/combobox.test.tsx +22 -20
- package/src/form/radio/radio.stories.tsx +39 -44
- package/src/form/search/Search.tsx +1 -0
- package/src/form/search/search.stories.tsx +22 -26
- package/src/form/stories/fieldset.stories.tsx +1 -1
- package/src/index.ts +1 -0
- package/src/layout/bleed/Bleed.stories.tsx +381 -0
- package/src/layout/bleed/Bleed.tsx +130 -0
- package/src/layout/bleed/index.ts +1 -0
- package/src/layout/box/Box.stories.tsx +251 -256
- package/src/layout/box/Box.tsx +2 -1
- package/src/layout/responsive/Responsive.tsx +21 -6
- package/src/layout/responsive/hide.stories.tsx +35 -0
- package/src/layout/responsive/show.stories.tsx +35 -0
- package/src/layout/sidemal-test/AvatarPanel.tsx +27 -0
- package/src/layout/sidemal-test/Content.tsx +129 -0
- package/src/layout/sidemal-test/Filter.tsx +46 -0
- package/src/layout/sidemal-test/Header.tsx +96 -0
- package/src/layout/sidemal-test/Intro.tsx +91 -0
- package/src/layout/sidemal-test/Sidebar.tsx +77 -0
- package/src/layout/sidemal-test/content-box/ContentBox.tsx +46 -0
- package/src/layout/sidemal-test/content-box/index.ts +1 -0
- package/src/layout/sidemal-test/navno-sidemal.stories.mdx +29 -0
- package/src/layout/sidemal-test/navno-sidemal.stories.tsx +65 -0
- package/src/layout/sidemal-test/styling.css +43 -0
- package/src/layout/stack/Stack.tsx +14 -8
- package/src/layout/stack/index.ts +1 -0
- package/src/layout/stack/stack.stories.tsx +23 -1
- package/src/layout/utilities/css.ts +59 -20
- package/src/loader/Loader.tsx +2 -3
- package/src/modal/dialog-polyfill.ts +2 -0
- package/src/pagination/pagination.stories.tsx +35 -42
- package/src/popover/Popover.test.tsx +21 -35
- package/src/popover/Popover.tsx +2 -2
- package/src/popover/popover.stories.tsx +25 -41
- package/src/react-css.d.ts +0 -1
- package/src/read-more/readmore.stories.tsx +35 -36
- package/src/stepper/stepper.stories.tsx +45 -52
- package/src/table/stories/table-expandable.stories.tsx +59 -63
- package/src/tabs/TabList.tsx +4 -6
- package/src/tabs/Tabs.stories.tsx +3 -3
- package/src/tag/tag.stories.tsx +4 -4
- package/src/timeline/Pin.tsx +44 -39
- package/src/timeline/Timeline.tsx +6 -6
- package/src/timeline/TimelineRow.tsx +1 -0
- package/src/timeline/hooks/usePeriodContext.tsx +1 -1
- package/src/timeline/period/ClickablePeriod.tsx +42 -38
- package/src/timeline/period/index.tsx +5 -4
- package/src/timeline/timeline.stories.tsx +11 -10
- package/src/timeline/utils/timeline.ts +3 -3
- package/src/toggle-group/ToggleGroup.stories.tsx +25 -29
- package/src/toggle-group/ToggleGroup.tsx +0 -1
- package/src/tooltip/Tooltip.test.tsx +40 -54
- package/src/tooltip/Tooltip.tsx +1 -1
- package/src/typography/Heading.tsx +1 -1
- package/src/util/RandomIcon.tsx +1 -0
- package/src/util/Slot.tsx +69 -0
- package/src/util/__tests__/Slot.test.tsx +98 -0
- package/src/util/mergeRefs.tsx +1 -1
- package/src/util/useId.ts +1 -3
- package/cjs/date/datepicker/caption/Caption.js +0 -23
- package/cjs/date/datepicker/caption/index.js +0 -10
- package/cjs/date/datepicker/caption/package.json +0 -6
- package/esm/date/datepicker/DayButton.d.ts +0 -3
- package/esm/date/datepicker/DayButton.js.map +0 -1
- package/esm/date/datepicker/TableHead.d.ts +0 -3
- package/esm/date/datepicker/TableHead.js.map +0 -1
- package/esm/date/datepicker/caption/Caption.js +0 -17
- package/esm/date/datepicker/caption/Caption.js.map +0 -1
- package/esm/date/datepicker/caption/DropdownCaption.js +0 -38
- package/esm/date/datepicker/caption/DropdownCaption.js.map +0 -1
- package/esm/date/datepicker/caption/index.d.ts +0 -2
- package/esm/date/datepicker/caption/index.js +0 -3
- package/esm/date/datepicker/caption/index.js.map +0 -1
- package/src/date/datepicker/caption/DropdownCaption.tsx +0 -108
- package/src/date/datepicker/caption/index.ts +0 -2
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/* https://github.com/gpbl/react-day-picker/blob/main/src/components/Table/utils/getMonthWeeks.test.ts */
|
|
2
|
+
import { nb, enGB } from "date-fns/locale";
|
|
3
|
+
|
|
4
|
+
import { getMonthWeeks } from "../get-month-weeks";
|
|
5
|
+
|
|
6
|
+
describe('when using the "nB" locale', () => {
|
|
7
|
+
const locale = nb;
|
|
8
|
+
describe("when getting the weeks for January 2022", () => {
|
|
9
|
+
const date = new Date(2022, 0);
|
|
10
|
+
const weeks = getMonthWeeks(date, { locale });
|
|
11
|
+
test("the first week should be the last of the previous year", () => {
|
|
12
|
+
const weekNumbers = weeks.map((week) => week.weekNumber);
|
|
13
|
+
expect(weekNumbers[0]).toEqual(52);
|
|
14
|
+
});
|
|
15
|
+
test("the first week should contain days from previous year", () => {
|
|
16
|
+
expect(weeks[0].dates.map((date) => date.getDate())).toEqual([
|
|
17
|
+
27, 28, 29, 30, 31, 1, 2,
|
|
18
|
+
]);
|
|
19
|
+
});
|
|
20
|
+
test("the last week should be the last of January", () => {
|
|
21
|
+
const weekNumbers = weeks.map((week) => week.weekNumber);
|
|
22
|
+
expect(weekNumbers[weekNumbers.length - 1]).toEqual(5);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('when using the "enGB" locale', () => {
|
|
28
|
+
const locale = enGB;
|
|
29
|
+
describe("when using fixed weeks", () => {
|
|
30
|
+
const useFixedWeeks = true;
|
|
31
|
+
describe("when getting the weeks for December 2022", () => {
|
|
32
|
+
const date = new Date(2022, 11);
|
|
33
|
+
const weeks = getMonthWeeks(date, { useFixedWeeks, locale });
|
|
34
|
+
test("should return 48 - 1 week numbers", () => {
|
|
35
|
+
const weekNumbers = weeks.map((week) => week.weekNumber);
|
|
36
|
+
const expectedResult = [48, 49, 50, 51, 52, 1];
|
|
37
|
+
expect(weekNumbers).toEqual(expectedResult);
|
|
38
|
+
});
|
|
39
|
+
test("the last week should be the one in the next year", () => {
|
|
40
|
+
const lastWeek = weeks[weeks.length - 1];
|
|
41
|
+
const lastWeekDates = lastWeek.dates.map((date) => date.getDate());
|
|
42
|
+
const expectedResult = [2, 3, 4, 5, 6, 7, 8];
|
|
43
|
+
expect(lastWeekDates).toEqual(expectedResult);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
describe("when getting the weeks for December 2021", () => {
|
|
47
|
+
const weeks = getMonthWeeks(new Date(2021, 11), {
|
|
48
|
+
useFixedWeeks,
|
|
49
|
+
locale,
|
|
50
|
+
});
|
|
51
|
+
test("should return 48 - 1 week numbers", () => {
|
|
52
|
+
const weekNumbers = weeks.map((week) => week.weekNumber);
|
|
53
|
+
const expectedResult = [48, 49, 50, 51, 52, 1];
|
|
54
|
+
expect(weekNumbers).toEqual(expectedResult);
|
|
55
|
+
});
|
|
56
|
+
test("week 1 contains the first day of the new year", () => {
|
|
57
|
+
expect(weeks[4].dates.map((date) => date.getDate())).toEqual([
|
|
58
|
+
27, 28, 29, 30, 31, 1, 2,
|
|
59
|
+
]);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('when using the "nb" locale', () => {
|
|
66
|
+
const locale = nb;
|
|
67
|
+
describe("when using fixed weeks", () => {
|
|
68
|
+
const useFixedWeeks = true;
|
|
69
|
+
describe("when getting the weeks for December 2022", () => {
|
|
70
|
+
const date = new Date(2022, 11);
|
|
71
|
+
const weeks = getMonthWeeks(date, { useFixedWeeks, locale });
|
|
72
|
+
test("should return 48 - 1 week numbers", () => {
|
|
73
|
+
const weekNumbers = weeks.map((week) => week.weekNumber);
|
|
74
|
+
const expectedResult = [48, 49, 50, 51, 52, 1];
|
|
75
|
+
expect(weekNumbers).toEqual(expectedResult);
|
|
76
|
+
});
|
|
77
|
+
test("the last week should be the one in the next year", () => {
|
|
78
|
+
const lastWeek = weeks[weeks.length - 1];
|
|
79
|
+
const lastWeekDates = lastWeek.dates.map((date) => date.getDate());
|
|
80
|
+
const expectedResult = [2, 3, 4, 5, 6, 7, 8];
|
|
81
|
+
expect(lastWeekDates).toEqual(expectedResult);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
describe("when getting the weeks for December 2021", () => {
|
|
85
|
+
const weeks = getMonthWeeks(new Date(2021, 11), {
|
|
86
|
+
useFixedWeeks,
|
|
87
|
+
locale,
|
|
88
|
+
});
|
|
89
|
+
test("should return 48 - 1 week numbers", () => {
|
|
90
|
+
const weekNumbers = weeks.map((week) => week.weekNumber);
|
|
91
|
+
const expectedResult = [48, 49, 50, 51, 52, 1];
|
|
92
|
+
expect(weekNumbers).toEqual(expectedResult);
|
|
93
|
+
});
|
|
94
|
+
test("week 1 contains the first day of the new year", () => {
|
|
95
|
+
expect(weeks[4].dates.map((date) => date.getDate())).toEqual([
|
|
96
|
+
27, 28, 29, 30, 31, 1, 2,
|
|
97
|
+
]);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe("getMonthWeeks should calculate week-number corectly", () => {
|
|
104
|
+
const locale = nb;
|
|
105
|
+
describe("when getting the weeks for September 2022", () => {
|
|
106
|
+
const date = new Date(2022, 8);
|
|
107
|
+
const weeks = getMonthWeeks(date, { locale });
|
|
108
|
+
test("the last week should have number 39", () => {
|
|
109
|
+
const weekNumbers = weeks.map((week) => week.weekNumber);
|
|
110
|
+
expect(weekNumbers[weekNumbers.length - 1]).toEqual(39);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -13,13 +13,13 @@ describe("Returns if date is disabled", () => {
|
|
|
13
13
|
test("Date should be disabled type Date[] (true)", () => {
|
|
14
14
|
expect(isMatch(new Date("Dec 4 2011"), disabled)).toBeTruthy();
|
|
15
15
|
});
|
|
16
|
-
test("Date should be disabled type Range (
|
|
16
|
+
test("Date should be disabled type Range (false)", () => {
|
|
17
17
|
expect(isMatch(new Date("Sep 5 2023"), disabled)).toBeTruthy();
|
|
18
18
|
});
|
|
19
19
|
test("Date should be disabled type Range (true)", () => {
|
|
20
20
|
expect(isMatch(new Date("Sep 3 2023"), disabled)).toBeTruthy();
|
|
21
21
|
});
|
|
22
|
-
test("Date should be disabled type After (true)", () => {
|
|
22
|
+
test("Date should be disabled type After (same month)(true)", () => {
|
|
23
23
|
expect(
|
|
24
24
|
isMatch(new Date("Aug 5 2018"), [{ after: new Date("Aug 2 2018") }])
|
|
25
25
|
).toBeTruthy();
|
|
@@ -34,7 +34,7 @@ describe("Returns if date is disabled", () => {
|
|
|
34
34
|
isMatch(new Date("Aug 1 2018"), [{ before: new Date("Aug 2 2018") }])
|
|
35
35
|
).toBeTruthy();
|
|
36
36
|
});
|
|
37
|
-
test("Date should be disabled type Before (
|
|
37
|
+
test("Date should be disabled type Before (false)", () => {
|
|
38
38
|
expect(
|
|
39
39
|
isMatch(new Date("Jul 1 2018"), [{ before: new Date("Aug 2 2018") }])
|
|
40
40
|
).toBeTruthy();
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import { isValidDate } from "..";
|
|
1
|
+
/* eslint-disable jest/expect-expect */
|
|
2
|
+
import { parseDate, isValidDate } from "..";
|
|
3
3
|
import nb from "date-fns/locale/nb";
|
|
4
4
|
import getMonth from "date-fns/getMonth";
|
|
5
5
|
|
|
6
6
|
const check = (inp: string) =>
|
|
7
|
+
// eslint-disable-next-line jest/valid-expect
|
|
7
8
|
expect(isValidDate(parseDate(inp, new Date(), nb, "date", false)));
|
|
8
9
|
|
|
9
10
|
const checkTwoDigit = (inp: string) =>
|
|
11
|
+
// eslint-disable-next-line jest/valid-expect
|
|
10
12
|
expect(isValidDate(parseDate(inp, new Date(), nb, "date", true)));
|
|
11
13
|
|
|
12
14
|
const parse = (inp: string) => parseDate(inp, new Date(), nb, "date", false);
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addDays,
|
|
3
|
+
addWeeks,
|
|
4
|
+
differenceInCalendarDays,
|
|
5
|
+
endOfMonth,
|
|
6
|
+
endOfWeek,
|
|
7
|
+
getWeek,
|
|
8
|
+
getWeeksInMonth,
|
|
9
|
+
Locale,
|
|
10
|
+
startOfMonth,
|
|
11
|
+
startOfWeek,
|
|
12
|
+
} from "date-fns";
|
|
13
|
+
|
|
14
|
+
export type MonthWeek = {
|
|
15
|
+
/** The week number from the start of the year. */
|
|
16
|
+
weekNumber: number;
|
|
17
|
+
/** The dates in the week. */
|
|
18
|
+
dates: Date[];
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export function getMonthWeeks(
|
|
22
|
+
month: Date,
|
|
23
|
+
options: {
|
|
24
|
+
locale: Locale;
|
|
25
|
+
useFixedWeeks?: boolean;
|
|
26
|
+
}
|
|
27
|
+
): MonthWeek[] {
|
|
28
|
+
const _options = {
|
|
29
|
+
...options,
|
|
30
|
+
weekStartsOn: 1 as const,
|
|
31
|
+
};
|
|
32
|
+
const weeksInMonth: MonthWeek[] = daysToMonthWeeks(
|
|
33
|
+
startOfMonth(month),
|
|
34
|
+
endOfMonth(month),
|
|
35
|
+
_options
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
if (_options?.useFixedWeeks) {
|
|
39
|
+
// Add extra weeks to the month, up to 6 weeks
|
|
40
|
+
const nrOfMonthWeeks = getWeeksInMonth(month, _options);
|
|
41
|
+
if (nrOfMonthWeeks < 6) {
|
|
42
|
+
const lastWeek = weeksInMonth[weeksInMonth.length - 1];
|
|
43
|
+
const lastDate = lastWeek.dates[lastWeek.dates.length - 1];
|
|
44
|
+
const toDate = addWeeks(lastDate, 6 - nrOfMonthWeeks);
|
|
45
|
+
const extraWeeks = daysToMonthWeeks(
|
|
46
|
+
addWeeks(lastDate, 1),
|
|
47
|
+
toDate,
|
|
48
|
+
_options
|
|
49
|
+
);
|
|
50
|
+
weeksInMonth.push(...extraWeeks);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return weeksInMonth;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Return the weeks between two dates. */
|
|
57
|
+
export function daysToMonthWeeks(
|
|
58
|
+
fromDate: Date,
|
|
59
|
+
toDate: Date,
|
|
60
|
+
options?: {
|
|
61
|
+
locale?: Locale;
|
|
62
|
+
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
63
|
+
}
|
|
64
|
+
): MonthWeek[] {
|
|
65
|
+
const toWeek = endOfWeek(toDate, options);
|
|
66
|
+
const fromWeek = startOfWeek(fromDate, options);
|
|
67
|
+
|
|
68
|
+
const nOfDays = differenceInCalendarDays(toWeek, fromWeek);
|
|
69
|
+
const days: Date[] = [];
|
|
70
|
+
|
|
71
|
+
for (let i = 0; i <= nOfDays; i++) {
|
|
72
|
+
days.push(addDays(fromWeek, i));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const weeksInMonth = days.reduce((result: MonthWeek[], date) => {
|
|
76
|
+
const weekNumber = getWeek(date, options);
|
|
77
|
+
|
|
78
|
+
const existingWeek = result.find(
|
|
79
|
+
(value) => value.weekNumber === weekNumber
|
|
80
|
+
);
|
|
81
|
+
if (existingWeek) {
|
|
82
|
+
existingWeek.dates.push(date);
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
result.push({
|
|
86
|
+
weekNumber,
|
|
87
|
+
dates: [date],
|
|
88
|
+
});
|
|
89
|
+
return result;
|
|
90
|
+
}, []);
|
|
91
|
+
|
|
92
|
+
return weeksInMonth;
|
|
93
|
+
}
|
package/src/date/utils/labels.ts
CHANGED
|
@@ -82,3 +82,54 @@ export const labels: Partial<Labels> = {
|
|
|
82
82
|
labelNext,
|
|
83
83
|
labelPrevious,
|
|
84
84
|
};
|
|
85
|
+
|
|
86
|
+
export const labelWeekNumber = ({
|
|
87
|
+
localeCode,
|
|
88
|
+
week,
|
|
89
|
+
}: {
|
|
90
|
+
localeCode?: string;
|
|
91
|
+
week: number;
|
|
92
|
+
}): string => {
|
|
93
|
+
switch (localeCode) {
|
|
94
|
+
case "nb":
|
|
95
|
+
return `Uke ${week}`;
|
|
96
|
+
case "nn":
|
|
97
|
+
return `Veke ${week}`;
|
|
98
|
+
case "en-GB":
|
|
99
|
+
return `Week ${week}`;
|
|
100
|
+
default:
|
|
101
|
+
return `Uke ${week}`;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const labelWeekNumberButton = ({
|
|
106
|
+
localeCode,
|
|
107
|
+
week,
|
|
108
|
+
}: {
|
|
109
|
+
localeCode?: string;
|
|
110
|
+
week: number;
|
|
111
|
+
}): string => {
|
|
112
|
+
switch (localeCode) {
|
|
113
|
+
case "nb":
|
|
114
|
+
return `Velg uke ${week}`;
|
|
115
|
+
case "nn":
|
|
116
|
+
return `Vel veke ${week}`;
|
|
117
|
+
case "en-GB":
|
|
118
|
+
return `Pick week ${week}`;
|
|
119
|
+
default:
|
|
120
|
+
return `Velg uke ${week}`;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export const labelWeek = (localeCode?: string): string => {
|
|
125
|
+
switch (localeCode) {
|
|
126
|
+
case "nb":
|
|
127
|
+
return `Uke:`;
|
|
128
|
+
case "nn":
|
|
129
|
+
return `Veke:`;
|
|
130
|
+
case "en-GB":
|
|
131
|
+
return `Week:`;
|
|
132
|
+
default:
|
|
133
|
+
return `Uke:`;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
@@ -6,7 +6,7 @@ export const nextEnabled = (
|
|
|
6
6
|
key: string,
|
|
7
7
|
disabled: Matcher[],
|
|
8
8
|
currentMonth: Date,
|
|
9
|
-
setYearState:
|
|
9
|
+
setYearState: (date: Date) => void,
|
|
10
10
|
yearState: Date,
|
|
11
11
|
dropdownCaption: boolean,
|
|
12
12
|
fromDate?: Date,
|
|
@@ -148,7 +148,7 @@ const loopBack = (
|
|
|
148
148
|
months: Date[],
|
|
149
149
|
disabled: Matcher[],
|
|
150
150
|
yearState: Date,
|
|
151
|
-
setYearState:
|
|
151
|
+
setYearState: (date: Date) => void,
|
|
152
152
|
rowCheck: boolean,
|
|
153
153
|
dropdownCaption: boolean,
|
|
154
154
|
fromDate?: Date,
|
|
@@ -191,7 +191,7 @@ const loopForward = (
|
|
|
191
191
|
currentIndex: number,
|
|
192
192
|
months: Date[],
|
|
193
193
|
yearState: Date,
|
|
194
|
-
setYearState:
|
|
194
|
+
setYearState: (date: Date) => void,
|
|
195
195
|
disabled: Matcher[],
|
|
196
196
|
rowCheck: boolean,
|
|
197
197
|
dropdownCaption: boolean,
|
package/src/dropdown/Toggle.tsx
CHANGED
|
@@ -60,32 +60,29 @@ export const DefaultOpen = {
|
|
|
60
60
|
args: { chromatic: { delay: 300 } },
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
-
export const ControlledOpen = {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
</Dropdown>
|
|
88
|
-
);
|
|
89
|
-
},
|
|
90
|
-
args: { chromatic: { delay: 300 } },
|
|
63
|
+
export const ControlledOpen = () => {
|
|
64
|
+
const [openState, setOpenState] = useState(true);
|
|
65
|
+
return (
|
|
66
|
+
<Dropdown onSelect={(event) => console.log(event)} open={openState}>
|
|
67
|
+
<Button as={Dropdown.Toggle} onClick={() => setOpenState(!openState)}>
|
|
68
|
+
Toggle
|
|
69
|
+
</Button>
|
|
70
|
+
<Dropdown.Menu
|
|
71
|
+
strategy="fixed"
|
|
72
|
+
onClose={() => console.log("ONCLOSE CONTROLLED")}
|
|
73
|
+
>
|
|
74
|
+
<Dropdown.Menu.GroupedList>
|
|
75
|
+
<Dropdown.Menu.GroupedList.Heading>
|
|
76
|
+
Systemer og oppslagsverk
|
|
77
|
+
</Dropdown.Menu.GroupedList.Heading>
|
|
78
|
+
<Dropdown.Menu.GroupedList.Item
|
|
79
|
+
onClick={() => console.log("GroupedList.Item-click")}
|
|
80
|
+
>
|
|
81
|
+
Gosys
|
|
82
|
+
</Dropdown.Menu.GroupedList.Item>
|
|
83
|
+
</Dropdown.Menu.GroupedList>
|
|
84
|
+
</Dropdown.Menu>
|
|
85
|
+
</Dropdown>
|
|
86
|
+
);
|
|
91
87
|
};
|
|
88
|
+
ControlledOpen.args = { chromatic: { delay: 300 } };
|
package/src/dropdown/index.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export { default as Dropdown } from "./Dropdown";
|
|
2
|
-
export * from "./Dropdown";
|
|
1
|
+
export { default as Dropdown, type DropdownProps } from "./Dropdown";
|