@helsenorge/designsystem-react 7.0.0-beta.2 → 7.0.0-beta.6
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/CHANGELOG.md +27 -0
- package/__mocks__/usePseudoClasses.d.ts +1 -0
- package/__mocks__/usePseudoClasses.js +5 -0
- package/__mocks__/usePseudoClasses.js.map +1 -0
- package/components/AnchorLink/AnchorLink.d.ts +2 -1
- package/components/AnchorLink/AnchorLink.js.map +1 -1
- package/components/Badge/Badge.stories.d.ts +1 -1
- package/components/Button/Button.d.ts +2 -1
- package/components/Button/Button.js +88 -88
- package/components/Button/Button.js.map +1 -1
- package/components/Button/Button.stories.d.ts +2 -1
- package/components/Button/styles.module.scss +4 -0
- package/components/Button/styles.module.scss.d.ts +1 -0
- package/components/Checkbox/Checkbox.d.ts +2 -0
- package/components/Checkbox/Checkbox.js +72 -70
- package/components/Checkbox/Checkbox.js.map +1 -1
- package/components/Dropdown/Dropdown.d.ts +2 -0
- package/components/Dropdown/Dropdown.js +32 -31
- package/components/Dropdown/Dropdown.js.map +1 -1
- package/components/ErrorWrapper/ErrorWrapper.d.ts +4 -2
- package/components/ErrorWrapper/ErrorWrapper.js +7 -7
- package/components/ErrorWrapper/ErrorWrapper.js.map +1 -1
- package/components/Expander/Expander.d.ts +4 -0
- package/components/Expander/Expander.js +34 -31
- package/components/Expander/Expander.js.map +1 -1
- package/components/ExpanderHierarchy/expander.module.scss +0 -20
- package/components/ExpanderHierarchy/expander.module.scss.d.ts +0 -1
- package/components/ExpanderList/ExpanderList.d.ts +4 -0
- package/components/ExpanderList/ExpanderList.js +78 -75
- package/components/ExpanderList/ExpanderList.js.map +1 -1
- package/components/ExpanderList/ExpanderList.stories.d.ts +1 -1
- package/components/FormExample/FormExample.js +136 -216
- package/components/FormExample/FormExample.js.map +1 -1
- package/components/FormGroup/FormGroup.d.ts +2 -0
- package/components/FormGroup/FormGroup.js +62 -48
- package/components/FormGroup/FormGroup.js.map +1 -1
- package/components/FormGroup/FormGroup.stories.d.ts +1 -0
- package/components/FormLayout/styles.module.scss +1 -2
- package/components/GridExample/GridExample.js +1 -1
- package/components/GridExample/GridExample.js.map +1 -1
- package/components/HelpQuestion/styles.module.scss +3 -3
- package/components/Icon/Icon.stories.d.ts +5 -2
- package/components/Input/Input.d.ts +2 -0
- package/components/Input/Input.js +75 -74
- package/components/Input/Input.js.map +1 -1
- package/components/Input/Input.stories.d.ts +2 -2
- package/components/LinkList/LinkList.stories.d.ts +1 -1
- package/components/Loader/Loader.stories.d.ts +1 -1
- package/components/Logo/Logo.stories.d.ts +1 -1
- package/components/NotificationPanel/DetailButton/styles.module.scss +1 -1
- package/components/PopMenu/PopMenu.js +73 -61
- package/components/PopMenu/PopMenu.js.map +1 -1
- package/components/PopOver/PopOver.d.ts +2 -0
- package/components/PopOver/PopOver.js +37 -36
- package/components/PopOver/PopOver.js.map +1 -1
- package/components/RadioButton/RadioButton.d.ts +2 -0
- package/components/RadioButton/RadioButton.js +62 -60
- package/components/RadioButton/RadioButton.js.map +1 -1
- package/components/Select/Select.d.ts +2 -0
- package/components/Select/Select.js +40 -39
- package/components/Select/Select.js.map +1 -1
- package/components/SharingStatus/styles.module.scss +2 -0
- package/components/Textarea/Textarea.d.ts +4 -0
- package/components/Textarea/Textarea.js +70 -67
- package/components/Textarea/Textarea.js.map +1 -1
- package/components/Trigger/styles.module.scss +24 -4
- package/components/Validation/ErrorList.d.ts +7 -0
- package/components/Validation/ErrorList.js +8 -0
- package/components/Validation/ErrorList.js.map +1 -0
- package/components/Validation/ErrorListItem.d.ts +8 -0
- package/components/Validation/ErrorListItem.js +12 -0
- package/components/Validation/ErrorListItem.js.map +1 -0
- package/components/Validation/Validation.d.ts +9 -1
- package/components/Validation/Validation.js +15 -13
- package/components/Validation/Validation.js.map +1 -1
- package/components/Validation/ValidationSummary.d.ts +15 -0
- package/components/Validation/ValidationSummary.js +17 -0
- package/components/Validation/ValidationSummary.js.map +1 -0
- package/components/Validation/styles.module.scss +13 -5
- package/components/Validation/styles.module.scss.d.ts +4 -1
- package/components/Validation/types.d.ts +9 -0
- package/constants.d.ts +1 -0
- package/constants.js +1 -1
- package/constants.js.map +1 -1
- package/fonts/source-sans-pro-200-extralight.woff +0 -0
- package/fonts/source-sans-pro-200-extralight.woff2 +0 -0
- package/fonts/source-sans-pro-300-light.woff +0 -0
- package/fonts/source-sans-pro-300-light.woff2 +0 -0
- package/fonts/source-sans-pro-400-regular.woff +0 -0
- package/fonts/source-sans-pro-400-regular.woff2 +0 -0
- package/fonts/source-sans-pro-600-semibold.woff +0 -0
- package/fonts/source-sans-pro-600-semibold.woff2 +0 -0
- package/fonts/source-sans-pro-700-bold.woff +0 -0
- package/fonts/source-sans-pro-700-bold.woff2 +0 -0
- package/fonts/source-sans-pro-900-black.woff +0 -0
- package/fonts/source-sans-pro-900-black.woff2 +0 -0
- package/package.json +3 -3
- package/scss/_icon.scss +8 -0
- package/utils/tests/setup-test.d.ts +1 -0
|
@@ -1,241 +1,161 @@
|
|
|
1
1
|
import e from "react";
|
|
2
|
-
import { useForm as
|
|
3
|
-
import { isTest as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
2
|
+
import { useForm as h } from "react-hook-form";
|
|
3
|
+
import { isTest as q } from "../../utils/environment.js";
|
|
4
|
+
import H from "../Button/Button.js";
|
|
5
|
+
import s from "../Checkbox/Checkbox.js";
|
|
6
|
+
import a from "../FormGroup/FormGroup.js";
|
|
7
|
+
import w, { FormLayoutColumns as C } from "../FormLayout/FormLayout.js";
|
|
8
|
+
import L from "../Icons/Hospital.js";
|
|
9
|
+
import B from "../Input/Input.js";
|
|
10
|
+
import n from "../Label/Label.js";
|
|
11
|
+
import p from "../RadioButton/RadioButton.js";
|
|
12
|
+
import N from "../Select/Select.js";
|
|
13
|
+
import R from "../Spacer/Spacer.js";
|
|
14
|
+
import G from "../Textarea/Textarea.js";
|
|
15
15
|
import _ from "../Validation/Validation.js";
|
|
16
|
-
var j = /* @__PURE__ */ ((
|
|
17
|
-
const
|
|
16
|
+
var j = /* @__PURE__ */ ((t) => (t.formgroup = "formgroup", t.checkbox = "checkbox", t.radiobutton = "radiobutton", t.textarea = "textarea", t.input = "input", t.select = "select", t))(j || {});
|
|
17
|
+
const P = (t) => {
|
|
18
18
|
const {
|
|
19
|
-
exampleType:
|
|
19
|
+
exampleType: l = "formgroup"
|
|
20
20
|
/* formgroup */
|
|
21
|
-
} =
|
|
22
|
-
register:
|
|
23
|
-
handleSubmit:
|
|
24
|
-
formState: { errors:
|
|
25
|
-
} =
|
|
26
|
-
|
|
21
|
+
} = t, {
|
|
22
|
+
register: o,
|
|
23
|
+
handleSubmit: z,
|
|
24
|
+
formState: { errors: r }
|
|
25
|
+
} = h(), i = /* @__PURE__ */ new Date();
|
|
26
|
+
i.setHours(0), i.setMinutes(0), i.setSeconds(0);
|
|
27
27
|
const c = /* @__PURE__ */ new Date();
|
|
28
|
-
c.setDate(
|
|
28
|
+
c.setDate(i.getDate() - 5), c.setHours(6), c.setMinutes(10), c.setSeconds(0);
|
|
29
29
|
const u = /* @__PURE__ */ new Date();
|
|
30
|
-
u.setDate(
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
),
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
/* @__PURE__ */ e.createElement(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
{
|
|
99
|
-
inputId: "radiobutton1",
|
|
100
|
-
label: /* @__PURE__ */ e.createElement(i, { labelTexts: [{ text: "Radiobutton 1" }] }),
|
|
101
|
-
...l(b, { required: o })
|
|
102
|
-
}
|
|
103
|
-
), /* @__PURE__ */ e.createElement(
|
|
104
|
-
x,
|
|
105
|
-
{
|
|
106
|
-
inputId: "radiobutton2",
|
|
107
|
-
label: /* @__PURE__ */ e.createElement(i, { labelTexts: [{ text: "Radiobutton 2" }] }),
|
|
108
|
-
...l(b, { required: o })
|
|
109
|
-
}
|
|
110
|
-
), /* @__PURE__ */ e.createElement(
|
|
111
|
-
x,
|
|
112
|
-
{
|
|
113
|
-
inputId: "radiobutton3",
|
|
114
|
-
label: /* @__PURE__ */ e.createElement(i, { labelTexts: [{ text: "Radiobutton 3" }] }),
|
|
115
|
-
...l(b, { required: o })
|
|
116
|
-
}
|
|
117
|
-
)),
|
|
118
|
-
/* @__PURE__ */ e.createElement(m, { key: 3, error: t.field4 ? t.field4.message : void 0 }, /* @__PURE__ */ e.createElement(
|
|
119
|
-
I,
|
|
120
|
-
{
|
|
121
|
-
defaultValue: `Dette er en test
|
|
30
|
+
u.setDate(i.getDate() + 5), u.setHours(22), u.setMinutes(0), u.setSeconds(0);
|
|
31
|
+
const d = "Du må velge minst én farge", I = "Du må velge minst to størrelser", g = "Du må velge minst én plassering", y = "Historien må være på maks 40 tegn", D = "Navn må fylles ut", F = 'Du må velge "Frankenstein"', E = (m) => m.length >= 2 || I, k = (m) => m.toString() === "Frankenstein" || F, x = () => /* @__PURE__ */ e.createElement(
|
|
32
|
+
a,
|
|
33
|
+
{
|
|
34
|
+
title: "FormGroup-tittel",
|
|
35
|
+
legend: "Farge",
|
|
36
|
+
error: r.colour ? r.colour.message : void 0,
|
|
37
|
+
errorTextId: "error",
|
|
38
|
+
size: t.size
|
|
39
|
+
},
|
|
40
|
+
/* @__PURE__ */ e.createElement(w, { maxColumns: C.two }, /* @__PURE__ */ e.createElement(
|
|
41
|
+
s,
|
|
42
|
+
{
|
|
43
|
+
inputId: "colour1",
|
|
44
|
+
label: /* @__PURE__ */ e.createElement(n, { labelTexts: [{ text: "Blueberry" }] }),
|
|
45
|
+
...o("colour", { required: d })
|
|
46
|
+
}
|
|
47
|
+
), /* @__PURE__ */ e.createElement(
|
|
48
|
+
s,
|
|
49
|
+
{
|
|
50
|
+
inputId: "colour2",
|
|
51
|
+
label: /* @__PURE__ */ e.createElement(n, { labelTexts: [{ text: "Cherry" }] }),
|
|
52
|
+
...o("colour", { required: d })
|
|
53
|
+
}
|
|
54
|
+
), /* @__PURE__ */ e.createElement(
|
|
55
|
+
s,
|
|
56
|
+
{
|
|
57
|
+
inputId: "colour3",
|
|
58
|
+
label: /* @__PURE__ */ e.createElement(n, { labelTexts: [{ text: "Neutral" }] }),
|
|
59
|
+
...o("colour", { required: d })
|
|
60
|
+
}
|
|
61
|
+
))
|
|
62
|
+
), S = () => /* @__PURE__ */ e.createElement(a, { legend: "Størrelser", error: r.sizes ? r.sizes.message : void 0, size: t.size, errorTextId: "error1" }, /* @__PURE__ */ e.createElement(s, { inputId: "sizes1", label: /* @__PURE__ */ e.createElement(n, { labelTexts: [{ text: "Small" }] }), ...o("sizes", { validate: E }) }), /* @__PURE__ */ e.createElement(s, { inputId: "sizes2", label: /* @__PURE__ */ e.createElement(n, { labelTexts: [{ text: "Medium" }] }), ...o("sizes", { validate: E }) }), /* @__PURE__ */ e.createElement(s, { inputId: "sizes3", label: /* @__PURE__ */ e.createElement(n, { labelTexts: [{ text: "Large" }] }), ...o("sizes", { validate: E }) })), b = () => /* @__PURE__ */ e.createElement(
|
|
63
|
+
a,
|
|
64
|
+
{
|
|
65
|
+
legend: "Plassering",
|
|
66
|
+
error: r.positions ? r.positions.message : void 0,
|
|
67
|
+
size: t.size,
|
|
68
|
+
errorTextId: "error2"
|
|
69
|
+
},
|
|
70
|
+
/* @__PURE__ */ e.createElement(
|
|
71
|
+
p,
|
|
72
|
+
{
|
|
73
|
+
inputId: "positions1",
|
|
74
|
+
label: /* @__PURE__ */ e.createElement(n, { labelTexts: [{ text: "Venstre" }] }),
|
|
75
|
+
...o("positions", { required: g })
|
|
76
|
+
}
|
|
77
|
+
),
|
|
78
|
+
/* @__PURE__ */ e.createElement(
|
|
79
|
+
p,
|
|
80
|
+
{
|
|
81
|
+
inputId: "positions2",
|
|
82
|
+
label: /* @__PURE__ */ e.createElement(n, { labelTexts: [{ text: "Høyre" }] }),
|
|
83
|
+
...o("positions", { required: g })
|
|
84
|
+
}
|
|
85
|
+
),
|
|
86
|
+
/* @__PURE__ */ e.createElement(
|
|
87
|
+
p,
|
|
88
|
+
{
|
|
89
|
+
inputId: "positions3",
|
|
90
|
+
label: /* @__PURE__ */ e.createElement(n, { labelTexts: [{ text: "Midten" }] }),
|
|
91
|
+
...o("positions", { required: g })
|
|
92
|
+
}
|
|
93
|
+
)
|
|
94
|
+
), f = () => /* @__PURE__ */ e.createElement(a, { error: r.story ? r.story.message : void 0, errorTextId: "error3" }, /* @__PURE__ */ e.createElement(
|
|
95
|
+
G,
|
|
96
|
+
{
|
|
97
|
+
defaultValue: `Dette er en test
|
|
122
98
|
|
|
123
99
|
Hello
|
|
124
100
|
|
|
125
101
|
test
|
|
126
102
|
|
|
127
103
|
test test`,
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
)),
|
|
145
|
-
/* @__PURE__ */ e.createElement(m, { key: 5, size: r.size, error: t.field6 ? t.field6.message : void 0 }, /* @__PURE__ */ e.createElement(
|
|
146
|
-
z,
|
|
147
|
-
{
|
|
148
|
-
label: /* @__PURE__ */ e.createElement(i, { labelTexts: [{ text: "Skriv inn din tekst", type: "semibold" }] }),
|
|
149
|
-
...l(v, { validate: y })
|
|
150
|
-
},
|
|
151
|
-
/* @__PURE__ */ e.createElement("option", { value: "Option 1" }, "Option 1"),
|
|
152
|
-
/* @__PURE__ */ e.createElement("option", { value: "Option 2" }, "Option 2"),
|
|
153
|
-
/* @__PURE__ */ e.createElement("option", { value: "Option 3" }, "Option 3")
|
|
154
|
-
))
|
|
155
|
-
];
|
|
156
|
-
} else {
|
|
157
|
-
if (s === "checkbox")
|
|
158
|
-
return /* @__PURE__ */ e.createElement(
|
|
159
|
-
a,
|
|
160
|
-
{
|
|
161
|
-
inputId: "checkbox1",
|
|
162
|
-
label: /* @__PURE__ */ e.createElement(i, { labelTexts: [{ text: "Checkbox 1" }] }),
|
|
163
|
-
errorText: t.field1 ? t.field1.message : void 0,
|
|
164
|
-
size: r.size,
|
|
165
|
-
...l(f, { required: o })
|
|
166
|
-
}
|
|
167
|
-
);
|
|
168
|
-
if (s === "radiobutton")
|
|
169
|
-
return /* @__PURE__ */ e.createElement(
|
|
170
|
-
x,
|
|
171
|
-
{
|
|
172
|
-
inputId: "radiobutton1",
|
|
173
|
-
label: /* @__PURE__ */ e.createElement(i, { labelTexts: [{ text: "Radiobutton 1" }] }),
|
|
174
|
-
errorText: t.field3 ? t.field3.message : void 0,
|
|
175
|
-
size: r.size,
|
|
176
|
-
...l(b, { required: o })
|
|
177
|
-
}
|
|
178
|
-
);
|
|
179
|
-
if (s === "textarea")
|
|
180
|
-
return /* @__PURE__ */ e.createElement(
|
|
181
|
-
I,
|
|
182
|
-
{
|
|
183
|
-
defaultValue: `Dette er min historie
|
|
184
|
-
|
|
185
|
-
Hello
|
|
186
|
-
|
|
187
|
-
test`,
|
|
188
|
-
grow: !0,
|
|
189
|
-
maxCharacters: 40,
|
|
190
|
-
minRows: 5,
|
|
191
|
-
errorText: t.field4 ? t.field4.message : void 0,
|
|
192
|
-
label: /* @__PURE__ */ e.createElement(i, { labelTexts: [{ text: "Skriv din historie her", type: "semibold" }] }),
|
|
193
|
-
textareaId: "textarea1",
|
|
194
|
-
...l(k, { maxLength: { value: 40, message: h } })
|
|
195
|
-
}
|
|
196
|
-
);
|
|
197
|
-
if (s === "input")
|
|
198
|
-
return /* @__PURE__ */ e.createElement(
|
|
199
|
-
D,
|
|
200
|
-
{
|
|
201
|
-
inputId: "input1",
|
|
202
|
-
label: /* @__PURE__ */ e.createElement(i, { labelTexts: [{ text: "Skriv inn din tekst", type: "semibold" }] }),
|
|
203
|
-
placeholder: "Skriv noe!",
|
|
204
|
-
errorText: t.field5 ? t.field5.message : void 0,
|
|
205
|
-
icon: S,
|
|
206
|
-
...l(g, { required: T })
|
|
207
|
-
}
|
|
208
|
-
);
|
|
209
|
-
if (s === "select")
|
|
210
|
-
return /* @__PURE__ */ e.createElement(
|
|
211
|
-
z,
|
|
212
|
-
{
|
|
213
|
-
errorText: t.field6 ? t.field6.message : void 0,
|
|
214
|
-
label: /* @__PURE__ */ e.createElement(i, { labelTexts: [{ text: "Skriv inn din tekst", type: "semibold" }] }),
|
|
215
|
-
...l(v, { validate: y })
|
|
216
|
-
},
|
|
217
|
-
/* @__PURE__ */ e.createElement("option", { value: "Option 1" }, "Option 1"),
|
|
218
|
-
/* @__PURE__ */ e.createElement("option", { value: "Option 2" }, "Option 2"),
|
|
219
|
-
/* @__PURE__ */ e.createElement("option", { value: "Option 3" }, "Option 3")
|
|
220
|
-
);
|
|
104
|
+
grow: !0,
|
|
105
|
+
maxCharacters: 40,
|
|
106
|
+
minRows: 5,
|
|
107
|
+
label: /* @__PURE__ */ e.createElement(n, { labelTexts: [{ text: "Historie", type: "semibold" }] }),
|
|
108
|
+
textareaId: "story",
|
|
109
|
+
...o("story", { maxLength: { value: 40, message: y } })
|
|
110
|
+
}
|
|
111
|
+
)), T = () => /* @__PURE__ */ e.createElement(a, { size: t.size, error: r.name ? r.name.message : void 0, errorTextId: "error4" }, /* @__PURE__ */ e.createElement(
|
|
112
|
+
B,
|
|
113
|
+
{
|
|
114
|
+
label: /* @__PURE__ */ e.createElement(n, { labelTexts: [{ text: "Navn", type: "semibold" }] }),
|
|
115
|
+
placeholder: "Skriv noe!",
|
|
116
|
+
icon: L,
|
|
117
|
+
inputId: "name",
|
|
118
|
+
...o("name", { required: D })
|
|
221
119
|
}
|
|
120
|
+
)), v = () => /* @__PURE__ */ e.createElement(a, { size: t.size, error: r.monster ? r.monster.message : void 0, errorTextId: "error5" }, /* @__PURE__ */ e.createElement(
|
|
121
|
+
N,
|
|
122
|
+
{
|
|
123
|
+
selectId: "monster",
|
|
124
|
+
label: /* @__PURE__ */ e.createElement(n, { labelTexts: [{ text: "Velg et monster", type: "semibold" }] }),
|
|
125
|
+
...o("monster", { validate: k })
|
|
126
|
+
},
|
|
127
|
+
/* @__PURE__ */ e.createElement("option", { value: "Troll" }, "Troll"),
|
|
128
|
+
/* @__PURE__ */ e.createElement("option", { value: "Frankenstein" }, "Frankenstein")
|
|
129
|
+
)), M = () => {
|
|
130
|
+
if (l === "formgroup")
|
|
131
|
+
return /* @__PURE__ */ e.createElement(e.Fragment, null, x(), S(), b(), f(), T(), v());
|
|
132
|
+
if (l === "checkbox")
|
|
133
|
+
return /* @__PURE__ */ e.createElement(e.Fragment, null, x());
|
|
134
|
+
if (l === "radiobutton")
|
|
135
|
+
return /* @__PURE__ */ e.createElement(e.Fragment, null, b());
|
|
136
|
+
if (l === "textarea")
|
|
137
|
+
return /* @__PURE__ */ e.createElement(e.Fragment, null, f());
|
|
138
|
+
if (l === "input")
|
|
139
|
+
return /* @__PURE__ */ e.createElement(e.Fragment, null, T());
|
|
140
|
+
if (l === "select")
|
|
141
|
+
return /* @__PURE__ */ e.createElement(e.Fragment, null, v());
|
|
222
142
|
};
|
|
223
143
|
return /* @__PURE__ */ e.createElement(
|
|
224
144
|
"form",
|
|
225
145
|
{
|
|
226
146
|
noValidate: !0,
|
|
227
|
-
onSubmit:
|
|
228
|
-
!
|
|
147
|
+
onSubmit: z((m) => {
|
|
148
|
+
!q() && console.log(m);
|
|
229
149
|
})
|
|
230
150
|
},
|
|
231
|
-
/* @__PURE__ */ e.createElement(_, { size:
|
|
232
|
-
/* @__PURE__ */ e.createElement(
|
|
233
|
-
/* @__PURE__ */ e.createElement(
|
|
151
|
+
/* @__PURE__ */ e.createElement(_, { size: t.size, errorTitle: "Sjekk at alt er riktig utfylt:", errors: r }, M()),
|
|
152
|
+
/* @__PURE__ */ e.createElement(R, null),
|
|
153
|
+
/* @__PURE__ */ e.createElement(H, { type: "submit" }, "Send inn")
|
|
234
154
|
);
|
|
235
|
-
},
|
|
155
|
+
}, oe = P;
|
|
236
156
|
export {
|
|
237
|
-
|
|
157
|
+
P as FormExample,
|
|
238
158
|
j as FormExampleVariants,
|
|
239
|
-
|
|
159
|
+
oe as default
|
|
240
160
|
};
|
|
241
161
|
//# sourceMappingURL=FormExample.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormExample.js","sources":["../../../src/components/FormExample/FormExample.tsx"],"sourcesContent":["import React from 'react';\n\nimport { useForm } from 'react-hook-form';\n\nimport { FormSize } from '../../constants';\nimport { isTest } from '../../utils/environment';\nimport Button from '../Button';\nimport Checkbox from '../Checkbox';\nimport FormGroup from '../FormGroup/FormGroup';\nimport FormLayout, { FormLayoutColumns } from '../FormLayout';\nimport Hospital from '../Icons/Hospital';\nimport Input from '../Input';\nimport Label from '../Label';\nimport RadioButton from '../RadioButton';\nimport Select from '../Select';\nimport Spacer from '../Spacer';\nimport Textarea from '../Textarea';\nimport Validation from '../Validation';\n\nexport interface FormExampleProps {\n exampleType: FormExampleVariants;\n size?: keyof typeof FormSize;\n}\n\nexport enum FormExampleVariants {\n formgroup = 'formgroup',\n checkbox = 'checkbox',\n radiobutton = 'radiobutton',\n textarea = 'textarea',\n input = 'input',\n select = 'select',\n}\n\nexport const FormExample = (props: FormExampleProps): JSX.Element => {\n const { exampleType = FormExampleVariants.formgroup } = props;\n const {\n register,\n handleSubmit,\n formState: { errors },\n } = useForm();\n\n const defaultDate = new Date();\n defaultDate.setHours(0);\n defaultDate.setMinutes(0);\n defaultDate.setSeconds(0);\n const minDate = new Date();\n minDate.setDate(defaultDate.getDate() - 5);\n minDate.setHours(6);\n minDate.setMinutes(10);\n minDate.setSeconds(0);\n const maxDate = new Date();\n maxDate.setDate(defaultDate.getDate() + 5);\n maxDate.setHours(22);\n maxDate.setMinutes(0);\n maxDate.setSeconds(0);\n\n const field1 = 'field1';\n const field2 = 'field2';\n const field3 = 'field3';\n const field4 = 'field4';\n const field5 = 'field5';\n const field6 = 'field6';\n const allErrors =\n errors.field1 ||\n errors.field2 ||\n errors.field3 ||\n errors.field4 ||\n errors.field5 ||\n errors.field6 ||\n errors.field7 ||\n errors.field8 ||\n errors.field9;\n const errorMessage = 'Du må velge et alternativ';\n const errorMessage2 = 'Du må velge to alternativ';\n const errorMessage3 = 'Det kan ikke legges inn mer enn 40 tegn';\n const errorMessage4 = 'Du må skrive noe her';\n const errorMessage5 = 'Du må velge \"Option 2\"';\n\n const requireTwo = (value: Array<string>): true | string => {\n return value.length >= 2 || errorMessage2;\n };\n const requireSelect = (value: Array<string>): true | string => {\n return value.toString() === 'Option 2' || errorMessage5;\n };\n\n const getFormExample = () => {\n if (exampleType === FormExampleVariants.formgroup) {\n const allCheckBoxes = [\n <Checkbox\n key={0}\n inputId=\"checkbox1\"\n label={<Label labelTexts={[{ text: 'Checkbox 1' }]} />}\n {...register(field1, { required: errorMessage })}\n />,\n <Checkbox\n key={1}\n inputId=\"checkbox2\"\n label={<Label labelTexts={[{ text: 'Checkbox 2' }]} />}\n {...register(field1, { required: errorMessage })}\n />,\n <Checkbox\n key={2}\n inputId=\"checkbox3\"\n label={<Label labelTexts={[{ text: 'Checkbox 3' }]} />}\n {...register(field1, { required: errorMessage })}\n />,\n ];\n\n return [\n <FormGroup\n key={0}\n title={'Gruppe tittel'}\n legend={'Velg minst en'}\n error={errors.field1 ? (errors.field1.message as string) : undefined}\n size={props.size}\n >\n <FormLayout maxColumns={FormLayoutColumns.two}>\n {allCheckBoxes.map(check => {\n return check;\n })}\n </FormLayout>\n </FormGroup>,\n <FormGroup key={1} legend={'Velg minst to'} error={errors.field2 ? (errors.field2.message as string) : undefined} size={props.size}>\n <Checkbox\n inputId=\"checkbox4\"\n label={<Label labelTexts={[{ text: 'Checkbox 4' }]} />}\n {...register(field2, { validate: requireTwo })}\n />\n <Checkbox\n inputId=\"checkbox5\"\n label={<Label labelTexts={[{ text: 'Checkbox 5' }]} />}\n {...register(field2, { validate: requireTwo })}\n />\n <Checkbox\n inputId=\"checkbox6\"\n label={<Label labelTexts={[{ text: 'Checkbox 6' }]} />}\n {...register(field2, { validate: requireTwo })}\n />\n </FormGroup>,\n <FormGroup key={2} legend={'Velg en'} error={errors.field3 ? (errors.field3.message as string) : undefined} size={props.size}>\n <RadioButton\n inputId=\"radiobutton1\"\n label={<Label labelTexts={[{ text: 'Radiobutton 1' }]} />}\n {...register(field3, { required: errorMessage })}\n />\n <RadioButton\n inputId=\"radiobutton2\"\n label={<Label labelTexts={[{ text: 'Radiobutton 2' }]} />}\n {...register(field3, { required: errorMessage })}\n />\n <RadioButton\n inputId=\"radiobutton3\"\n label={<Label labelTexts={[{ text: 'Radiobutton 3' }]} />}\n {...register(field3, { required: errorMessage })}\n />\n </FormGroup>,\n <FormGroup key={3} error={errors.field4 ? (errors.field4.message as string) : undefined}>\n <Textarea\n defaultValue={`Dette er en test \\n\\n Hello \\n\\n test \\n\\n test test`}\n grow\n maxCharacters={40}\n minRows={5}\n label={<Label labelTexts={[{ text: 'Skriv din historie her', type: 'semibold' }]} />}\n textareaId=\"textarea1\"\n {...register(field4, { maxLength: { value: 40, message: errorMessage3 } })}\n />\n </FormGroup>,\n <FormGroup key={4} size={props.size} error={errors.field5 ? (errors.field5.message as string) : undefined}>\n <Input\n label={<Label labelTexts={[{ text: 'Skriv inn din tekst', type: 'semibold' }]} />}\n placeholder={'Skriv noe!'}\n icon={Hospital}\n {...register(field5, { required: errorMessage4 })}\n />\n </FormGroup>,\n <FormGroup key={5} size={props.size} error={errors.field6 ? (errors.field6.message as string) : undefined}>\n <Select\n label={<Label labelTexts={[{ text: 'Skriv inn din tekst', type: 'semibold' }]} />}\n {...register(field6, { validate: requireSelect })}\n >\n <option value={'Option 1'}>{'Option 1'}</option>\n <option value={'Option 2'}>{'Option 2'}</option>\n <option value={'Option 3'}>{'Option 3'}</option>\n </Select>\n </FormGroup>,\n ];\n } else if (exampleType === FormExampleVariants.checkbox) {\n return (\n <Checkbox\n inputId=\"checkbox1\"\n label={<Label labelTexts={[{ text: 'Checkbox 1' }]} />}\n errorText={errors.field1 ? (errors.field1.message as string) : undefined}\n size={props.size}\n {...register(field1, { required: errorMessage })}\n />\n );\n } else if (exampleType === FormExampleVariants.radiobutton) {\n return (\n <RadioButton\n inputId=\"radiobutton1\"\n label={<Label labelTexts={[{ text: 'Radiobutton 1' }]} />}\n errorText={errors.field3 ? (errors.field3.message as string) : undefined}\n size={props.size}\n {...register(field3, { required: errorMessage })}\n />\n );\n } else if (exampleType === FormExampleVariants.textarea) {\n return (\n <Textarea\n defaultValue={`Dette er min historie \\n\\n Hello \\n\\n test`}\n grow\n maxCharacters={40}\n minRows={5}\n errorText={errors.field4 ? (errors.field4.message as string) : undefined}\n label={<Label labelTexts={[{ text: 'Skriv din historie her', type: 'semibold' }]} />}\n textareaId=\"textarea1\"\n {...register(field4, { maxLength: { value: 40, message: errorMessage3 } })}\n />\n );\n } else if (exampleType === FormExampleVariants.input) {\n return (\n <Input\n inputId={'input1'}\n label={<Label labelTexts={[{ text: 'Skriv inn din tekst', type: 'semibold' }]} />}\n placeholder={'Skriv noe!'}\n errorText={errors.field5 ? (errors.field5.message as string) : undefined}\n icon={Hospital}\n {...register(field5, { required: errorMessage4 })}\n />\n );\n } else if (exampleType === FormExampleVariants.select) {\n return (\n <Select\n errorText={errors.field6 ? (errors.field6.message as string) : undefined}\n label={<Label labelTexts={[{ text: 'Skriv inn din tekst', type: 'semibold' }]} />}\n {...register(field6, { validate: requireSelect })}\n >\n <option value={'Option 1'}>{'Option 1'}</option>\n <option value={'Option 2'}>{'Option 2'}</option>\n <option value={'Option 3'}>{'Option 3'}</option>\n </Select>\n );\n }\n };\n\n return (\n <form\n noValidate\n onSubmit={handleSubmit(data => {\n // eslint-disable-next-line no-console\n !isTest() && console.log(data);\n })}\n >\n <Validation size={props.size} errorSummary={allErrors ? 'Sjekk at alt er riktig utfylt' : undefined}>\n {getFormExample()}\n </Validation>\n <Spacer />\n <Button type=\"submit\">{'Send inn'}</Button>\n </form>\n );\n};\n\nexport default FormExample;\n"],"names":["FormExampleVariants","FormExample","props","exampleType","register","handleSubmit","errors","useForm","defaultDate","minDate","maxDate","field1","field2","field3","field4","field5","field6","allErrors","errorMessage","errorMessage2","errorMessage3","errorMessage4","errorMessage5","requireTwo","value","requireSelect","getFormExample","allCheckBoxes","React","Checkbox","Label","FormGroup","FormLayout","FormLayoutColumns","check","RadioButton","Textarea","Input","Hospital","Select","data","isTest","Validation","Spacer","Button","FormExample$1"],"mappings":";;;;;;;;;;;;;;;AAwBY,IAAAA,sBAAAA,OACVA,EAAA,YAAY,aACZA,EAAA,WAAW,YACXA,EAAA,cAAc,eACdA,EAAA,WAAW,YACXA,EAAA,QAAQ,SACRA,EAAA,SAAS,UANCA,IAAAA,KAAA,CAAA,C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A;AAAA,IAEDZ,gBAAAA,EAAA,cAACc,GAAW,EAAA,MAAMxC,EAAM,MAAM,cAAce,IAAY,kCAAkC,OACvF,GAAAS,EAAA,CACH;AAAA,oCACCiB,GAAO,IAAA;AAAA,IACPf,gBAAAA,EAAA,cAAAgB,GAAA,EAAO,MAAK,SAAA,GAAU,UAAW;AAAA,EAAA;AAGxC,GAEAC,KAAe5C;"}
|
|
1
|
+
{"version":3,"file":"FormExample.js","sources":["../../../src/components/FormExample/FormExample.tsx"],"sourcesContent":["import React from 'react';\n\nimport { useForm } from 'react-hook-form';\n\nimport { FormSize } from '../../constants';\nimport { isTest } from '../../utils/environment';\nimport Button from '../Button';\nimport Checkbox from '../Checkbox';\nimport FormGroup from '../FormGroup/FormGroup';\nimport FormLayout, { FormLayoutColumns } from '../FormLayout';\nimport Hospital from '../Icons/Hospital';\nimport Input from '../Input';\nimport Label from '../Label';\nimport RadioButton from '../RadioButton';\nimport Select from '../Select';\nimport Spacer from '../Spacer';\nimport Textarea from '../Textarea';\nimport Validation from '../Validation';\n\nexport interface FormExampleProps {\n exampleType: FormExampleVariants;\n size?: keyof typeof FormSize;\n}\n\nexport enum FormExampleVariants {\n formgroup = 'formgroup',\n checkbox = 'checkbox',\n radiobutton = 'radiobutton',\n textarea = 'textarea',\n input = 'input',\n select = 'select',\n}\n\ninterface FormExampleData {\n colour: string;\n sizes: string[];\n positions: string;\n story: string;\n name: string;\n monster: string[];\n}\n\nexport const FormExample = (props: FormExampleProps): JSX.Element => {\n const { exampleType = FormExampleVariants.formgroup } = props;\n const {\n register,\n handleSubmit,\n formState: { errors },\n } = useForm<FormExampleData>();\n\n const defaultDate = new Date();\n defaultDate.setHours(0);\n defaultDate.setMinutes(0);\n defaultDate.setSeconds(0);\n const minDate = new Date();\n minDate.setDate(defaultDate.getDate() - 5);\n minDate.setHours(6);\n minDate.setMinutes(10);\n minDate.setSeconds(0);\n const maxDate = new Date();\n maxDate.setDate(defaultDate.getDate() + 5);\n maxDate.setHours(22);\n maxDate.setMinutes(0);\n maxDate.setSeconds(0);\n\n const colorErrorMessage = 'Du må velge minst én farge';\n const sizeErrorMessage = 'Du må velge minst to størrelser';\n const positionErrorMessage = 'Du må velge minst én plassering';\n const storyErrorMessage = 'Historien må være på maks 40 tegn';\n const nameErrorMessage = 'Navn må fylles ut';\n const monsterErrorMessage = 'Du må velge \"Frankenstein\"';\n\n const requireTwo = (value: Array<string>): true | string => {\n return value.length >= 2 || sizeErrorMessage;\n };\n\n const requireFrankenstein = (value: Array<string>): true | string => {\n return value.toString() === 'Frankenstein' || monsterErrorMessage;\n };\n\n const color = () => (\n <FormGroup\n title={'FormGroup-tittel'}\n legend={'Farge'}\n error={errors.colour ? errors.colour.message : undefined}\n errorTextId=\"error\"\n size={props.size}\n >\n <FormLayout maxColumns={FormLayoutColumns.two}>\n <Checkbox\n inputId=\"colour1\"\n label={<Label labelTexts={[{ text: 'Blueberry' }]} />}\n {...register('colour', { required: colorErrorMessage })}\n />\n <Checkbox\n inputId=\"colour2\"\n label={<Label labelTexts={[{ text: 'Cherry' }]} />}\n {...register('colour', { required: colorErrorMessage })}\n />\n <Checkbox\n inputId=\"colour3\"\n label={<Label labelTexts={[{ text: 'Neutral' }]} />}\n {...register('colour', { required: colorErrorMessage })}\n />\n </FormLayout>\n </FormGroup>\n );\n\n const size = () => (\n <FormGroup legend={'Størrelser'} error={errors.sizes ? errors.sizes.message : undefined} size={props.size} errorTextId=\"error1\">\n <Checkbox inputId=\"sizes1\" label={<Label labelTexts={[{ text: 'Small' }]} />} {...register('sizes', { validate: requireTwo })} />\n <Checkbox inputId=\"sizes2\" label={<Label labelTexts={[{ text: 'Medium' }]} />} {...register('sizes', { validate: requireTwo })} />\n <Checkbox inputId=\"sizes3\" label={<Label labelTexts={[{ text: 'Large' }]} />} {...register('sizes', { validate: requireTwo })} />\n </FormGroup>\n );\n\n const position = () => (\n <FormGroup\n legend={'Plassering'}\n error={errors.positions ? (errors.positions.message as string) : undefined}\n size={props.size}\n errorTextId=\"error2\"\n >\n <RadioButton\n inputId=\"positions1\"\n label={<Label labelTexts={[{ text: 'Venstre' }]} />}\n {...register('positions', { required: positionErrorMessage })}\n />\n <RadioButton\n inputId=\"positions2\"\n label={<Label labelTexts={[{ text: 'Høyre' }]} />}\n {...register('positions', { required: positionErrorMessage })}\n />\n <RadioButton\n inputId=\"positions3\"\n label={<Label labelTexts={[{ text: 'Midten' }]} />}\n {...register('positions', { required: positionErrorMessage })}\n />\n </FormGroup>\n );\n\n const story = () => (\n <FormGroup error={errors.story ? (errors.story.message as string) : undefined} errorTextId=\"error3\">\n <Textarea\n defaultValue={`Dette er en test \\n\\n Hello \\n\\n test \\n\\n test test`}\n grow\n maxCharacters={40}\n minRows={5}\n label={<Label labelTexts={[{ text: 'Historie', type: 'semibold' }]} />}\n textareaId=\"story\"\n {...register('story', { maxLength: { value: 40, message: storyErrorMessage } })}\n />\n </FormGroup>\n );\n\n const name = () => (\n <FormGroup size={props.size} error={errors.name ? (errors.name.message as string) : undefined} errorTextId=\"error4\">\n <Input\n label={<Label labelTexts={[{ text: 'Navn', type: 'semibold' }]} />}\n placeholder={'Skriv noe!'}\n icon={Hospital}\n inputId=\"name\"\n {...register('name', { required: nameErrorMessage })}\n />\n </FormGroup>\n );\n\n const monster = () => (\n <FormGroup size={props.size} error={errors.monster ? (errors.monster.message as string) : undefined} errorTextId=\"error5\">\n <Select\n selectId=\"monster\"\n label={<Label labelTexts={[{ text: 'Velg et monster', type: 'semibold' }]} />}\n {...register('monster', { validate: requireFrankenstein })}\n >\n <option value={'Troll'}>{'Troll'}</option>\n <option value={'Frankenstein'}>{'Frankenstein'}</option>\n </Select>\n </FormGroup>\n );\n\n const getFormExample = () => {\n if (exampleType === FormExampleVariants.formgroup) {\n return (\n <>\n {color()}\n {size()}\n {position()}\n {story()}\n {name()}\n {monster()}\n </>\n );\n } else if (exampleType === FormExampleVariants.checkbox) {\n return <>{color()}</>;\n } else if (exampleType === FormExampleVariants.radiobutton) {\n return <>{position()}</>;\n } else if (exampleType === FormExampleVariants.textarea) {\n return <>{story()}</>;\n } else if (exampleType === FormExampleVariants.input) {\n return <>{name()}</>;\n } else if (exampleType === FormExampleVariants.select) {\n return <>{monster()}</>;\n }\n };\n\n return (\n <form\n noValidate\n onSubmit={handleSubmit(data => {\n // eslint-disable-next-line no-console\n !isTest() && console.log(data);\n })}\n >\n <Validation size={props.size} errorTitle={'Sjekk at alt er riktig utfylt:'} errors={errors}>\n {getFormExample()}\n </Validation>\n <Spacer />\n <Button type=\"submit\">{'Send inn'}</Button>\n </form>\n );\n};\n\nexport default FormExample;\n"],"names":["FormExampleVariants","FormExample","props","exampleType","register","handleSubmit","errors","useForm","defaultDate","minDate","maxDate","colorErrorMessage","sizeErrorMessage","positionErrorMessage","storyErrorMessage","nameErrorMessage","monsterErrorMessage","requireTwo","value","requireFrankenstein","color","React","FormGroup","FormLayout","FormLayoutColumns","Checkbox","Label","size","position","RadioButton","story","Textarea","name","Input","Hospital","monster","Select","getFormExample","data","isTest","Validation","Spacer","Button","FormExample$1"],"mappings":";;;;;;;;;;;;;;;AAwBY,IAAAA,sBAAAA,OACVA,EAAA,YAAY,aACZA,EAAA,WAAW,YACXA,EAAA,cAAc,eACdA,EAAA,WAAW,YACXA,EAAA,QAAQ,SACRA,EAAA,SAAS,UANCA,IAAAA,KAAA,CAAA,CAAA;AAkBC,MAAAC,IAAc,CAACC,MAAyC;AAC7D,QAAA;AAAA,IAAE,aAAAC,IAAc;AAAA;AAAA,EAAkC,IAAAD,GAClD;AAAA,IACJ,UAAAE;AAAA,IACA,cAAAC;AAAA,IACA,WAAW,EAAE,QAAAC,EAAO;AAAA,MAClBC,EAAyB,GAEvBC,wBAAkB;AACxB,EAAAA,EAAY,SAAS,CAAC,GACtBA,EAAY,WAAW,CAAC,GACxBA,EAAY,WAAW,CAAC;AAClB,QAAAC,wBAAc;AACpB,EAAAA,EAAQ,QAAQD,EAAY,QAAQ,IAAI,CAAC,GACzCC,EAAQ,SA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AA,UAAA,MAAGc,GAAU;AAAA,EACtB;AAIA,SAAAd,gBAAAA,EAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,YAAU;AAAA,MACV,UAAUhB,EAAa,CAAQiC,MAAA;AAE7B,SAACC,EAAO,KAAK,QAAQ,IAAID,CAAI;AAAA,MAAA,CAC9B;AAAA,IAAA;AAAA,IAEDjB,gBAAAA,EAAA,cAACmB,KAAW,MAAMtC,EAAM,MAAM,YAAY,kCAAkC,QAAAI,EACzE,GAAA+B,EAAA,CACH;AAAA,oCACCI,GAAO,IAAA;AAAA,IACPpB,gBAAAA,EAAA,cAAAqB,GAAA,EAAO,MAAK,SAAA,GAAU,UAAW;AAAA,EAAA;AAGxC,GAEAC,KAAe1C;"}
|
|
@@ -20,6 +20,8 @@ export interface FormGroupProps {
|
|
|
20
20
|
size?: keyof typeof FormSize;
|
|
21
21
|
/** Error message */
|
|
22
22
|
error?: string;
|
|
23
|
+
/** Error text id */
|
|
24
|
+
errorTextId?: string;
|
|
23
25
|
/** Sets the data-testid attribute. */
|
|
24
26
|
testId?: string;
|
|
25
27
|
/** Sets the data-testid attribute for the error-wrapper. */
|
|
@@ -1,88 +1,102 @@
|
|
|
1
|
-
import r, { useState as
|
|
2
|
-
import
|
|
3
|
-
import { FormMode as
|
|
1
|
+
import r, { useState as U } from "react";
|
|
2
|
+
import d from "classnames";
|
|
3
|
+
import { FormMode as N, FormSize as T, AnalyticsId as A } from "../../constants.js";
|
|
4
|
+
import { useUuid as k } from "../../hooks/useUuid.js";
|
|
4
5
|
import { isComponent as m } from "../../utils/component.js";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
const
|
|
6
|
+
import D from "../Checkbox/Checkbox.js";
|
|
7
|
+
import H from "../ErrorWrapper/ErrorWrapper.js";
|
|
8
|
+
import $ from "../FormLayout/FormLayout.js";
|
|
9
|
+
import j from "../Input/Input.js";
|
|
10
|
+
import q, { getRadioLabelClasses as J } from "../RadioButton/RadioButton.js";
|
|
11
|
+
import K from "../Select/Select.js";
|
|
12
|
+
import O from "../Textarea/Textarea.js";
|
|
13
|
+
import P from "../Title/Title.js";
|
|
14
|
+
import p from "./styles.module.scss";
|
|
15
|
+
const f = r.forwardRef((t, F) => {
|
|
15
16
|
const {
|
|
16
|
-
className:
|
|
17
|
-
fieldsetClassName:
|
|
18
|
-
mode: a =
|
|
19
|
-
size:
|
|
17
|
+
className: G,
|
|
18
|
+
fieldsetClassName: _,
|
|
19
|
+
mode: a = N.onwhite,
|
|
20
|
+
size: s = T.medium,
|
|
20
21
|
error: o,
|
|
22
|
+
errorTextId: y,
|
|
21
23
|
name: l,
|
|
22
|
-
htmlMarkup:
|
|
24
|
+
htmlMarkup: u = "fieldset",
|
|
23
25
|
renderError: R = !0,
|
|
24
26
|
errorWrapperClassName: b,
|
|
25
27
|
errorWrapperTestId: w
|
|
26
|
-
} = t, [
|
|
27
|
-
[
|
|
28
|
-
}),
|
|
29
|
-
[
|
|
30
|
-
}), g = p
|
|
31
|
-
if (m(e,
|
|
28
|
+
} = t, [S, W] = U(), v = k(), n = k(y), c = a === N.ondark, L = s === T.large, M = d(p["form-group-wrapper"], G), z = d({
|
|
29
|
+
[p["form-group-wrapper__title--on-dark"]]: c && !o
|
|
30
|
+
}), I = d(p["field-set__legend"], {
|
|
31
|
+
[p["field-set__legend--on-dark"]]: c && !o
|
|
32
|
+
}), g = d(p["field-set"], _), i = (e, B) => {
|
|
33
|
+
if (m(e, $))
|
|
32
34
|
return r.cloneElement(e, {
|
|
33
|
-
size:
|
|
35
|
+
size: s,
|
|
34
36
|
mapHelper: i
|
|
35
37
|
});
|
|
36
|
-
if (m(e,
|
|
38
|
+
if (m(e, f))
|
|
37
39
|
return r.cloneElement(e, {
|
|
38
40
|
mode: a,
|
|
39
|
-
size:
|
|
41
|
+
size: s,
|
|
40
42
|
error: o,
|
|
41
|
-
renderError: !1
|
|
43
|
+
renderError: !1,
|
|
44
|
+
errorTextId: n
|
|
42
45
|
});
|
|
43
|
-
if (m(e,
|
|
46
|
+
if (m(e, D))
|
|
44
47
|
return r.cloneElement(e, {
|
|
45
48
|
name: l ?? e.props.name,
|
|
46
49
|
mode: a,
|
|
47
|
-
size:
|
|
48
|
-
error: !!o
|
|
50
|
+
size: s,
|
|
51
|
+
error: !!o,
|
|
52
|
+
errorTextId: n
|
|
49
53
|
});
|
|
50
|
-
if (m(e,
|
|
51
|
-
const E = typeof e.props.inputId > "u" ?
|
|
54
|
+
if (m(e, q)) {
|
|
55
|
+
const E = typeof e.props.inputId > "u" ? v + B : e.props.inputId;
|
|
52
56
|
return r.cloneElement(e, {
|
|
53
57
|
inputId: E,
|
|
54
58
|
name: l ?? e.props.name,
|
|
55
59
|
mode: a,
|
|
56
|
-
size:
|
|
57
|
-
onChange: (
|
|
58
|
-
|
|
60
|
+
size: s,
|
|
61
|
+
onChange: (x) => {
|
|
62
|
+
W(x.target.id), e.props.onChange && e.props.onChange(x);
|
|
59
63
|
},
|
|
60
64
|
error: !!o,
|
|
61
|
-
|
|
65
|
+
errorTextId: n,
|
|
66
|
+
labelClassNames: J(E, a, L, S)
|
|
62
67
|
});
|
|
63
68
|
} else {
|
|
64
|
-
if (m(e,
|
|
69
|
+
if (m(e, j))
|
|
70
|
+
return r.cloneElement(e, {
|
|
71
|
+
name: l ?? e.props.name,
|
|
72
|
+
mode: a,
|
|
73
|
+
size: s,
|
|
74
|
+
error: !!o,
|
|
75
|
+
errorTextId: n
|
|
76
|
+
});
|
|
77
|
+
if (m(e, O))
|
|
65
78
|
return r.cloneElement(e, {
|
|
66
79
|
name: l ?? e.props.name,
|
|
67
80
|
mode: a,
|
|
68
|
-
|
|
69
|
-
|
|
81
|
+
error: !!o,
|
|
82
|
+
errorTextId: n
|
|
70
83
|
});
|
|
71
|
-
if (m(e,
|
|
84
|
+
if (m(e, K))
|
|
72
85
|
return r.cloneElement(e, {
|
|
73
86
|
name: l ?? e.props.name,
|
|
74
87
|
mode: a,
|
|
75
|
-
error: !!o
|
|
88
|
+
error: !!o,
|
|
89
|
+
errorTextId: n
|
|
76
90
|
});
|
|
77
91
|
}
|
|
78
92
|
return e;
|
|
79
|
-
}, C = () => /* @__PURE__ */ r.createElement("div", null,
|
|
80
|
-
return /* @__PURE__ */ r.createElement("div", { "data-testid": t.testId, "data-analyticsid":
|
|
93
|
+
}, C = () => /* @__PURE__ */ r.createElement("div", null, u === "div" && /* @__PURE__ */ r.createElement("div", { className: g }, t.legend && /* @__PURE__ */ r.createElement("h5", { className: I }, t.legend), r.Children.map(t.children, i)), u === "fieldset" && /* @__PURE__ */ r.createElement("fieldset", { name: t.fieldsetName, className: g }, t.legend && /* @__PURE__ */ r.createElement("legend", { className: I }, t.legend), r.Children.map(t.children, i)));
|
|
94
|
+
return /* @__PURE__ */ r.createElement("div", { "data-testid": t.testId, "data-analyticsid": A.FormGroup, className: M, ref: F, tabIndex: -1 }, t.title && /* @__PURE__ */ r.createElement(P, { className: z, htmlMarkup: "h4", appearance: "title4", margin: { marginTop: 0, marginBottom: o ? 1 : 2 } }, t.title), R ? /* @__PURE__ */ r.createElement(H, { className: b, errorText: o, testId: w, errorTextId: n }, C()) : C());
|
|
81
95
|
});
|
|
82
|
-
|
|
83
|
-
const
|
|
96
|
+
f.displayName = "FormGroup";
|
|
97
|
+
const le = f;
|
|
84
98
|
export {
|
|
85
|
-
|
|
86
|
-
|
|
99
|
+
f as FormGroup,
|
|
100
|
+
le as default
|
|
87
101
|
};
|
|
88
102
|
//# sourceMappingURL=FormGroup.js.map
|