@mattilsynet/design 2.2.23 → 2.2.25
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/mtds/alert/alert.js +9 -8
- package/mtds/alert/alert.js.map +1 -1
- package/mtds/analytics/analytics.d.ts +1 -1
- package/mtds/analytics/analytics.js +163 -101
- package/mtds/analytics/analytics.js.map +1 -1
- package/mtds/app/app-observer.js +73 -27
- package/mtds/app/app-observer.js.map +1 -1
- package/mtds/app/app-toggle.js +2 -24
- package/mtds/app/app-toggle.js.map +1 -1
- package/mtds/app/app-toggle2.js +16 -10
- package/mtds/app/app-toggle2.js.map +1 -1
- package/mtds/app/app.d.ts +5 -5
- package/mtds/app/app.js +36 -32
- package/mtds/app/app.js.map +1 -1
- package/mtds/atlas/atlas-element.d.ts +8 -14
- package/mtds/atlas/atlas-element.js +90 -76
- package/mtds/atlas/atlas-element.js.map +1 -1
- package/mtds/atlas/atlas-marker.d.ts +20 -0
- package/mtds/atlas/atlas-marker.js +69 -0
- package/mtds/atlas/atlas-marker.js.map +1 -0
- package/mtds/atlas/atlas-matgeo.d.ts +29 -0
- package/mtds/atlas/atlas-matgeo.js +71 -0
- package/mtds/atlas/atlas-matgeo.js.map +1 -0
- package/mtds/atlas/atlas.css.js +76 -96
- package/mtds/atlas/atlas.css.js.map +1 -1
- package/mtds/atlas/atlas.d.ts +42 -0
- package/mtds/atlas/atlas.js +33 -0
- package/mtds/atlas/atlas.js.map +1 -0
- package/mtds/atlas/atlas.stories.d.ts +5 -1
- package/mtds/atlas/cluster.js +1576 -697
- package/mtds/atlas/cluster.js.map +1 -1
- package/mtds/atlas.iife.js +80 -100
- package/mtds/atlas.js +8 -4
- package/mtds/atlas.js.map +1 -1
- package/mtds/avatar/avatar.js +8 -8
- package/mtds/avatar/avatar.js.map +1 -1
- package/mtds/badge/badge.d.ts +2 -2
- package/mtds/badge/badge.js +7 -7
- package/mtds/badge/badge.js.map +1 -1
- package/mtds/breadcrumbs/breadcrumbs-observer.js +10 -9
- package/mtds/breadcrumbs/breadcrumbs-observer.js.map +1 -1
- package/mtds/breadcrumbs/breadcrumbs.js +14 -13
- package/mtds/breadcrumbs/breadcrumbs.js.map +1 -1
- package/mtds/button/button.js +16 -14
- package/mtds/button/button.js.map +1 -1
- package/mtds/card/card.js +14 -12
- package/mtds/card/card.js.map +1 -1
- package/mtds/chart/chart-axis.js +27 -15
- package/mtds/chart/chart-axis.js.map +1 -1
- package/mtds/chart/chart-bars.js +15 -13
- package/mtds/chart/chart-bars.js.map +1 -1
- package/mtds/chart/chart-element.d.ts +5 -0
- package/mtds/chart/chart-element.js +83 -48
- package/mtds/chart/chart-element.js.map +1 -1
- package/mtds/chart/chart-lines.js +54 -32
- package/mtds/chart/chart-lines.js.map +1 -1
- package/mtds/chart/chart-pies.js +34 -14
- package/mtds/chart/chart-pies.js.map +1 -1
- package/mtds/chart/chart.css.js +2 -2
- package/mtds/chart/chart.css.js.map +1 -1
- package/mtds/chart/chart.d.ts +3 -4
- package/mtds/chart/chart.js +12 -12
- package/mtds/chart/chart.js.map +1 -1
- package/mtds/chip/chip.js +8 -8
- package/mtds/chip/chip.js.map +1 -1
- package/mtds/details/details.d.ts +3 -3
- package/mtds/details/details.js +14 -12
- package/mtds/details/details.js.map +1 -1
- package/mtds/dialog/dialog-observer.js +35 -22
- package/mtds/dialog/dialog-observer.js.map +1 -1
- package/mtds/dialog/dialog.d.ts +2 -2
- package/mtds/dialog/dialog.js +12 -12
- package/mtds/dialog/dialog.js.map +1 -1
- package/mtds/divider/divider.d.ts +2 -2
- package/mtds/divider/divider.js +10 -10
- package/mtds/divider/divider.js.map +1 -1
- package/mtds/errorsummary/errorsummary-observer.js +11 -8
- package/mtds/errorsummary/errorsummary-observer.js.map +1 -1
- package/mtds/errorsummary/errorsummary.d.ts +1 -1
- package/mtds/errorsummary/errorsummary.js +11 -11
- package/mtds/errorsummary/errorsummary.js.map +1 -1
- package/mtds/external/leaflet/dist/leaflet-src.js +6006 -3098
- package/mtds/external/leaflet/dist/leaflet-src.js.map +1 -1
- package/mtds/external/leaflet/dist/leaflet.css.js +2 -2
- package/mtds/external/leaflet/dist/leaflet.css.js.map +1 -1
- package/mtds/field/field-observer.js +114 -62
- package/mtds/field/field-observer.js.map +1 -1
- package/mtds/field/field.d.ts +6 -6
- package/mtds/field/field.js +166 -133
- package/mtds/field/field.js.map +1 -1
- package/mtds/field/field.stories.d.ts +2 -0
- package/mtds/fieldset/fieldset-observer.js +24 -14
- package/mtds/fieldset/fieldset-observer.js.map +1 -1
- package/mtds/fieldset/fieldset.d.ts +1 -1
- package/mtds/fieldset/fieldset.js +11 -11
- package/mtds/fieldset/fieldset.js.map +1 -1
- package/mtds/fileupload/fileupload.js +9 -8
- package/mtds/fileupload/fileupload.js.map +1 -1
- package/mtds/helptext/helptext.d.ts +1 -1
- package/mtds/helptext/helptext.js +15 -15
- package/mtds/helptext/helptext.js.map +1 -1
- package/mtds/index.iife.js +9 -9
- package/mtds/index.js +26 -24
- package/mtds/input/input.d.ts +3 -3
- package/mtds/input/input.js +22 -20
- package/mtds/input/input.js.map +1 -1
- package/mtds/law/law-helper.d.ts +6 -2
- package/mtds/law/law-helper.js +145 -63
- package/mtds/law/law-helper.js.map +1 -1
- package/mtds/law/law.d.ts +6 -2
- package/mtds/law/law.js +6 -6
- package/mtds/law/law.js.map +1 -1
- package/mtds/law/law.stories.d.ts +1 -0
- package/mtds/layout/layout.js +13 -10
- package/mtds/layout/layout.js.map +1 -1
- package/mtds/link/link.js +8 -7
- package/mtds/link/link.js.map +1 -1
- package/mtds/logo/logo-observer.js +18 -12
- package/mtds/logo/logo-observer.js.map +1 -1
- package/mtds/logo/logo.js +8 -8
- package/mtds/logo/logo.js.map +1 -1
- package/mtds/package.json.js +2 -2
- package/mtds/pagination/pagination-helper.js +17 -11
- package/mtds/pagination/pagination-helper.js.map +1 -1
- package/mtds/pagination/pagination.d.ts +1 -1
- package/mtds/pagination/pagination.js +30 -30
- package/mtds/pagination/pagination.js.map +1 -1
- package/mtds/popover/popover-observer.js +37 -28
- package/mtds/popover/popover-observer.js.map +1 -1
- package/mtds/popover/popover.js +13 -11
- package/mtds/popover/popover.js.map +1 -1
- package/mtds/progress/progress.d.ts +1 -1
- package/mtds/progress/progress.js +8 -8
- package/mtds/progress/progress.js.map +1 -1
- package/mtds/react-atlas.d.ts +1 -0
- package/mtds/react-atlas.js +13 -0
- package/mtds/react-atlas.js.map +1 -0
- package/mtds/react-types.d.ts +3 -0
- package/mtds/react.js +79 -79
- package/mtds/skeleton/skeleton.js +8 -8
- package/mtds/skeleton/skeleton.js.map +1 -1
- package/mtds/spinner/spinner.d.ts +2 -2
- package/mtds/spinner/spinner.js +8 -8
- package/mtds/spinner/spinner.js.map +1 -1
- package/mtds/steps/steps.d.ts +2 -2
- package/mtds/steps/steps.js +7 -7
- package/mtds/steps/steps.js.map +1 -1
- package/mtds/styles.css +4586 -1
- package/mtds/styles.module.css.js +167 -112
- package/mtds/styles.module.css.js.map +1 -1
- package/mtds/table/table-observer.js +22 -19
- package/mtds/table/table-observer.js.map +1 -1
- package/mtds/table/table.d.ts +4 -4
- package/mtds/table/table.js +18 -16
- package/mtds/table/table.js.map +1 -1
- package/mtds/tabs/tabs.d.ts +4 -4
- package/mtds/tabs/tabs.js +25 -21
- package/mtds/tabs/tabs.js.map +1 -1
- package/mtds/tag/tag.js +8 -8
- package/mtds/tag/tag.js.map +1 -1
- package/mtds/tailwind.css +24 -6
- package/mtds/toast/toast-helper.js +35 -20
- package/mtds/toast/toast-helper.js.map +1 -1
- package/mtds/toast/toast-observer.js +30 -15
- package/mtds/toast/toast-observer.js.map +1 -1
- package/mtds/toast/toast.js +45 -37
- package/mtds/toast/toast.js.map +1 -1
- package/mtds/togglegroup/togglegroup-observer.js +15 -10
- package/mtds/togglegroup/togglegroup-observer.js.map +1 -1
- package/mtds/togglegroup/togglegroup.d.ts +3 -3
- package/mtds/togglegroup/togglegroup.js +20 -18
- package/mtds/togglegroup/togglegroup.js.map +1 -1
- package/mtds/tooltip/tooltip-observer.js +48 -32
- package/mtds/tooltip/tooltip-observer.js.map +1 -1
- package/mtds/typography/typography.js +28 -19
- package/mtds/typography/typography.js.map +1 -1
- package/mtds/utils.d.ts +12 -3
- package/mtds/utils.js +133 -81
- package/mtds/utils.js.map +1 -1
- package/mtds/validation/validation.d.ts +1 -1
- package/mtds/validation/validation.js +12 -12
- package/mtds/validation/validation.js.map +1 -1
- package/package.json +14 -10
package/mtds/field/field.js
CHANGED
|
@@ -1,167 +1,200 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx
|
|
3
|
-
import
|
|
4
|
-
import { forwardRef
|
|
5
|
-
import { HelpText
|
|
6
|
-
import { Input
|
|
7
|
-
import
|
|
8
|
-
import { toCustomElementProps
|
|
9
|
-
import { Validation
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
"data-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
2
|
+
import { jsx, Fragment, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import { forwardRef, useRef, useImperativeHandle, useEffect } from "react";
|
|
5
|
+
import { HelpText } from "../helptext/helptext.js";
|
|
6
|
+
import { Input } from "../input/input.js";
|
|
7
|
+
import styles from "../styles.module.css.js";
|
|
8
|
+
import { toCustomElementProps } from "../utils.js";
|
|
9
|
+
import { Validation } from "../validation/validation.js";
|
|
10
|
+
const toOption = (o) => typeof o === "string" ? { label: o, value: o } : o;
|
|
11
|
+
const FieldComp = forwardRef(function Field2({
|
|
12
|
+
"data-size": size,
|
|
13
|
+
"data-validation": validationType,
|
|
14
|
+
as,
|
|
15
|
+
className,
|
|
16
|
+
count,
|
|
17
|
+
description,
|
|
18
|
+
error,
|
|
19
|
+
helpText,
|
|
20
|
+
helpTextLabel,
|
|
21
|
+
label,
|
|
22
|
+
prefix,
|
|
23
|
+
style,
|
|
24
|
+
suffix,
|
|
25
|
+
validation: validationContent,
|
|
26
|
+
...rest
|
|
27
|
+
}, ref) {
|
|
28
|
+
const Tag = as || "div";
|
|
29
|
+
const affixes = !!suffix || !!prefix;
|
|
30
|
+
const validation = validationContent || error;
|
|
31
|
+
const shared = {
|
|
32
|
+
"data-size": size,
|
|
33
|
+
"data-validation": validationType,
|
|
34
|
+
className: clsx(styles.field, className),
|
|
35
|
+
style
|
|
32
36
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
!!
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
if (as === "select" && !rest.children)
|
|
38
|
+
Object.assign(rest, {
|
|
39
|
+
options: void 0,
|
|
40
|
+
// Ensure options is not passed to DOM
|
|
41
|
+
children: /* @__PURE__ */ jsx(Fragment, { children: rest.options?.map(toOption).map(({ label: label2, value }) => /* @__PURE__ */ jsx("option", { value, children: label2 }, value)) })
|
|
42
|
+
});
|
|
43
|
+
return as ? /* @__PURE__ */ jsxs("div", { ...shared, children: [
|
|
44
|
+
!!label && /* @__PURE__ */ jsx("label", { suppressHydrationWarning: true, children: label }),
|
|
45
|
+
!!helpText && /* @__PURE__ */ jsx(HelpText, { "aria-label": helpTextLabel, children: helpText }),
|
|
46
|
+
!!description && /* @__PURE__ */ jsx("p", { suppressHydrationWarning: true, children: description }),
|
|
47
|
+
affixes ? /* @__PURE__ */ jsxs(FieldAffixes, { children: [
|
|
48
|
+
!!prefix && /* @__PURE__ */ jsx("span", { children: prefix }),
|
|
49
|
+
/* @__PURE__ */ jsx(
|
|
50
|
+
Tag,
|
|
45
51
|
{
|
|
46
|
-
className:
|
|
47
|
-
suppressHydrationWarning:
|
|
48
|
-
ref
|
|
49
|
-
...
|
|
52
|
+
className: styles.input,
|
|
53
|
+
suppressHydrationWarning: true,
|
|
54
|
+
ref,
|
|
55
|
+
...rest
|
|
50
56
|
}
|
|
51
57
|
),
|
|
52
|
-
!!
|
|
53
|
-
] }) : /* @__PURE__ */
|
|
54
|
-
|
|
58
|
+
!!suffix && /* @__PURE__ */ jsx("span", { children: suffix })
|
|
59
|
+
] }) : /* @__PURE__ */ jsx(
|
|
60
|
+
Tag,
|
|
55
61
|
{
|
|
56
|
-
className: typeof
|
|
57
|
-
suppressHydrationWarning:
|
|
58
|
-
ref
|
|
59
|
-
...
|
|
62
|
+
className: typeof as === "string" ? styles.input : void 0,
|
|
63
|
+
suppressHydrationWarning: true,
|
|
64
|
+
ref,
|
|
65
|
+
...rest
|
|
60
66
|
}
|
|
61
67
|
),
|
|
62
|
-
!!
|
|
63
|
-
!!
|
|
64
|
-
] }) : /* @__PURE__ */
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
!!validation && /* @__PURE__ */ jsx(Validation, { hidden: validationType === "form", children: validation }),
|
|
69
|
+
!!count && /* @__PURE__ */ jsx("p", { suppressHydrationWarning: true, "data-count": count })
|
|
70
|
+
] }) : /* @__PURE__ */ jsx("div", { ref, ...shared, ...rest });
|
|
71
|
+
});
|
|
72
|
+
const FieldAffixes = forwardRef(
|
|
73
|
+
function FieldAffixes2({ className, ...rest }, ref) {
|
|
74
|
+
return /* @__PURE__ */ jsx("div", { className: clsx(styles.affixes, className), ref, ...rest });
|
|
68
75
|
}
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
|
|
76
|
+
);
|
|
77
|
+
const FieldDatalist = forwardRef(
|
|
78
|
+
function FieldDatalist2({ "data-nofilter": filter, ...rest }, ref) {
|
|
79
|
+
return /* @__PURE__ */ jsx(
|
|
72
80
|
"u-datalist",
|
|
73
81
|
{
|
|
74
|
-
"data-nofilter": !!
|
|
75
|
-
ref
|
|
76
|
-
...
|
|
82
|
+
"data-nofilter": !!filter || void 0,
|
|
83
|
+
ref,
|
|
84
|
+
...toCustomElementProps(rest)
|
|
77
85
|
}
|
|
78
86
|
);
|
|
79
87
|
}
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
|
|
88
|
+
);
|
|
89
|
+
const FieldOption = forwardRef(
|
|
90
|
+
function FieldOption2(props, ref) {
|
|
91
|
+
return /* @__PURE__ */ jsx("u-option", { ref, ...toCustomElementProps(props) });
|
|
83
92
|
}
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
"
|
|
88
|
-
"data-
|
|
89
|
-
"data-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
93
|
+
);
|
|
94
|
+
const FieldCombobox = forwardRef(
|
|
95
|
+
function FieldCombobox2({
|
|
96
|
+
"aria-required": required,
|
|
97
|
+
"data-position": position,
|
|
98
|
+
"data-nofilter": nofilter,
|
|
99
|
+
"data-multiple": multiple,
|
|
100
|
+
onAfterChange,
|
|
101
|
+
onAfterSelect,
|
|
102
|
+
onBeforeChange,
|
|
103
|
+
onBeforeMatch,
|
|
104
|
+
onBeforeSelect,
|
|
105
|
+
onSelectedChange,
|
|
106
|
+
onInput,
|
|
107
|
+
onChange,
|
|
108
|
+
children,
|
|
109
|
+
disabled,
|
|
110
|
+
name,
|
|
111
|
+
options,
|
|
112
|
+
placeholder,
|
|
113
|
+
readOnly,
|
|
114
|
+
selected,
|
|
115
|
+
type,
|
|
116
|
+
...props
|
|
117
|
+
}, ref) {
|
|
118
|
+
const innerRef = useRef(null);
|
|
119
|
+
const onSelected = useRef(onSelectedChange);
|
|
120
|
+
onSelected.current = onSelectedChange;
|
|
121
|
+
if (onAfterChange) {
|
|
122
|
+
onAfterSelect = onAfterChange;
|
|
123
|
+
console.warn(
|
|
124
|
+
`Combobox onAfterChange is deprecated, use onAfterSelect instead.`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
if (onBeforeChange) {
|
|
128
|
+
onBeforeSelect = onBeforeChange;
|
|
129
|
+
console.warn(
|
|
130
|
+
`Combobox onBeforeChange is deprecated, use onBeforeSelect instead.`
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
useImperativeHandle(ref, () => innerRef.current);
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
const self = innerRef.current;
|
|
136
|
+
const handleChange = (event) => {
|
|
137
|
+
const handleSelected = onSelected.current;
|
|
138
|
+
if (!onSelected) return;
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
const { isConnected: remove, textContent, value } = event.detail;
|
|
141
|
+
const label = textContent?.trim() || "";
|
|
142
|
+
const prev = selected || [];
|
|
143
|
+
if (remove) handleSelected?.(prev.filter((i) => i.value !== value));
|
|
144
|
+
else if (multiple) handleSelected?.([...prev, { value, label }]);
|
|
145
|
+
else handleSelected?.([{ value, label }]);
|
|
118
146
|
};
|
|
119
|
-
|
|
120
|
-
|
|
147
|
+
self?.addEventListener("comboboxbeforeselect", handleChange);
|
|
148
|
+
return () => self?.removeEventListener("comboboxbeforeselect", handleChange);
|
|
149
|
+
}, [multiple, selected]);
|
|
150
|
+
return /* @__PURE__ */ jsxs(
|
|
121
151
|
"u-combobox",
|
|
122
152
|
{
|
|
123
|
-
"data-multiple":
|
|
124
|
-
...
|
|
125
|
-
oncomboboxbeforeselect:
|
|
126
|
-
oncomboboxbeforematch:
|
|
127
|
-
oncomboboxafterselect:
|
|
128
|
-
ref:
|
|
129
|
-
...
|
|
153
|
+
"data-multiple": multiple || void 0,
|
|
154
|
+
...toCustomElementProps({
|
|
155
|
+
oncomboboxbeforeselect: onBeforeSelect,
|
|
156
|
+
oncomboboxbeforematch: onBeforeMatch,
|
|
157
|
+
oncomboboxafterselect: onAfterSelect,
|
|
158
|
+
ref: innerRef,
|
|
159
|
+
...props
|
|
130
160
|
}),
|
|
131
161
|
children: [
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
/* @__PURE__ */
|
|
135
|
-
|
|
162
|
+
selected?.map(({ children: children2, label, value }) => /* @__PURE__ */ jsx("data", { value, suppressHydrationWarning: true, children: children2 ?? label }, value)),
|
|
163
|
+
children || /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
164
|
+
/* @__PURE__ */ jsx(
|
|
165
|
+
Input,
|
|
136
166
|
{
|
|
137
|
-
"aria-required":
|
|
138
|
-
disabled
|
|
139
|
-
name
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
167
|
+
"aria-required": required,
|
|
168
|
+
disabled,
|
|
169
|
+
name,
|
|
170
|
+
onInput,
|
|
171
|
+
onChange,
|
|
172
|
+
placeholder,
|
|
173
|
+
readOnly,
|
|
174
|
+
type
|
|
143
175
|
}
|
|
144
176
|
),
|
|
145
|
-
/* @__PURE__ */
|
|
177
|
+
/* @__PURE__ */ jsx("del", { ...toCustomElementProps({ "aria-label": "Fjern tekst" }) })
|
|
146
178
|
] }),
|
|
147
|
-
!!
|
|
179
|
+
!!options && /* @__PURE__ */ jsx(FieldDatalist, { "data-nofilter": nofilter, "data-position": position, children: options.map(toOption).map(({ children: children2, label, value }) => /* @__PURE__ */ jsx(FieldOption, { value, label, children: children2 ?? label }, value)) })
|
|
148
180
|
]
|
|
149
181
|
}
|
|
150
182
|
);
|
|
151
183
|
}
|
|
152
|
-
)
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
184
|
+
);
|
|
185
|
+
const Field = Object.assign(FieldComp, {
|
|
186
|
+
Affixes: FieldAffixes,
|
|
187
|
+
Combobox: FieldCombobox,
|
|
188
|
+
Datalist: FieldDatalist,
|
|
189
|
+
Option: FieldOption,
|
|
190
|
+
Label: forwardRef(
|
|
191
|
+
function FieldLabel(rest, ref) {
|
|
192
|
+
return /* @__PURE__ */ jsx("label", { suppressHydrationWarning: true, ref, ...rest });
|
|
160
193
|
}
|
|
161
194
|
)
|
|
162
195
|
});
|
|
163
196
|
export {
|
|
164
|
-
|
|
165
|
-
|
|
197
|
+
Field,
|
|
198
|
+
FieldComp
|
|
166
199
|
};
|
|
167
200
|
//# sourceMappingURL=field.js.map
|
package/mtds/field/field.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field.js","sources":["../../designsystem/field/field.tsx"],"sourcesContent":["\"use client\";\nimport type { Placement } from \"@floating-ui/dom\";\nimport type {\n\tReactUcombobox,\n\tUHTMLComboboxElement,\n} from \"@u-elements/u-combobox\";\nimport clsx from \"clsx\";\nimport type { JSX } from \"react\";\nimport { forwardRef, useEffect, useImperativeHandle, useRef } from \"react\";\nimport { HelpText } from \"../helptext/helptext\";\nimport { Input, type InputProps } from \"../input/input\";\nimport type {\n\tPolymorphicComponentPropWithRef,\n\tPolymorphicRef,\n} from \"../react-types\";\nimport styles from \"../styles.module.css\";\nimport { toCustomElementProps } from \"../utils\";\nimport { Validation } from \"../validation/validation\";\n\ntype FieldBaseProps = {\n\t\"data-validation\"?: \"form\" | \"false\" | false;\n\tcount?: number;\n\tdescription?: React.ReactNode;\n\terror?: React.ReactNode; // Kept for backwards compatibility\n\thelpText?: React.ReactNode;\n\thelpTextLabel?: string;\n\tlabel?: React.ReactNode;\n\toptions?: string[] | FieldComboboxSelected;\n\tprefix?: string;\n\treadOnly?: boolean; // Allow readoOnly also on <select>\n\tsuffix?: string;\n\tvalidation?: React.ReactNode;\n};\n\nexport type FieldProps<As extends React.ElementType = \"div\"> =\n\tPolymorphicComponentPropWithRef<As, FieldBaseProps>;\n\ntype FieldComponent = <As extends React.ElementType = \"div\">(\n\tprops: FieldProps<As>,\n) => JSX.Element;\n\nconst toOption = (\n\to: FieldComboboxSelected[number] | string,\n): FieldComboboxSelected[number] =>\n\ttypeof o === \"string\" ? { label: o, value: o } : o;\n\nexport const FieldComp: FieldComponent = forwardRef<null>(function Field<\n\tAs extends React.ElementType = \"div\",\n>(\n\t{\n\t\t\"data-size\": size,\n\t\t\"data-validation\": validationType,\n\t\tas,\n\t\tclassName,\n\t\tcount,\n\t\tdescription,\n\t\terror,\n\t\thelpText,\n\t\thelpTextLabel,\n\t\tlabel,\n\t\tprefix,\n\t\tstyle,\n\t\tsuffix,\n\t\tvalidation: validationContent,\n\t\t...rest\n\t}: FieldProps<As>,\n\tref?: PolymorphicRef<As>,\n) {\n\tconst Tag = as || \"div\";\n\tconst affixes = !!suffix || !!prefix;\n\tconst validation = validationContent || error; // error kept for backwards compatibility\n\tconst shared = {\n\t\t\"data-size\": size,\n\t\t\"data-validation\": validationType,\n\t\tclassName: clsx(styles.field, className),\n\t\tstyle,\n\t};\n\n\t// Render options if select\n\tif (as === \"select\" && !rest.children)\n\t\tObject.assign(rest, {\n\t\t\toptions: undefined, // Ensure options is not passed to DOM\n\t\t\tchildren: (\n\t\t\t\t<>\n\t\t\t\t\t{(rest.options as FieldBaseProps[\"options\"])\n\t\t\t\t\t\t?.map(toOption)\n\t\t\t\t\t\t.map(({ label, value }) => (\n\t\t\t\t\t\t\t<option key={value} value={value}>\n\t\t\t\t\t\t\t\t{label}\n\t\t\t\t\t\t\t</option>\n\t\t\t\t\t\t))}\n\t\t\t\t</>\n\t\t\t),\n\t\t});\n\n\t// Using suppressHydrationWarning to avoid Next.js vs field-observer.ts hydration conflict\n\treturn as ? (\n\t\t<div {...shared}>\n\t\t\t{!!label && <label suppressHydrationWarning>{label}</label>}\n\t\t\t{!!helpText && <HelpText aria-label={helpTextLabel}>{helpText}</HelpText>}\n\t\t\t{!!description && <p suppressHydrationWarning>{description}</p>}\n\t\t\t{affixes ? (\n\t\t\t\t<FieldAffixes>\n\t\t\t\t\t{!!prefix && <span>{prefix}</span>}\n\t\t\t\t\t<Tag\n\t\t\t\t\t\tclassName={styles.input}\n\t\t\t\t\t\tsuppressHydrationWarning\n\t\t\t\t\t\tref={ref}\n\t\t\t\t\t\t{...rest}\n\t\t\t\t\t/>\n\t\t\t\t\t{!!suffix && <span>{suffix}</span>}\n\t\t\t\t</FieldAffixes>\n\t\t\t) : (\n\t\t\t\t<Tag\n\t\t\t\t\tclassName={typeof as === \"string\" ? styles.input : undefined}\n\t\t\t\t\tsuppressHydrationWarning\n\t\t\t\t\tref={ref}\n\t\t\t\t\t{...rest}\n\t\t\t\t/>\n\t\t\t)}\n\t\t\t{!!validation && (\n\t\t\t\t<Validation hidden={validationType === \"form\"}>{validation}</Validation>\n\t\t\t)}\n\t\t\t{!!count && <p suppressHydrationWarning data-count={count} />}\n\t\t</div>\n\t) : (\n\t\t<div ref={ref} {...shared} {...rest} />\n\t);\n}) as FieldComponent; // Needed to tell Typescript this does not return ReactNode but acutally JSX.Element\n\nexport type FieldAffixProps = React.ComponentPropsWithoutRef<\"div\">;\nconst FieldAffixes = forwardRef<HTMLDivElement, FieldAffixProps>(\n\tfunction FieldAffixes({ className, ...rest }, ref) {\n\t\treturn (\n\t\t\t<div className={clsx(styles.affixes, className)} ref={ref} {...rest} />\n\t\t);\n\t},\n);\n\nexport type FieldDatalistProps = React.ComponentPropsWithoutRef<\"datalist\"> & {\n\t\"data-nofilter\"?: boolean;\n\t\"data-position\"?: Placement;\n};\n\nconst FieldDatalist = forwardRef<HTMLDataListElement, FieldDatalistProps>(\n\tfunction FieldDatalist({ \"data-nofilter\": filter, ...rest }, ref) {\n\t\treturn (\n\t\t\t<u-datalist\n\t\t\t\tdata-nofilter={!!filter || undefined} // Ensure data-nofilter is set correctly\n\t\t\t\tref={ref}\n\t\t\t\t{...toCustomElementProps(rest)}\n\t\t\t/>\n\t\t);\n\t},\n);\n\nexport type FieldOptionProps = React.ComponentPropsWithoutRef<\"option\">;\nconst FieldOption = forwardRef<HTMLOptionElement, FieldOptionProps>(\n\tfunction FieldOption(props, ref) {\n\t\treturn <u-option ref={ref} {...toCustomElementProps(props)} />;\n\t},\n);\n\nexport type FieldComboboxSelected = {\n\tlabel: string;\n\tvalue: string;\n\tchildren?: React.ReactNode;\n}[];\nexport type FieldComboboxProps = Omit<\n\tReactUcombobox,\n\t\"onChange\" | \"onInput\"\n> & {\n\t\"data-creatable\"?: boolean;\n\t\"data-multiple\"?: boolean;\n\tonAfterChange?: (e: CustomEvent<HTMLDataElement>) => void; // deprecated\n\tonAfterSelect?: (e: CustomEvent<HTMLDataElement>) => void; // Custom event to handle before change\n\tonBeforeChange?: (e: CustomEvent<HTMLDataElement>) => void; // deprecated\n\tonBeforeMatch?: (e: CustomEvent<HTMLOptionElement>) => void; // Custom event to handle before change\n\tonBeforeSelect?: (e: CustomEvent<HTMLDataElement>) => void; // Custom event to handle before change\n\tonSelectedChange?: (selected: FieldComboboxSelected) => void; // Allow onChange to be a function that returns void\n\toptions?: FieldComboboxSelected;\n\tselected?: FieldComboboxSelected; // Allow value to be a string or an array of strings for multiple select\n} & Pick<\n\t\tInputProps,\n\t\t| \"disabled\"\n\t\t| \"name\"\n\t\t| \"onChange\"\n\t\t| \"onInput\"\n\t\t| \"placeholder\"\n\t\t| \"readOnly\"\n\t\t| \"type\"\n\t\t| \"value\"\n\t> & // Allow input props to be passed down\n\tPick<FieldDatalistProps, \"data-position\" | \"data-nofilter\">; // Allow datalist props to be passed down\n\nconst FieldCombobox = forwardRef<UHTMLComboboxElement, FieldComboboxProps>(\n\tfunction FieldCombobox(\n\t\t{\n\t\t\t\"aria-required\": required,\n\t\t\t\"data-position\": position,\n\t\t\t\"data-nofilter\": nofilter,\n\t\t\t\"data-multiple\": multiple,\n\t\t\tonAfterChange,\n\t\t\tonAfterSelect,\n\t\t\tonBeforeChange,\n\t\t\tonBeforeMatch,\n\t\t\tonBeforeSelect,\n\t\t\tonSelectedChange,\n\t\t\tchildren,\n\t\t\tdisabled,\n\t\t\tname,\n\t\t\toptions,\n\t\t\tplaceholder,\n\t\t\treadOnly,\n\t\t\tselected,\n\t\t\ttype,\n\t\t\t...props\n\t\t},\n\t\tref,\n\t) {\n\t\tconst innerRef = useRef<UHTMLComboboxElement>(null);\n\t\tconst onSelected = useRef(onSelectedChange);\n\t\tonSelected.current = onSelectedChange; // Sync the latest onSelectedChange function\n\n\t\t// Deprecated props\n\t\tif (onAfterChange) {\n\t\t\tonAfterSelect = onAfterChange;\n\t\t\tconsole.warn(\n\t\t\t\t`Combobox onAfterChange is deprecated, use onAfterSelect instead.`,\n\t\t\t);\n\t\t}\n\t\tif (onBeforeChange) {\n\t\t\tonBeforeSelect = onBeforeChange;\n\t\t\tconsole.warn(\n\t\t\t\t`Combobox onBeforeChange is deprecated, use onBeforeSelect instead.`,\n\t\t\t);\n\t\t}\n\n\t\t// Using useEffect for React 18 and lower compatibility\n\t\tuseImperativeHandle(ref, () => innerRef.current as UHTMLComboboxElement); // Forward innerRef\n\t\tuseEffect(() => {\n\t\t\tconst self = innerRef.current;\n\t\t\tconst handleChange = (event: CustomEvent<HTMLDataElement>) => {\n\t\t\t\tconst handleSelected = onSelected.current;\n\t\t\t\tif (!onSelected) return; // No onSelectedChange function provided, let u-combobox handle it\n\t\t\t\tevent.preventDefault();\n\t\t\t\tconst { isConnected: remove, textContent, value } = event.detail;\n\t\t\t\tconst label = textContent?.trim() || \"\";\n\t\t\t\tconst prev = selected || [];\n\n\t\t\t\tif (remove) handleSelected?.(prev.filter((i) => i.value !== value));\n\t\t\t\telse if (multiple) handleSelected?.([...prev, { value, label }]);\n\t\t\t\telse handleSelected?.([{ value, label }]);\n\t\t\t};\n\n\t\t\tself?.addEventListener(\"comboboxbeforeselect\", handleChange);\n\t\t\treturn () =>\n\t\t\t\tself?.removeEventListener(\"comboboxbeforeselect\", handleChange);\n\t\t}, [multiple, selected]);\n\n\t\treturn (\n\t\t\t<u-combobox\n\t\t\t\tdata-multiple={multiple || undefined}\n\t\t\t\t{...toCustomElementProps({\n\t\t\t\t\toncomboboxbeforeselect: onBeforeSelect,\n\t\t\t\t\toncomboboxbeforematch: onBeforeMatch,\n\t\t\t\t\toncomboboxafterselect: onAfterSelect,\n\t\t\t\t\tref: innerRef,\n\t\t\t\t\t...props,\n\t\t\t\t})}\n\t\t\t>\n\t\t\t\t{selected?.map(({ children, label, value }) => (\n\t\t\t\t\t<data key={value} value={value} suppressHydrationWarning>\n\t\t\t\t\t\t{children ?? label}\n\t\t\t\t\t</data>\n\t\t\t\t))}\n\t\t\t\t{children || (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<Input\n\t\t\t\t\t\t\taria-required={required}\n\t\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\t\tname={name}\n\t\t\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\t\ttype={type}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<del {...toCustomElementProps({ \"aria-label\": \"Fjern tekst\" })} />\n\t\t\t\t\t</>\n\t\t\t\t)}\n\t\t\t\t{!!options && (\n\t\t\t\t\t<FieldDatalist data-nofilter={nofilter} data-position={position}>\n\t\t\t\t\t\t{options.map(toOption).map(({ children, label, value }) => (\n\t\t\t\t\t\t\t<FieldOption key={value} value={value} label={label}>\n\t\t\t\t\t\t\t\t{children ?? label}\n\t\t\t\t\t\t\t</FieldOption>\n\t\t\t\t\t\t))}\n\t\t\t\t\t</FieldDatalist>\n\t\t\t\t)}\n\t\t\t</u-combobox>\n\t\t);\n\t},\n);\n\nexport type FieldLabelProps = React.ComponentPropsWithoutRef<\"label\">;\nexport const Field = Object.assign(FieldComp, {\n\tAffixes: FieldAffixes,\n\tCombobox: FieldCombobox,\n\tDatalist: FieldDatalist,\n\tOption: FieldOption,\n\tLabel: forwardRef<HTMLLabelElement, FieldLabelProps>(\n\t\tfunction FieldLabel(rest, ref) {\n\t\t\treturn <label suppressHydrationWarning ref={ref} {...rest} />;\n\t\t},\n\t),\n});\n"],"names":["toOption","FieldComp","forwardRef","size","validationType","as","className","count","description","error","helpText","helpTextLabel","label","prefix","style","suffix","validationContent","rest","ref","Tag","affixes","validation","shared","clsx","styles","value","jsx","jsxs","HelpText","FieldAffixes","Validation","FieldDatalist","filter","toCustomElementProps","FieldOption","props","FieldCombobox","required","position","nofilter","multiple","onAfterChange","onAfterSelect","onBeforeChange","onBeforeMatch","onBeforeSelect","onSelectedChange","children","disabled","name","options","placeholder","readOnly","selected","type","innerRef","useRef","onSelected","useImperativeHandle","useEffect","self","handleChange","event","handleSelected","remove","textContent","prev","i","Fragment","Input","Field"],"mappings":";;;;;;;;AAyCA,MAAMA,IAAW,CAChB,MAEA,OAAO,KAAM,WAAW,EAAE,OAAO,GAAG,OAAO,EAAA,IAAM,GAErCC,IAA4BC,EAAiB,SAGzD;AAAA,EACC,aAAaC;AAAA,EACb,mBAAmBC;AAAA,EACnB,IAAAC;AAAA,EACA,WAAAC;AAAA,EACA,OAAAC;AAAA,EACA,aAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,eAAAC;AAAA,EACA,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,YAAYC;AAAA,EACZ,GAAGC;AACJ,GACAC,GACC;AACD,QAAMC,IAAMd,KAAM,OACZe,IAAU,CAAC,CAACL,KAAU,CAAC,CAACF,GACxBQ,IAAaL,KAAqBP,GAClCa,IAAS;AAAA,IACd,aAAanB;AAAA,IACb,mBAAmBC;AAAA,IACnB,WAAWmB,EAAKC,EAAO,OAAOlB,CAAS;AAAA,IACvC,OAAAQ;AAAA,EAAA;AAID,SAAIT,MAAO,YAAY,CAACY,EAAK,YAC5B,OAAO,OAAOA,GAAM;AAAA,IACnB,SAAS;AAAA;AAAA,IACT,iCAEI,UAAAA,E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AAAA,cAAA;AAAA,gBACA,iBAAehC;AAAA,gBACf,UAAAW;AAAA,gBACA,MAAAC;AAAA,gBACA,aAAAE;AAAA,gBACA,UAAAC;AAAA,gBACA,MAAAE;AAAA,cAAA;AAAA,YAAA;AAAA,YAED,gBAAA5B,EAAC,SAAK,GAAGO,EAAqB,EAAE,cAAc,cAAA,CAAe,EAAA,CAAG;AAAA,UAAA,GACjE;AAAA,UAEA,CAAC,CAACiB,KACF,gBAAAxB,EAACK,GAAA,EAAc,iBAAeQ,GAAU,iBAAeD,GACrD,UAAAY,EAAQ,IAAIlD,CAAQ,EAAE,IAAI,CAAC,EAAE,UAAA+C,GAAU,OAAAnC,GAAO,OAAAa,EAAA,MAC9C,gBAAAC,EAACQ,GAAA,EAAwB,OAAAT,GAAc,OAAAb,GACrC,UAAAmC,KAAYnC,EAAA,GADIa,CAElB,CACA,EAAA,CACF;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAIJ;AACD,GAGa6C,KAAQ,OAAO,OAAOrE,GAAW;AAAA,EAC7C,SAAS4B;AAAA,EACT,UAAUO;AAAA,EACV,UAAUL;AAAA,EACV,QAAQG;AAAA,EACR,OAAOhC;AAAA,IACN,SAAoBe,GAAMC,GAAK;AAC9B,+BAAQ,SAAA,EAAM,0BAAwB,IAAC,KAAAA,GAAW,GAAGD,GAAM;AAAA,IAC5D;AAAA,EAAA;AAEF,CAAC;"}
|
|
1
|
+
{"version":3,"file":"field.js","sources":["../../designsystem/field/field.tsx"],"sourcesContent":["\"use client\";\nimport type { Placement } from \"@floating-ui/dom\";\nimport type {\n\tReactUcombobox,\n\tUHTMLComboboxElement,\n} from \"@u-elements/u-combobox\";\nimport clsx from \"clsx\";\nimport type { JSX } from \"react\";\nimport { forwardRef, useEffect, useImperativeHandle, useRef } from \"react\";\nimport { HelpText } from \"../helptext/helptext\";\nimport { Input, type InputProps } from \"../input/input\";\nimport type {\n\tPolymorphicComponentPropWithRef,\n\tPolymorphicRef,\n} from \"../react-types\";\nimport styles from \"../styles.module.css\";\nimport { toCustomElementProps } from \"../utils\";\nimport { Validation } from \"../validation/validation\";\n\ntype FieldBaseProps = {\n\t\"data-validation\"?: \"form\" | \"false\" | false;\n\tcount?: number;\n\tdescription?: React.ReactNode;\n\terror?: React.ReactNode; // Kept for backwards compatibility\n\thelpText?: React.ReactNode;\n\thelpTextLabel?: string;\n\tlabel?: React.ReactNode;\n\toptions?: string[] | FieldComboboxSelected;\n\tprefix?: string;\n\treadOnly?: boolean; // Allow readoOnly also on <select>\n\tsuffix?: string;\n\tvalidation?: React.ReactNode;\n};\n\nexport type FieldProps<As extends React.ElementType = \"div\"> =\n\tPolymorphicComponentPropWithRef<As, FieldBaseProps>;\n\ntype FieldComponent = <As extends React.ElementType = \"div\">(\n\tprops: FieldProps<As>,\n) => JSX.Element;\n\nconst toOption = (\n\to: FieldComboboxSelected[number] | string,\n): FieldComboboxSelected[number] =>\n\ttypeof o === \"string\" ? { label: o, value: o } : o;\n\nexport const FieldComp: FieldComponent = forwardRef<null>(function Field<\n\tAs extends React.ElementType = \"div\",\n>(\n\t{\n\t\t\"data-size\": size,\n\t\t\"data-validation\": validationType,\n\t\tas,\n\t\tclassName,\n\t\tcount,\n\t\tdescription,\n\t\terror,\n\t\thelpText,\n\t\thelpTextLabel,\n\t\tlabel,\n\t\tprefix,\n\t\tstyle,\n\t\tsuffix,\n\t\tvalidation: validationContent,\n\t\t...rest\n\t}: FieldProps<As>,\n\tref?: PolymorphicRef<As>,\n) {\n\tconst Tag = as || \"div\";\n\tconst affixes = !!suffix || !!prefix;\n\tconst validation = validationContent || error; // error kept for backwards compatibility\n\tconst shared = {\n\t\t\"data-size\": size,\n\t\t\"data-validation\": validationType,\n\t\tclassName: clsx(styles.field, className),\n\t\tstyle,\n\t};\n\n\t// Render options if select\n\tif (as === \"select\" && !rest.children)\n\t\tObject.assign(rest, {\n\t\t\toptions: undefined, // Ensure options is not passed to DOM\n\t\t\tchildren: (\n\t\t\t\t<>\n\t\t\t\t\t{(rest.options as FieldBaseProps[\"options\"])\n\t\t\t\t\t\t?.map(toOption)\n\t\t\t\t\t\t.map(({ label, value }) => (\n\t\t\t\t\t\t\t<option key={value} value={value}>\n\t\t\t\t\t\t\t\t{label}\n\t\t\t\t\t\t\t</option>\n\t\t\t\t\t\t))}\n\t\t\t\t</>\n\t\t\t),\n\t\t});\n\n\t// Using suppressHydrationWarning to avoid Next.js vs field-observer.ts hydration conflict\n\treturn as ? (\n\t\t<div {...shared}>\n\t\t\t{!!label && <label suppressHydrationWarning>{label}</label>}\n\t\t\t{!!helpText && <HelpText aria-label={helpTextLabel}>{helpText}</HelpText>}\n\t\t\t{!!description && <p suppressHydrationWarning>{description}</p>}\n\t\t\t{affixes ? (\n\t\t\t\t<FieldAffixes>\n\t\t\t\t\t{!!prefix && <span>{prefix}</span>}\n\t\t\t\t\t<Tag\n\t\t\t\t\t\tclassName={styles.input}\n\t\t\t\t\t\tsuppressHydrationWarning\n\t\t\t\t\t\tref={ref}\n\t\t\t\t\t\t{...rest}\n\t\t\t\t\t/>\n\t\t\t\t\t{!!suffix && <span>{suffix}</span>}\n\t\t\t\t</FieldAffixes>\n\t\t\t) : (\n\t\t\t\t<Tag\n\t\t\t\t\tclassName={typeof as === \"string\" ? styles.input : undefined}\n\t\t\t\t\tsuppressHydrationWarning\n\t\t\t\t\tref={ref}\n\t\t\t\t\t{...rest}\n\t\t\t\t/>\n\t\t\t)}\n\t\t\t{!!validation && (\n\t\t\t\t<Validation hidden={validationType === \"form\"}>{validation}</Validation>\n\t\t\t)}\n\t\t\t{!!count && <p suppressHydrationWarning data-count={count} />}\n\t\t</div>\n\t) : (\n\t\t<div ref={ref} {...shared} {...rest} />\n\t);\n}) as FieldComponent; // Needed to tell Typescript this does not return ReactNode but acutally JSX.Element\n\nexport type FieldAffixProps = React.ComponentPropsWithoutRef<\"div\">;\nconst FieldAffixes = forwardRef<HTMLDivElement, FieldAffixProps>(\n\tfunction FieldAffixes({ className, ...rest }, ref) {\n\t\treturn (\n\t\t\t<div className={clsx(styles.affixes, className)} ref={ref} {...rest} />\n\t\t);\n\t},\n);\n\nexport type FieldDatalistProps = React.ComponentPropsWithoutRef<\"datalist\"> & {\n\t\"data-nofilter\"?: boolean;\n\t\"data-position\"?: Placement;\n};\n\nconst FieldDatalist = forwardRef<HTMLDataListElement, FieldDatalistProps>(\n\tfunction FieldDatalist({ \"data-nofilter\": filter, ...rest }, ref) {\n\t\treturn (\n\t\t\t<u-datalist\n\t\t\t\tdata-nofilter={!!filter || undefined} // Ensure data-nofilter is set correctly\n\t\t\t\tref={ref}\n\t\t\t\t{...toCustomElementProps(rest)}\n\t\t\t/>\n\t\t);\n\t},\n);\n\nexport type FieldOptionProps = React.ComponentPropsWithoutRef<\"option\">;\nconst FieldOption = forwardRef<HTMLOptionElement, FieldOptionProps>(\n\tfunction FieldOption(props, ref) {\n\t\treturn <u-option ref={ref} {...toCustomElementProps(props)} />;\n\t},\n);\n\nexport type FieldComboboxSelected = {\n\tlabel: string;\n\tvalue: string;\n\tchildren?: React.ReactNode;\n}[];\nexport type FieldComboboxProps = Omit<\n\tReactUcombobox,\n\t\"onChange\" | \"onInput\"\n> & {\n\t\"data-creatable\"?: boolean;\n\t\"data-multiple\"?: boolean;\n\tonAfterChange?: (e: CustomEvent<HTMLDataElement>) => void; // deprecated\n\tonAfterSelect?: (e: CustomEvent<HTMLDataElement>) => void; // Custom event to handle before change\n\tonBeforeChange?: (e: CustomEvent<HTMLDataElement>) => void; // deprecated\n\tonBeforeMatch?: (e: CustomEvent<HTMLOptionElement>) => void; // Custom event to handle before change\n\tonBeforeSelect?: (e: CustomEvent<HTMLDataElement>) => void; // Custom event to handle before change\n\tonSelectedChange?: (selected: FieldComboboxSelected) => void; // Allow onChange to be a function that returns void\n\toptions?: FieldComboboxSelected;\n\tselected?: FieldComboboxSelected; // Allow value to be a string or an array of strings for multiple select\n} & Pick<\n\t\tInputProps,\n\t\t| \"disabled\"\n\t\t| \"name\"\n\t\t| \"onChange\"\n\t\t| \"onInput\"\n\t\t| \"placeholder\"\n\t\t| \"readOnly\"\n\t\t| \"type\"\n\t\t| \"value\"\n\t> & // Allow input props to be passed down\n\tPick<FieldDatalistProps, \"data-position\" | \"data-nofilter\">; // Allow datalist props to be passed down\n\nconst FieldCombobox = forwardRef<UHTMLComboboxElement, FieldComboboxProps>(\n\tfunction FieldCombobox(\n\t\t{\n\t\t\t\"aria-required\": required,\n\t\t\t\"data-position\": position,\n\t\t\t\"data-nofilter\": nofilter,\n\t\t\t\"data-multiple\": multiple,\n\t\t\tonAfterChange,\n\t\t\tonAfterSelect,\n\t\t\tonBeforeChange,\n\t\t\tonBeforeMatch,\n\t\t\tonBeforeSelect,\n\t\t\tonSelectedChange,\n\t\t\tonInput,\n\t\t\tonChange,\n\t\t\tchildren,\n\t\t\tdisabled,\n\t\t\tname,\n\t\t\toptions,\n\t\t\tplaceholder,\n\t\t\treadOnly,\n\t\t\tselected,\n\t\t\ttype,\n\t\t\t...props\n\t\t},\n\t\tref,\n\t) {\n\t\tconst innerRef = useRef<UHTMLComboboxElement>(null);\n\t\tconst onSelected = useRef(onSelectedChange);\n\t\tonSelected.current = onSelectedChange; // Sync the latest onSelectedChange function\n\n\t\t// Deprecated props\n\t\tif (onAfterChange) {\n\t\t\tonAfterSelect = onAfterChange;\n\t\t\tconsole.warn(\n\t\t\t\t`Combobox onAfterChange is deprecated, use onAfterSelect instead.`,\n\t\t\t);\n\t\t}\n\t\tif (onBeforeChange) {\n\t\t\tonBeforeSelect = onBeforeChange;\n\t\t\tconsole.warn(\n\t\t\t\t`Combobox onBeforeChange is deprecated, use onBeforeSelect instead.`,\n\t\t\t);\n\t\t}\n\n\t\t// Using useEffect for React 18 and lower compatibility\n\t\tuseImperativeHandle(ref, () => innerRef.current as UHTMLComboboxElement); // Forward innerRef\n\t\tuseEffect(() => {\n\t\t\tconst self = innerRef.current;\n\t\t\tconst handleChange = (event: CustomEvent<HTMLDataElement>) => {\n\t\t\t\tconst handleSelected = onSelected.current;\n\t\t\t\tif (!onSelected) return; // No onSelectedChange function provided, let u-combobox handle it\n\t\t\t\tevent.preventDefault();\n\t\t\t\tconst { isConnected: remove, textContent, value } = event.detail;\n\t\t\t\tconst label = textContent?.trim() || \"\";\n\t\t\t\tconst prev = selected || [];\n\n\t\t\t\tif (remove) handleSelected?.(prev.filter((i) => i.value !== value));\n\t\t\t\telse if (multiple) handleSelected?.([...prev, { value, label }]);\n\t\t\t\telse handleSelected?.([{ value, label }]);\n\t\t\t};\n\n\t\t\tself?.addEventListener(\"comboboxbeforeselect\", handleChange);\n\t\t\treturn () =>\n\t\t\t\tself?.removeEventListener(\"comboboxbeforeselect\", handleChange);\n\t\t}, [multiple, selected]);\n\n\t\treturn (\n\t\t\t<u-combobox\n\t\t\t\tdata-multiple={multiple || undefined}\n\t\t\t\t{...toCustomElementProps({\n\t\t\t\t\toncomboboxbeforeselect: onBeforeSelect,\n\t\t\t\t\toncomboboxbeforematch: onBeforeMatch,\n\t\t\t\t\toncomboboxafterselect: onAfterSelect,\n\t\t\t\t\tref: innerRef,\n\t\t\t\t\t...props,\n\t\t\t\t})}\n\t\t\t>\n\t\t\t\t{selected?.map(({ children, label, value }) => (\n\t\t\t\t\t<data key={value} value={value} suppressHydrationWarning>\n\t\t\t\t\t\t{children ?? label}\n\t\t\t\t\t</data>\n\t\t\t\t))}\n\t\t\t\t{children || (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<Input\n\t\t\t\t\t\t\taria-required={required}\n\t\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\t\tname={name}\n\t\t\t\t\t\t\tonInput={onInput}\n\t\t\t\t\t\t\tonChange={onChange}\n\t\t\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\t\ttype={type}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<del {...toCustomElementProps({ \"aria-label\": \"Fjern tekst\" })} />\n\t\t\t\t\t</>\n\t\t\t\t)}\n\t\t\t\t{!!options && (\n\t\t\t\t\t<FieldDatalist data-nofilter={nofilter} data-position={position}>\n\t\t\t\t\t\t{options.map(toOption).map(({ children, label, value }) => (\n\t\t\t\t\t\t\t<FieldOption key={value} value={value} label={label}>\n\t\t\t\t\t\t\t\t{children ?? label}\n\t\t\t\t\t\t\t</FieldOption>\n\t\t\t\t\t\t))}\n\t\t\t\t\t</FieldDatalist>\n\t\t\t\t)}\n\t\t\t</u-combobox>\n\t\t);\n\t},\n);\n\nexport type FieldLabelProps = React.ComponentPropsWithoutRef<\"label\">;\nexport const Field = Object.assign(FieldComp, {\n\tAffixes: FieldAffixes,\n\tCombobox: FieldCombobox,\n\tDatalist: FieldDatalist,\n\tOption: FieldOption,\n\tLabel: forwardRef<HTMLLabelElement, FieldLabelProps>(\n\t\tfunction FieldLabel(rest, ref) {\n\t\t\treturn <label suppressHydrationWarning ref={ref} {...rest} />;\n\t\t},\n\t),\n});\n"],"names":["Field","label","FieldAffixes","FieldDatalist","FieldOption","FieldCombobox","children"],"mappings":";;;;;;;;AAyCA,MAAM,WAAW,CAChB,MAEA,OAAO,MAAM,WAAW,EAAE,OAAO,GAAG,OAAO,EAAA,IAAM;AAE3C,MAAM,YAA4B,WAAiB,SAASA,OAGlE;AAAA,EACC,aAAa;AAAA,EACb,mBAAmB;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ,GAAG;AACJ,GACA,KACC;AACD,QAAM,MAAM,MAAM;AAClB,QAAM,UAAU,CAAC,CAAC,UAAU,CAAC,CAAC;AAC9B,QAAM,aAAa,qBAAqB;AACxC,QAAM,SAAS;AAAA,IACd,aAAa;AAAA,IACb,mBAAmB;AAAA,IACnB,WAAW,KAAK,OAAO,OAAO,SAAS;AAAA,IACvC;AAAA,EAAA;AAID,MAAI,OAAO,YA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,oBAAC,eAAA,EAAc,iBAAe,UAAU,iBAAe,UACrD,UAAA,QAAQ,IAAI,QAAQ,EAAE,IAAI,CAAC,EAAE,UAAAA,WAAU,OAAO,MAAA,MAC9C,oBAAC,aAAA,EAAwB,OAAc,OACrC,UAAAA,aAAY,MAAA,GADI,KAElB,CACA,EAAA,CACF;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAIJ;AACD;AAGO,MAAM,QAAQ,OAAO,OAAO,WAAW;AAAA,EAC7C,SAAS;AAAA,EACT,UAAU;AAAA,EACV,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,OAAO;AAAA,IACN,SAAS,WAAW,MAAM,KAAK;AAC9B,iCAAQ,SAAA,EAAM,0BAAwB,MAAC,KAAW,GAAG,MAAM;AAAA,IAC5D;AAAA,EAAA;AAEF,CAAC;"}
|
|
@@ -152,10 +152,12 @@ export declare const WithCharacterCount: Story;
|
|
|
152
152
|
export declare const WithCustomDescriptionTag: Story;
|
|
153
153
|
export declare const WithCombobox: Story;
|
|
154
154
|
export declare const WithComboboxMultiple: Story;
|
|
155
|
+
export declare const WithComboboxCreatable: Story;
|
|
155
156
|
export declare const WithComboboxAPI: Story;
|
|
156
157
|
export declare const WithComboboxCustomFilter: Story;
|
|
157
158
|
export declare const ReactWithCombobox: Story;
|
|
158
159
|
export declare const ReactWithComboboxWithChildren: Story;
|
|
159
160
|
export declare const ReactWithComboboxMultiple: Story;
|
|
161
|
+
export declare const ReactWithComboboxCreatable: Story;
|
|
160
162
|
export declare const ReactWithComboboxLong: Story;
|
|
161
163
|
export declare const ReactWithCombobxCustomFilter: Story;
|
|
@@ -1,20 +1,30 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
const
|
|
4
|
-
|
|
1
|
+
import styles from "../styles.module.css.js";
|
|
2
|
+
import { isBrowser, onLoaded, onMutation, attr, useId, isInputLike } from "../utils.js";
|
|
3
|
+
const CSS_FIELDSET = styles.fieldset.split(" ")[0];
|
|
4
|
+
const CSS_VALIDATION = styles.validation.split(" ")[0];
|
|
5
|
+
const ARIA_DESC = "aria-describedby";
|
|
6
|
+
const ARIA_INVALID = "aria-invalid";
|
|
7
|
+
const FIELDSETS = isBrowser() ? document.getElementsByClassName(CSS_FIELDSET) : [];
|
|
8
|
+
function handleFieldsetMutation() {
|
|
5
9
|
setTimeout(() => {
|
|
6
|
-
for (const
|
|
7
|
-
if (
|
|
8
|
-
const
|
|
9
|
-
let
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
for (const fieldset of FIELDSETS)
|
|
11
|
+
if (fieldset.isConnected) {
|
|
12
|
+
const inputs = [];
|
|
13
|
+
let validId = null;
|
|
14
|
+
let valid = true;
|
|
15
|
+
for (const el of fieldset.getElementsByTagName("*")) {
|
|
16
|
+
if (el.classList.contains(CSS_VALIDATION)) {
|
|
17
|
+
valid = attr(el, "data-color") === "success" || !el.clientHeight;
|
|
18
|
+
validId = useId(el);
|
|
19
|
+
} else if (isInputLike(el)) inputs.push(el);
|
|
20
|
+
}
|
|
21
|
+
for (const input of inputs) {
|
|
22
|
+
const desc = attr(input, ARIA_DESC)?.replace(validId || "#", "");
|
|
23
|
+
attr(input, ARIA_DESC, `${validId || ""} ${desc || ""}`.trim());
|
|
24
|
+
attr(input, ARIA_INVALID, `${!valid}`);
|
|
15
25
|
}
|
|
16
26
|
}
|
|
17
27
|
});
|
|
18
28
|
}
|
|
19
|
-
|
|
29
|
+
onLoaded(() => [onMutation(handleFieldsetMutation, "class")]);
|
|
20
30
|
//# sourceMappingURL=fieldset-observer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fieldset-observer.js","sources":["../../designsystem/fieldset/fieldset-observer.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport {\n\tattr,\n\
|
|
1
|
+
{"version":3,"file":"fieldset-observer.js","sources":["../../designsystem/fieldset/fieldset-observer.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport {\n\tattr,\n\tisBrowser,\n\tisInputLike,\n\tonLoaded,\n\tonMutation,\n\tuseId,\n} from \"../utils\";\n\nconst CSS_FIELDSET = styles.fieldset.split(\" \")[0];\nconst CSS_VALIDATION = styles.validation.split(\" \")[0];\nconst ARIA_DESC = \"aria-describedby\";\nconst ARIA_INVALID = \"aria-invalid\";\nconst FIELDSETS = isBrowser()\n\t? document.getElementsByClassName(CSS_FIELDSET)\n\t: [];\n\n// Using setTimeout to ensure it runs after field-observer\nfunction handleFieldsetMutation() {\n\tsetTimeout(() => {\n\t\tfor (const fieldset of FIELDSETS)\n\t\t\tif (fieldset.isConnected) {\n\t\t\t\tconst inputs: HTMLInputElement[] = [];\n\t\t\t\tlet validId: string | null = null;\n\t\t\t\tlet valid = true;\n\n\t\t\t\tfor (const el of fieldset.getElementsByTagName(\"*\")) {\n\t\t\t\t\tif (el.classList.contains(CSS_VALIDATION)) {\n\t\t\t\t\t\tvalid = attr(el, \"data-color\") === \"success\" || !el.clientHeight; // Only set invalid if Validation is visible\n\t\t\t\t\t\tvalidId = useId(el);\n\t\t\t\t\t} else if (isInputLike(el)) inputs.push(el);\n\t\t\t\t}\n\n\t\t\t\tfor (const input of inputs) {\n\t\t\t\t\tconst desc = attr(input, ARIA_DESC)?.replace(validId || \"#\", \"\");\n\n\t\t\t\t\tattr(input, ARIA_DESC, `${validId || \"\"} ${desc || \"\"}`.trim());\n\t\t\t\t\tattr(input, ARIA_INVALID, `${!valid}`);\n\t\t\t\t}\n\t\t\t}\n\t});\n}\n\nonLoaded(() => [onMutation(handleFieldsetMutation, \"class\")]);\n"],"names":[],"mappings":";;AAUA,MAAM,eAAe,OAAO,SAAS,MAAM,GAAG,EAAE,CAAC;AACjD,MAAM,iBAAiB,OAAO,WAAW,MAAM,GAAG,EAAE,CAAC;AACrD,MAAM,YAAY;AAClB,MAAM,eAAe;AACrB,MAAM,YAAY,UAAA,IACf,SAAS,uBAAuB,YAAY,IAC5C,CAAA;AAGH,SAAS,yBAAyB;AACjC,aAAW,MAAM;AAChB,eAAW,YAAY;AACtB,UAAI,SAAS,aAAa;AACzB,cAAM,SAA6B,CAAA;AACnC,YAAI,UAAyB;AAC7B,YAAI,QAAQ;AAEZ,mBAAW,MAAM,SAAS,qBAAqB,GAAG,GAAG;AACpD,cAAI,GAAG,UAAU,SAAS,cAAc,GAAG;AAC1C,oBAAQ,KAAK,IAAI,YAAY,MAAM,aAAa,CAAC,GAAG;AACpD,sBAAU,MAAM,EAAE;AAAA,UACnB,WAAW,YAAY,EAAE,EAAG,QAAO,KAAK,EAAE;AAAA,QAC3C;AAEA,mBAAW,SAAS,QAAQ;AAC3B,gBAAM,OAAO,KAAK,OAAO,SAAS,GAAG,QAAQ,WAAW,KAAK,EAAE;AAE/D,eAAK,OAAO,WAAW,GAAG,WAAW,EAAE,IAAI,QAAQ,EAAE,GAAG,KAAA,CAAM;AAC9D,eAAK,OAAO,cAAc,GAAG,CAAC,KAAK,EAAE;AAAA,QACtC;AAAA,MACD;AAAA,EACF,CAAC;AACF;AAEA,SAAS,MAAM,CAAC,WAAW,wBAAwB,OAAO,CAAC,CAAC;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export type FieldsetProps = React.ComponentPropsWithoutRef<"fieldset">;
|
|
2
|
-
export declare const Fieldset:
|
|
2
|
+
export declare const Fieldset: import('react').ForwardRefExoticComponent<Omit<import('react').DetailedHTMLProps<import('react').FieldsetHTMLAttributes<HTMLFieldSetElement>, HTMLFieldSetElement>, "ref"> & import('react').RefAttributes<HTMLFieldSetElement>>;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { jsx
|
|
2
|
-
import
|
|
3
|
-
import { forwardRef
|
|
4
|
-
import
|
|
5
|
-
const
|
|
6
|
-
function({ className
|
|
7
|
-
return /* @__PURE__ */
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import clsx from "clsx";
|
|
3
|
+
import { forwardRef } from "react";
|
|
4
|
+
import styles from "../styles.module.css.js";
|
|
5
|
+
const Fieldset = forwardRef(
|
|
6
|
+
function Fieldset2({ className, ...rest }, ref) {
|
|
7
|
+
return /* @__PURE__ */ jsx(
|
|
8
8
|
"fieldset",
|
|
9
9
|
{
|
|
10
|
-
className:
|
|
11
|
-
ref
|
|
12
|
-
...
|
|
10
|
+
className: clsx(styles.fieldset, className),
|
|
11
|
+
ref,
|
|
12
|
+
...rest
|
|
13
13
|
}
|
|
14
14
|
);
|
|
15
15
|
}
|
|
16
16
|
);
|
|
17
17
|
export {
|
|
18
|
-
|
|
18
|
+
Fieldset
|
|
19
19
|
};
|
|
20
20
|
//# sourceMappingURL=fieldset.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fieldset.js","sources":["../../designsystem/fieldset/fieldset.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport { forwardRef } from \"react\";\nimport styles from \"../styles.module.css\";\n\nexport type FieldsetProps = React.ComponentPropsWithoutRef<\"fieldset\">;\n\nexport const Fieldset = forwardRef<HTMLFieldSetElement, FieldsetProps>(\n\tfunction Fieldset({ className, ...rest }, ref) {\n\t\treturn (\n\t\t\t<fieldset\n\t\t\t\tclassName={clsx(styles.fieldset, className)}\n\t\t\t\tref={ref}\n\t\t\t\t{...rest}\n\t\t\t/>\n\t\t);\n\t},\n);\n"],"names":["Fieldset"
|
|
1
|
+
{"version":3,"file":"fieldset.js","sources":["../../designsystem/fieldset/fieldset.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport { forwardRef } from \"react\";\nimport styles from \"../styles.module.css\";\n\nexport type FieldsetProps = React.ComponentPropsWithoutRef<\"fieldset\">;\n\nexport const Fieldset = forwardRef<HTMLFieldSetElement, FieldsetProps>(\n\tfunction Fieldset({ className, ...rest }, ref) {\n\t\treturn (\n\t\t\t<fieldset\n\t\t\t\tclassName={clsx(styles.fieldset, className)}\n\t\t\t\tref={ref}\n\t\t\t\t{...rest}\n\t\t\t/>\n\t\t);\n\t},\n);\n"],"names":["Fieldset"],"mappings":";;;;AAMO,MAAM,WAAW;AAAA,EACvB,SAASA,UAAS,EAAE,WAAW,GAAG,KAAA,GAAQ,KAAK;AAC9C,WACC;AAAA,MAAC;AAAA,MAAA;AAAA,QACA,WAAW,KAAK,OAAO,UAAU,SAAS;AAAA,QAC1C;AAAA,QACC,GAAG;AAAA,MAAA;AAAA,IAAA;AAAA,EAGP;AACD;"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { jsx
|
|
2
|
-
import
|
|
3
|
-
import { forwardRef
|
|
4
|
-
import
|
|
5
|
-
const
|
|
6
|
-
function({ as
|
|
7
|
-
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import clsx from "clsx";
|
|
3
|
+
import { forwardRef } from "react";
|
|
4
|
+
import styles from "../styles.module.css.js";
|
|
5
|
+
const Fileupload = forwardRef(
|
|
6
|
+
function Fileupload2({ as, className, ...rest }, ref) {
|
|
7
|
+
const Tag = as || "label";
|
|
8
|
+
return /* @__PURE__ */ jsx(Tag, { className: clsx(styles.fileupload, className), ref, ...rest });
|
|
8
9
|
}
|
|
9
10
|
);
|
|
10
11
|
export {
|
|
11
|
-
|
|
12
|
+
Fileupload
|
|
12
13
|
};
|
|
13
14
|
//# sourceMappingURL=fileupload.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileupload.js","sources":["../../designsystem/fileupload/fileupload.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport { forwardRef, type JSX } from \"react\";\nimport type {\n\tPolymorphicComponentPropWithRef,\n\tPolymorphicRef,\n} from \"../react-types\";\nimport styles from \"../styles.module.css\";\n\nexport type FileuploadProps<As extends React.ElementType = \"label\"> =\n\tPolymorphicComponentPropWithRef<As>;\n\ntype FileuploadComponent = <As extends React.ElementType = \"label\">(\n\tprops: FileuploadProps<As>,\n) => JSX.Element;\n\nexport const Fileupload: FileuploadComponent = forwardRef<null>(\n\tfunction Fileupload<As extends React.ElementType = \"label\">(\n\t\t{ as, className, ...rest }: FileuploadProps<As>,\n\t\tref?: PolymorphicRef<As>,\n\t) {\n\t\tconst Tag = as || \"label\";\n\n\t\treturn (\n\t\t\t<Tag className={clsx(styles.fileupload, className)} ref={ref} {...rest} />\n\t\t);\n\t},\n) as FileuploadComponent; // Needed to tell Typescript this does not return ReactNode but acutally JSX.Element\n"],"names":["Fileupload"
|
|
1
|
+
{"version":3,"file":"fileupload.js","sources":["../../designsystem/fileupload/fileupload.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport { forwardRef, type JSX } from \"react\";\nimport type {\n\tPolymorphicComponentPropWithRef,\n\tPolymorphicRef,\n} from \"../react-types\";\nimport styles from \"../styles.module.css\";\n\nexport type FileuploadProps<As extends React.ElementType = \"label\"> =\n\tPolymorphicComponentPropWithRef<As>;\n\ntype FileuploadComponent = <As extends React.ElementType = \"label\">(\n\tprops: FileuploadProps<As>,\n) => JSX.Element;\n\nexport const Fileupload: FileuploadComponent = forwardRef<null>(\n\tfunction Fileupload<As extends React.ElementType = \"label\">(\n\t\t{ as, className, ...rest }: FileuploadProps<As>,\n\t\tref?: PolymorphicRef<As>,\n\t) {\n\t\tconst Tag = as || \"label\";\n\n\t\treturn (\n\t\t\t<Tag className={clsx(styles.fileupload, className)} ref={ref} {...rest} />\n\t\t);\n\t},\n) as FileuploadComponent; // Needed to tell Typescript this does not return ReactNode but acutally JSX.Element\n"],"names":["Fileupload"],"mappings":";;;;AAeO,MAAM,aAAkC;AAAA,EAC9C,SAASA,YACR,EAAE,IAAI,WAAW,GAAG,KAAA,GACpB,KACC;AACD,UAAM,MAAM,MAAM;AAElB,WACC,oBAAC,KAAA,EAAI,WAAW,KAAK,OAAO,YAAY,SAAS,GAAG,KAAW,GAAG,KAAA,CAAM;AAAA,EAE1E;AACD;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export type HelpTextProps = React.ComponentPropsWithoutRef<"button">;
|
|
2
|
-
export declare const HelpText:
|
|
2
|
+
export declare const HelpText: import('react').ForwardRefExoticComponent<Omit<import('react').DetailedHTMLProps<import('react').ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & import('react').RefAttributes<HTMLButtonElement>>;
|