@entur/form 8.2.10 → 8.3.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.
@@ -55,6 +55,8 @@ export type BaseFormControlProps = React.HTMLAttributes<HTMLDivElement> & {
55
55
  after?: React.ReactNode;
56
56
  /** Legg til et element før feltet */
57
57
  before?: React.ReactNode;
58
+ /** Aria-label som brukes når inputfeltet er i read-only modus */
59
+ ariaLabelOnReadOnly?: string;
58
60
  };
59
61
  export declare const BaseFormControl: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
60
62
  /** Et skjemaelement med `eds-form-control`-klassen */
@@ -105,5 +107,7 @@ export declare const BaseFormControl: React.ForwardRefExoticComponent<React.HTML
105
107
  after?: React.ReactNode;
106
108
  /** Legg til et element før feltet */
107
109
  before?: React.ReactNode;
110
+ /** Aria-label som brukes når inputfeltet er i read-only modus */
111
+ ariaLabelOnReadOnly?: string;
108
112
  } & React.RefAttributes<HTMLDivElement>>;
109
113
  export {};
@@ -13,12 +13,20 @@ export type CheckboxProps = {
13
13
  * @default false
14
14
  */
15
15
  disabled?: boolean;
16
+ /** Sett til true om skjema-elementet er i read-only modus
17
+ * @default false
18
+ */
19
+ readOnly?: boolean;
16
20
  /**Ekstra styling til komponenten */
17
21
  style?: CSSProperties;
18
22
  /** Reduserer klikkflaten for Checkbox'en
19
23
  * @default false
20
24
  */
21
25
  reduceClickArea?: boolean;
26
+ /** Om animasjon skal deaktiveres
27
+ * @default false
28
+ */
29
+ disableAnimation?: boolean;
22
30
  } & Omit<React.InputHTMLAttributes<HTMLInputElement>, 'checked'>;
23
31
  export declare const Checkbox: React.ForwardRefExoticComponent<{
24
32
  /** Ekstra klassenavn */
@@ -33,10 +41,18 @@ export declare const Checkbox: React.ForwardRefExoticComponent<{
33
41
  * @default false
34
42
  */
35
43
  disabled?: boolean;
44
+ /** Sett til true om skjema-elementet er i read-only modus
45
+ * @default false
46
+ */
47
+ readOnly?: boolean;
36
48
  /**Ekstra styling til komponenten */
37
49
  style?: CSSProperties;
38
50
  /** Reduserer klikkflaten for Checkbox'en
39
51
  * @default false
40
52
  */
41
53
  reduceClickArea?: boolean;
54
+ /** Om animasjon skal deaktiveres
55
+ * @default false
56
+ */
57
+ disableAnimation?: boolean;
42
58
  } & Omit<React.InputHTMLAttributes<HTMLInputElement>, "checked"> & React.RefAttributes<HTMLInputElement>>;
package/dist/Radio.d.ts CHANGED
@@ -11,6 +11,8 @@ export type RadioProps = {
11
11
  * @default false
12
12
  */
13
13
  disabled?: boolean;
14
+ /** Beskrivelse som leses opp av skjermlesere når radiobutton er readonly */
15
+ readOnlyLabelDescription?: string;
14
16
  } & React.InputHTMLAttributes<HTMLInputElement>;
15
17
  export declare const Radio: React.ForwardRefExoticComponent<{
16
18
  /** Ekstra klassenavn */
@@ -23,4 +25,6 @@ export declare const Radio: React.ForwardRefExoticComponent<{
23
25
  * @default false
24
26
  */
25
27
  disabled?: boolean;
28
+ /** Beskrivelse som leses opp av skjermlesere når radiobutton er readonly */
29
+ readOnlyLabelDescription?: string;
26
30
  } & React.InputHTMLAttributes<HTMLInputElement> & React.RefAttributes<HTMLInputElement>>;
@@ -11,5 +11,7 @@ export type RadioGroupProps = {
11
11
  /** En callback som blir kalles hver gang en radioknapp klikkes på */
12
12
  onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
13
13
  [key: string]: any;
14
+ /** Sett radiogruppen i readonly-modus */
15
+ readOnly?: boolean;
14
16
  };
15
17
  export declare const RadioGroup: React.FC<RadioGroupProps>;
@@ -3,6 +3,7 @@ type RadioGroupContextProps = {
3
3
  name: string;
4
4
  onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
5
5
  value: string | null;
6
+ readOnly?: boolean;
6
7
  };
7
8
  export declare const RadioGroupContextProvider: React.Provider<RadioGroupContextProps | null>;
8
9
  export declare const useRadioGroupContext: () => RadioGroupContextProps;
@@ -163,7 +163,7 @@ var useVariant = function useVariant() {
163
163
  return context;
164
164
  };
165
165
 
166
- 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"];
166
+ 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"];
167
167
  /** @deprecated use variant="negative" instead */
168
168
  var error = 'error';
169
169
  var BaseFormControl = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
@@ -196,6 +196,8 @@ var BaseFormControl = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
196
196
  disableLabelAnimation = _ref$disableLabelAnim === void 0 ? false : _ref$disableLabelAnim,
197
197
  _ref$ariaAlertOnFeedb = _ref.ariaAlertOnFeedback,
198
198
  ariaAlertOnFeedback = _ref$ariaAlertOnFeedb === void 0 ? false : _ref$ariaAlertOnFeedb,
199
+ _ref$ariaLabelOnReadO = _ref.ariaLabelOnReadOnly,
200
+ ariaLabelOnReadOnly = _ref$ariaLabelOnReadO === void 0 ? 'Dette skjemafeltet kan bare leses' : _ref$ariaLabelOnReadO,
199
201
  rest = _objectWithoutPropertiesLoose(_ref, _excluded$e);
200
202
  var contextVariant = useVariant();
201
203
  var currentVariant = variant || contextVariant;
@@ -212,14 +214,16 @@ var BaseFormControl = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
212
214
  'eds-form-control-wrapper--readonly': readOnly,
213
215
  'eds-form-control-wrapper--is-filled': isFilled
214
216
  }),
215
- ref: ref
217
+ ref: ref,
218
+ tabIndex: readOnly ? -1 : 0
216
219
  }, rest), prepend && React.createElement("div", {
217
220
  className: "eds-form-control__prepend"
218
221
  }, prepend), React.createElement(InputGroupLabel, _extends({
219
222
  label: label,
220
223
  required: required,
221
224
  labelId: labelId,
222
- staticAnimation: disableLabelAnimation
225
+ staticAnimation: disableLabelAnimation,
226
+ "aria-label": readOnly ? label + ", " + ariaLabelOnReadOnly : undefined
223
227
  }, labelProps)), labelTooltip && React.createElement(tooltip.Tooltip, {
224
228
  content: labelTooltip,
225
229
  placement: labelTooltipPlacement,
@@ -245,7 +249,7 @@ var BaseFormControl = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
245
249
  }, feedback), after));
246
250
  });
247
251
 
248
- var _excluded$d = ["checked", "className", "children", "style", "disabled", "reduceClickArea"];
252
+ var _excluded$d = ["checked", "className", "children", "style", "disabled", "readOnly", "reduceClickArea", "disableAnimation"];
249
253
  var Checkbox = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
250
254
  var checked = _ref.checked,
251
255
  className = _ref.className,
@@ -253,7 +257,11 @@ var Checkbox = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
253
257
  style = _ref.style,
254
258
  _ref$disabled = _ref.disabled,
255
259
  disabled = _ref$disabled === void 0 ? false : _ref$disabled,
260
+ _ref$readOnly = _ref.readOnly,
261
+ readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
256
262
  reduceClickArea = _ref.reduceClickArea,
263
+ _ref$disableAnimation = _ref.disableAnimation,
264
+ disableAnimation = _ref$disableAnimation === void 0 ? false : _ref$disableAnimation,
257
265
  rest = _objectWithoutPropertiesLoose(_ref, _excluded$d);
258
266
  var inputRef = React.useRef(null);
259
267
  var isIndeterminate = checked === 'indeterminate';
@@ -266,6 +274,7 @@ var Checkbox = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
266
274
  return React.createElement("label", {
267
275
  className: classNames('eds-checkbox__container', className, {
268
276
  'eds-checkbox--disabled': disabled,
277
+ 'eds-checkbox--readonly': readOnly,
269
278
  'eds-checkbox__container--reduced-click-area': reduceClickArea
270
279
  }),
271
280
  style: style
@@ -273,11 +282,20 @@ var Checkbox = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
273
282
  type: "checkbox",
274
283
  ref: utils.mergeRefs(ref, inputRef),
275
284
  checked: isControlled ? checked === true : undefined,
276
- disabled: disabled
285
+ disabled: disabled,
286
+ onKeyDown: function onKeyDown(e) {
287
+ if (readOnly && (e.key === ' ' || e.key === 'Enter')) {
288
+ e.preventDefault();
289
+ e.stopPropagation();
290
+ }
291
+ },
292
+ "aria-label": readOnly ? " " + (children == null ? void 0 : children.toString()) + ". Kan ikke endres" : undefined
277
293
  }, rest)), React.createElement("span", {
278
294
  className: classNames('eds-checkbox__icon', {
279
295
  'eds-checkbox__icon--disabled': disabled,
280
- 'eds-checkbox__icon--reduced-click-area': reduceClickArea
296
+ 'eds-checkbox__icon--readonly': readOnly,
297
+ 'eds-checkbox__icon--reduced-click-area': reduceClickArea,
298
+ 'eds-checkbox__icon--no-animation': disableAnimation || disabled || readOnly
281
299
  })
282
300
  }, React.createElement(CheckboxIcon, {
283
301
  indeterminate: isIndeterminate
@@ -331,21 +349,24 @@ var useRadioGroupContext = function useRadioGroupContext() {
331
349
  return context;
332
350
  };
333
351
 
334
- var _excluded$b = ["className", "children", "value", "disabled"];
352
+ var _excluded$b = ["className", "children", "value", "disabled", "readOnlyLabelDescription"];
335
353
  var Radio = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
336
- var _rest$name, _rest$checked, _rest$onChange;
354
+ var _rest$name, _rest$checked;
337
355
  var className = _ref.className,
338
356
  children = _ref.children,
339
357
  value = _ref.value,
340
358
  disabled = _ref.disabled,
359
+ readOnlyLabelDescription = _ref.readOnlyLabelDescription,
341
360
  rest = _objectWithoutPropertiesLoose(_ref, _excluded$b);
342
- var classList = classNames(className, 'eds-form-component--radio__radio', {
343
- 'eds-form-component--radio__radio--disabled': disabled
344
- });
345
361
  var _useRadioGroupContext = useRadioGroupContext(),
346
362
  name = _useRadioGroupContext.name,
347
363
  selectedValue = _useRadioGroupContext.value,
348
- onChange = _useRadioGroupContext.onChange;
364
+ _onChange = _useRadioGroupContext.onChange,
365
+ readOnly = _useRadioGroupContext.readOnly;
366
+ var classList = classNames(className, 'eds-form-component--radio__radio', {
367
+ 'eds-form-component--radio__radio--disabled': disabled,
368
+ 'eds-form-component--radio__radio--readonly': readOnly
369
+ });
349
370
  return React.createElement("label", {
350
371
  className: "eds-form-component--radio__container"
351
372
  }, React.createElement("input", _extends({
@@ -354,8 +375,21 @@ var Radio = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
354
375
  ref: ref,
355
376
  value: value,
356
377
  checked: (_rest$checked = rest.checked) != null ? _rest$checked : selectedValue === value,
357
- onChange: (_rest$onChange = rest.onChange) != null ? _rest$onChange : onChange,
358
- disabled: disabled
378
+ onChange: function onChange(e) {
379
+ var _ref2, _rest$onChange;
380
+ if (readOnly) {
381
+ e.preventDefault();
382
+ return;
383
+ }
384
+ (_ref2 = (_rest$onChange = rest.onChange) != null ? _rest$onChange : _onChange) == null || _ref2(e);
385
+ },
386
+ onClick: function onClick(e) {
387
+ if (readOnly) {
388
+ e.preventDefault();
389
+ }
390
+ },
391
+ disabled: disabled,
392
+ "aria-label": readOnly ? (children == null ? void 0 : children.toString()) + ". " + (readOnlyLabelDescription != null ? readOnlyLabelDescription : 'Kan ikke endres') : undefined
359
393
  }, rest)), React.createElement("span", {
360
394
  className: classList
361
395
  }, React.createElement("span", {
@@ -521,21 +555,24 @@ var CheckboxPanel = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
521
555
  }), children);
522
556
  });
523
557
 
524
- var _excluded$7 = ["name", "value", "children", "onChange", "label"];
558
+ var _excluded$7 = ["name", "value", "children", "onChange", "label", "readOnly"];
525
559
  var RadioGroup = function RadioGroup(_ref) {
526
560
  var name = _ref.name,
527
561
  value = _ref.value,
528
562
  children = _ref.children,
529
563
  onChange = _ref.onChange,
530
564
  label = _ref.label,
565
+ _ref$readOnly = _ref.readOnly,
566
+ readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
531
567
  rest = _objectWithoutPropertiesLoose(_ref, _excluded$7);
532
568
  var contextValue = React.useMemo(function () {
533
569
  return {
534
570
  name: name,
535
571
  value: value,
536
- onChange: onChange
572
+ onChange: onChange,
573
+ readOnly: readOnly
537
574
  };
538
- }, [name, value, onChange]);
575
+ }, [name, value, onChange, readOnly]);
539
576
  return React.createElement(RadioGroupContextProvider, {
540
577
  value: contextValue
541
578
  }, label ? React.createElement(Fieldset, _extends({