@navikt/ds-react 7.7.0 → 7.8.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/chips/Removable.d.ts +0 -5
- package/cjs/chips/Removable.js +2 -2
- package/cjs/chips/Removable.js.map +1 -1
- package/cjs/date/context/index.d.ts +2 -1
- package/cjs/date/context/index.js +5 -2
- package/cjs/date/context/index.js.map +1 -1
- package/cjs/date/context/useDateInputContext.d.ts +3 -3
- package/cjs/date/context/useDateInputContext.js +4 -4
- package/cjs/date/context/useDateInputContext.js.map +1 -1
- package/cjs/date/context/useDateTranslationContext.d.ts +8 -0
- package/cjs/date/context/useDateTranslationContext.js +7 -0
- package/cjs/date/context/useDateTranslationContext.js.map +1 -0
- package/cjs/date/datepicker/DatePicker.js +18 -16
- package/cjs/date/datepicker/DatePicker.js.map +1 -1
- package/cjs/date/datepicker/DatePickerStandalone.js +17 -14
- package/cjs/date/datepicker/DatePickerStandalone.js.map +1 -1
- package/cjs/date/datepicker/parts/Caption.js +2 -3
- package/cjs/date/datepicker/parts/Caption.js.map +1 -1
- package/cjs/date/datepicker/parts/DropdownCaption.js +2 -2
- package/cjs/date/datepicker/parts/DropdownCaption.js.map +1 -1
- package/cjs/date/datepicker/parts/WeekNumber.js +3 -4
- package/cjs/date/datepicker/parts/WeekNumber.js.map +1 -1
- package/cjs/date/datepicker/parts/WeekRow.js +2 -3
- package/cjs/date/datepicker/parts/WeekRow.js.map +1 -1
- package/cjs/date/datepicker/types.d.ts +8 -0
- package/cjs/date/monthpicker/MonthCaption.js +1 -3
- package/cjs/date/monthpicker/MonthCaption.js.map +1 -1
- package/cjs/date/monthpicker/MonthPicker.js +30 -28
- package/cjs/date/monthpicker/MonthPicker.js.map +1 -1
- package/cjs/date/monthpicker/MonthPickerStandalone.js +16 -12
- package/cjs/date/monthpicker/MonthPickerStandalone.js.map +1 -1
- package/cjs/date/monthpicker/types.d.ts +8 -0
- package/cjs/date/parts/DateInput.js +1 -2
- package/cjs/date/parts/DateInput.js.map +1 -1
- package/cjs/date/parts/DateWrapper.d.ts +3 -1
- package/cjs/date/parts/DateWrapper.js +3 -3
- package/cjs/date/parts/DateWrapper.js.map +1 -1
- package/cjs/date/utils/index.d.ts +1 -1
- package/cjs/date/utils/index.js +2 -1
- package/cjs/date/utils/index.js.map +1 -1
- package/cjs/date/utils/locale.d.ts +12 -2
- package/cjs/date/utils/locale.js +18 -2
- package/cjs/date/utils/locale.js.map +1 -1
- package/cjs/form/combobox/Combobox.d.ts +1 -1
- package/cjs/form/combobox/ComboboxWrapper.js +6 -7
- package/cjs/form/combobox/ComboboxWrapper.js.map +1 -1
- package/cjs/form/combobox/FilteredOptions/FilteredOptions.js +4 -4
- package/cjs/form/combobox/FilteredOptions/FilteredOptions.js.map +1 -1
- package/cjs/form/combobox/FilteredOptions/FilteredOptionsItem.js +1 -1
- package/cjs/form/combobox/FilteredOptions/FilteredOptionsItem.js.map +1 -1
- package/cjs/form/combobox/FilteredOptions/MaxSelectedMessage.d.ts +1 -1
- package/cjs/form/combobox/FilteredOptions/MaxSelectedMessage.js +2 -5
- package/cjs/form/combobox/FilteredOptions/MaxSelectedMessage.js.map +1 -1
- package/cjs/form/combobox/FilteredOptions/filteredOptionsContext.js +4 -4
- package/cjs/form/combobox/FilteredOptions/filteredOptionsContext.js.map +1 -1
- package/cjs/form/combobox/Input/Input.js +10 -10
- package/cjs/form/combobox/Input/Input.js.map +1 -1
- package/cjs/form/combobox/Input/InputController.d.ts +1 -1
- package/cjs/form/combobox/Input/InputController.js +15 -11
- package/cjs/form/combobox/Input/InputController.js.map +1 -1
- package/cjs/form/combobox/SelectedOptions/selectedOptionsContext.d.ts +2 -1
- package/cjs/form/combobox/SelectedOptions/selectedOptionsContext.js +14 -5
- package/cjs/form/combobox/SelectedOptions/selectedOptionsContext.js.map +1 -1
- package/cjs/form/combobox/types.d.ts +7 -17
- package/cjs/form/search/Search.d.ts +3 -2
- package/cjs/form/search/Search.js +1 -1
- package/cjs/form/search/Search.js.map +1 -1
- package/cjs/form/textarea/Textarea.d.ts +1 -0
- package/cjs/form/textarea/Textarea.js.map +1 -1
- package/cjs/guide-panel/GuidePanel.js +11 -3
- package/cjs/guide-panel/GuidePanel.js.map +1 -1
- package/cjs/guide-panel/Illustration.d.ts +2 -8
- package/cjs/guide-panel/Illustration.darkside.d.ts +2 -0
- package/cjs/guide-panel/Illustration.darkside.js +30 -0
- package/cjs/guide-panel/Illustration.darkside.js.map +1 -0
- package/cjs/guide-panel/Illustration.js +2 -18
- package/cjs/guide-panel/Illustration.js.map +1 -1
- package/cjs/guide-panel/index.d.ts +0 -1
- package/cjs/guide-panel/index.js +1 -3
- package/cjs/guide-panel/index.js.map +1 -1
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +2 -3
- package/cjs/index.js.map +1 -1
- package/cjs/layout/box/Box.d.ts +3 -2
- package/cjs/layout/box/Box.darkside.d.ts +10 -6
- package/cjs/layout/box/Box.darkside.js.map +1 -1
- package/cjs/layout/box/Box.js.map +1 -1
- package/cjs/layout/utilities/types.d.ts +7 -23
- package/cjs/modal/Modal.js +1 -1
- package/cjs/modal/Modal.js.map +1 -1
- package/cjs/modal/ModalHeader.js +1 -1
- package/cjs/modal/ModalHeader.js.map +1 -1
- package/cjs/popover/Popover.js +1 -1
- package/cjs/popover/Popover.js.map +1 -1
- package/cjs/provider/Provider.d.ts +35 -10
- package/cjs/provider/Provider.js +13 -14
- package/cjs/provider/Provider.js.map +1 -1
- package/cjs/table/ExpandableRow.js +3 -3
- package/cjs/table/ExpandableRow.js.map +1 -1
- package/cjs/tabs/Tabs.context.d.ts +1 -1
- package/cjs/tag/Tag.d.ts +1 -1
- package/cjs/tag/Tag.js +4 -1
- package/cjs/tag/Tag.js.map +1 -1
- package/cjs/timeline/Pin.js +5 -2
- package/cjs/timeline/Pin.js.map +1 -1
- package/cjs/timeline/Timeline.d.ts +1 -0
- package/cjs/timeline/Timeline.js.map +1 -1
- package/cjs/timeline/hooks/useTimelineRows.d.ts +5 -1
- package/cjs/timeline/hooks/useTimelineRows.js +14 -3
- package/cjs/timeline/hooks/useTimelineRows.js.map +1 -1
- package/cjs/timeline/period/ClickablePeriod.js +5 -2
- package/cjs/timeline/period/ClickablePeriod.js.map +1 -1
- package/cjs/tooltip/Tooltip.js +6 -3
- package/cjs/tooltip/Tooltip.js.map +1 -1
- package/cjs/util/i18n/i18n.context.d.ts +1 -1
- package/cjs/util/i18n/i18n.context.js +15 -14
- package/cjs/util/i18n/i18n.context.js.map +1 -1
- package/cjs/util/i18n/locales/en.d.ts +50 -54
- package/cjs/util/i18n/locales/en.js +52 -56
- package/cjs/util/i18n/locales/en.js.map +1 -1
- package/cjs/util/i18n/locales/index.d.ts +3 -0
- package/cjs/util/i18n/locales/index.js +14 -0
- package/cjs/util/i18n/locales/index.js.map +1 -0
- package/cjs/util/i18n/locales/nb.d.ts +53 -57
- package/cjs/util/i18n/locales/nb.js +56 -60
- package/cjs/util/i18n/locales/nb.js.map +1 -1
- package/cjs/util/i18n/locales/nn.d.ts +50 -54
- package/cjs/util/i18n/locales/nn.js +52 -56
- package/cjs/util/i18n/locales/nn.js.map +1 -1
- package/esm/chips/Removable.d.ts +0 -5
- package/esm/chips/Removable.js +2 -2
- package/esm/chips/Removable.js.map +1 -1
- package/esm/date/context/index.d.ts +2 -1
- package/esm/date/context/index.js +2 -1
- package/esm/date/context/index.js.map +1 -1
- package/esm/date/context/useDateInputContext.d.ts +3 -3
- package/esm/date/context/useDateInputContext.js +3 -3
- package/esm/date/context/useDateInputContext.js.map +1 -1
- package/esm/date/context/useDateTranslationContext.d.ts +8 -0
- package/esm/date/context/useDateTranslationContext.js +3 -0
- package/esm/date/context/useDateTranslationContext.js.map +1 -0
- package/esm/date/datepicker/DatePicker.js +21 -19
- package/esm/date/datepicker/DatePicker.js.map +1 -1
- package/esm/date/datepicker/DatePickerStandalone.js +19 -16
- package/esm/date/datepicker/DatePickerStandalone.js.map +1 -1
- package/esm/date/datepicker/parts/Caption.js +2 -3
- package/esm/date/datepicker/parts/Caption.js.map +1 -1
- package/esm/date/datepicker/parts/DropdownCaption.js +3 -3
- package/esm/date/datepicker/parts/DropdownCaption.js.map +1 -1
- package/esm/date/datepicker/parts/WeekNumber.js +3 -4
- package/esm/date/datepicker/parts/WeekNumber.js.map +1 -1
- package/esm/date/datepicker/parts/WeekRow.js +2 -3
- package/esm/date/datepicker/parts/WeekRow.js.map +1 -1
- package/esm/date/datepicker/types.d.ts +8 -0
- package/esm/date/monthpicker/MonthCaption.js +2 -4
- package/esm/date/monthpicker/MonthCaption.js.map +1 -1
- package/esm/date/monthpicker/MonthPicker.js +33 -31
- package/esm/date/monthpicker/MonthPicker.js.map +1 -1
- package/esm/date/monthpicker/MonthPickerStandalone.js +18 -14
- package/esm/date/monthpicker/MonthPickerStandalone.js.map +1 -1
- package/esm/date/monthpicker/types.d.ts +8 -0
- package/esm/date/parts/DateInput.js +2 -3
- package/esm/date/parts/DateInput.js.map +1 -1
- package/esm/date/parts/DateWrapper.d.ts +3 -1
- package/esm/date/parts/DateWrapper.js +4 -4
- package/esm/date/parts/DateWrapper.js.map +1 -1
- package/esm/date/utils/index.d.ts +1 -1
- package/esm/date/utils/index.js +1 -1
- package/esm/date/utils/index.js.map +1 -1
- package/esm/date/utils/locale.d.ts +12 -2
- package/esm/date/utils/locale.js +16 -1
- package/esm/date/utils/locale.js.map +1 -1
- package/esm/form/combobox/Combobox.d.ts +1 -1
- package/esm/form/combobox/ComboboxWrapper.js +6 -7
- package/esm/form/combobox/ComboboxWrapper.js.map +1 -1
- package/esm/form/combobox/FilteredOptions/FilteredOptions.js +4 -4
- package/esm/form/combobox/FilteredOptions/FilteredOptions.js.map +1 -1
- package/esm/form/combobox/FilteredOptions/FilteredOptionsItem.js +1 -1
- package/esm/form/combobox/FilteredOptions/FilteredOptionsItem.js.map +1 -1
- package/esm/form/combobox/FilteredOptions/MaxSelectedMessage.d.ts +1 -1
- package/esm/form/combobox/FilteredOptions/MaxSelectedMessage.js +2 -5
- package/esm/form/combobox/FilteredOptions/MaxSelectedMessage.js.map +1 -1
- package/esm/form/combobox/FilteredOptions/filteredOptionsContext.js +4 -4
- package/esm/form/combobox/FilteredOptions/filteredOptionsContext.js.map +1 -1
- package/esm/form/combobox/Input/Input.js +10 -10
- package/esm/form/combobox/Input/Input.js.map +1 -1
- package/esm/form/combobox/Input/InputController.d.ts +1 -1
- package/esm/form/combobox/Input/InputController.js +15 -11
- package/esm/form/combobox/Input/InputController.js.map +1 -1
- package/esm/form/combobox/SelectedOptions/selectedOptionsContext.d.ts +2 -1
- package/esm/form/combobox/SelectedOptions/selectedOptionsContext.js +14 -5
- package/esm/form/combobox/SelectedOptions/selectedOptionsContext.js.map +1 -1
- package/esm/form/combobox/types.d.ts +7 -17
- package/esm/form/search/Search.d.ts +3 -2
- package/esm/form/search/Search.js +1 -1
- package/esm/form/search/Search.js.map +1 -1
- package/esm/form/textarea/Textarea.d.ts +1 -0
- package/esm/form/textarea/Textarea.js.map +1 -1
- package/esm/guide-panel/GuidePanel.js +11 -3
- package/esm/guide-panel/GuidePanel.js.map +1 -1
- package/esm/guide-panel/Illustration.d.ts +2 -8
- package/esm/guide-panel/Illustration.darkside.d.ts +2 -0
- package/esm/guide-panel/Illustration.darkside.js +23 -0
- package/esm/guide-panel/Illustration.darkside.js.map +1 -0
- package/esm/guide-panel/Illustration.js +2 -18
- package/esm/guide-panel/Illustration.js.map +1 -1
- package/esm/guide-panel/index.d.ts +0 -1
- package/esm/guide-panel/index.js +0 -1
- package/esm/guide-panel/index.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/layout/box/Box.d.ts +3 -2
- package/esm/layout/box/Box.darkside.d.ts +10 -6
- package/esm/layout/box/Box.darkside.js.map +1 -1
- package/esm/layout/box/Box.js.map +1 -1
- package/esm/layout/utilities/types.d.ts +7 -23
- package/esm/modal/Modal.js +2 -2
- package/esm/modal/Modal.js.map +1 -1
- package/esm/modal/ModalHeader.js +1 -1
- package/esm/modal/ModalHeader.js.map +1 -1
- package/esm/popover/Popover.js +2 -2
- package/esm/popover/Popover.js.map +1 -1
- package/esm/provider/Provider.d.ts +35 -10
- package/esm/provider/Provider.js +11 -15
- package/esm/provider/Provider.js.map +1 -1
- package/esm/table/ExpandableRow.js +3 -3
- package/esm/table/ExpandableRow.js.map +1 -1
- package/esm/tabs/Tabs.context.d.ts +1 -1
- package/esm/tag/Tag.d.ts +1 -1
- package/esm/tag/Tag.js +4 -1
- package/esm/tag/Tag.js.map +1 -1
- package/esm/timeline/Pin.js +5 -2
- package/esm/timeline/Pin.js.map +1 -1
- package/esm/timeline/Timeline.d.ts +1 -0
- package/esm/timeline/Timeline.js.map +1 -1
- package/esm/timeline/hooks/useTimelineRows.d.ts +5 -1
- package/esm/timeline/hooks/useTimelineRows.js +14 -3
- package/esm/timeline/hooks/useTimelineRows.js.map +1 -1
- package/esm/timeline/period/ClickablePeriod.js +5 -2
- package/esm/timeline/period/ClickablePeriod.js.map +1 -1
- package/esm/tooltip/Tooltip.js +6 -3
- package/esm/tooltip/Tooltip.js.map +1 -1
- package/esm/util/i18n/i18n.context.d.ts +1 -1
- package/esm/util/i18n/i18n.context.js +15 -14
- package/esm/util/i18n/i18n.context.js.map +1 -1
- package/esm/util/i18n/locales/en.d.ts +50 -54
- package/esm/util/i18n/locales/en.js +52 -56
- package/esm/util/i18n/locales/en.js.map +1 -1
- package/esm/util/i18n/locales/index.d.ts +3 -0
- package/esm/util/i18n/locales/index.js +5 -0
- package/esm/util/i18n/locales/index.js.map +1 -0
- package/esm/util/i18n/locales/nb.d.ts +53 -57
- package/esm/util/i18n/locales/nb.js +56 -60
- package/esm/util/i18n/locales/nb.js.map +1 -1
- package/esm/util/i18n/locales/nn.d.ts +50 -54
- package/esm/util/i18n/locales/nn.js +52 -56
- package/esm/util/i18n/locales/nn.js.map +1 -1
- package/package.json +14 -4
- package/src/chips/Removable.tsx +1 -9
- package/src/date/context/index.ts +5 -1
- package/src/date/context/useDateInputContext.tsx +6 -4
- package/src/date/context/useDateTranslationContext.ts +9 -0
- package/src/date/datepicker/DatePicker.tsx +41 -32
- package/src/date/datepicker/DatePickerStandalone.tsx +46 -37
- package/src/date/datepicker/parts/Caption.tsx +2 -3
- package/src/date/datepicker/parts/DropdownCaption.tsx +3 -3
- package/src/date/datepicker/parts/WeekNumber.tsx +3 -9
- package/src/date/datepicker/parts/WeekRow.tsx +2 -3
- package/src/date/datepicker/types.ts +8 -0
- package/src/date/monthpicker/MonthCaption.tsx +2 -4
- package/src/date/monthpicker/MonthPicker.tsx +67 -54
- package/src/date/monthpicker/MonthPickerStandalone.tsx +39 -26
- package/src/date/monthpicker/types.ts +8 -0
- package/src/date/parts/DateInput.tsx +2 -3
- package/src/date/parts/DateWrapper.tsx +6 -4
- package/src/date/utils/index.ts +5 -1
- package/src/date/utils/locale.ts +17 -1
- package/src/form/combobox/ComboboxWrapper.tsx +6 -7
- package/src/form/combobox/FilteredOptions/FilteredOptions.tsx +4 -4
- package/src/form/combobox/FilteredOptions/FilteredOptionsItem.tsx +1 -1
- package/src/form/combobox/FilteredOptions/MaxSelectedMessage.tsx +2 -9
- package/src/form/combobox/FilteredOptions/filteredOptionsContext.tsx +4 -4
- package/src/form/combobox/Input/Input.context.tsx +1 -1
- package/src/form/combobox/Input/Input.tsx +10 -10
- package/src/form/combobox/Input/InputController.tsx +14 -25
- package/src/form/combobox/SelectedOptions/selectedOptionsContext.tsx +14 -7
- package/src/form/combobox/types.ts +12 -20
- package/src/form/search/Search.tsx +3 -2
- package/src/form/textarea/Textarea.tsx +1 -0
- package/src/guide-panel/GuidePanel.tsx +59 -15
- package/src/guide-panel/Illustration.darkside.tsx +96 -0
- package/src/guide-panel/Illustration.tsx +2 -22
- package/src/guide-panel/index.ts +0 -1
- package/src/index.ts +1 -5
- package/src/layout/box/Box.darkside.tsx +19 -14
- package/src/layout/box/Box.tsx +4 -2
- package/src/layout/utilities/types.ts +20 -42
- package/src/modal/Modal.tsx +2 -2
- package/src/modal/ModalHeader.tsx +1 -1
- package/src/popover/Popover.tsx +2 -2
- package/src/provider/Provider.tsx +56 -13
- package/src/table/ExpandableRow.tsx +10 -3
- package/src/tag/Tag.tsx +32 -18
- package/src/timeline/Pin.tsx +16 -10
- package/src/timeline/Timeline.tsx +1 -0
- package/src/timeline/hooks/useTimelineRows.ts +25 -9
- package/src/timeline/period/ClickablePeriod.tsx +16 -10
- package/src/timeline/tests/useTimelineRows.test.ts +131 -0
- package/src/tooltip/Tooltip.tsx +7 -2
- package/src/util/i18n/i18n.context.test.tsx +29 -8
- package/src/util/i18n/i18n.context.ts +15 -14
- package/src/util/i18n/locales/en.ts +52 -56
- package/src/util/i18n/locales/index.ts +4 -0
- package/src/util/i18n/locales/nb.ts +56 -60
- package/src/util/i18n/locales/nn.ts +52 -56
- package/cjs/provider/i18n/LanguageProvider.d.ts +0 -26
- package/cjs/provider/i18n/LanguageProvider.js +0 -54
- package/cjs/provider/i18n/LanguageProvider.js.map +0 -1
- package/esm/provider/i18n/LanguageProvider.d.ts +0 -26
- package/esm/provider/i18n/LanguageProvider.js +0 -23
- package/esm/provider/i18n/LanguageProvider.js.map +0 -1
- package/src/provider/i18n/LanguageProvider.tsx +0 -49
|
@@ -1,20 +1,49 @@
|
|
|
1
1
|
import React, { createContext, useContext } from "react";
|
|
2
|
+
import { PartialTranslations, Translations } from "../util/i18n/i18n.types";
|
|
3
|
+
import nb from "../util/i18n/locales/nb";
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Global root-element to attach portals to (Tooltip)
|
|
6
|
-
*/
|
|
5
|
+
type ProviderContextType = {
|
|
7
6
|
rootElement?: HTMLElement;
|
|
8
|
-
|
|
7
|
+
locale: Translations;
|
|
8
|
+
translations?: PartialTranslations | PartialTranslations[];
|
|
9
|
+
};
|
|
9
10
|
|
|
10
|
-
export const ProviderContext = createContext<ProviderContextType
|
|
11
|
-
|
|
12
|
-
);
|
|
11
|
+
export const ProviderContext = createContext<ProviderContextType>({
|
|
12
|
+
locale: nb,
|
|
13
|
+
});
|
|
13
14
|
|
|
14
|
-
export
|
|
15
|
-
children
|
|
15
|
+
export type ProviderProps = {
|
|
16
|
+
children: React.ReactNode;
|
|
17
|
+
/**
|
|
18
|
+
* Global root-element to attach portals to. Used by Tooltip, Modal (optionally) and ActionMenu.
|
|
19
|
+
*/
|
|
16
20
|
rootElement?: HTMLElement;
|
|
17
|
-
}
|
|
21
|
+
} & (
|
|
22
|
+
| {
|
|
23
|
+
/**
|
|
24
|
+
* Aksel locale
|
|
25
|
+
* @default nb
|
|
26
|
+
* @example
|
|
27
|
+
* ```jsx
|
|
28
|
+
* import { en } from "@navikt/ds-react/locales";
|
|
29
|
+
* <Provider locale={en}>
|
|
30
|
+
* {app}
|
|
31
|
+
* </Provider>
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
locale: Translations;
|
|
35
|
+
/**
|
|
36
|
+
* Use this if you need to override some of the default translations.
|
|
37
|
+
* Can be a single object or an array of objects.
|
|
38
|
+
* Must be used together with the `locale` prop.
|
|
39
|
+
*/
|
|
40
|
+
translations?: PartialTranslations | PartialTranslations[];
|
|
41
|
+
}
|
|
42
|
+
| {
|
|
43
|
+
locale?: never;
|
|
44
|
+
translations?: never;
|
|
45
|
+
}
|
|
46
|
+
);
|
|
18
47
|
|
|
19
48
|
export const useProvider = () => useContext(ProviderContext);
|
|
20
49
|
|
|
@@ -31,9 +60,23 @@ export const useProvider = () => useContext(ProviderContext);
|
|
|
31
60
|
* </Provider>
|
|
32
61
|
* ```
|
|
33
62
|
*/
|
|
34
|
-
export const Provider = ({
|
|
63
|
+
export const Provider = ({
|
|
64
|
+
children,
|
|
65
|
+
rootElement,
|
|
66
|
+
locale,
|
|
67
|
+
translations,
|
|
68
|
+
}: ProviderProps) => {
|
|
69
|
+
const parentContext = useProvider();
|
|
35
70
|
return (
|
|
36
|
-
<ProviderContext.Provider
|
|
71
|
+
<ProviderContext.Provider
|
|
72
|
+
value={{
|
|
73
|
+
rootElement: rootElement || parentContext.rootElement,
|
|
74
|
+
locale: locale || parentContext.locale || nb,
|
|
75
|
+
translations: translations || parentContext.translations,
|
|
76
|
+
}}
|
|
77
|
+
>
|
|
78
|
+
{children}
|
|
79
|
+
</ProviderContext.Provider>
|
|
37
80
|
);
|
|
38
81
|
};
|
|
39
82
|
|
|
@@ -78,6 +78,7 @@ export const ExpandableRow: ExpandableRowType = forwardRef(
|
|
|
78
78
|
onChange: onOpenChange,
|
|
79
79
|
});
|
|
80
80
|
const translate = useI18n("global");
|
|
81
|
+
|
|
81
82
|
const id = useId();
|
|
82
83
|
|
|
83
84
|
const expansionHandler = (event: React.MouseEvent<HTMLElement>) => {
|
|
@@ -110,7 +111,7 @@ export const ExpandableRow: ExpandableRowType = forwardRef(
|
|
|
110
111
|
className={cl("navds-table__toggle-expand-cell", {
|
|
111
112
|
"navds-table__toggle-expand-cell--open": _open,
|
|
112
113
|
})}
|
|
113
|
-
onClick={expansionHandler}
|
|
114
|
+
onClick={!expansionDisabled ? expansionHandler : () => null}
|
|
114
115
|
>
|
|
115
116
|
{!expansionDisabled && (
|
|
116
117
|
<button
|
|
@@ -129,13 +130,19 @@ export const ExpandableRow: ExpandableRowType = forwardRef(
|
|
|
129
130
|
</DataCell>
|
|
130
131
|
{togglePlacement === "left" && children}
|
|
131
132
|
</Row>
|
|
132
|
-
<tr
|
|
133
|
+
<tr
|
|
134
|
+
data-state={_open ? "open" : "closed"}
|
|
135
|
+
className="navds-table__expanded-row"
|
|
136
|
+
aria-hidden={!_open}
|
|
137
|
+
id={id}
|
|
138
|
+
>
|
|
133
139
|
<td colSpan={colSpan} className="navds-table__expanded-row-cell">
|
|
134
140
|
<AnimateHeight
|
|
135
141
|
className="navds-table__expanded-row-collapse"
|
|
136
142
|
innerClassName="navds-table__expanded-row-content"
|
|
137
143
|
height={_open ? "auto" : 0}
|
|
138
|
-
duration={
|
|
144
|
+
duration={150}
|
|
145
|
+
easing="cubic-bezier(0.39,0.57,0.56,1)"
|
|
139
146
|
>
|
|
140
147
|
{content}
|
|
141
148
|
</AnimateHeight>
|
package/src/tag/Tag.tsx
CHANGED
|
@@ -31,7 +31,13 @@ export interface TagProps extends HTMLAttributes<HTMLSpanElement> {
|
|
|
31
31
|
| "alt2-moderate"
|
|
32
32
|
| "alt3"
|
|
33
33
|
| "alt3-filled"
|
|
34
|
-
| "alt3-moderate"
|
|
34
|
+
| "alt3-moderate"
|
|
35
|
+
| "meta-purple"
|
|
36
|
+
| "meta-purple-filled"
|
|
37
|
+
| "meta-purple-moderate"
|
|
38
|
+
| "meta-lime"
|
|
39
|
+
| "meta-lime-filled"
|
|
40
|
+
| "meta-lime-moderate";
|
|
35
41
|
/**
|
|
36
42
|
* @default "medium"
|
|
37
43
|
*/
|
|
@@ -54,23 +60,31 @@ export interface TagProps extends HTMLAttributes<HTMLSpanElement> {
|
|
|
54
60
|
* ```
|
|
55
61
|
*/
|
|
56
62
|
export const Tag = forwardRef<HTMLSpanElement, TagProps>(
|
|
57
|
-
({ children, className, variant, size = "medium", icon, ...rest }, ref) =>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
63
|
+
({ children, className, variant, size = "medium", icon, ...rest }, ref) => {
|
|
64
|
+
const filledVariant = variant?.endsWith("-filled") && "strong";
|
|
65
|
+
const moderateVariant = variant?.endsWith("-moderate") && "moderate";
|
|
66
|
+
const color = variant?.replace("-filled", "").replace("-moderate", "");
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<BodyShort
|
|
70
|
+
{...rest}
|
|
71
|
+
ref={ref}
|
|
72
|
+
as="span"
|
|
73
|
+
size={size === "medium" ? "medium" : "small"}
|
|
74
|
+
className={cl(
|
|
75
|
+
"navds-tag",
|
|
76
|
+
className,
|
|
77
|
+
`navds-tag--${variant}`,
|
|
78
|
+
`navds-tag--${size}`,
|
|
79
|
+
`navds-tag--${filledVariant || moderateVariant || "outline"}`,
|
|
80
|
+
`navds-tag--${color}`,
|
|
81
|
+
)}
|
|
82
|
+
>
|
|
83
|
+
{icon && <span className="navds-tag__icon--left">{icon}</span>}
|
|
84
|
+
{children}
|
|
85
|
+
</BodyShort>
|
|
86
|
+
);
|
|
87
|
+
},
|
|
74
88
|
);
|
|
75
89
|
|
|
76
90
|
export default Tag;
|
package/src/timeline/Pin.tsx
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
} from "@floating-ui/react";
|
|
16
16
|
import { format } from "date-fns";
|
|
17
17
|
import React, { forwardRef, useRef, useState } from "react";
|
|
18
|
+
import { UNSAFE_useAkselTheme } from "../provider";
|
|
18
19
|
import { useMergeRefs } from "../util/hooks/useMergeRefs";
|
|
19
20
|
import { useI18n } from "../util/i18n/i18n.context";
|
|
20
21
|
import { useTimelineContext } from "./hooks/useTimelineContext";
|
|
@@ -47,6 +48,9 @@ export const Pin = forwardRef<HTMLButtonElement, TimelinePinProps>(
|
|
|
47
48
|
const arrowRef = useRef<HTMLDivElement | null>(null);
|
|
48
49
|
const translate = useI18n("Timeline");
|
|
49
50
|
|
|
51
|
+
const themeContext = UNSAFE_useAkselTheme(false);
|
|
52
|
+
const showArrow = !themeContext;
|
|
53
|
+
|
|
50
54
|
const {
|
|
51
55
|
context,
|
|
52
56
|
placement,
|
|
@@ -59,7 +63,7 @@ export const Pin = forwardRef<HTMLButtonElement, TimelinePinProps>(
|
|
|
59
63
|
onOpenChange: (_open) => setOpen(_open),
|
|
60
64
|
whileElementsMounted: autoUpdate,
|
|
61
65
|
middleware: [
|
|
62
|
-
offset(16),
|
|
66
|
+
offset(showArrow ? 16 : 8),
|
|
63
67
|
shift(),
|
|
64
68
|
flip({ padding: 5, fallbackPlacements: ["bottom", "top"] }),
|
|
65
69
|
flArrow({ element: arrowRef, padding: 5 }),
|
|
@@ -135,15 +139,17 @@ export const Pin = forwardRef<HTMLButtonElement, TimelinePinProps>(
|
|
|
135
139
|
style={floatingStyles}
|
|
136
140
|
>
|
|
137
141
|
{children}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
142
|
+
{showArrow && (
|
|
143
|
+
<div
|
|
144
|
+
ref={arrowRef}
|
|
145
|
+
style={{
|
|
146
|
+
...(arrowX != null ? { left: arrowX } : {}),
|
|
147
|
+
...(arrowY != null ? { top: arrowY } : {}),
|
|
148
|
+
...(staticSide ? { [staticSide]: "-0.5rem" } : {}),
|
|
149
|
+
}}
|
|
150
|
+
className="navds-timeline__popover-arrow"
|
|
151
|
+
/>
|
|
152
|
+
)}
|
|
147
153
|
</div>
|
|
148
154
|
</FloatingFocusManager>
|
|
149
155
|
)}
|
|
@@ -39,6 +39,7 @@ export interface TimelineProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
39
39
|
/**
|
|
40
40
|
* Templates for label texts. The templates are passed to the date-fns `format` function.
|
|
41
41
|
* Defaults to { day: "dd.MM", month: "MMM yy", year: "yyyy" }.
|
|
42
|
+
* @deprecated Use `<Provider />`-component
|
|
42
43
|
*/
|
|
43
44
|
axisLabelTemplates?: AxisLabelTemplates;
|
|
44
45
|
}
|
|
@@ -134,17 +134,33 @@ export const useTimelineRows = (
|
|
|
134
134
|
[rows, startDate, endDate, direction],
|
|
135
135
|
);
|
|
136
136
|
|
|
137
|
-
const
|
|
138
|
-
|
|
137
|
+
export const useEarliestDate = ({
|
|
138
|
+
startDate,
|
|
139
|
+
rows,
|
|
140
|
+
}: {
|
|
141
|
+
startDate?: Date;
|
|
142
|
+
rows: Pick<Period, "start">[][];
|
|
143
|
+
}) =>
|
|
144
|
+
useMemo(() => {
|
|
145
|
+
if (startDate) {
|
|
146
|
+
return startDate;
|
|
147
|
+
}
|
|
139
148
|
|
|
140
|
-
const
|
|
141
|
-
|
|
149
|
+
const startDates = rows
|
|
150
|
+
.flat()
|
|
151
|
+
.filter((period) => period.start)
|
|
152
|
+
.map((period) => period.start);
|
|
142
153
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
154
|
+
if (startDates.length === 0) {
|
|
155
|
+
return new Date();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const earliestDate = startDates.reduce((earliest, current) =>
|
|
159
|
+
current < earliest ? current : earliest,
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
return earliestDate;
|
|
163
|
+
}, [startDate, rows]);
|
|
148
164
|
|
|
149
165
|
const latestDate = (latest: Date, period: Period) =>
|
|
150
166
|
period.end > latest ? period.end : latest;
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
} from "@floating-ui/react";
|
|
16
16
|
import cl from "clsx";
|
|
17
17
|
import React, { useRef, useState } from "react";
|
|
18
|
+
import { UNSAFE_useAkselTheme } from "../../provider";
|
|
18
19
|
import { useMergeRefs } from "../../util/hooks/useMergeRefs";
|
|
19
20
|
import { useI18n } from "../../util/i18n/i18n.context";
|
|
20
21
|
import { usePeriodContext } from "../hooks/usePeriodContext";
|
|
@@ -55,6 +56,9 @@ const ClickablePeriod = React.memo(
|
|
|
55
56
|
const arrowRef = useRef<HTMLDivElement | null>(null);
|
|
56
57
|
const translate = useI18n("Timeline");
|
|
57
58
|
|
|
59
|
+
const themeContext = UNSAFE_useAkselTheme(false);
|
|
60
|
+
const showArrow = !themeContext;
|
|
61
|
+
|
|
58
62
|
const {
|
|
59
63
|
context,
|
|
60
64
|
placement,
|
|
@@ -67,7 +71,7 @@ const ClickablePeriod = React.memo(
|
|
|
67
71
|
onOpenChange: (_open) => setOpen(_open),
|
|
68
72
|
whileElementsMounted: autoUpdate,
|
|
69
73
|
middleware: [
|
|
70
|
-
offset(16),
|
|
74
|
+
offset(showArrow ? 16 : 8),
|
|
71
75
|
shift(),
|
|
72
76
|
flip({ padding: 5, fallbackPlacements: ["bottom", "top"] }),
|
|
73
77
|
flArrow({ element: arrowRef, padding: 5 }),
|
|
@@ -164,15 +168,17 @@ const ClickablePeriod = React.memo(
|
|
|
164
168
|
style={floatingStyles}
|
|
165
169
|
>
|
|
166
170
|
{children}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
171
|
+
{showArrow && (
|
|
172
|
+
<div
|
|
173
|
+
ref={arrowRef}
|
|
174
|
+
style={{
|
|
175
|
+
...(arrowX != null ? { left: arrowX } : {}),
|
|
176
|
+
...(arrowY != null ? { top: arrowY } : {}),
|
|
177
|
+
...(staticSide ? { [staticSide]: "-0.5rem" } : {}),
|
|
178
|
+
}}
|
|
179
|
+
className="navds-timeline__popover-arrow"
|
|
180
|
+
/>
|
|
181
|
+
)}
|
|
176
182
|
</div>
|
|
177
183
|
</FloatingFocusManager>
|
|
178
184
|
)}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { renderHook } from "@testing-library/react";
|
|
2
|
+
import { addDays, isSameDay } from "date-fns";
|
|
3
|
+
import { describe, expect, test } from "vitest";
|
|
4
|
+
import {
|
|
5
|
+
useEarliestDate,
|
|
6
|
+
useLatestDate,
|
|
7
|
+
useTimelineRows,
|
|
8
|
+
} from "../hooks/useTimelineRows";
|
|
9
|
+
|
|
10
|
+
describe("useEarliestDate", () => {
|
|
11
|
+
test("returns the provided startDate if it exists", () => {
|
|
12
|
+
const startDate = new Date(2023, 0, 1);
|
|
13
|
+
const { result } = renderHook(() =>
|
|
14
|
+
useEarliestDate({ startDate, rows: [] }),
|
|
15
|
+
);
|
|
16
|
+
expect(result.current).toEqual(startDate);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("returns the earliest date from the rows if startDate is not provided", () => {
|
|
20
|
+
const rows = [
|
|
21
|
+
[{ start: new Date(2023, 0, 1) }],
|
|
22
|
+
[{ start: new Date(2022, 0, 1) }],
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const { result } = renderHook(() => useEarliestDate({ rows }));
|
|
26
|
+
expect(result.current).toEqual(new Date(2022, 0, 1));
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("returns the earliest date from the rows if startDate is not provided and date is later than todays date", () => {
|
|
30
|
+
const earliestDate = addDays(new Date(), 400);
|
|
31
|
+
const rows = [
|
|
32
|
+
[{ start: earliestDate }],
|
|
33
|
+
[{ start: addDays(earliestDate, 40) }],
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
const { result } = renderHook(() => useEarliestDate({ rows }));
|
|
37
|
+
expect(result.current).toEqual(earliestDate);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("returns the current date if no startDate and rows are empty", () => {
|
|
41
|
+
const { result } = renderHook(() => useEarliestDate({ rows: [] }));
|
|
42
|
+
expect(isSameDay(result.current, new Date())).toBeTruthy();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe("useLatestDate", () => {
|
|
47
|
+
test("returns the provided endDate if it exists", () => {
|
|
48
|
+
const endDate = new Date(2023, 0, 1);
|
|
49
|
+
const { result } = renderHook(() => useLatestDate({ endDate, rows: [] }));
|
|
50
|
+
expect(result.current).toEqual(endDate);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("returns the latest date from the rows plus one day if endDate is not provided", () => {
|
|
54
|
+
const rows = [
|
|
55
|
+
[{ start: new Date(2023, 0, 1), end: new Date(2023, 0, 10) }],
|
|
56
|
+
[{ start: new Date(2022, 0, 1), end: new Date(2022, 0, 5) }],
|
|
57
|
+
];
|
|
58
|
+
const { result } = renderHook(() => useLatestDate({ rows }));
|
|
59
|
+
expect(result.current).toEqual(addDays(new Date(2023, 0, 10), 1));
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("returns the current date plus one day if no endDate and rows are empty", () => {
|
|
63
|
+
const { result } = renderHook(() => useLatestDate({ rows: [] }));
|
|
64
|
+
expect(result.current).toEqual(addDays(new Date(0), 1));
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("useTimelineRows", () => {
|
|
69
|
+
const rows = [
|
|
70
|
+
{
|
|
71
|
+
label: "Row 1",
|
|
72
|
+
periods: [
|
|
73
|
+
{
|
|
74
|
+
start: new Date(2023, 0, 1),
|
|
75
|
+
end: new Date(2023, 0, 10),
|
|
76
|
+
status: "active",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
start: new Date(2023, 0, 15),
|
|
80
|
+
end: new Date(2023, 0, 20),
|
|
81
|
+
status: "inactive",
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
label: "Row 2",
|
|
87
|
+
periods: [
|
|
88
|
+
{
|
|
89
|
+
start: new Date(2022, 0, 1),
|
|
90
|
+
end: new Date(2022, 0, 5),
|
|
91
|
+
status: "active",
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
test("returns the correct timeline rows", () => {
|
|
98
|
+
const startDate = new Date(2022, 0, 1);
|
|
99
|
+
const endDate = new Date(2023, 0, 31);
|
|
100
|
+
const direction = "left";
|
|
101
|
+
const { result } = renderHook(() =>
|
|
102
|
+
useTimelineRows(rows, startDate, endDate, direction),
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
expect(result.current).toHaveLength(2);
|
|
106
|
+
expect(result.current[0].periods).toHaveLength(2);
|
|
107
|
+
expect(result.current[1].periods).toHaveLength(1);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("handles empty rows", () => {
|
|
111
|
+
const startDate = new Date(2022, 0, 1);
|
|
112
|
+
const endDate = new Date(2023, 0, 31);
|
|
113
|
+
const direction = "left";
|
|
114
|
+
const { result } = renderHook(() =>
|
|
115
|
+
useTimelineRows([], startDate, endDate, direction),
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
expect(result.current).toHaveLength(0);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("handles different directions", () => {
|
|
122
|
+
const startDate = new Date(2022, 0, 1);
|
|
123
|
+
const endDate = new Date(2023, 0, 31);
|
|
124
|
+
const direction = "right";
|
|
125
|
+
const { result } = renderHook(() =>
|
|
126
|
+
useTimelineRows(rows, startDate, endDate, direction),
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
expect(result.current[0].periods[0].start).toEqual(new Date(2023, 0, 15));
|
|
130
|
+
});
|
|
131
|
+
});
|
package/src/tooltip/Tooltip.tsx
CHANGED
|
@@ -15,6 +15,7 @@ import cl from "clsx";
|
|
|
15
15
|
import React, { HTMLAttributes, forwardRef, useRef } from "react";
|
|
16
16
|
import { useModalContext } from "../modal/Modal.context";
|
|
17
17
|
import { Portal } from "../portal";
|
|
18
|
+
import { UNSAFE_useAkselTheme } from "../provider";
|
|
18
19
|
import { Slot } from "../slot/Slot";
|
|
19
20
|
import { Detail } from "../typography";
|
|
20
21
|
import { useId } from "../util/hooks";
|
|
@@ -123,6 +124,9 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
|
|
|
123
124
|
},
|
|
124
125
|
ref,
|
|
125
126
|
) => {
|
|
127
|
+
const themeContext = UNSAFE_useAkselTheme(false);
|
|
128
|
+
const showArrow = _arrow && !themeContext;
|
|
129
|
+
|
|
126
130
|
const [_open, _setOpen] = useControllableState({
|
|
127
131
|
defaultValue: defaultOpen,
|
|
128
132
|
value: open,
|
|
@@ -149,7 +153,7 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
|
|
|
149
153
|
open: _open,
|
|
150
154
|
onOpenChange: (newState) => _setOpen(newState),
|
|
151
155
|
middleware: [
|
|
152
|
-
offset(_offset ?
|
|
156
|
+
offset(_offset ?? (themeContext ? 8 : _arrow ? 16 : 4)),
|
|
153
157
|
shift(),
|
|
154
158
|
flip({ padding: 5, fallbackPlacements: ["bottom", "top"] }),
|
|
155
159
|
flArrow({ element: arrowRef, padding: 5 }),
|
|
@@ -228,6 +232,7 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
|
|
|
228
232
|
),
|
|
229
233
|
})}
|
|
230
234
|
data-side={placement}
|
|
235
|
+
data-state="open"
|
|
231
236
|
>
|
|
232
237
|
{content}
|
|
233
238
|
{keys && (
|
|
@@ -239,7 +244,7 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
|
|
|
239
244
|
))}
|
|
240
245
|
</span>
|
|
241
246
|
)}
|
|
242
|
-
{
|
|
247
|
+
{showArrow && (
|
|
243
248
|
<div
|
|
244
249
|
ref={(node) => {
|
|
245
250
|
arrowRef.current = node;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { renderHook } from "@testing-library/react";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { describe, expect, test } from "vitest";
|
|
4
|
-
import
|
|
4
|
+
import { Provider } from "../../provider";
|
|
5
5
|
import { useI18n } from "./i18n.context";
|
|
6
|
+
import en from "./locales/en";
|
|
7
|
+
import nb from "./locales/nb";
|
|
6
8
|
|
|
7
9
|
describe("useI18n", () => {
|
|
8
10
|
test("should throw error if key is not found", () => {
|
|
@@ -12,13 +14,32 @@ describe("useI18n", () => {
|
|
|
12
14
|
expect(() => translate("item.nonexistentKey")).toThrowError();
|
|
13
15
|
});
|
|
14
16
|
|
|
15
|
-
test("should return the
|
|
17
|
+
test("should return the default NB translation when Provider is not used", () => {
|
|
18
|
+
const { result } = renderHook(() => useI18n("FileUpload"));
|
|
19
|
+
const translate = result.current;
|
|
20
|
+
expect(translate("item.uploading")).toBe(nb.FileUpload.item.uploading);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("should return the default translation when key is not in context object", () => {
|
|
24
|
+
const i18n = { FileUpload: { item: { downloading: "Test translation" } } };
|
|
25
|
+
const { result } = renderHook(() => useI18n("FileUpload"), {
|
|
26
|
+
wrapper: ({ children }) => (
|
|
27
|
+
<Provider locale={en} translations={i18n}>
|
|
28
|
+
{children}
|
|
29
|
+
</Provider>
|
|
30
|
+
),
|
|
31
|
+
});
|
|
32
|
+
const translate = result.current;
|
|
33
|
+
expect(translate("item.uploading")).toBe(en.FileUpload.item.uploading);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("should return the translated text from the context object", () => {
|
|
16
37
|
const i18n = { FileUpload: { item: { uploading: "Test translation" } } };
|
|
17
38
|
const { result } = renderHook(() => useI18n("FileUpload"), {
|
|
18
39
|
wrapper: ({ children }) => (
|
|
19
|
-
<
|
|
40
|
+
<Provider locale={en} translations={i18n}>
|
|
20
41
|
{children}
|
|
21
|
-
</
|
|
42
|
+
</Provider>
|
|
22
43
|
),
|
|
23
44
|
});
|
|
24
45
|
const translate = result.current;
|
|
@@ -32,9 +53,9 @@ describe("useI18n", () => {
|
|
|
32
53
|
const i18n2 = { FileUpload: { item: { uploading: "Wrong translation" } } };
|
|
33
54
|
const { result } = renderHook(() => useI18n("FileUpload"), {
|
|
34
55
|
wrapper: ({ children }) => (
|
|
35
|
-
<
|
|
56
|
+
<Provider locale={en} translations={[i18n1, i18n2]}>
|
|
36
57
|
{children}
|
|
37
|
-
</
|
|
58
|
+
</Provider>
|
|
38
59
|
),
|
|
39
60
|
});
|
|
40
61
|
const translate = result.current;
|
|
@@ -48,9 +69,9 @@ describe("useI18n", () => {
|
|
|
48
69
|
};
|
|
49
70
|
const { result } = renderHook(() => useI18n("FileUpload"), {
|
|
50
71
|
wrapper: ({ children }) => (
|
|
51
|
-
<
|
|
72
|
+
<Provider locale={en} translations={[i18n1, i18n2]}>
|
|
52
73
|
{children}
|
|
53
|
-
</
|
|
74
|
+
</Provider>
|
|
54
75
|
),
|
|
55
76
|
});
|
|
56
77
|
const translate = result.current;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Locale } from "date-fns";
|
|
2
|
-
import {
|
|
3
|
-
import { LanguageProviderContext } from "../../provider/i18n/LanguageProvider";
|
|
2
|
+
import { useProvider } from "../../provider/Provider";
|
|
4
3
|
import { get } from "./get";
|
|
5
4
|
import {
|
|
6
5
|
Component,
|
|
@@ -28,15 +27,16 @@ export type TFunction<T extends Component> = (
|
|
|
28
27
|
|
|
29
28
|
export function useI18n<T extends Component>(
|
|
30
29
|
componentName: T,
|
|
31
|
-
...
|
|
30
|
+
...localTranslations: (ComponentTranslation<T> | undefined)[]
|
|
32
31
|
) {
|
|
33
|
-
const
|
|
34
|
-
const
|
|
32
|
+
const context = useProvider();
|
|
33
|
+
const contextTranslations = context.translations || [];
|
|
35
34
|
const i18nObjects: (PartialTranslations | undefined)[] = [
|
|
36
|
-
...
|
|
37
|
-
...(Array.isArray(
|
|
38
|
-
?
|
|
39
|
-
: [
|
|
35
|
+
...localTranslations,
|
|
36
|
+
...(Array.isArray(contextTranslations)
|
|
37
|
+
? contextTranslations.map((t) => t[componentName])
|
|
38
|
+
: [contextTranslations[componentName]]),
|
|
39
|
+
context.locale[componentName],
|
|
40
40
|
];
|
|
41
41
|
|
|
42
42
|
/**
|
|
@@ -67,11 +67,12 @@ export function useI18n<T extends Component>(
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
export function useDateLocale() {
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
const i18nObjects = Array.isArray(
|
|
73
|
-
?
|
|
74
|
-
: [
|
|
70
|
+
const context = useProvider();
|
|
71
|
+
const contextTranslations = context.translations || [];
|
|
72
|
+
const i18nObjects = Array.isArray(contextTranslations)
|
|
73
|
+
? contextTranslations.map((t) => t.global)
|
|
74
|
+
: [contextTranslations.global];
|
|
75
|
+
i18nObjects.push(context.locale.global);
|
|
75
76
|
|
|
76
77
|
for (const obj of i18nObjects) {
|
|
77
78
|
if (obj?.dateLocale) {
|