@navikt/ds-react 7.12.2 → 7.14.0-alpha.1
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/cjs/date/Date.Dialog.d.ts +18 -0
- package/cjs/date/Date.Dialog.js +67 -0
- package/cjs/date/Date.Dialog.js.map +1 -0
- package/cjs/date/Date.Input.d.ts +50 -0
- package/cjs/date/Date.Input.js +96 -0
- package/cjs/date/Date.Input.js.map +1 -0
- package/cjs/date/Date.locale.d.ts +44 -0
- package/cjs/date/Date.locale.js +57 -0
- package/cjs/date/Date.locale.js.map +1 -0
- package/cjs/date/Date.typeutils.d.ts +14 -0
- package/cjs/date/Date.typeutils.js +15 -0
- package/cjs/date/Date.typeutils.js.map +1 -0
- package/cjs/date/date-utils/calendar-range.d.ts +11 -0
- package/cjs/date/date-utils/calendar-range.js +30 -0
- package/cjs/date/date-utils/calendar-range.js.map +1 -0
- package/cjs/date/date-utils/check-dates.d.ts +8 -0
- package/cjs/date/date-utils/check-dates.js +20 -0
- package/cjs/date/date-utils/check-dates.js.map +1 -0
- package/cjs/date/date-utils/clamp-dates.d.ts +19 -0
- package/cjs/date/date-utils/clamp-dates.js +41 -0
- package/cjs/date/date-utils/clamp-dates.js.map +1 -0
- package/cjs/date/date-utils/dates-disabled.d.ts +1 -0
- package/cjs/date/date-utils/dates-disabled.js +29 -0
- package/cjs/date/date-utils/dates-disabled.js.map +1 -0
- package/cjs/date/date-utils/dropdown-options.d.ts +13 -0
- package/cjs/date/date-utils/dropdown-options.js +45 -0
- package/cjs/date/date-utils/dropdown-options.js.map +1 -0
- package/cjs/date/date-utils/format-date.d.ts +2 -0
- package/cjs/date/date-utils/format-date.js +13 -0
- package/cjs/date/date-utils/format-date.js.map +1 -0
- package/cjs/date/date-utils/index.d.ts +8 -0
- package/cjs/date/date-utils/index.js +27 -0
- package/cjs/date/date-utils/index.js.map +1 -0
- package/cjs/date/date-utils/is-match.d.ts +3 -0
- package/cjs/date/date-utils/is-match.js +61 -0
- package/cjs/date/date-utils/is-match.js.map +1 -0
- package/cjs/date/date-utils/parse-date.d.ts +4 -0
- package/cjs/date/date-utils/parse-date.js +87 -0
- package/cjs/date/date-utils/parse-date.js.map +1 -0
- package/cjs/date/datepicker/DatePicker.d.ts +3 -3
- package/cjs/date/datepicker/DatePicker.js +47 -63
- package/cjs/date/datepicker/DatePicker.js.map +1 -1
- package/cjs/date/datepicker/DatePicker.types.d.ts +108 -0
- package/cjs/date/datepicker/DatePicker.types.js +3 -0
- package/cjs/date/datepicker/DatePicker.types.js.map +1 -0
- package/cjs/date/datepicker/hooks/useDatepicker.d.ts +90 -0
- package/cjs/date/datepicker/hooks/useDatepicker.js +164 -0
- package/cjs/date/datepicker/hooks/useDatepicker.js.map +1 -0
- package/cjs/date/datepicker/hooks/useRangeDatepicker.d.ts +76 -0
- package/cjs/date/datepicker/hooks/useRangeDatepicker.js +322 -0
- package/cjs/date/datepicker/hooks/useRangeDatepicker.js.map +1 -0
- package/cjs/date/datepicker/index.d.ts +4 -3
- package/cjs/date/datepicker/index.js +8 -7
- package/cjs/date/datepicker/index.js.map +1 -1
- package/cjs/date/datepicker/parts/DatePicker.DayButton.d.ts +9 -0
- package/cjs/date/datepicker/parts/DatePicker.DayButton.js +70 -0
- package/cjs/date/datepicker/parts/DatePicker.DayButton.js.map +1 -0
- package/cjs/date/datepicker/parts/DatePicker.Months.d.ts +11 -0
- package/cjs/date/datepicker/parts/DatePicker.Months.js +84 -0
- package/cjs/date/datepicker/parts/DatePicker.Months.js.map +1 -0
- package/cjs/date/datepicker/parts/DatePicker.RDP.d.ts +15 -0
- package/cjs/date/datepicker/parts/DatePicker.RDP.js +103 -0
- package/cjs/date/datepicker/parts/DatePicker.RDP.js.map +1 -0
- package/cjs/date/datepicker/parts/DatePicker.Standalone.d.ts +18 -0
- package/cjs/date/datepicker/parts/DatePicker.Standalone.js +60 -0
- package/cjs/date/datepicker/parts/DatePicker.Standalone.js.map +1 -0
- package/cjs/date/datepicker/parts/DatePicker.WeekNumber.d.ts +9 -0
- package/cjs/date/datepicker/parts/DatePicker.WeekNumber.js +64 -0
- package/cjs/date/datepicker/parts/DatePicker.WeekNumber.js.map +1 -0
- package/cjs/date/datepicker/parts/DatePicker.WeekRow.d.ts +8 -0
- package/cjs/date/datepicker/parts/DatePicker.WeekRow.js +28 -0
- package/cjs/date/datepicker/parts/DatePicker.WeekRow.js.map +1 -0
- package/cjs/date/monthpicker/MonthPicker.context.d.ts +21 -0
- package/cjs/date/monthpicker/MonthPicker.context.js +48 -0
- package/cjs/date/monthpicker/MonthPicker.context.js.map +1 -0
- package/cjs/date/monthpicker/MonthPicker.d.ts +3 -3
- package/cjs/date/monthpicker/MonthPicker.js +34 -43
- package/cjs/date/monthpicker/MonthPicker.js.map +1 -1
- package/cjs/date/monthpicker/MonthPicker.types.d.ts +86 -0
- package/cjs/date/monthpicker/MonthPicker.types.js +3 -0
- package/cjs/date/monthpicker/MonthPicker.types.js.map +1 -0
- package/cjs/date/monthpicker/MonthPicker.util.d.ts +2 -0
- package/cjs/date/monthpicker/MonthPicker.util.js +156 -0
- package/cjs/date/monthpicker/MonthPicker.util.js.map +1 -0
- package/cjs/date/monthpicker/hooks/useMonthPicker.d.ts +85 -0
- package/cjs/date/monthpicker/hooks/useMonthPicker.js +179 -0
- package/cjs/date/monthpicker/hooks/useMonthPicker.js.map +1 -0
- package/cjs/date/monthpicker/index.d.ts +4 -4
- package/cjs/date/monthpicker/index.js +6 -6
- package/cjs/date/monthpicker/index.js.map +1 -1
- package/cjs/date/monthpicker/parts/MonthPicker.Button.d.ts +11 -0
- package/cjs/date/monthpicker/parts/MonthPicker.Button.js +82 -0
- package/cjs/date/monthpicker/parts/MonthPicker.Button.js.map +1 -0
- package/cjs/date/monthpicker/parts/MonthPicker.Caption.d.ts +3 -0
- package/cjs/date/monthpicker/parts/MonthPicker.Caption.js +52 -0
- package/cjs/date/monthpicker/parts/MonthPicker.Caption.js.map +1 -0
- package/cjs/date/monthpicker/parts/MonthPicker.Standalone.d.ts +10 -0
- package/cjs/date/monthpicker/parts/MonthPicker.Standalone.js +51 -0
- package/cjs/date/monthpicker/parts/MonthPicker.Standalone.js.map +1 -0
- package/cjs/date/monthpicker/parts/MonthPicker.Table.d.ts +3 -0
- package/cjs/date/monthpicker/parts/MonthPicker.Table.js +79 -0
- package/cjs/date/monthpicker/parts/MonthPicker.Table.js.map +1 -0
- package/cjs/form/combobox/Combobox.d.ts +1 -1
- package/cjs/form/combobox/Input/InputController.d.ts +1 -1
- package/cjs/form/confirmation-panel/ConfirmationPanel.js +6 -1
- package/cjs/form/confirmation-panel/ConfirmationPanel.js.map +1 -1
- package/cjs/modal/Modal.js +2 -2
- package/cjs/modal/Modal.js.map +1 -1
- package/cjs/popover/Popover.js +3 -3
- package/cjs/popover/Popover.js.map +1 -1
- package/cjs/theme/Theme.d.ts +7 -1
- package/cjs/theme/Theme.js +24 -2
- package/cjs/theme/Theme.js.map +1 -1
- package/cjs/theme/index.d.ts +1 -1
- package/cjs/theme/index.js.map +1 -1
- package/cjs/tooltip/Tooltip.js +2 -5
- package/cjs/tooltip/Tooltip.js.map +1 -1
- package/esm/date/Date.Dialog.d.ts +18 -0
- package/esm/date/Date.Dialog.js +38 -0
- package/esm/date/Date.Dialog.js.map +1 -0
- package/esm/date/Date.Input.d.ts +50 -0
- package/esm/date/Date.Input.js +66 -0
- package/esm/date/Date.Input.js.map +1 -0
- package/esm/date/Date.locale.d.ts +44 -0
- package/esm/date/Date.locale.js +47 -0
- package/esm/date/Date.locale.js.map +1 -0
- package/esm/date/Date.typeutils.d.ts +14 -0
- package/esm/date/Date.typeutils.js +10 -0
- package/esm/date/Date.typeutils.js.map +1 -0
- package/esm/date/date-utils/calendar-range.d.ts +11 -0
- package/esm/date/date-utils/calendar-range.js +27 -0
- package/esm/date/date-utils/calendar-range.js.map +1 -0
- package/esm/date/date-utils/check-dates.d.ts +8 -0
- package/esm/date/date-utils/check-dates.js +14 -0
- package/esm/date/date-utils/check-dates.js.map +1 -0
- package/esm/date/date-utils/clamp-dates.d.ts +19 -0
- package/esm/date/date-utils/clamp-dates.js +37 -0
- package/esm/date/date-utils/clamp-dates.js.map +1 -0
- package/esm/date/date-utils/dates-disabled.d.ts +1 -0
- package/esm/date/date-utils/dates-disabled.js +25 -0
- package/esm/date/date-utils/dates-disabled.js.map +1 -0
- package/esm/date/date-utils/dropdown-options.d.ts +13 -0
- package/esm/date/date-utils/dropdown-options.js +41 -0
- package/esm/date/date-utils/dropdown-options.js.map +1 -0
- package/esm/date/date-utils/format-date.d.ts +2 -0
- package/esm/date/date-utils/format-date.js +9 -0
- package/esm/date/date-utils/format-date.js.map +1 -0
- package/esm/date/date-utils/index.d.ts +8 -0
- package/esm/date/date-utils/index.js +9 -0
- package/esm/date/date-utils/index.js.map +1 -0
- package/esm/date/date-utils/is-match.d.ts +3 -0
- package/esm/date/date-utils/is-match.js +57 -0
- package/esm/date/date-utils/is-match.js.map +1 -0
- package/esm/date/date-utils/parse-date.d.ts +4 -0
- package/esm/date/date-utils/parse-date.js +83 -0
- package/esm/date/date-utils/parse-date.js.map +1 -0
- package/esm/date/datepicker/DatePicker.d.ts +3 -3
- package/esm/date/datepicker/DatePicker.js +46 -62
- package/esm/date/datepicker/DatePicker.js.map +1 -1
- package/esm/date/datepicker/DatePicker.types.d.ts +108 -0
- package/esm/date/datepicker/DatePicker.types.js +2 -0
- package/esm/date/datepicker/DatePicker.types.js.map +1 -0
- package/esm/date/datepicker/hooks/useDatepicker.d.ts +90 -0
- package/esm/date/datepicker/hooks/useDatepicker.js +160 -0
- package/esm/date/datepicker/hooks/useDatepicker.js.map +1 -0
- package/esm/date/datepicker/hooks/useRangeDatepicker.d.ts +76 -0
- package/esm/date/datepicker/hooks/useRangeDatepicker.js +318 -0
- package/esm/date/datepicker/hooks/useRangeDatepicker.js.map +1 -0
- package/esm/date/datepicker/index.d.ts +4 -3
- package/esm/date/datepicker/index.js +4 -3
- package/esm/date/datepicker/index.js.map +1 -1
- package/esm/date/datepicker/parts/DatePicker.DayButton.d.ts +9 -0
- package/esm/date/datepicker/parts/DatePicker.DayButton.js +41 -0
- package/esm/date/datepicker/parts/DatePicker.DayButton.js.map +1 -0
- package/esm/date/datepicker/parts/DatePicker.Months.d.ts +11 -0
- package/esm/date/datepicker/parts/DatePicker.Months.js +58 -0
- package/esm/date/datepicker/parts/DatePicker.Months.js.map +1 -0
- package/esm/date/datepicker/parts/DatePicker.RDP.d.ts +15 -0
- package/esm/date/datepicker/parts/DatePicker.RDP.js +74 -0
- package/esm/date/datepicker/parts/DatePicker.RDP.js.map +1 -0
- package/esm/date/datepicker/parts/DatePicker.Standalone.d.ts +18 -0
- package/esm/date/datepicker/parts/DatePicker.Standalone.js +31 -0
- package/esm/date/datepicker/parts/DatePicker.Standalone.js.map +1 -0
- package/esm/date/datepicker/parts/DatePicker.WeekNumber.d.ts +9 -0
- package/esm/date/datepicker/parts/DatePicker.WeekNumber.js +35 -0
- package/esm/date/datepicker/parts/DatePicker.WeekNumber.js.map +1 -0
- package/esm/date/datepicker/parts/DatePicker.WeekRow.d.ts +8 -0
- package/esm/date/datepicker/parts/DatePicker.WeekRow.js +22 -0
- package/esm/date/datepicker/parts/DatePicker.WeekRow.js.map +1 -0
- package/esm/date/monthpicker/MonthPicker.context.d.ts +21 -0
- package/esm/date/monthpicker/MonthPicker.context.js +41 -0
- package/esm/date/monthpicker/MonthPicker.context.js.map +1 -0
- package/esm/date/monthpicker/MonthPicker.d.ts +3 -3
- package/esm/date/monthpicker/MonthPicker.js +31 -40
- package/esm/date/monthpicker/MonthPicker.js.map +1 -1
- package/esm/date/monthpicker/MonthPicker.types.d.ts +86 -0
- package/esm/date/monthpicker/MonthPicker.types.js +2 -0
- package/esm/date/monthpicker/MonthPicker.types.js.map +1 -0
- package/esm/date/monthpicker/MonthPicker.util.d.ts +2 -0
- package/esm/date/monthpicker/MonthPicker.util.js +152 -0
- package/esm/date/monthpicker/MonthPicker.util.js.map +1 -0
- package/esm/date/monthpicker/hooks/useMonthPicker.d.ts +85 -0
- package/esm/date/monthpicker/hooks/useMonthPicker.js +175 -0
- package/esm/date/monthpicker/hooks/useMonthPicker.js.map +1 -0
- package/esm/date/monthpicker/index.d.ts +4 -4
- package/esm/date/monthpicker/index.js +3 -3
- package/esm/date/monthpicker/index.js.map +1 -1
- package/esm/date/monthpicker/parts/MonthPicker.Button.d.ts +11 -0
- package/esm/date/monthpicker/parts/MonthPicker.Button.js +52 -0
- package/esm/date/monthpicker/parts/MonthPicker.Button.js.map +1 -0
- package/esm/date/monthpicker/parts/MonthPicker.Caption.d.ts +3 -0
- package/esm/date/monthpicker/parts/MonthPicker.Caption.js +46 -0
- package/esm/date/monthpicker/parts/MonthPicker.Caption.js.map +1 -0
- package/esm/date/monthpicker/parts/MonthPicker.Standalone.d.ts +10 -0
- package/esm/date/monthpicker/parts/MonthPicker.Standalone.js +22 -0
- package/esm/date/monthpicker/parts/MonthPicker.Standalone.js.map +1 -0
- package/esm/date/monthpicker/parts/MonthPicker.Table.d.ts +3 -0
- package/esm/date/monthpicker/parts/MonthPicker.Table.js +50 -0
- package/esm/date/monthpicker/parts/MonthPicker.Table.js.map +1 -0
- package/esm/form/combobox/Combobox.d.ts +1 -1
- package/esm/form/combobox/Input/InputController.d.ts +1 -1
- package/esm/form/confirmation-panel/ConfirmationPanel.js +6 -1
- package/esm/form/confirmation-panel/ConfirmationPanel.js.map +1 -1
- package/esm/modal/Modal.js +3 -3
- package/esm/modal/Modal.js.map +1 -1
- package/esm/popover/Popover.js +4 -4
- package/esm/popover/Popover.js.map +1 -1
- package/esm/theme/Theme.d.ts +7 -1
- package/esm/theme/Theme.js +22 -2
- package/esm/theme/Theme.js.map +1 -1
- package/esm/theme/index.d.ts +1 -1
- package/esm/theme/index.js.map +1 -1
- package/esm/tooltip/Tooltip.js +2 -5
- package/esm/tooltip/Tooltip.js.map +1 -1
- package/package.json +7 -8
- package/src/date/{parts/DateWrapper.tsx → Date.Dialog.tsx} +12 -9
- package/src/date/{parts/DateInput.tsx → Date.Input.tsx} +30 -5
- package/src/date/{utils/locale.ts → Date.locale.ts} +11 -2
- package/src/date/Date.typeutils.ts +32 -0
- package/src/date/date-utils/calendar-range.test.ts +54 -0
- package/src/date/date-utils/calendar-range.ts +46 -0
- package/src/date/date-utils/check-dates.test.ts +49 -0
- package/src/date/date-utils/check-dates.ts +28 -0
- package/src/date/date-utils/clamp-dates.test.ts +156 -0
- package/src/date/date-utils/clamp-dates.ts +63 -0
- package/src/date/{utils/__tests__ → date-utils}/dates-disabled.test.ts +1 -1
- package/src/date/{utils → date-utils}/dates-disabled.ts +1 -2
- package/src/date/date-utils/dropdown-options.test.ts +143 -0
- package/src/date/date-utils/dropdown-options.ts +79 -0
- package/src/date/{utils/__tests__ → date-utils}/format-dates.test.ts +2 -2
- package/src/date/date-utils/index.ts +16 -0
- package/src/date/{utils/__tests__ → date-utils}/is-match.test.ts +1 -1
- package/src/date/{utils → date-utils}/is-match.ts +2 -11
- package/src/date/{utils/__tests__ → date-utils}/parse-dates.test.ts +2 -1
- package/src/date/datepicker/DatePicker.tsx +67 -92
- package/src/date/datepicker/{types.ts → DatePicker.types.ts} +10 -4
- package/src/date/{hooks → datepicker/hooks}/useDatepicker.tsx +12 -13
- package/src/date/{hooks → datepicker/hooks}/useRangeDatepicker.test.tsx +1 -1
- package/src/date/{hooks → datepicker/hooks}/useRangeDatepicker.tsx +19 -19
- package/src/date/datepicker/index.ts +4 -5
- package/src/date/datepicker/parts/DatePicker.DayButton.tsx +56 -0
- package/src/date/datepicker/parts/DatePicker.Months.tsx +149 -0
- package/src/date/datepicker/parts/DatePicker.RDP.tsx +170 -0
- package/src/date/datepicker/parts/DatePicker.Standalone.tsx +93 -0
- package/src/date/datepicker/parts/DatePicker.WeekNumber.tsx +86 -0
- package/src/date/datepicker/parts/{WeekRow.tsx → DatePicker.WeekRow.tsx} +20 -21
- package/src/date/monthpicker/MonthPicker.context.tsx +103 -0
- package/src/date/monthpicker/MonthPicker.tsx +63 -68
- package/src/date/monthpicker/{types.ts → MonthPicker.types.ts} +1 -1
- package/src/date/{utils/navigation.ts → monthpicker/MonthPicker.util.ts} +2 -1
- package/src/date/{hooks → monthpicker/hooks}/useMonthPicker.tsx +14 -13
- package/src/date/monthpicker/index.ts +4 -4
- package/src/date/monthpicker/{MonthButton.tsx → parts/MonthPicker.Button.tsx} +21 -10
- package/src/date/monthpicker/{MonthCaption.tsx → parts/MonthPicker.Caption.tsx} +20 -21
- package/src/date/monthpicker/parts/MonthPicker.Standalone.tsx +86 -0
- package/src/date/monthpicker/{MonthSelector.tsx → parts/MonthPicker.Table.tsx} +7 -7
- package/src/form/confirmation-panel/ConfirmationPanel.tsx +7 -0
- package/src/modal/Modal.tsx +3 -3
- package/src/popover/Popover.tsx +4 -4
- package/src/react-css.d.ts +4 -0
- package/src/theme/RenameCSS.test.ts +80 -0
- package/src/theme/Theme.tsx +45 -8
- package/src/theme/index.ts +1 -1
- package/src/tooltip/Tooltip.tsx +2 -6
- package/src/date/context/index.ts +0 -9
- package/src/date/context/useDateInputContext.tsx +0 -34
- package/src/date/context/useDateTranslationContext.ts +0 -9
- package/src/date/context/useSharedMonthContext.tsx +0 -68
- package/src/date/datepicker/DatePickerStandalone.tsx +0 -136
- package/src/date/datepicker/datepicker.test.tsx +0 -28
- package/src/date/datepicker/parts/Caption.tsx +0 -54
- package/src/date/datepicker/parts/DayButton.tsx +0 -32
- package/src/date/datepicker/parts/DropdownCaption.tsx +0 -110
- package/src/date/datepicker/parts/HeadRow.tsx +0 -56
- package/src/date/datepicker/parts/Row.tsx +0 -48
- package/src/date/datepicker/parts/TableHead.tsx +0 -17
- package/src/date/datepicker/parts/WeekNumber.tsx +0 -75
- package/src/date/hooks/index.ts +0 -6
- package/src/date/monthpicker/MonthPickerStandalone.tsx +0 -102
- package/src/date/utils/__tests__/check-dates.test.ts +0 -22
- package/src/date/utils/__tests__/get-dates.test.ts +0 -121
- package/src/date/utils/__tests__/get-initial-year.test.ts +0 -83
- package/src/date/utils/__tests__/get-month-weeks.test.ts +0 -116
- package/src/date/utils/check-dates.ts +0 -13
- package/src/date/utils/get-dates.ts +0 -60
- package/src/date/utils/get-initial-year.ts +0 -25
- package/src/date/utils/get-month-weeks.ts +0 -93
- package/src/date/utils/index.ts +0 -18
- /package/src/date/{utils → date-utils}/format-date.ts +0 -0
- /package/src/date/{utils → date-utils}/parse-date.ts +0 -0
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import React, { useCallback, useMemo, useState } from "react";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { DateInputProps } from "
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
isMatch,
|
|
9
|
-
isValidDate,
|
|
10
|
-
parseDate,
|
|
11
|
-
} from "../utils";
|
|
2
|
+
import { dateMatchModifiers } from "react-day-picker";
|
|
3
|
+
import { useDateLocale } from "../../../util/i18n/i18n.hooks";
|
|
4
|
+
import { DateInputProps } from "../../Date.Input";
|
|
5
|
+
import { getLocaleFromString } from "../../Date.locale";
|
|
6
|
+
import { formatDateForInput, isValidDate, parseDate } from "../../date-utils";
|
|
7
|
+
import { MonthPickerProps } from "../MonthPicker.types";
|
|
12
8
|
|
|
13
9
|
export interface UseMonthPickerOptions
|
|
14
10
|
extends Pick<
|
|
@@ -267,11 +263,14 @@ export const useMonthpicker = (
|
|
|
267
263
|
const isBefore = getIsBefore({ fromDate, date: month });
|
|
268
264
|
const isAfter = getIsAfter({ toDate, date: month });
|
|
269
265
|
|
|
270
|
-
if (
|
|
266
|
+
if (
|
|
267
|
+
!isValidDate(month) ||
|
|
268
|
+
(disabled && dateMatchModifiers(month, disabled))
|
|
269
|
+
) {
|
|
271
270
|
updateMonth(undefined);
|
|
272
271
|
updateValidation({
|
|
273
272
|
isInvalid: isValidDate(month),
|
|
274
|
-
isDisabled: disabled &&
|
|
273
|
+
isDisabled: disabled && dateMatchModifiers(month, disabled),
|
|
275
274
|
isValidMonth: false,
|
|
276
275
|
isEmpty: !e.target.value,
|
|
277
276
|
isBefore: isBefore ?? false,
|
|
@@ -283,7 +282,9 @@ export const useMonthpicker = (
|
|
|
283
282
|
if (
|
|
284
283
|
isAfter ||
|
|
285
284
|
isBefore ||
|
|
286
|
-
(fromDate &&
|
|
285
|
+
(fromDate &&
|
|
286
|
+
toDate &&
|
|
287
|
+
!dateMatchModifiers(month, [{ from: fromDate, to: toDate }]))
|
|
287
288
|
) {
|
|
288
289
|
updateMonth(undefined);
|
|
289
290
|
updateValidation({
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
export { useMonthpicker, type MonthValidationT } from "
|
|
2
|
+
export { useMonthpicker, type MonthValidationT } from "./hooks/useMonthPicker";
|
|
3
3
|
export { default as MonthPicker } from "./MonthPicker";
|
|
4
|
-
export { type MonthPickerProps } from "./types";
|
|
4
|
+
export { type MonthPickerProps } from "./MonthPicker.types";
|
|
5
5
|
export {
|
|
6
6
|
MonthPickerStandalone,
|
|
7
7
|
type MonthPickerStandaloneProps,
|
|
8
|
-
} from "./
|
|
9
|
-
export { MonthPickerInput } from "../
|
|
8
|
+
} from "./parts/MonthPicker.Standalone";
|
|
9
|
+
export { MonthPickerInput } from "../Date.Input";
|
|
@@ -7,9 +7,9 @@ import {
|
|
|
7
7
|
setYear,
|
|
8
8
|
} from "date-fns";
|
|
9
9
|
import React, { useEffect, useRef } from "react";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
10
|
+
import { dateIsInCurrentMonth, isMatch } from "../../date-utils";
|
|
11
|
+
import { useMonthPickerContext } from "../MonthPicker.context";
|
|
12
|
+
import { nextEnabled } from "../MonthPicker.util";
|
|
13
13
|
|
|
14
14
|
interface MonthType {
|
|
15
15
|
month: Date;
|
|
@@ -47,10 +47,18 @@ export const MonthButton = ({
|
|
|
47
47
|
setTabRoot,
|
|
48
48
|
}: MonthType) => {
|
|
49
49
|
const ref = useRef<HTMLButtonElement>(null);
|
|
50
|
-
const { hasDropdown, selected, onSelect, year, toYear, disabled } =
|
|
51
|
-
useSharedMonthContext();
|
|
52
50
|
|
|
53
|
-
const {
|
|
51
|
+
const {
|
|
52
|
+
fromDate,
|
|
53
|
+
toDate,
|
|
54
|
+
locale,
|
|
55
|
+
selected,
|
|
56
|
+
disabled,
|
|
57
|
+
year,
|
|
58
|
+
onYearChange,
|
|
59
|
+
onMonthSelect,
|
|
60
|
+
caption,
|
|
61
|
+
} = useMonthPickerContext();
|
|
54
62
|
const isSelected = selected && isSameMonth(month, selected);
|
|
55
63
|
|
|
56
64
|
useEffect(() => {
|
|
@@ -64,15 +72,18 @@ export const MonthButton = ({
|
|
|
64
72
|
isMatch(setYear(month, year.getFullYear()), disabled) ||
|
|
65
73
|
disableMonth(month, fromDate, toDate);
|
|
66
74
|
|
|
75
|
+
const isThisMonth = dateIsInCurrentMonth(month, year);
|
|
76
|
+
|
|
67
77
|
return (
|
|
68
78
|
<button
|
|
69
79
|
ref={ref}
|
|
70
80
|
type="button"
|
|
71
|
-
onClick={() =>
|
|
81
|
+
onClick={() => onMonthSelect?.(isSelected ? undefined : month)}
|
|
72
82
|
disabled={isDisabled}
|
|
73
83
|
aria-pressed={!!isSelected}
|
|
84
|
+
data-current-month={isThisMonth}
|
|
74
85
|
className={cl("navds-date__month-button", {
|
|
75
|
-
"rdp-day_today":
|
|
86
|
+
"rdp-day_today": isThisMonth,
|
|
76
87
|
"rdp-day_selected": isSelected,
|
|
77
88
|
"rdp-day_disabled": isDisabled,
|
|
78
89
|
})}
|
|
@@ -87,9 +98,9 @@ export const MonthButton = ({
|
|
|
87
98
|
e.key,
|
|
88
99
|
disabled,
|
|
89
100
|
month,
|
|
90
|
-
|
|
101
|
+
onYearChange,
|
|
91
102
|
year,
|
|
92
|
-
|
|
103
|
+
caption === "dropdown",
|
|
93
104
|
fromDate,
|
|
94
105
|
toDate,
|
|
95
106
|
);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
format,
|
|
2
3
|
isAfter,
|
|
3
4
|
isBefore,
|
|
4
5
|
setYear,
|
|
@@ -6,25 +7,21 @@ import {
|
|
|
6
7
|
startOfYear,
|
|
7
8
|
} from "date-fns";
|
|
8
9
|
import React from "react";
|
|
9
|
-
import { useDayPicker } from "react-day-picker";
|
|
10
10
|
import { ArrowLeftIcon, ArrowRightIcon } from "@navikt/aksel-icons";
|
|
11
|
-
import { Button } from "
|
|
12
|
-
import { Select } from "
|
|
13
|
-
import { useDateTranslationContext
|
|
11
|
+
import { Button } from "../../../button";
|
|
12
|
+
import { Select } from "../../../form/select";
|
|
13
|
+
import { useDateTranslationContext } from "../../Date.locale";
|
|
14
|
+
import { useMonthPickerContext } from "../MonthPicker.context";
|
|
15
|
+
|
|
16
|
+
const MonthPickerCaption = () => {
|
|
17
|
+
const { fromDate, toDate, locale, year, onYearChange, caption } =
|
|
18
|
+
useMonthPickerContext();
|
|
14
19
|
|
|
15
|
-
export const MonthCaption = () => {
|
|
16
|
-
const {
|
|
17
|
-
fromDate,
|
|
18
|
-
toDate,
|
|
19
|
-
formatters: { formatYearCaption },
|
|
20
|
-
locale,
|
|
21
|
-
} = useDayPicker();
|
|
22
|
-
const { hasDropdown, year, toYear } = useSharedMonthContext();
|
|
23
20
|
const translate = useDateTranslationContext().translate;
|
|
24
21
|
|
|
25
22
|
const years: Date[] = [];
|
|
26
23
|
|
|
27
|
-
if (
|
|
24
|
+
if (caption === "dropdown" && fromDate && toDate) {
|
|
28
25
|
const fromYear = fromDate.getFullYear();
|
|
29
26
|
const toDateYear = toDate.getFullYear();
|
|
30
27
|
for (let currYear = fromYear; currYear <= toDateYear; currYear++) {
|
|
@@ -37,12 +34,14 @@ export const MonthCaption = () => {
|
|
|
37
34
|
years.sort((a, b) => b.getFullYear() - a.getFullYear());
|
|
38
35
|
}
|
|
39
36
|
|
|
40
|
-
const handleYearChange = (event: React.ChangeEvent<HTMLSelectElement>) =>
|
|
41
|
-
|
|
37
|
+
const handleYearChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
|
|
38
|
+
onYearChange(setYear(startOfMonth(new Date()), Number(event.target.value)));
|
|
39
|
+
};
|
|
42
40
|
|
|
43
41
|
const handleButtonClick = (val: number) => {
|
|
44
42
|
const newYear = Number(year.getFullYear() + val);
|
|
45
|
-
|
|
43
|
+
|
|
44
|
+
onYearChange(setYear(year, newYear));
|
|
46
45
|
};
|
|
47
46
|
|
|
48
47
|
const disablePreviousYear = () => {
|
|
@@ -64,11 +63,11 @@ export const MonthCaption = () => {
|
|
|
64
63
|
disabled={disablePreviousYear()}
|
|
65
64
|
onClick={() => handleButtonClick(-1)}
|
|
66
65
|
icon={<ArrowLeftIcon title={translate("goToPreviousYear")} />}
|
|
67
|
-
variant="tertiary"
|
|
66
|
+
variant="tertiary-neutral"
|
|
68
67
|
type="button"
|
|
69
68
|
/>
|
|
70
69
|
|
|
71
|
-
{
|
|
70
|
+
{caption === "dropdown" ? (
|
|
72
71
|
<Select
|
|
73
72
|
label={translate("year")}
|
|
74
73
|
hideLabel
|
|
@@ -78,7 +77,7 @@ export const MonthCaption = () => {
|
|
|
78
77
|
>
|
|
79
78
|
{years.map((yearOpt) => (
|
|
80
79
|
<option key={yearOpt.getFullYear()} value={yearOpt.getFullYear()}>
|
|
81
|
-
{
|
|
80
|
+
{format(yearOpt, "yyyy", { locale })}
|
|
82
81
|
</option>
|
|
83
82
|
))}
|
|
84
83
|
</Select>
|
|
@@ -92,11 +91,11 @@ export const MonthCaption = () => {
|
|
|
92
91
|
disabled={disableNextYear()}
|
|
93
92
|
onClick={() => handleButtonClick(1)}
|
|
94
93
|
icon={<ArrowRightIcon title={translate("goToNextYear")} />}
|
|
95
|
-
variant="tertiary"
|
|
94
|
+
variant="tertiary-neutral"
|
|
96
95
|
type="button"
|
|
97
96
|
/>
|
|
98
97
|
</div>
|
|
99
98
|
);
|
|
100
99
|
};
|
|
101
100
|
|
|
102
|
-
export
|
|
101
|
+
export { MonthPickerCaption };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import cl from "clsx";
|
|
2
|
+
import React, { forwardRef } from "react";
|
|
3
|
+
import { useDateLocale, useI18n } from "../../../util/i18n/i18n.hooks";
|
|
4
|
+
import {
|
|
5
|
+
DateTranslationContextProvider,
|
|
6
|
+
getLocaleFromString,
|
|
7
|
+
getTranslations,
|
|
8
|
+
} from "../../Date.locale";
|
|
9
|
+
import { MonthPickerProvider } from "../MonthPicker.context";
|
|
10
|
+
import { MonthPickerProps } from "../MonthPicker.types";
|
|
11
|
+
import { MonthPickerCaption } from "./MonthPicker.Caption";
|
|
12
|
+
import { MonthPickerTable } from "./MonthPicker.Table";
|
|
13
|
+
|
|
14
|
+
export interface MonthPickerStandaloneProps
|
|
15
|
+
extends Omit<
|
|
16
|
+
MonthPickerProps,
|
|
17
|
+
"open" | "onClose" | "onOpenToggle" | "wrapperClassName" | "strategy"
|
|
18
|
+
> {
|
|
19
|
+
/**
|
|
20
|
+
* Monthpicker classname
|
|
21
|
+
*/
|
|
22
|
+
className?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type MonthPickerStandaloneType = React.ForwardRefExoticComponent<
|
|
26
|
+
MonthPickerStandaloneProps & React.RefAttributes<HTMLDivElement>
|
|
27
|
+
>;
|
|
28
|
+
|
|
29
|
+
export const MonthPickerStandalone = forwardRef<
|
|
30
|
+
HTMLDivElement,
|
|
31
|
+
MonthPickerStandaloneProps
|
|
32
|
+
>(
|
|
33
|
+
(
|
|
34
|
+
{
|
|
35
|
+
dropdownCaption = false,
|
|
36
|
+
fromDate,
|
|
37
|
+
toDate,
|
|
38
|
+
disabled = [],
|
|
39
|
+
selected,
|
|
40
|
+
className,
|
|
41
|
+
locale,
|
|
42
|
+
translations,
|
|
43
|
+
onMonthSelect,
|
|
44
|
+
defaultSelected,
|
|
45
|
+
year,
|
|
46
|
+
onYearChange,
|
|
47
|
+
},
|
|
48
|
+
ref,
|
|
49
|
+
) => {
|
|
50
|
+
const translate = useI18n(
|
|
51
|
+
"DatePicker",
|
|
52
|
+
translations,
|
|
53
|
+
getTranslations(locale),
|
|
54
|
+
);
|
|
55
|
+
const langProviderLocale = useDateLocale();
|
|
56
|
+
|
|
57
|
+
if (dropdownCaption && (!fromDate || !toDate)) {
|
|
58
|
+
console.warn("Using dropdownCaption required fromDate and toDate");
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<div ref={ref} className={cl("navds-date__wrapper", className)}>
|
|
64
|
+
<DateTranslationContextProvider translate={translate}>
|
|
65
|
+
<MonthPickerProvider
|
|
66
|
+
dropdownCaption={dropdownCaption}
|
|
67
|
+
defaultSelected={defaultSelected}
|
|
68
|
+
selected={selected}
|
|
69
|
+
disabled={disabled}
|
|
70
|
+
fromDate={fromDate}
|
|
71
|
+
toDate={toDate}
|
|
72
|
+
year={year}
|
|
73
|
+
onYearChange={onYearChange}
|
|
74
|
+
onMonthSelect={onMonthSelect}
|
|
75
|
+
locale={locale ? getLocaleFromString(locale) : langProviderLocale}
|
|
76
|
+
>
|
|
77
|
+
<div className="navds-date rdp-month">
|
|
78
|
+
<MonthPickerCaption />
|
|
79
|
+
<MonthPickerTable />
|
|
80
|
+
</div>
|
|
81
|
+
</MonthPickerProvider>
|
|
82
|
+
</DateTranslationContextProvider>
|
|
83
|
+
</div>
|
|
84
|
+
);
|
|
85
|
+
},
|
|
86
|
+
);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { isSameMonth, setMonth, setYear, startOfMonth } from "date-fns";
|
|
2
2
|
import React, { useState } from "react";
|
|
3
|
-
import { BodyShort } from "
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import MonthButton from "./
|
|
3
|
+
import { BodyShort } from "../../../typography";
|
|
4
|
+
import { isMatch } from "../../date-utils";
|
|
5
|
+
import { useMonthPickerContext } from "../MonthPicker.context";
|
|
6
|
+
import MonthButton from "./MonthPicker.Button";
|
|
7
7
|
|
|
8
8
|
const getAllMonths = () => {
|
|
9
9
|
const months: Date[] = [];
|
|
@@ -14,10 +14,10 @@ const getAllMonths = () => {
|
|
|
14
14
|
return months;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
const MonthPickerTable = () => {
|
|
18
18
|
const [focus, setFocus] = useState<Date>();
|
|
19
19
|
|
|
20
|
-
const { selected, year, disabled } =
|
|
20
|
+
const { selected, year, disabled } = useMonthPickerContext();
|
|
21
21
|
|
|
22
22
|
const months: Date[] = getAllMonths();
|
|
23
23
|
|
|
@@ -82,4 +82,4 @@ export const MonthSelector = () => {
|
|
|
82
82
|
);
|
|
83
83
|
};
|
|
84
84
|
|
|
85
|
-
export
|
|
85
|
+
export { MonthPickerTable };
|
|
@@ -57,6 +57,12 @@ export const ConfirmationPanel = forwardRef<
|
|
|
57
57
|
|
|
58
58
|
const id = useId();
|
|
59
59
|
|
|
60
|
+
const currentRole = hasError
|
|
61
|
+
? "danger"
|
|
62
|
+
: props.checked
|
|
63
|
+
? "success"
|
|
64
|
+
: "warning";
|
|
65
|
+
|
|
60
66
|
return (
|
|
61
67
|
<div
|
|
62
68
|
className={cl("navds-confirmation-panel", "navds-form-field", className, {
|
|
@@ -64,6 +70,7 @@ export const ConfirmationPanel = forwardRef<
|
|
|
64
70
|
"navds-confirmation-panel--error": hasError,
|
|
65
71
|
"navds-confirmation-panel--checked": !!props.checked,
|
|
66
72
|
})}
|
|
73
|
+
data-color-role={currentRole}
|
|
67
74
|
>
|
|
68
75
|
<div className="navds-confirmation-panel__inner">
|
|
69
76
|
{children && (
|
package/src/modal/Modal.tsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useFloatingPortalNode } from "@floating-ui/react";
|
|
2
2
|
import cl from "clsx";
|
|
3
|
-
import React, { forwardRef,
|
|
3
|
+
import React, { forwardRef, useEffect, useRef } from "react";
|
|
4
4
|
import { createPortal } from "react-dom";
|
|
5
|
-
import {
|
|
5
|
+
import { useDateInputContext } from "../date/Date.Input";
|
|
6
6
|
import { useProvider } from "../provider/Provider";
|
|
7
7
|
import { Detail, Heading } from "../typography";
|
|
8
8
|
import { composeEventHandlers } from "../util/composeEventHandlers";
|
|
@@ -106,7 +106,7 @@ export const Modal = forwardRef<HTMLDialogElement, ModalProps>(
|
|
|
106
106
|
const rootElement = useProvider()?.rootElement;
|
|
107
107
|
const portalNode = useFloatingPortalNode({ root: rootElement });
|
|
108
108
|
|
|
109
|
-
const dateContext =
|
|
109
|
+
const dateContext = useDateInputContext(false);
|
|
110
110
|
const isNested = useModalContext(false) !== undefined;
|
|
111
111
|
if (isNested && !dateContext) {
|
|
112
112
|
console.error("Modals should not be nested");
|
package/src/popover/Popover.tsx
CHANGED
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
useFloating,
|
|
8
8
|
} from "@floating-ui/react";
|
|
9
9
|
import cl from "clsx";
|
|
10
|
-
import React, { HTMLAttributes, forwardRef,
|
|
11
|
-
import {
|
|
10
|
+
import React, { HTMLAttributes, forwardRef, useRef } from "react";
|
|
11
|
+
import { useDateInputContext } from "../date/Date.Input";
|
|
12
12
|
import { useModalContext } from "../modal/Modal.context";
|
|
13
13
|
import { DismissableLayer } from "../overlays/dismissablelayer/DismissableLayer";
|
|
14
14
|
import { useThemeInternal } from "../theme/Theme";
|
|
@@ -121,9 +121,9 @@ export const Popover = forwardRef<HTMLDivElement, PopoverProps>(
|
|
|
121
121
|
) => {
|
|
122
122
|
const arrowRef = useRef<HTMLDivElement | null>(null);
|
|
123
123
|
const isInModal = useModalContext(false) !== undefined;
|
|
124
|
-
const
|
|
124
|
+
const datepickerContext = useDateInputContext(false);
|
|
125
125
|
const chosenStrategy = userStrategy ?? (isInModal ? "fixed" : "absolute");
|
|
126
|
-
const chosenFlip =
|
|
126
|
+
const chosenFlip = datepickerContext ? false : _flip;
|
|
127
127
|
|
|
128
128
|
const themeContext = useThemeInternal(false);
|
|
129
129
|
|
package/src/react-css.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import "react";
|
|
2
|
+
import type { GlobalColorRoles } from "@navikt/ds-tokens/types";
|
|
2
3
|
|
|
3
4
|
declare module "react" {
|
|
4
5
|
interface CSSProperties {
|
|
@@ -7,4 +8,7 @@ declare module "react" {
|
|
|
7
8
|
[key: `--axc-${string}`]: string | number | undefined;
|
|
8
9
|
[key: `--__axc-${string}`]: string | number | undefined;
|
|
9
10
|
}
|
|
11
|
+
interface HTMLAttributes {
|
|
12
|
+
"data-color-role"?: GlobalColorRoles;
|
|
13
|
+
}
|
|
10
14
|
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { compositeClassFunction } from "./Theme";
|
|
3
|
+
|
|
4
|
+
const start = "navds-accordion testclass navds-heading endclass";
|
|
5
|
+
const end =
|
|
6
|
+
"startclass navds-accordion navds-heading endclass navds-accordion__header";
|
|
7
|
+
|
|
8
|
+
const both = start + " " + end;
|
|
9
|
+
|
|
10
|
+
describe("RenameCSS", () => {
|
|
11
|
+
test("String starts with navds", () => {
|
|
12
|
+
expect(compositeClassFunction(start)).toBe(
|
|
13
|
+
"aksel-accordion testclass aksel-heading endclass",
|
|
14
|
+
);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("String ends with navds", () => {
|
|
18
|
+
expect(compositeClassFunction(end)).toBe(
|
|
19
|
+
"startclass aksel-accordion aksel-heading endclass aksel-accordion__header",
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("String starts and ends with navds", () => {
|
|
24
|
+
expect(compositeClassFunction(both)).toBe(
|
|
25
|
+
"aksel-accordion testclass aksel-heading endclass startclass aksel-accordion aksel-heading endclass aksel-accordion__header",
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("String does not contain navds", () => {
|
|
30
|
+
expect(compositeClassFunction("startclass endclass")).toBe(
|
|
31
|
+
"startclass endclass",
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("String is empty", () => {
|
|
36
|
+
expect(compositeClassFunction("")).toBe("");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("String contains navds as a substring", () => {
|
|
40
|
+
expect(compositeClassFunction("startclass test-navds-class endclass")).toBe(
|
|
41
|
+
"startclass test-navds-class endclass",
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("String contains multiple navds occurrences", () => {
|
|
46
|
+
const input = "navds-button navds-icon navds-label";
|
|
47
|
+
const expected = "aksel-button aksel-icon aksel-label";
|
|
48
|
+
expect(compositeClassFunction(input)).toBe(expected);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("String contains navds with special characters", () => {
|
|
52
|
+
const input = "navds-button! navds-icon@ navds-#label navds#-label";
|
|
53
|
+
const expected = "aksel-button! aksel-icon@ aksel-#label navds#-label";
|
|
54
|
+
expect(compositeClassFunction(input)).toBe(expected);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("String contains mixed navds and non-navds classes", () => {
|
|
58
|
+
const input = "navds-button custom-class navds-icon";
|
|
59
|
+
const expected = "aksel-button custom-class aksel-icon";
|
|
60
|
+
expect(compositeClassFunction(input)).toBe(expected);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("String contains only navds", () => {
|
|
64
|
+
const input = "navds";
|
|
65
|
+
const expected = "navds";
|
|
66
|
+
expect(compositeClassFunction(input)).toBe(expected);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("String contains navds with numbers", () => {
|
|
70
|
+
const input = "navds-1 navds-2 navds-3";
|
|
71
|
+
const expected = "aksel-1 aksel-2 aksel-3";
|
|
72
|
+
expect(compositeClassFunction(input)).toBe(expected);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("String contains different casings", () => {
|
|
76
|
+
const input = "Navds-button NAVds-icon NAVDS-label navDS-component";
|
|
77
|
+
const expected = "Navds-button NAVds-icon NAVDS-label navDS-component";
|
|
78
|
+
expect(compositeClassFunction(input)).toBe(expected);
|
|
79
|
+
});
|
|
80
|
+
});
|
package/src/theme/Theme.tsx
CHANGED
|
@@ -4,6 +4,41 @@ import { Slot } from "../slot/Slot";
|
|
|
4
4
|
import { createContext } from "../util/create-context";
|
|
5
5
|
import { AsChildProps } from "../util/types";
|
|
6
6
|
|
|
7
|
+
/* -------------------------------------------------------------------------- */
|
|
8
|
+
/* CSS Trsnalation */
|
|
9
|
+
/* -------------------------------------------------------------------------- */
|
|
10
|
+
type RenameCSSContext = {
|
|
11
|
+
cn: (...inputs: Parameters<typeof cl>) => ReturnType<typeof cl>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const [RenameCSSProvider, useRenameCSS] = createContext<RenameCSSContext>({
|
|
15
|
+
hookName: "useRenameCSS",
|
|
16
|
+
name: "RenameCSS",
|
|
17
|
+
providerName: "RenameCSSProvider",
|
|
18
|
+
defaultValue: { cn: cl },
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export const compositeClassFunction = (
|
|
22
|
+
...inputs: Parameters<typeof cl>
|
|
23
|
+
): string => {
|
|
24
|
+
const classes = cl(inputs)
|
|
25
|
+
/* Replaces only if start of string "navds- navds-"*/
|
|
26
|
+
.replace(/^navds-/g, "aksel-")
|
|
27
|
+
/* Replaces all " navds-" hits */
|
|
28
|
+
.replace(/\snavds-/g, " aksel-");
|
|
29
|
+
|
|
30
|
+
return classes.trim();
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const RenameCSS = ({ children }: { children: React.ReactNode }) => {
|
|
34
|
+
/* Replace function with this when implementation is complete and CSS is updated */
|
|
35
|
+
/* <RenameCSSProvider cn={compositeClassFunction}> */
|
|
36
|
+
return <RenameCSSProvider cn={cl}>{children}</RenameCSSProvider>;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/* -------------------------------------------------------------------------- */
|
|
40
|
+
/* Theme provider */
|
|
41
|
+
/* -------------------------------------------------------------------------- */
|
|
7
42
|
type ThemeContext = {
|
|
8
43
|
/**
|
|
9
44
|
* Color theme
|
|
@@ -45,16 +80,18 @@ const Theme = forwardRef<HTMLDivElement, ThemeProps>(
|
|
|
45
80
|
|
|
46
81
|
return (
|
|
47
82
|
<ThemeProvider theme={theme}>
|
|
48
|
-
<
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
83
|
+
<RenameCSS>
|
|
84
|
+
<SlotElement
|
|
85
|
+
ref={ref}
|
|
86
|
+
className={cl("navds-theme", className, theme)}
|
|
87
|
+
data-background={hasBackground}
|
|
88
|
+
>
|
|
89
|
+
{children}
|
|
90
|
+
</SlotElement>
|
|
91
|
+
</RenameCSS>
|
|
55
92
|
</ThemeProvider>
|
|
56
93
|
);
|
|
57
94
|
},
|
|
58
95
|
);
|
|
59
96
|
|
|
60
|
-
export { Theme, useThemeInternal };
|
|
97
|
+
export { Theme, useRenameCSS, useThemeInternal };
|
package/src/theme/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
export { Theme, ThemeProps } from "./Theme";
|
|
2
|
+
export { Theme, type ThemeProps } from "./Theme";
|
package/src/tooltip/Tooltip.tsx
CHANGED
|
@@ -16,7 +16,6 @@ import React, { HTMLAttributes, forwardRef, useRef } from "react";
|
|
|
16
16
|
import { useModalContext } from "../modal/Modal.context";
|
|
17
17
|
import { Portal } from "../portal";
|
|
18
18
|
import { Slot } from "../slot/Slot";
|
|
19
|
-
import { useThemeInternal } from "../theme/Theme";
|
|
20
19
|
import { Detail } from "../typography";
|
|
21
20
|
import { useId } from "../util/hooks";
|
|
22
21
|
import { useControllableState } from "../util/hooks/useControllableState";
|
|
@@ -124,9 +123,6 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
|
|
|
124
123
|
},
|
|
125
124
|
ref,
|
|
126
125
|
) => {
|
|
127
|
-
const themeContext = useThemeInternal(false);
|
|
128
|
-
const showArrow = _arrow && !themeContext;
|
|
129
|
-
|
|
130
126
|
const [_open, _setOpen] = useControllableState({
|
|
131
127
|
defaultValue: defaultOpen,
|
|
132
128
|
value: open,
|
|
@@ -153,7 +149,7 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
|
|
|
153
149
|
open: _open,
|
|
154
150
|
onOpenChange: (newState) => _setOpen(newState),
|
|
155
151
|
middleware: [
|
|
156
|
-
offset(_offset ?? (
|
|
152
|
+
offset(_offset ?? (_arrow ? 8 : 4)),
|
|
157
153
|
shift(),
|
|
158
154
|
flip({ padding: 5, fallbackPlacements: ["bottom", "top"] }),
|
|
159
155
|
flArrow({ element: arrowRef, padding: 5 }),
|
|
@@ -244,7 +240,7 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
|
|
|
244
240
|
))}
|
|
245
241
|
</span>
|
|
246
242
|
)}
|
|
247
|
-
{
|
|
243
|
+
{_arrow && (
|
|
248
244
|
<div
|
|
249
245
|
ref={(node) => {
|
|
250
246
|
arrowRef.current = node;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { useDateInputContext, DateInputContext } from "./useDateInputContext";
|
|
2
|
-
export {
|
|
3
|
-
useSharedMonthContext,
|
|
4
|
-
SharedMonthProvider,
|
|
5
|
-
} from "./useSharedMonthContext";
|
|
6
|
-
export {
|
|
7
|
-
useDateTranslationContext,
|
|
8
|
-
DateTranslationContextProvider,
|
|
9
|
-
} from "./useDateTranslationContext";
|