@entur/form 8.3.1 → 8.3.2-beta.0

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