@entur/form 8.3.2-beta.3 → 8.3.2-beta.4

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/dist/form.cjs.js DELETED
@@ -1,1054 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const utils = require("@entur/utils");
4
- const jsxRuntime = require("react/jsx-runtime");
5
- const React = require("react");
6
- const classNames = require("classnames");
7
- const icons = require("@entur/icons");
8
- const tooltip = require("@entur/tooltip");
9
- const button = require("@entur/button");
10
- const typography = require("@entur/typography");
11
- const tokens = require("@entur/tokens");
12
- function _interopNamespaceDefault(e) {
13
- const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
14
- if (e) {
15
- for (const k in e) {
16
- if (k !== "default") {
17
- const d = Object.getOwnPropertyDescriptor(e, k);
18
- Object.defineProperty(n, k, d.get ? d : {
19
- enumerable: true,
20
- get: () => e[k]
21
- });
22
- }
23
- }
24
- }
25
- n.default = e;
26
- return Object.freeze(n);
27
- }
28
- const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
29
- const info = "info";
30
- const error$1 = "error";
31
- const AlertIcon = ({ variant }) => {
32
- const iconClass = `eds-feedback-text__icon eds-feedback-text__icon--${variant}`;
33
- switch (variant) {
34
- case "success":
35
- return /* @__PURE__ */ jsxRuntime.jsx(
36
- icons.ValidationSuccessFilledIcon,
37
- {
38
- "aria-label": "Suksessmelding",
39
- className: iconClass
40
- }
41
- );
42
- case "negative":
43
- return /* @__PURE__ */ jsxRuntime.jsx(
44
- icons.ValidationErrorFilledIcon,
45
- {
46
- "aria-label": "Feilmelding",
47
- className: iconClass
48
- }
49
- );
50
- case "information":
51
- return null;
52
- case "warning":
53
- return /* @__PURE__ */ jsxRuntime.jsx(
54
- icons.ValidationExclamationFilledIcon,
55
- {
56
- "aria-label": "Varselmelding",
57
- className: iconClass
58
- }
59
- );
60
- case error$1:
61
- return /* @__PURE__ */ jsxRuntime.jsx(
62
- icons.ValidationErrorFilledIcon,
63
- {
64
- "aria-label": "Feilmelding",
65
- className: iconClass
66
- }
67
- );
68
- case info:
69
- return null;
70
- default:
71
- return null;
72
- }
73
- };
74
- const FeedbackText = ({
75
- children,
76
- hideIcon = false,
77
- variant,
78
- className,
79
- ...rest
80
- }) => {
81
- return /* @__PURE__ */ jsxRuntime.jsxs(
82
- typography.SubLabel,
83
- {
84
- className: classNames(
85
- "eds-feedback-text",
86
- {
87
- "eds-feedback-text--information": variant === info || variant === "information"
88
- },
89
- className
90
- ),
91
- ...rest,
92
- children: [
93
- !hideIcon && /* @__PURE__ */ jsxRuntime.jsx(AlertIcon, { variant }),
94
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "eds-feedback-text__text", children })
95
- ]
96
- }
97
- );
98
- };
99
- const InputGroupContext = React__namespace.createContext({
100
- isFilled: false,
101
- setFilled: () => null
102
- });
103
- const InputGroupContextProvider = ({ children }) => {
104
- const [filled, setFilled] = React__namespace.useState(false);
105
- return /* @__PURE__ */ jsxRuntime.jsx(
106
- InputGroupContext.Provider,
107
- {
108
- value: { isFilled: filled, setFilled },
109
- children
110
- }
111
- );
112
- };
113
- const useInputGroupContext = () => React__namespace.useContext(InputGroupContext);
114
- const InputGroupLabel = ({
115
- label,
116
- required,
117
- labelId,
118
- staticAnimation = false,
119
- ...rest
120
- }) => {
121
- const { isFilled: isFilled2 } = useInputGroupContext();
122
- const filler = staticAnimation || isFilled2;
123
- return /* @__PURE__ */ jsxRuntime.jsx(
124
- "label",
125
- {
126
- className: classNames(rest.className, {
127
- "eds-input-group-label-wrapper--filled": filler
128
- }),
129
- id: labelId,
130
- ...rest,
131
- children: /* @__PURE__ */ jsxRuntime.jsxs(
132
- "span",
133
- {
134
- className: classNames("eds-input-group__label", {
135
- "eds-input-group__label--filled": filler
136
- }),
137
- children: [
138
- label,
139
- " ",
140
- required && /* @__PURE__ */ jsxRuntime.jsx("span", { children: "*" })
141
- ]
142
- }
143
- )
144
- }
145
- );
146
- };
147
- const VariantContext = React.createContext(null);
148
- const VariantProvider = ({
149
- children,
150
- variant = null
151
- }) => {
152
- return /* @__PURE__ */ jsxRuntime.jsx(VariantContext.Provider, { value: variant, children });
153
- };
154
- const useVariant = () => {
155
- const context = React.useContext(VariantContext);
156
- return context;
157
- };
158
- const error = "error";
159
- const BaseFormControl = React.forwardRef(
160
- ({
161
- after,
162
- before,
163
- children,
164
- className,
165
- disabled = false,
166
- readOnly = false,
167
- variant,
168
- prepend,
169
- append,
170
- size = "medium",
171
- isFilled: isFilled2,
172
- label,
173
- required,
174
- labelTooltip,
175
- labelTooltipButtonAriaLabel = `Klikk for tilleggsinfo om ${label}-feltet`,
176
- labelTooltipPlacement = "top",
177
- feedback,
178
- labelId,
179
- labelProps,
180
- style,
181
- disableLabelAnimation = false,
182
- ariaAlertOnFeedback = false,
183
- ariaLabelOnReadOnly = "Dette skjemafeltet kan bare leses",
184
- ...rest
185
- }, ref) => {
186
- const contextVariant = useVariant();
187
- const currentVariant = variant || contextVariant;
188
- return /* @__PURE__ */ jsxRuntime.jsx(InputGroupContextProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(
189
- "div",
190
- {
191
- className: classNames(
192
- "eds-form-control__field-and-feedback-text",
193
- className,
194
- {
195
- "eds-form-control__field-and-feedback-text--has-tooltip": labelTooltip !== void 0
196
- }
197
- ),
198
- style,
199
- children: [
200
- before,
201
- /* @__PURE__ */ jsxRuntime.jsxs(
202
- "div",
203
- {
204
- className: classNames(
205
- "eds-form-control-wrapper",
206
- `eds-form-control-wrapper--size-${size}`,
207
- {
208
- "eds-form-control-wrapper--success": currentVariant === "success",
209
- "eds-form-control-wrapper--negative": currentVariant === "negative" || currentVariant === error,
210
- "eds-form-control-wrapper--disabled": disabled,
211
- "eds-form-control-wrapper--readonly": readOnly,
212
- "eds-form-control-wrapper--is-filled": isFilled2
213
- }
214
- ),
215
- ref,
216
- tabIndex: readOnly ? -1 : void 0,
217
- ...rest,
218
- children: [
219
- prepend && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "eds-form-control__prepend", children: prepend }),
220
- /* @__PURE__ */ jsxRuntime.jsx(
221
- InputGroupLabel,
222
- {
223
- label,
224
- required,
225
- labelId,
226
- staticAnimation: disableLabelAnimation,
227
- "aria-label": readOnly ? `${label}, ${ariaLabelOnReadOnly}` : void 0,
228
- ...labelProps
229
- }
230
- ),
231
- labelTooltip && /* @__PURE__ */ jsxRuntime.jsx(
232
- tooltip.Tooltip,
233
- {
234
- content: labelTooltip,
235
- placement: labelTooltipPlacement,
236
- showCloseButton: false,
237
- disableFocusListener: true,
238
- disableHoverListener: true,
239
- disableClickListner: false,
240
- disableKeyboardListener: false,
241
- children: /* @__PURE__ */ jsxRuntime.jsx(
242
- button.IconButton,
243
- {
244
- as: "span",
245
- tabIndex: 0,
246
- role: "button",
247
- className: "eds-form-control__append eds-form-control__append--tooltip",
248
- "aria-label": labelTooltipButtonAriaLabel,
249
- children: /* @__PURE__ */ jsxRuntime.jsx(
250
- icons.QuestionIcon,
251
- {
252
- className: "eds-input-group__label-tooltip-icon",
253
- "aria-hidden": "true"
254
- }
255
- )
256
- }
257
- )
258
- }
259
- ),
260
- children,
261
- append && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "eds-form-control__append", children: append })
262
- ]
263
- }
264
- ),
265
- feedback && currentVariant && /* @__PURE__ */ jsxRuntime.jsx(
266
- FeedbackText,
267
- {
268
- variant: currentVariant,
269
- role: ariaAlertOnFeedback ? "alert" : void 0,
270
- children: feedback
271
- }
272
- ),
273
- after
274
- ]
275
- }
276
- ) });
277
- }
278
- );
279
- const Checkbox = React.forwardRef(
280
- ({
281
- checked,
282
- className,
283
- children,
284
- style,
285
- disabled = false,
286
- readOnly = false,
287
- reduceClickArea,
288
- disableAnimation = false,
289
- ...rest
290
- }, ref) => {
291
- const inputRef = React.useRef(null);
292
- const isIndeterminate = checked === "indeterminate";
293
- const isControlled = checked !== void 0;
294
- React.useEffect(() => {
295
- if (inputRef && inputRef.current) {
296
- inputRef.current.indeterminate = isIndeterminate;
297
- }
298
- }, [isIndeterminate]);
299
- return /* @__PURE__ */ jsxRuntime.jsxs(
300
- "label",
301
- {
302
- className: classNames("eds-checkbox__container", className, {
303
- "eds-checkbox--disabled": disabled,
304
- "eds-checkbox--readonly": readOnly,
305
- "eds-checkbox__container--reduced-click-area": reduceClickArea
306
- }),
307
- style,
308
- children: [
309
- /* @__PURE__ */ jsxRuntime.jsx(
310
- "input",
311
- {
312
- type: "checkbox",
313
- ref: utils.mergeRefs(ref, inputRef),
314
- checked: isControlled ? checked === true : void 0,
315
- disabled,
316
- onKeyDown: (e) => {
317
- if (readOnly && (e.key === " " || e.key === "Enter")) {
318
- e.preventDefault();
319
- e.stopPropagation();
320
- }
321
- },
322
- "aria-label": readOnly ? ` ${children?.toString()}. Kan ikke endres` : void 0,
323
- ...rest
324
- }
325
- ),
326
- /* @__PURE__ */ jsxRuntime.jsx(
327
- "span",
328
- {
329
- className: classNames("eds-checkbox__icon", {
330
- "eds-checkbox__icon--disabled": disabled,
331
- "eds-checkbox__icon--readonly": readOnly,
332
- "eds-checkbox__icon--reduced-click-area": reduceClickArea,
333
- "eds-checkbox__icon--no-animation": disableAnimation || disabled || readOnly
334
- }),
335
- children: /* @__PURE__ */ jsxRuntime.jsx(CheckboxIcon, { indeterminate: isIndeterminate })
336
- }
337
- ),
338
- children && /* @__PURE__ */ jsxRuntime.jsx(typography.Paragraph, { className: "eds-checkbox__label", margin: "none", as: "span", children })
339
- ]
340
- }
341
- );
342
- }
343
- );
344
- const CheckboxIcon = ({
345
- indeterminate = false
346
- }) => {
347
- return /* @__PURE__ */ jsxRuntime.jsx(
348
- "svg",
349
- {
350
- className: "eds-checkbox-icon",
351
- width: "11px",
352
- height: "9px",
353
- viewBox: "6 11 37 33",
354
- "aria-hidden": true,
355
- children: indeterminate ? /* @__PURE__ */ jsxRuntime.jsx("rect", { x: "10", y: "25", width: "28", height: "5", fill: "white" }) : /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M14.1 27.2l7.1 7.2 14.6-14.8", fill: "none" })
356
- }
357
- );
358
- };
359
- const Fieldset = ({
360
- children,
361
- className,
362
- label,
363
- ...rest
364
- }) => /* @__PURE__ */ jsxRuntime.jsxs("fieldset", { className: classNames("eds-fieldset", className), ...rest, children: [
365
- label && /* @__PURE__ */ jsxRuntime.jsx(typography.Heading5, { as: "legend", children: label }),
366
- children
367
- ] });
368
- const RadioGroupContext = React.createContext(
369
- null
370
- );
371
- const RadioGroupContextProvider = RadioGroupContext.Provider;
372
- const useRadioGroupContext = () => {
373
- const context = React.useContext(RadioGroupContext);
374
- if (!context) {
375
- throw new Error(
376
- "You need to wrap your RadioButtons in a RadioGroup component"
377
- );
378
- }
379
- return context;
380
- };
381
- const Radio = React.forwardRef(
382
- ({ className, children, value, disabled, readOnlyLabelDescription, ...rest }, ref) => {
383
- const {
384
- name,
385
- value: selectedValue,
386
- onChange,
387
- readOnly
388
- } = useRadioGroupContext();
389
- const classList = classNames(className, "eds-form-component--radio__radio", {
390
- "eds-form-component--radio__radio--disabled": disabled,
391
- "eds-form-component--radio__radio--readonly": readOnly
392
- });
393
- return /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "eds-form-component--radio__container", children: [
394
- /* @__PURE__ */ jsxRuntime.jsx(
395
- "input",
396
- {
397
- type: "radio",
398
- name: rest.name ?? name,
399
- ref,
400
- value,
401
- checked: rest.checked ?? selectedValue === value,
402
- onChange: (e) => {
403
- if (readOnly) {
404
- e.preventDefault();
405
- return;
406
- }
407
- (rest.onChange ?? onChange)?.(e);
408
- },
409
- onClick: (e) => {
410
- if (readOnly) {
411
- e.preventDefault();
412
- }
413
- },
414
- disabled,
415
- "aria-label": readOnly ? `${children?.toString()}. ${readOnlyLabelDescription ?? "Kan ikke endres"}` : void 0,
416
- ...rest
417
- }
418
- ),
419
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: classList, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "eds-form-component--radio__circle" }) }),
420
- children && /* @__PURE__ */ jsxRuntime.jsx(
421
- typography.Paragraph,
422
- {
423
- margin: "none",
424
- as: "span",
425
- className: "eds-form-component--radio__label",
426
- children
427
- }
428
- )
429
- ] });
430
- }
431
- );
432
- const InputPanelBase = React.forwardRef(
433
- ({
434
- className,
435
- children,
436
- value,
437
- title,
438
- secondaryLabel,
439
- size = "medium",
440
- hideSelectionIndicator = false,
441
- style,
442
- id,
443
- disabled = false,
444
- type = "radio",
445
- onChange,
446
- checked,
447
- name,
448
- ...rest
449
- }, ref) => {
450
- const classList = classNames(
451
- className,
452
- "eds-input-panel__container",
453
- `eds-input-panel--${size}`
454
- );
455
- const inputRef = React.useRef(null);
456
- const defaultId = utils.useRandomId("eds-inputpanel");
457
- const inputPanelId = id || defaultId;
458
- const forceUpdate = utils.useForceUpdate();
459
- const handleOnChange = (e) => {
460
- if (onChange === void 0) forceUpdate();
461
- onChange?.(e);
462
- };
463
- return /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "eds-input-panel", htmlFor: inputPanelId, children: [
464
- /* @__PURE__ */ jsxRuntime.jsx(
465
- "input",
466
- {
467
- type,
468
- name,
469
- ref: utils.mergeRefs(ref, inputRef),
470
- value,
471
- checked,
472
- onChange: handleOnChange,
473
- id: inputPanelId,
474
- disabled,
475
- ...rest
476
- }
477
- ),
478
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classList, style, children: [
479
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "eds-input-panel__title-wrapper", children: [
480
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "eds-input-panel__title", children: title }),
481
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "eds-input-panel__secondary-label-and-icon-wrapper", children: [
482
- secondaryLabel !== void 0 && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: secondaryLabel }),
483
- /* @__PURE__ */ jsxRuntime.jsx("span", { style: { pointerEvents: "none" }, children: !(disabled || hideSelectionIndicator) && (type === "radio" ? /* @__PURE__ */ jsxRuntime.jsx(
484
- Radio,
485
- {
486
- name: "",
487
- value: "",
488
- checked: checked ?? inputRef.current?.checked ?? false,
489
- onChange: () => {
490
- return;
491
- },
492
- "aria-hidden": "true",
493
- tabIndex: -1
494
- }
495
- ) : /* @__PURE__ */ jsxRuntime.jsx(
496
- Checkbox,
497
- {
498
- checked: checked ?? inputRef.current?.checked ?? false,
499
- onChange: () => null,
500
- "aria-hidden": "true",
501
- tabIndex: -1
502
- }
503
- )) })
504
- ] })
505
- ] }),
506
- children && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "eds-input-panel__additional-content", children })
507
- ] })
508
- ] });
509
- }
510
- );
511
- const RadioPanel = React.forwardRef(
512
- ({
513
- className,
514
- children,
515
- value,
516
- title,
517
- secondaryLabel,
518
- size = "medium",
519
- hideRadioButton = false,
520
- style,
521
- id,
522
- disabled = false,
523
- ...rest
524
- }, ref) => {
525
- const { name, value: selected, onChange } = useRadioGroupContext();
526
- return /* @__PURE__ */ jsxRuntime.jsx(
527
- InputPanelBase,
528
- {
529
- type: "radio",
530
- name,
531
- title,
532
- value,
533
- checked: selected === value,
534
- onChange,
535
- className,
536
- secondaryLabel,
537
- size,
538
- hideSelectionIndicator: hideRadioButton,
539
- style,
540
- id,
541
- disabled,
542
- ...rest,
543
- ref,
544
- children
545
- }
546
- );
547
- }
548
- );
549
- const CheckboxPanel = React.forwardRef(
550
- ({
551
- name,
552
- checked,
553
- onChange,
554
- className,
555
- children,
556
- value,
557
- title,
558
- secondaryLabel,
559
- size = "medium",
560
- hideCheckbox = false,
561
- style,
562
- id,
563
- disabled = false,
564
- ...rest
565
- }, ref) => {
566
- return /* @__PURE__ */ jsxRuntime.jsx(
567
- InputPanelBase,
568
- {
569
- type: "checkbox",
570
- name,
571
- title,
572
- value,
573
- checked,
574
- onChange,
575
- className,
576
- secondaryLabel,
577
- size,
578
- hideSelectionIndicator: hideCheckbox,
579
- style,
580
- id,
581
- disabled,
582
- ...rest,
583
- ref,
584
- children
585
- }
586
- );
587
- }
588
- );
589
- const RadioGroup = ({
590
- name,
591
- value,
592
- children,
593
- onChange,
594
- label,
595
- readOnly = false,
596
- ...rest
597
- }) => {
598
- const contextValue = React.useMemo(
599
- () => ({ name, value, onChange, readOnly }),
600
- [name, value, onChange, readOnly]
601
- );
602
- return /* @__PURE__ */ jsxRuntime.jsx(RadioGroupContextProvider, { value: contextValue, children: label ? /* @__PURE__ */ jsxRuntime.jsx(Fieldset, { label, ...rest, children }) : children });
603
- };
604
- const Switch = React.forwardRef(
605
- ({
606
- className,
607
- children,
608
- labelPlacement = "right",
609
- icon,
610
- hideIcon = false,
611
- color = tokens.colors.validation.mint,
612
- contrastColor = tokens.colors.validation.mintContrast,
613
- size = "medium",
614
- checked,
615
- ...rest
616
- }, ref) => {
617
- const displayedIcon = () => {
618
- if (icon) return icon;
619
- if (checked === void 0) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {});
620
- const iconSize = size === "large" ? 23 : void 0;
621
- return checked ? /* @__PURE__ */ jsxRuntime.jsx(icons.CheckIcon, { size: iconSize }) : /* @__PURE__ */ jsxRuntime.jsx(icons.CloseSmallIcon, { size: iconSize });
622
- };
623
- return /* @__PURE__ */ jsxRuntime.jsxs(
624
- "label",
625
- {
626
- className: classNames(
627
- "eds-switch",
628
- `eds-switch--${labelPlacement}`,
629
- className
630
- ),
631
- style: { ...rest.style },
632
- children: [
633
- /* @__PURE__ */ jsxRuntime.jsx("input", { type: "checkbox", ref, checked, ...rest }),
634
- /* @__PURE__ */ jsxRuntime.jsx(
635
- "span",
636
- {
637
- className: classNames(
638
- "eds-switch__switch",
639
- `eds-switch__switch--${size}`
640
- ),
641
- style: {
642
- "--eds-switch-color": color,
643
- "--eds-switch-contrast-color": contrastColor
644
- },
645
- "aria-hidden": "true",
646
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "eds-switch__circle", children: !hideIcon && displayedIcon() })
647
- }
648
- ),
649
- children && /* @__PURE__ */ jsxRuntime.jsx(
650
- "span",
651
- {
652
- className: classNames(
653
- "eds-switch__label",
654
- `eds-switch__label--${size}--${labelPlacement}`
655
- ),
656
- children
657
- }
658
- )
659
- ]
660
- }
661
- );
662
- }
663
- );
664
- function hasValue(value) {
665
- return value != null && !(Array.isArray(value) && value.length === 0);
666
- }
667
- function isFilled(obj, SSR = false) {
668
- return obj && (hasValue(obj.value) && obj.value !== "" || SSR && hasValue(obj.defaultValue) && obj.defaultValue !== "");
669
- }
670
- const TextArea = React.forwardRef(
671
- ({
672
- variant,
673
- disabled = false,
674
- readOnly = false,
675
- className,
676
- style,
677
- label,
678
- feedback,
679
- labelTooltip,
680
- labelTooltipButtonAriaLabel,
681
- labelTooltipPlacement,
682
- onChange,
683
- disableLabelAnimation,
684
- ...rest
685
- }, ref) => {
686
- const textAreaId = utils.useRandomId("eds-textarea");
687
- const textareaRef = React.useRef(null);
688
- return /* @__PURE__ */ jsxRuntime.jsx(
689
- BaseFormControl,
690
- {
691
- className: classNames(className, "eds-textarea__wrapper"),
692
- disabled,
693
- readOnly,
694
- variant,
695
- style,
696
- label,
697
- labelId: textAreaId,
698
- feedback,
699
- labelTooltip,
700
- labelTooltipButtonAriaLabel,
701
- labelTooltipPlacement,
702
- labelProps: { className: "eds-textarea__label" },
703
- disableLabelAnimation,
704
- onClick: (e) => {
705
- if (e.target === e.currentTarget) textareaRef?.current?.focus();
706
- },
707
- children: /* @__PURE__ */ jsxRuntime.jsx(
708
- TextAreaBase,
709
- {
710
- readOnly,
711
- disabled,
712
- ref: utils.mergeRefs(ref, textareaRef),
713
- "aria-labelledby": textAreaId,
714
- onChange,
715
- variant,
716
- ...rest
717
- }
718
- )
719
- }
720
- );
721
- }
722
- );
723
- const TextAreaBase = React.forwardRef(
724
- ({ readOnly, disabled, onChange, value, variant, ...rest }, ref) => {
725
- const contextVariant = useVariant();
726
- const currentVariant = variant || contextVariant;
727
- const { isFilled: isInputFilled, setFilled: setFiller } = useInputGroupContext();
728
- utils.useOnMount(() => {
729
- if (value?.toString() || rest.defaultValue) {
730
- setFiller && !isInputFilled && setFiller(true);
731
- }
732
- });
733
- React.useEffect(() => {
734
- if (value?.toString() && setFiller && !isInputFilled) {
735
- setFiller(true);
736
- }
737
- }, [value, setFiller, isInputFilled]);
738
- const handleChange = (event) => {
739
- if (isFilled(event.target)) {
740
- setFiller && !isInputFilled && setFiller(true);
741
- } else {
742
- setFiller && isInputFilled && setFiller(false);
743
- }
744
- if (onChange) {
745
- onChange(event);
746
- }
747
- };
748
- return /* @__PURE__ */ jsxRuntime.jsx(
749
- "textarea",
750
- {
751
- className: "eds-form-control eds-textarea",
752
- ref,
753
- readOnly,
754
- disabled,
755
- onChange: handleChange,
756
- value,
757
- "aria-invalid": currentVariant === "error",
758
- ...rest
759
- }
760
- );
761
- }
762
- );
763
- const TextField = React.forwardRef(
764
- ({
765
- prepend,
766
- append,
767
- variant,
768
- disabled = false,
769
- readOnly = false,
770
- className,
771
- style,
772
- size = "medium",
773
- label,
774
- required,
775
- labelTooltip,
776
- labelTooltipButtonAriaLabel,
777
- labelTooltipPlacement,
778
- feedback,
779
- onChange,
780
- disableLabelAnimation,
781
- labelProps,
782
- clearable = false,
783
- onClear,
784
- value,
785
- ariaAlertOnFeedback = false,
786
- ...rest
787
- }, ref) => {
788
- const randomId = utils.useRandomId("eds-textfield");
789
- const textFieldId = labelProps && labelProps.id ? labelProps.id : randomId;
790
- const textFieldRef = React.useRef(null);
791
- return /* @__PURE__ */ jsxRuntime.jsx(
792
- BaseFormControl,
793
- {
794
- disabled,
795
- readOnly,
796
- variant,
797
- prepend,
798
- append: clearable && onClear ? /* @__PURE__ */ jsxRuntime.jsx(ClearButton, { onClear }) : append,
799
- className: classNames(className, "eds-textfield__wrapper"),
800
- style,
801
- size,
802
- label,
803
- required,
804
- labelTooltip,
805
- labelTooltipButtonAriaLabel,
806
- labelTooltipPlacement,
807
- labelId: textFieldId,
808
- feedback,
809
- disableLabelAnimation,
810
- labelProps,
811
- ariaAlertOnFeedback,
812
- onClick: (e) => {
813
- if (e.target === e.currentTarget) textFieldRef?.current?.focus();
814
- },
815
- children: /* @__PURE__ */ jsxRuntime.jsx(
816
- TextFieldBase,
817
- {
818
- disabled,
819
- readOnly,
820
- ref: utils.mergeRefs(ref, textFieldRef),
821
- "aria-labelledby": textFieldId,
822
- onChange,
823
- value,
824
- variant,
825
- ...rest
826
- }
827
- )
828
- }
829
- );
830
- }
831
- );
832
- const TextFieldBase = React.forwardRef(
833
- ({ disabled, readOnly, placeholder, onChange, value, variant, ...rest }, forwardRef) => {
834
- const contextVariant = useVariant();
835
- const currentVariant = variant || contextVariant;
836
- const { isFilled: isInputFilled, setFilled: setFiller } = useInputGroupContext();
837
- utils.useOnMount(() => {
838
- if (value?.toString() || rest.defaultValue) {
839
- setFiller && !isInputFilled && setFiller(true);
840
- }
841
- });
842
- React.useEffect(() => {
843
- if (value?.toString() && setFiller && !isInputFilled) {
844
- setFiller(true);
845
- }
846
- }, [value, setFiller, isInputFilled]);
847
- const handleChange = (event) => {
848
- if (isFilled(event.target)) {
849
- setFiller && !isInputFilled && setFiller(true);
850
- } else {
851
- setFiller && isInputFilled && setFiller(false);
852
- }
853
- if (onChange) {
854
- onChange(event);
855
- }
856
- };
857
- return /* @__PURE__ */ jsxRuntime.jsx(
858
- "input",
859
- {
860
- "aria-invalid": currentVariant === "error",
861
- className: "eds-form-control",
862
- disabled,
863
- readOnly,
864
- ref: forwardRef,
865
- placeholder,
866
- onChange: handleChange,
867
- value,
868
- ...rest
869
- }
870
- );
871
- }
872
- );
873
- const ClearButton = ({ onClear, ...props }) => {
874
- const { isFilled: hasValue2, setFilled } = useInputGroupContext();
875
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "eds-textfield__clear-button-wrapper", children: [
876
- hasValue2 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "eds-textfield__divider" }),
877
- hasValue2 && /* @__PURE__ */ jsxRuntime.jsx(
878
- "button",
879
- {
880
- className: "eds-textfield__clear-button",
881
- type: "button",
882
- tabIndex: -1,
883
- onClick: () => {
884
- setFilled(false);
885
- onClear();
886
- },
887
- ...props,
888
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.CloseSmallIcon, {})
889
- }
890
- )
891
- ] });
892
- };
893
- const SegmentedContext = React.createContext(
894
- null
895
- );
896
- const SegmentedProvider = ({
897
- name,
898
- onChange = () => void 0,
899
- selectedValue,
900
- multiple,
901
- size,
902
- ...rest
903
- }) => {
904
- const generatedName = utils.useRandomId("eds-segmented-control");
905
- const contextValue = React.useMemo(
906
- () => ({
907
- name: name || generatedName,
908
- onChange,
909
- multiple,
910
- selectedValue,
911
- size
912
- }),
913
- [generatedName, multiple, name, onChange, selectedValue, size]
914
- );
915
- return /* @__PURE__ */ jsxRuntime.jsx(SegmentedContext.Provider, { value: contextValue, ...rest });
916
- };
917
- const useSegmentedContext = () => {
918
- const context = React.useContext(SegmentedContext);
919
- if (!context) {
920
- throw new Error(
921
- "You need to wrap your SegmentedChoice in either SegmentedControl or MultipleSegmentedControl"
922
- );
923
- }
924
- return context;
925
- };
926
- const SegmentedChoice = React.forwardRef(
927
- ({
928
- children,
929
- className,
930
- style,
931
- value,
932
- name,
933
- onChange = () => void 0,
934
- ...rest
935
- }, ref) => {
936
- const {
937
- name: commonName,
938
- selectedValue,
939
- onChange: commonOnChange,
940
- multiple,
941
- size
942
- } = useSegmentedContext();
943
- const isChecked = multiple ? selectedValue[value] : selectedValue === value;
944
- const handleChange = (e) => {
945
- onChange(e);
946
- if (multiple) {
947
- commonOnChange({
948
- ...selectedValue,
949
- [value]: e.target.checked
950
- });
951
- } else if (e.target.checked) {
952
- commonOnChange(value);
953
- }
954
- };
955
- return /* @__PURE__ */ jsxRuntime.jsxs(
956
- "label",
957
- {
958
- className: classNames("eds-segmented-choice", className),
959
- style,
960
- children: [
961
- /* @__PURE__ */ jsxRuntime.jsx(
962
- "input",
963
- {
964
- type: multiple ? "checkbox" : "radio",
965
- name: name || commonName,
966
- checked: isChecked,
967
- value,
968
- onChange: handleChange,
969
- ref,
970
- ...rest
971
- }
972
- ),
973
- /* @__PURE__ */ jsxRuntime.jsx(
974
- "div",
975
- {
976
- className: classNames("eds-base-segmented", {
977
- "eds-base-segmented--large": size === "large"
978
- }),
979
- children
980
- }
981
- )
982
- ]
983
- }
984
- );
985
- }
986
- );
987
- const SegmentedControl = ({
988
- children,
989
- label,
990
- name,
991
- onChange,
992
- selectedValue,
993
- size = "medium",
994
- className,
995
- ...rest
996
- }) => {
997
- return /* @__PURE__ */ jsxRuntime.jsx(
998
- SegmentedProvider,
999
- {
1000
- name,
1001
- selectedValue,
1002
- onChange,
1003
- multiple: false,
1004
- size,
1005
- children: /* @__PURE__ */ jsxRuntime.jsx(Fieldset, { label, children: /* @__PURE__ */ jsxRuntime.jsx(
1006
- "div",
1007
- {
1008
- className: classNames("eds-segmented-control", className),
1009
- ...rest,
1010
- children
1011
- }
1012
- ) })
1013
- }
1014
- );
1015
- };
1016
- const MultipleSegmentedControl = ({ children, label, name, onChange, selectedValue, ...rest }) => {
1017
- return /* @__PURE__ */ jsxRuntime.jsxs(
1018
- SegmentedProvider,
1019
- {
1020
- name,
1021
- selectedValue,
1022
- onChange,
1023
- multiple: true,
1024
- size: "medium",
1025
- children: [
1026
- /* @__PURE__ */ jsxRuntime.jsx(typography.Label, { as: "div", children: label }),
1027
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "eds-segmented-control", ...rest, children })
1028
- ]
1029
- }
1030
- );
1031
- };
1032
- utils.warnAboutMissingStyles("form", "icons", "typography");
1033
- exports.BaseFormControl = BaseFormControl;
1034
- exports.Checkbox = Checkbox;
1035
- exports.CheckboxPanel = CheckboxPanel;
1036
- exports.FeedbackText = FeedbackText;
1037
- exports.Fieldset = Fieldset;
1038
- exports.InputGroupContextProvider = InputGroupContextProvider;
1039
- exports.InputGroupLabel = InputGroupLabel;
1040
- exports.MultipleSegmentedControl = MultipleSegmentedControl;
1041
- exports.Radio = Radio;
1042
- exports.RadioGroup = RadioGroup;
1043
- exports.RadioPanel = RadioPanel;
1044
- exports.SegmentedChoice = SegmentedChoice;
1045
- exports.SegmentedControl = SegmentedControl;
1046
- exports.Switch = Switch;
1047
- exports.TextArea = TextArea;
1048
- exports.TextField = TextField;
1049
- exports.VariantProvider = VariantProvider;
1050
- exports.hasValue = hasValue;
1051
- exports.isFilled = isFilled;
1052
- exports.useInputGroupContext = useInputGroupContext;
1053
- exports.useVariant = useVariant;
1054
- //# sourceMappingURL=form.cjs.js.map