@navikt/ds-react 4.6.1 → 4.7.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 +1711 -169
- package/cjs/chips/Chips.js +1 -2
- package/cjs/form/combobox/ClearButton.js +27 -0
- package/cjs/form/combobox/Combobox.js +78 -0
- package/cjs/form/combobox/ComboboxProvider.js +99 -0
- package/cjs/form/combobox/ComboboxWrapper.js +51 -0
- package/cjs/form/combobox/FilteredOptions/CheckIcon.js +11 -0
- package/cjs/form/combobox/FilteredOptions/FilteredOptions.js +46 -0
- package/cjs/form/combobox/FilteredOptions/filteredOptionsContext.js +208 -0
- package/cjs/form/combobox/Input/Input.js +143 -0
- package/cjs/form/combobox/Input/inputContext.js +86 -0
- package/cjs/form/combobox/SelectedOptions/SelectedOptions.js +27 -0
- package/cjs/form/combobox/SelectedOptions/selectedOptionsContext.js +107 -0
- package/cjs/form/combobox/ToggleListButton.js +36 -0
- package/cjs/form/combobox/customOptionsContext.js +56 -0
- package/cjs/form/combobox/index.js +8 -0
- package/cjs/form/combobox/package.json +6 -0
- package/cjs/form/combobox/types.js +2 -0
- package/cjs/form/index.js +3 -1
- package/cjs/timeline/AxisLabels.js +12 -12
- package/cjs/timeline/Timeline.js +2 -2
- package/cjs/util/usePrevious.js +18 -0
- package/esm/chips/Chips.js +1 -2
- package/esm/chips/Chips.js.map +1 -1
- package/esm/date/datepicker/TableHead.d.ts +1 -0
- package/esm/form/Fieldset/useFieldset.d.ts +1 -1
- package/esm/form/checkbox/useCheckbox.d.ts +4 -4
- package/esm/form/combobox/ClearButton.d.ts +7 -0
- package/esm/form/combobox/ClearButton.js +21 -0
- package/esm/form/combobox/ClearButton.js.map +1 -0
- package/esm/form/combobox/Combobox.d.ts +4 -0
- package/esm/form/combobox/Combobox.js +50 -0
- package/esm/form/combobox/Combobox.js.map +1 -0
- package/esm/form/combobox/ComboboxProvider.d.ts +26 -0
- package/esm/form/combobox/ComboboxProvider.js +72 -0
- package/esm/form/combobox/ComboboxProvider.js.map +1 -0
- package/esm/form/combobox/ComboboxWrapper.d.ts +14 -0
- package/esm/form/combobox/ComboboxWrapper.js +24 -0
- package/esm/form/combobox/ComboboxWrapper.js.map +1 -0
- package/esm/form/combobox/FilteredOptions/CheckIcon.d.ts +3 -0
- package/esm/form/combobox/FilteredOptions/CheckIcon.js +7 -0
- package/esm/form/combobox/FilteredOptions/CheckIcon.js.map +1 -0
- package/esm/form/combobox/FilteredOptions/FilteredOptions.d.ts +3 -0
- package/esm/form/combobox/FilteredOptions/FilteredOptions.js +42 -0
- package/esm/form/combobox/FilteredOptions/FilteredOptions.js.map +1 -0
- package/esm/form/combobox/FilteredOptions/filteredOptionsContext.d.ts +27 -0
- package/esm/form/combobox/FilteredOptions/filteredOptionsContext.js +178 -0
- package/esm/form/combobox/FilteredOptions/filteredOptionsContext.js.map +1 -0
- package/esm/form/combobox/Input/Input.d.ts +10 -0
- package/esm/form/combobox/Input/Input.js +116 -0
- package/esm/form/combobox/Input/Input.js.map +1 -0
- package/esm/form/combobox/Input/inputContext.d.ts +19 -0
- package/esm/form/combobox/Input/inputContext.js +59 -0
- package/esm/form/combobox/Input/inputContext.js.map +1 -0
- package/esm/form/combobox/SelectedOptions/SelectedOptions.d.ts +8 -0
- package/esm/form/combobox/SelectedOptions/SelectedOptions.js +23 -0
- package/esm/form/combobox/SelectedOptions/SelectedOptions.js.map +1 -0
- package/esm/form/combobox/SelectedOptions/selectedOptionsContext.d.ts +17 -0
- package/esm/form/combobox/SelectedOptions/selectedOptionsContext.js +77 -0
- package/esm/form/combobox/SelectedOptions/selectedOptionsContext.js.map +1 -0
- package/esm/form/combobox/ToggleListButton.d.ts +6 -0
- package/esm/form/combobox/ToggleListButton.js +11 -0
- package/esm/form/combobox/ToggleListButton.js.map +1 -0
- package/esm/form/combobox/customOptionsContext.d.ts +11 -0
- package/esm/form/combobox/customOptionsContext.js +29 -0
- package/esm/form/combobox/customOptionsContext.js.map +1 -0
- package/esm/form/combobox/index.d.ts +2 -0
- package/esm/form/combobox/index.js +2 -0
- package/esm/form/combobox/index.js.map +1 -0
- package/esm/form/combobox/types.d.ts +119 -0
- package/esm/form/combobox/types.js +2 -0
- package/esm/form/combobox/types.js.map +1 -0
- package/esm/form/index.d.ts +1 -0
- package/esm/form/index.js +1 -0
- package/esm/form/index.js.map +1 -1
- package/esm/form/radio/useRadio.d.ts +4 -4
- package/esm/form/useFormField.d.ts +11 -10
- package/esm/form/useFormField.js.map +1 -1
- package/esm/timeline/AxisLabels.d.ts +7 -5
- package/esm/timeline/AxisLabels.js +12 -12
- package/esm/timeline/AxisLabels.js.map +1 -1
- package/esm/timeline/Timeline.d.ts +6 -0
- package/esm/timeline/Timeline.js +2 -2
- package/esm/timeline/Timeline.js.map +1 -1
- package/esm/timeline/utils/types.external.d.ts +5 -0
- package/esm/util/usePrevious.d.ts +2 -0
- package/esm/util/usePrevious.js +17 -0
- package/esm/util/usePrevious.js.map +1 -0
- package/package.json +2 -2
- package/src/chips/Chips.tsx +1 -1
- package/src/form/combobox/ClearButton.tsx +29 -0
- package/src/form/combobox/Combobox.tsx +136 -0
- package/src/form/combobox/ComboboxProvider.tsx +99 -0
- package/src/form/combobox/ComboboxWrapper.tsx +63 -0
- package/src/form/combobox/FilteredOptions/CheckIcon.tsx +23 -0
- package/src/form/combobox/FilteredOptions/FilteredOptions.tsx +106 -0
- package/src/form/combobox/FilteredOptions/filteredOptionsContext.tsx +266 -0
- package/src/form/combobox/Input/Input.tsx +170 -0
- package/src/form/combobox/Input/inputContext.tsx +127 -0
- package/src/form/combobox/SelectedOptions/SelectedOptions.tsx +45 -0
- package/src/form/combobox/SelectedOptions/selectedOptionsContext.tsx +147 -0
- package/src/form/combobox/ToggleListButton.tsx +37 -0
- package/src/form/combobox/combobox.stories.tsx +413 -0
- package/src/form/combobox/combobox.test.tsx +123 -0
- package/src/form/combobox/customOptionsContext.tsx +57 -0
- package/src/form/combobox/index.ts +2 -0
- package/src/form/combobox/types.ts +122 -0
- package/src/form/index.ts +1 -0
- package/src/form/useFormField.ts +19 -1
- package/src/timeline/AxisLabels.tsx +23 -13
- package/src/timeline/Timeline.tsx +18 -2
- package/src/timeline/utils/types.external.ts +6 -0
- package/src/util/usePrevious.ts +19 -0
|
@@ -30,20 +30,21 @@ export interface FormFieldProps {
|
|
|
30
30
|
*/
|
|
31
31
|
readOnly?: boolean;
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
* Handles props and their state for various form-fields in context with Fieldset
|
|
35
|
-
*/
|
|
36
|
-
export declare const useFormField: (props: FormFieldProps, prefix: string) => {
|
|
33
|
+
export interface FormFieldType {
|
|
37
34
|
showErrorMsg: boolean;
|
|
38
35
|
hasError: boolean;
|
|
39
36
|
errorId: string;
|
|
40
37
|
inputDescriptionId: string;
|
|
41
|
-
size: "
|
|
42
|
-
readOnly: true | undefined;
|
|
38
|
+
size: "small" | "medium";
|
|
43
39
|
inputProps: {
|
|
44
|
-
"aria-describedby": string | undefined;
|
|
45
|
-
disabled: boolean | undefined;
|
|
46
|
-
"aria-invalid"?: boolean | undefined;
|
|
47
40
|
id: string;
|
|
41
|
+
"aria-invalid"?: boolean;
|
|
42
|
+
"aria-describedby"?: string;
|
|
43
|
+
disabled?: boolean;
|
|
48
44
|
};
|
|
49
|
-
|
|
45
|
+
readOnly?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Handles props and their state for various form-fields in context with Fieldset
|
|
49
|
+
*/
|
|
50
|
+
export declare const useFormField: (props: FormFieldProps, prefix: string) => FormFieldType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormField.js","sourceRoot":"","sources":["../../src/form/useFormField.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE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ACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { AxisLabel } from "./utils/types.external";
|
|
3
|
-
export declare const dayLabels: (start: Date, end: Date, totalDays: number, direction: "left" | "right") => AxisLabel[];
|
|
4
|
-
export declare const monthLabels: (start: Date, end: Date, direction: "left" | "right") => AxisLabel[];
|
|
5
|
-
export declare const yearLabels: (start: Date, end: Date, direction: "left" | "right") => AxisLabel[];
|
|
6
|
-
export declare const AxisLabels: (
|
|
2
|
+
import { AxisLabel, AxisLabelTemplates } from "./utils/types.external";
|
|
3
|
+
export declare const dayLabels: (start: Date, end: Date, totalDays: number, direction: "left" | "right", template?: string) => AxisLabel[];
|
|
4
|
+
export declare const monthLabels: (start: Date, end: Date, direction: "left" | "right", template?: string) => AxisLabel[];
|
|
5
|
+
export declare const yearLabels: (start: Date, end: Date, direction: "left" | "right", template?: string) => AxisLabel[];
|
|
6
|
+
export declare const AxisLabels: ({ templates, }: {
|
|
7
|
+
templates?: AxisLabelTemplates | undefined;
|
|
8
|
+
}) => React.JSX.Element;
|
|
@@ -5,7 +5,7 @@ import React from "react";
|
|
|
5
5
|
import { useTimelineContext } from "./hooks/useTimelineContext";
|
|
6
6
|
import { isVisible } from "./utils";
|
|
7
7
|
import { horizontalPositionAndWidth } from "./utils/calc";
|
|
8
|
-
export const dayLabels = (start, end, totalDays, direction) => {
|
|
8
|
+
export const dayLabels = (start, end, totalDays, direction, template = "dd.MM") => {
|
|
9
9
|
const increment = Math.ceil(totalDays / 10);
|
|
10
10
|
const lastDay = startOfDay(end);
|
|
11
11
|
return new Array(totalDays)
|
|
@@ -18,14 +18,14 @@ export const dayLabels = (start, end, totalDays, direction) => {
|
|
|
18
18
|
return {
|
|
19
19
|
direction: direction,
|
|
20
20
|
horizontalPosition: horizontalPosition,
|
|
21
|
-
label: format(day,
|
|
21
|
+
label: format(day, template, { locale: nbLocale }),
|
|
22
22
|
date: day,
|
|
23
23
|
width: width,
|
|
24
24
|
};
|
|
25
25
|
})
|
|
26
26
|
.filter((label) => label !== null);
|
|
27
27
|
};
|
|
28
|
-
export const monthLabels = (start, end, direction) => {
|
|
28
|
+
export const monthLabels = (start, end, direction, template = "MMM yy") => {
|
|
29
29
|
const startMonth = startOfMonth(start);
|
|
30
30
|
const endMonth = endOfMonth(end);
|
|
31
31
|
const numberOfMonths = differenceInMonths(endMonth, startMonth) + 1;
|
|
@@ -35,13 +35,13 @@ export const monthLabels = (start, end, direction) => {
|
|
|
35
35
|
return {
|
|
36
36
|
direction: direction,
|
|
37
37
|
horizontalPosition: horizontalPosition,
|
|
38
|
-
label: format(month,
|
|
38
|
+
label: format(month, template, { locale: nbLocale }),
|
|
39
39
|
date: month,
|
|
40
40
|
width: width,
|
|
41
41
|
};
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
|
-
export const yearLabels = (start, end, direction) => {
|
|
44
|
+
export const yearLabels = (start, end, direction, template = "yyyy") => {
|
|
45
45
|
const firstYear = startOfYear(start);
|
|
46
46
|
const lastYear = endOfYear(end);
|
|
47
47
|
const yearCount = differenceInYears(lastYear, start) + 1;
|
|
@@ -51,27 +51,27 @@ export const yearLabels = (start, end, direction) => {
|
|
|
51
51
|
return {
|
|
52
52
|
direction: direction,
|
|
53
53
|
horizontalPosition: horizontalPosition,
|
|
54
|
-
label: year
|
|
54
|
+
label: format(year, template, { locale: nbLocale }),
|
|
55
55
|
date: year,
|
|
56
56
|
width: width,
|
|
57
57
|
};
|
|
58
58
|
});
|
|
59
59
|
};
|
|
60
|
-
const axisLabels = (start, end, direction) => {
|
|
60
|
+
const axisLabels = (start, end, direction, templates) => {
|
|
61
61
|
const totalDays = differenceInDays(end, start);
|
|
62
62
|
if (totalDays < 40) {
|
|
63
|
-
return dayLabels(start, end, totalDays, direction);
|
|
63
|
+
return dayLabels(start, end, totalDays, direction, templates === null || templates === void 0 ? void 0 : templates.day);
|
|
64
64
|
}
|
|
65
65
|
else if (totalDays < 370) {
|
|
66
|
-
return monthLabels(start, end, direction);
|
|
66
|
+
return monthLabels(start, end, direction, templates === null || templates === void 0 ? void 0 : templates.month);
|
|
67
67
|
}
|
|
68
68
|
else {
|
|
69
|
-
return yearLabels(start, end, direction);
|
|
69
|
+
return yearLabels(start, end, direction, templates === null || templates === void 0 ? void 0 : templates.year);
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
|
-
export const AxisLabels = () => {
|
|
72
|
+
export const AxisLabels = ({ templates, }) => {
|
|
73
73
|
const { endDate, startDate, direction } = useTimelineContext();
|
|
74
|
-
const labels = axisLabels(startDate, endDate, direction).filter(isVisible);
|
|
74
|
+
const labels = axisLabels(startDate, endDate, direction, templates).filter(isVisible);
|
|
75
75
|
return (React.createElement("div", { className: "navds-timeline__axislabels", "aria-hidden": "true" }, labels.map((etikett) => (React.createElement(Detail, { className: "navds-timeline__axislabels-label", as: "div", key: etikett.label, style: {
|
|
76
76
|
justifyContent: direction === "left" ? "flex-start" : "flex-end",
|
|
77
77
|
[direction]: `${etikett.horizontalPosition}%`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AxisLabels.js","sourceRoot":"","sources":["../../src/timeline/AxisLabels.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EACL,OAAO,EACP,SAAS,EACT,QAAQ,EACR,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,EACV,SAAS,EACT,MAAM,EACN,UAAU,EACV,YAAY,EACZ,WAAW,EACX,OAAO,GACR,MAAM,UAAU,CAAC;AAClB,OAAO,QAAQ,MAAM,oBAAoB,CAAC;AAC1C,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,C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Type } from "./TimelineRow";
|
|
5
5
|
import { ZoomType } from "./zoom";
|
|
6
|
+
import { AxisLabelTemplates } from "./utils/types.external";
|
|
6
7
|
export interface TimelineProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
7
8
|
children: React.ReactNode;
|
|
8
9
|
/**
|
|
@@ -22,6 +23,11 @@ export interface TimelineProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
22
23
|
* @default "left"
|
|
23
24
|
*/
|
|
24
25
|
direction?: "left" | "right";
|
|
26
|
+
/**
|
|
27
|
+
* Templates for label texts. The templates are passed to the date-fns `format` function.
|
|
28
|
+
* Defaults to { day: "dd.MM", month: "MMM yy", year: "yyyy" }.
|
|
29
|
+
*/
|
|
30
|
+
axisLabelTemplates?: AxisLabelTemplates;
|
|
25
31
|
}
|
|
26
32
|
interface TimelineComponent extends React.ForwardRefExoticComponent<TimelineProps> {
|
|
27
33
|
/**
|
package/esm/timeline/Timeline.js
CHANGED
|
@@ -39,7 +39,7 @@ import Zoom from "./zoom";
|
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
41
|
export const Timeline = forwardRef((_a, ref) => {
|
|
42
|
-
var { children, startDate, endDate, direction = "left" } = _a, rest = __rest(_a, ["children", "startDate", "endDate", "direction"]);
|
|
42
|
+
var { children, startDate, endDate, direction = "left", axisLabelTemplates } = _a, rest = __rest(_a, ["children", "startDate", "endDate", "direction", "axisLabelTemplates"]);
|
|
43
43
|
const isMultipleRows = Array.isArray(children);
|
|
44
44
|
const firstFocusabled = useRef([]);
|
|
45
45
|
if (!isMultipleRows) {
|
|
@@ -129,7 +129,7 @@ export const Timeline = forwardRef((_a, ref) => {
|
|
|
129
129
|
} },
|
|
130
130
|
React.createElement("div", Object.assign({}, rest, { ref: ref }),
|
|
131
131
|
React.createElement("div", { className: "navds-timeline" },
|
|
132
|
-
React.createElement(AxisLabels,
|
|
132
|
+
React.createElement(AxisLabels, { templates: axisLabelTemplates }),
|
|
133
133
|
pins.map((pin) => {
|
|
134
134
|
return pin;
|
|
135
135
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Timeline.js","sourceRoot":"","sources":["../../src/timeline/Timeline.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EACL,eAAe,EACf,aAAa,EACb,eAAe,GAChB,MAAM,yBAAyB,CAAC;AACjC,OAAO,MAAsB,MAAM,UAAU,CAAC;AAC9C,OAAO,GAAgB,MAAM,OAAO,CAAC;AACrC,OAAO,WAAgC,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,IAAkB,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"Timeline.js","sourceRoot":"","sources":["../../src/timeline/Timeline.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EACL,eAAe,EACf,aAAa,EACb,eAAe,GAChB,MAAM,yBAAyB,C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ACzB,QAAQ,CAAC,GAAG,GAAG,GAAG,CAAC;AACnB,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC;AAErB,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
/*
|
|
3
|
+
* usePrevious hook
|
|
4
|
+
* The ref object's "current" property is mutable and when changed wont re-render the component
|
|
5
|
+
* meaning it can be used to stay "one render behind" the current state
|
|
6
|
+
* https://usehooks.com/usePrevious/
|
|
7
|
+
* https://blog.logrocket.com/accessing-previous-props-state-react-hooks/
|
|
8
|
+
*/
|
|
9
|
+
const usePrevious = (value) => {
|
|
10
|
+
const ref = useRef(value);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
ref.current = value;
|
|
13
|
+
}, [value]);
|
|
14
|
+
return ref.current;
|
|
15
|
+
};
|
|
16
|
+
export default usePrevious;
|
|
17
|
+
//# sourceMappingURL=usePrevious.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePrevious.js","sourceRoot":"","sources":["../../src/util/usePrevious.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE1C;;;;;;GAMG;AAEH,MAAM,WAAW,GAAG,CAAI,KAAQ,EAAiB,EAAE;IACjD,MAAM,GAAG,GAAG,MAAM,CAAI,KAAK,CAAC,CAAC;IAC7B,SAAS,CAAC,GAAG,EAAE;QACb,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;IACtB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IACZ,OAAO,GAAG,CAAC,OAAO,CAAC;AACrB,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navikt/ds-react",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.0",
|
|
4
4
|
"description": "Aksel react-components for NAV designsystem",
|
|
5
5
|
"author": "Aksel | NAV designsystem team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@floating-ui/react": "0.24.1",
|
|
41
|
-
"@navikt/aksel-icons": "^4.
|
|
41
|
+
"@navikt/aksel-icons": "^4.7.0",
|
|
42
42
|
"@radix-ui/react-tabs": "1.0.0",
|
|
43
43
|
"@radix-ui/react-toggle-group": "1.0.0",
|
|
44
44
|
"clsx": "^1.2.1",
|
package/src/chips/Chips.tsx
CHANGED
|
@@ -70,7 +70,7 @@ export const Chips: ChipsComponent = forwardRef<HTMLUListElement, ChipsProps>(
|
|
|
70
70
|
})}
|
|
71
71
|
>
|
|
72
72
|
{React.Children.map(children, (chip, index) => {
|
|
73
|
-
return <li key={
|
|
73
|
+
return <li key={chip?.toString() || index}>{chip}</li>;
|
|
74
74
|
})}
|
|
75
75
|
</ul>
|
|
76
76
|
);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { XMarkIcon } from "@navikt/aksel-icons";
|
|
3
|
+
|
|
4
|
+
interface ClearButtonProps extends React.HTMLAttributes<HTMLButtonElement> {
|
|
5
|
+
handleClear: (event: any) => void;
|
|
6
|
+
clearButtonLabel?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const ClearButton: React.FC<ClearButtonProps> = ({
|
|
10
|
+
handleClear,
|
|
11
|
+
clearButtonLabel,
|
|
12
|
+
...rest
|
|
13
|
+
}) => {
|
|
14
|
+
return (
|
|
15
|
+
<button
|
|
16
|
+
type="button"
|
|
17
|
+
onClick={handleClear}
|
|
18
|
+
className="navds-combobox__button-clear"
|
|
19
|
+
{...rest}
|
|
20
|
+
>
|
|
21
|
+
<span className="navds-sr-only">
|
|
22
|
+
{clearButtonLabel ? clearButtonLabel : "Tøm"}
|
|
23
|
+
</span>
|
|
24
|
+
<XMarkIcon aria-hidden />
|
|
25
|
+
</button>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default ClearButton;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import cl from "clsx";
|
|
2
|
+
import React, { forwardRef, useMemo, useRef } from "react";
|
|
3
|
+
import { BodyShort, Label, mergeRefs } from "../..";
|
|
4
|
+
import ClearButton from "./ClearButton";
|
|
5
|
+
import FilteredOptions from "./FilteredOptions/FilteredOptions";
|
|
6
|
+
import { useFilteredOptionsContext } from "./FilteredOptions/filteredOptionsContext";
|
|
7
|
+
import SelectedOptions from "./SelectedOptions/SelectedOptions";
|
|
8
|
+
import ToggleListButton from "./ToggleListButton";
|
|
9
|
+
import { ComboboxProps } from "./types";
|
|
10
|
+
import { useSelectedOptionsContext } from "./SelectedOptions/selectedOptionsContext";
|
|
11
|
+
import ComboboxWrapper from "./ComboboxWrapper";
|
|
12
|
+
import { useInputContext } from "./Input/inputContext";
|
|
13
|
+
import Input from "./Input/Input";
|
|
14
|
+
|
|
15
|
+
export const Combobox = forwardRef<
|
|
16
|
+
HTMLInputElement,
|
|
17
|
+
Omit<ComboboxProps, "onChange" | "options" | "size">
|
|
18
|
+
>((props, ref) => {
|
|
19
|
+
const {
|
|
20
|
+
value: externalValue,
|
|
21
|
+
onClear,
|
|
22
|
+
className,
|
|
23
|
+
hideLabel = false,
|
|
24
|
+
description,
|
|
25
|
+
label,
|
|
26
|
+
clearButton = true,
|
|
27
|
+
clearButtonLabel,
|
|
28
|
+
toggleListButton = true,
|
|
29
|
+
toggleListButtonLabel,
|
|
30
|
+
inputClassName,
|
|
31
|
+
shouldShowSelectedOptions = true,
|
|
32
|
+
...rest
|
|
33
|
+
} = props;
|
|
34
|
+
|
|
35
|
+
const toggleListButtonRef = useRef<HTMLButtonElement>(null);
|
|
36
|
+
|
|
37
|
+
const { currentOption, toggleIsListOpen } = useFilteredOptionsContext();
|
|
38
|
+
const { selectedOptions } = useSelectedOptionsContext();
|
|
39
|
+
|
|
40
|
+
const {
|
|
41
|
+
clearInput,
|
|
42
|
+
focusInput,
|
|
43
|
+
hasError,
|
|
44
|
+
inputDescriptionId,
|
|
45
|
+
inputProps,
|
|
46
|
+
inputRef,
|
|
47
|
+
value,
|
|
48
|
+
size = "medium",
|
|
49
|
+
} = useInputContext();
|
|
50
|
+
|
|
51
|
+
const mergedInputRef = useMemo(
|
|
52
|
+
() => mergeRefs([inputRef, ref]),
|
|
53
|
+
[inputRef, ref]
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<ComboboxWrapper
|
|
58
|
+
className={className}
|
|
59
|
+
hasError={hasError}
|
|
60
|
+
inputProps={inputProps}
|
|
61
|
+
inputSize={size}
|
|
62
|
+
toggleIsListOpen={toggleIsListOpen}
|
|
63
|
+
toggleListButtonRef={toggleListButtonRef}
|
|
64
|
+
>
|
|
65
|
+
<Label
|
|
66
|
+
htmlFor={inputProps.id}
|
|
67
|
+
size={size}
|
|
68
|
+
className={cl("navds-form-field__label", {
|
|
69
|
+
"navds-sr-only": hideLabel,
|
|
70
|
+
})}
|
|
71
|
+
>
|
|
72
|
+
{label}
|
|
73
|
+
</Label>
|
|
74
|
+
{!!description && (
|
|
75
|
+
<BodyShort
|
|
76
|
+
as="div"
|
|
77
|
+
className={cl("navds-form-field__description", {
|
|
78
|
+
"navds-sr-only": hideLabel,
|
|
79
|
+
})}
|
|
80
|
+
id={inputDescriptionId}
|
|
81
|
+
size={size}
|
|
82
|
+
>
|
|
83
|
+
{description}
|
|
84
|
+
</BodyShort>
|
|
85
|
+
)}
|
|
86
|
+
<div className="navds-combobox__wrapper">
|
|
87
|
+
<div
|
|
88
|
+
className={cl(
|
|
89
|
+
"navds-combobox__wrapper-inner navds-text-field__input",
|
|
90
|
+
{
|
|
91
|
+
"navds-combobox__wrapper-inner--virtually-unfocused":
|
|
92
|
+
currentOption !== null,
|
|
93
|
+
}
|
|
94
|
+
)}
|
|
95
|
+
onClick={focusInput}
|
|
96
|
+
>
|
|
97
|
+
{!shouldShowSelectedOptions ? (
|
|
98
|
+
<Input
|
|
99
|
+
id={inputProps.id}
|
|
100
|
+
ref={mergedInputRef}
|
|
101
|
+
inputClassName={inputClassName}
|
|
102
|
+
{...rest}
|
|
103
|
+
/>
|
|
104
|
+
) : (
|
|
105
|
+
<SelectedOptions selectedOptions={selectedOptions} size={size}>
|
|
106
|
+
<Input
|
|
107
|
+
id={inputProps.id}
|
|
108
|
+
ref={mergedInputRef}
|
|
109
|
+
inputClassName={inputClassName}
|
|
110
|
+
{...rest}
|
|
111
|
+
/>
|
|
112
|
+
</SelectedOptions>
|
|
113
|
+
)}
|
|
114
|
+
<div>
|
|
115
|
+
{value && clearButton && (
|
|
116
|
+
<ClearButton
|
|
117
|
+
handleClear={clearInput}
|
|
118
|
+
clearButtonLabel={clearButtonLabel}
|
|
119
|
+
tabIndex={-1}
|
|
120
|
+
/>
|
|
121
|
+
)}
|
|
122
|
+
{toggleListButton && (
|
|
123
|
+
<ToggleListButton
|
|
124
|
+
toggleListButtonLabel={toggleListButtonLabel}
|
|
125
|
+
ref={toggleListButtonRef}
|
|
126
|
+
/>
|
|
127
|
+
)}
|
|
128
|
+
</div>
|
|
129
|
+
</div>
|
|
130
|
+
<FilteredOptions />
|
|
131
|
+
</div>
|
|
132
|
+
</ComboboxWrapper>
|
|
133
|
+
);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
export default Combobox;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import React, { forwardRef } from "react";
|
|
2
|
+
import Combobox from "./Combobox";
|
|
3
|
+
import { FilteredOptionsProvider } from "./FilteredOptions/filteredOptionsContext";
|
|
4
|
+
import { CustomOptionsProvider } from "./customOptionsContext";
|
|
5
|
+
import { SelectedOptionsProvider } from "./SelectedOptions/selectedOptionsContext";
|
|
6
|
+
import { InputContextProvider } from "./Input/inputContext";
|
|
7
|
+
import { ComboboxProps } from "./types";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A component that allows the user to search in a list of options
|
|
11
|
+
*
|
|
12
|
+
* Has options for allowing only one or multiple options to be selected,
|
|
13
|
+
* or adding new, user-submitted values.
|
|
14
|
+
*
|
|
15
|
+
* @see [📝 Documentation](https://aksel.nav.no/komponenter/core/combobox)
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```jsx
|
|
19
|
+
* const options = ["apple", "banana", "orange"];
|
|
20
|
+
*
|
|
21
|
+
* return (
|
|
22
|
+
* <Combobox
|
|
23
|
+
* label="Velg en verdi"
|
|
24
|
+
* options={options}
|
|
25
|
+
* id="my-combobox"
|
|
26
|
+
* shouldAutoComplete
|
|
27
|
+
* />
|
|
28
|
+
* )
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
const ComboboxProvider = forwardRef<HTMLInputElement, ComboboxProps>(
|
|
32
|
+
(props, ref) => {
|
|
33
|
+
const {
|
|
34
|
+
allowNewValues = false,
|
|
35
|
+
children,
|
|
36
|
+
defaultValue,
|
|
37
|
+
error,
|
|
38
|
+
errorId,
|
|
39
|
+
filteredOptions,
|
|
40
|
+
id,
|
|
41
|
+
isListOpen,
|
|
42
|
+
isLoading = false,
|
|
43
|
+
isMultiSelect,
|
|
44
|
+
onToggleSelected,
|
|
45
|
+
selectedOptions,
|
|
46
|
+
options,
|
|
47
|
+
value,
|
|
48
|
+
onChange,
|
|
49
|
+
onClear,
|
|
50
|
+
shouldAutocomplete,
|
|
51
|
+
size,
|
|
52
|
+
...rest
|
|
53
|
+
} = props;
|
|
54
|
+
return (
|
|
55
|
+
<InputContextProvider
|
|
56
|
+
value={{
|
|
57
|
+
defaultValue,
|
|
58
|
+
error,
|
|
59
|
+
errorId,
|
|
60
|
+
id,
|
|
61
|
+
value,
|
|
62
|
+
onChange,
|
|
63
|
+
onClear,
|
|
64
|
+
shouldAutocomplete,
|
|
65
|
+
size,
|
|
66
|
+
}}
|
|
67
|
+
>
|
|
68
|
+
<CustomOptionsProvider>
|
|
69
|
+
<SelectedOptionsProvider
|
|
70
|
+
value={{
|
|
71
|
+
allowNewValues,
|
|
72
|
+
isMultiSelect,
|
|
73
|
+
selectedOptions,
|
|
74
|
+
onToggleSelected,
|
|
75
|
+
options,
|
|
76
|
+
}}
|
|
77
|
+
>
|
|
78
|
+
<FilteredOptionsProvider
|
|
79
|
+
value={{
|
|
80
|
+
allowNewValues,
|
|
81
|
+
filteredOptions,
|
|
82
|
+
isListOpen,
|
|
83
|
+
isLoading,
|
|
84
|
+
isMultiSelect,
|
|
85
|
+
options,
|
|
86
|
+
}}
|
|
87
|
+
>
|
|
88
|
+
<Combobox ref={ref} {...rest}>
|
|
89
|
+
{children}
|
|
90
|
+
</Combobox>
|
|
91
|
+
</FilteredOptionsProvider>
|
|
92
|
+
</SelectedOptionsProvider>
|
|
93
|
+
</CustomOptionsProvider>
|
|
94
|
+
</InputContextProvider>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
export default ComboboxProvider;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import cl from "clsx";
|
|
2
|
+
import React, { useRef } from "react";
|
|
3
|
+
|
|
4
|
+
type ComboboxWrapperProps = {
|
|
5
|
+
children: any;
|
|
6
|
+
className?: string;
|
|
7
|
+
hasError: boolean;
|
|
8
|
+
inputProps: {
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
};
|
|
11
|
+
inputSize: string;
|
|
12
|
+
toggleIsListOpen: (isListOpen: boolean) => void;
|
|
13
|
+
toggleListButtonRef: React.RefObject<HTMLButtonElement>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const ComboboxWrapper = ({
|
|
17
|
+
children,
|
|
18
|
+
className,
|
|
19
|
+
hasError,
|
|
20
|
+
inputProps,
|
|
21
|
+
inputSize,
|
|
22
|
+
toggleIsListOpen,
|
|
23
|
+
toggleListButtonRef,
|
|
24
|
+
}: ComboboxWrapperProps) => {
|
|
25
|
+
const wrapperRef = useRef<HTMLDivElement | null>(null);
|
|
26
|
+
|
|
27
|
+
function onFocusInsideWrapper(e) {
|
|
28
|
+
if (
|
|
29
|
+
!wrapperRef.current?.contains(e.relatedTarget) &&
|
|
30
|
+
toggleListButtonRef?.current !== e.target
|
|
31
|
+
) {
|
|
32
|
+
toggleIsListOpen(true);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function onBlurWrapper(e) {
|
|
37
|
+
if (!wrapperRef.current?.contains(e.relatedTarget)) {
|
|
38
|
+
toggleIsListOpen(false);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div
|
|
44
|
+
ref={wrapperRef}
|
|
45
|
+
className={cl(
|
|
46
|
+
className,
|
|
47
|
+
"navds-form-field",
|
|
48
|
+
`navds-form-field--${inputSize}`,
|
|
49
|
+
"navds-search",
|
|
50
|
+
{
|
|
51
|
+
"navds-search--error": hasError,
|
|
52
|
+
"navds-search--disabled": !!inputProps.disabled,
|
|
53
|
+
}
|
|
54
|
+
)}
|
|
55
|
+
onFocus={onFocusInsideWrapper}
|
|
56
|
+
onBlur={onBlurWrapper}
|
|
57
|
+
>
|
|
58
|
+
{children}
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export default ComboboxWrapper;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
const CheckIcon = () => {
|
|
4
|
+
return (
|
|
5
|
+
<svg
|
|
6
|
+
width="16"
|
|
7
|
+
height="13"
|
|
8
|
+
viewBox="0 0 16 13"
|
|
9
|
+
fill="none"
|
|
10
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
11
|
+
aria-hidden="true"
|
|
12
|
+
>
|
|
13
|
+
<path
|
|
14
|
+
fillRule="evenodd"
|
|
15
|
+
clipRule="evenodd"
|
|
16
|
+
fill="#005B82"
|
|
17
|
+
d="M14.2014 0L16 1.89047L4.77943 13L0 8.39552L1.79361 6.5L4.77418 9.3019L14.2014 0Z"
|
|
18
|
+
/>
|
|
19
|
+
</svg>
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default CheckIcon;
|