@entur/form 8.3.2-beta.8 → 8.3.2

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