carbon-react 128.1.2 → 128.2.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.
Files changed (98) hide show
  1. package/esm/__internal__/checkable-input/checkable-input.component.d.ts +2 -0
  2. package/esm/__internal__/checkable-input/checkable-input.component.js +4 -2
  3. package/esm/__internal__/fieldset/fieldset.style.js +7 -6
  4. package/esm/__internal__/form-field/form-field.component.d.ts +1 -1
  5. package/esm/__internal__/form-field/form-field.component.js +1 -0
  6. package/esm/__internal__/label/label.style.js +6 -5
  7. package/esm/components/checkbox/checkbox-group/checkbox-group.component.d.ts +2 -0
  8. package/esm/components/checkbox/checkbox-group/checkbox-group.component.js +5 -2
  9. package/esm/components/checkbox/checkbox.component.js +3 -0
  10. package/esm/components/date-range/date-range.component.d.ts +5 -1
  11. package/esm/components/date-range/date-range.component.js +5 -1
  12. package/esm/components/decimal/decimal.component.d.ts +0 -2
  13. package/esm/components/decimal/decimal.component.js +1 -2
  14. package/esm/components/fieldset/fieldset.component.d.ts +8 -3
  15. package/esm/components/fieldset/fieldset.component.js +16 -2
  16. package/esm/components/fieldset/fieldset.style.d.ts +4 -0
  17. package/esm/components/fieldset/fieldset.style.js +29 -2
  18. package/esm/components/file-input/file-input.component.d.ts +4 -0
  19. package/esm/components/file-input/file-input.component.js +3 -0
  20. package/esm/components/form/index.d.ts +1 -0
  21. package/esm/components/form/index.js +2 -1
  22. package/esm/components/form/required-fields-indicator/index.d.ts +1 -0
  23. package/esm/components/form/required-fields-indicator/index.js +1 -0
  24. package/esm/components/form/required-fields-indicator/required-fields-indicator.component.d.ts +7 -0
  25. package/esm/components/form/required-fields-indicator/required-fields-indicator.component.js +20 -0
  26. package/esm/components/inline-inputs/inline-inputs.component.d.ts +3 -1
  27. package/esm/components/inline-inputs/inline-inputs.component.js +13 -3
  28. package/esm/components/numeral-date/numeral-date.component.d.ts +3 -1
  29. package/esm/components/numeral-date/numeral-date.component.js +4 -3
  30. package/esm/components/radio-button/radio-button-group/radio-button-group.component.d.ts +2 -0
  31. package/esm/components/radio-button/radio-button-group/radio-button-group.component.js +5 -3
  32. package/esm/components/radio-button/radio-button.component.d.ts +1 -2
  33. package/esm/components/radio-button/radio-button.component.js +1 -3
  34. package/esm/components/select/filterable-select/filterable-select.component.d.ts +4 -0
  35. package/esm/components/select/filterable-select/filterable-select.component.js +5 -0
  36. package/esm/components/select/multi-select/multi-select.component.d.ts +2 -0
  37. package/esm/components/select/multi-select/multi-select.component.js +5 -0
  38. package/esm/components/select/select-textbox/select-textbox.component.d.ts +2 -0
  39. package/esm/components/select/select-textbox/select-textbox.component.js +3 -0
  40. package/esm/components/select/simple-select/simple-select.component.d.ts +4 -0
  41. package/esm/components/select/simple-select/simple-select.component.js +6 -0
  42. package/esm/components/switch/switch.component.js +1 -0
  43. package/esm/components/text-editor/text-editor.component.d.ts +3 -1
  44. package/esm/components/text-editor/text-editor.component.js +16 -2
  45. package/esm/components/textarea/textarea.component.d.ts +2 -2
  46. package/esm/components/textarea/textarea.component.js +7 -2
  47. package/esm/components/textbox/textbox.component.d.ts +2 -2
  48. package/esm/components/tile-select/tile-select.style.d.ts +1 -1
  49. package/lib/__internal__/checkable-input/checkable-input.component.d.ts +2 -0
  50. package/lib/__internal__/checkable-input/checkable-input.component.js +4 -2
  51. package/lib/__internal__/fieldset/fieldset.style.js +7 -6
  52. package/lib/__internal__/form-field/form-field.component.d.ts +1 -1
  53. package/lib/__internal__/form-field/form-field.component.js +1 -0
  54. package/lib/__internal__/label/label.style.js +6 -5
  55. package/lib/components/checkbox/checkbox-group/checkbox-group.component.d.ts +2 -0
  56. package/lib/components/checkbox/checkbox-group/checkbox-group.component.js +5 -2
  57. package/lib/components/checkbox/checkbox.component.js +3 -0
  58. package/lib/components/date-range/date-range.component.d.ts +5 -1
  59. package/lib/components/date-range/date-range.component.js +5 -1
  60. package/lib/components/decimal/decimal.component.d.ts +0 -2
  61. package/lib/components/decimal/decimal.component.js +1 -2
  62. package/lib/components/fieldset/fieldset.component.d.ts +8 -3
  63. package/lib/components/fieldset/fieldset.component.js +18 -2
  64. package/lib/components/fieldset/fieldset.style.d.ts +4 -0
  65. package/lib/components/fieldset/fieldset.style.js +31 -2
  66. package/lib/components/file-input/file-input.component.d.ts +4 -0
  67. package/lib/components/file-input/file-input.component.js +3 -0
  68. package/lib/components/form/index.d.ts +1 -0
  69. package/lib/components/form/index.js +7 -0
  70. package/lib/components/form/required-fields-indicator/index.d.ts +1 -0
  71. package/lib/components/form/required-fields-indicator/index.js +13 -0
  72. package/lib/components/form/required-fields-indicator/package.json +6 -0
  73. package/lib/components/form/required-fields-indicator/required-fields-indicator.component.d.ts +7 -0
  74. package/lib/components/form/required-fields-indicator/required-fields-indicator.component.js +28 -0
  75. package/lib/components/inline-inputs/inline-inputs.component.d.ts +3 -1
  76. package/lib/components/inline-inputs/inline-inputs.component.js +14 -4
  77. package/lib/components/numeral-date/numeral-date.component.d.ts +3 -1
  78. package/lib/components/numeral-date/numeral-date.component.js +4 -3
  79. package/lib/components/radio-button/radio-button-group/radio-button-group.component.d.ts +2 -0
  80. package/lib/components/radio-button/radio-button-group/radio-button-group.component.js +5 -3
  81. package/lib/components/radio-button/radio-button.component.d.ts +1 -2
  82. package/lib/components/radio-button/radio-button.component.js +1 -3
  83. package/lib/components/select/filterable-select/filterable-select.component.d.ts +4 -0
  84. package/lib/components/select/filterable-select/filterable-select.component.js +5 -0
  85. package/lib/components/select/multi-select/multi-select.component.d.ts +2 -0
  86. package/lib/components/select/multi-select/multi-select.component.js +5 -0
  87. package/lib/components/select/select-textbox/select-textbox.component.d.ts +2 -0
  88. package/lib/components/select/select-textbox/select-textbox.component.js +3 -0
  89. package/lib/components/select/simple-select/simple-select.component.d.ts +4 -0
  90. package/lib/components/select/simple-select/simple-select.component.js +6 -0
  91. package/lib/components/switch/switch.component.js +1 -0
  92. package/lib/components/text-editor/text-editor.component.d.ts +3 -1
  93. package/lib/components/text-editor/text-editor.component.js +16 -2
  94. package/lib/components/textarea/textarea.component.d.ts +2 -2
  95. package/lib/components/textarea/textarea.component.js +7 -2
  96. package/lib/components/textbox/textbox.component.d.ts +2 -2
  97. package/lib/components/tile-select/tile-select.style.d.ts +1 -1
  98. package/package.json +1 -1
@@ -29,7 +29,6 @@ const RadioButton = /*#__PURE__*/React.forwardRef(({
29
29
  onFocus,
30
30
  value,
31
31
  reverse = false,
32
- required,
33
32
  size,
34
33
  error,
35
34
  warning,
@@ -97,7 +96,6 @@ const RadioButton = /*#__PURE__*/React.forwardRef(({
97
96
  * opposite way around by default)
98
97
  */
99
98
  reverse: !reverse,
100
- required,
101
99
  ref: ref || inputRef,
102
100
  ...props
103
101
  };
@@ -225,6 +223,7 @@ if (process.env.NODE_ENV !== "production") {
225
223
  })]),
226
224
  "inputWidth": PropTypes.number,
227
225
  "is": PropTypes.string,
226
+ "isOptional": PropTypes.bool,
228
227
  "itemID": PropTypes.string,
229
228
  "itemProp": PropTypes.string,
230
229
  "itemRef": PropTypes.string,
@@ -565,7 +564,6 @@ if (process.env.NODE_ENV !== "production") {
565
564
  "radioGroup": PropTypes.string,
566
565
  "readOnly": PropTypes.bool,
567
566
  "rel": PropTypes.string,
568
- "required": PropTypes.bool,
569
567
  "resource": PropTypes.string,
570
568
  "results": PropTypes.number,
571
569
  "rev": PropTypes.string,
@@ -61,6 +61,10 @@ export interface FilterableSelectProps extends Omit<FormInputPropTypes, "default
61
61
  /** Boolean to disable automatic filtering and highlighting of options.
62
62
  * This allows custom filtering and option styling to be performed outside of the component when the filter text changes. */
63
63
  disableDefaultFiltering?: boolean;
64
+ /** Flag to configure component as optional. */
65
+ isOptional?: boolean;
66
+ /** Flag to configure component as mandatory */
67
+ required?: boolean;
64
68
  }
65
69
  export declare const FilterableSelect: React.ForwardRefExoticComponent<FilterableSelectProps & React.RefAttributes<unknown>>;
66
70
  export default FilterableSelect;
@@ -54,6 +54,8 @@ const FilterableSelect = /*#__PURE__*/React.forwardRef(({
54
54
  enableVirtualScroll,
55
55
  virtualScrollOverscan,
56
56
  disableDefaultFiltering = false,
57
+ isOptional,
58
+ required,
57
59
  ...textboxProps
58
60
  }, ref) => {
59
61
  const [activeDescendantId, setActiveDescendantId] = useState();
@@ -397,6 +399,8 @@ const FilterableSelect = /*#__PURE__*/React.forwardRef(({
397
399
  onMouseDown: handleTextboxMouseDown,
398
400
  tooltipPosition,
399
401
  inputRef,
402
+ required,
403
+ isOptional,
400
404
  ...filterOutStyledSystemSpacingProps(textboxProps)
401
405
  };
402
406
  }
@@ -565,6 +569,7 @@ if (process.env.NODE_ENV !== "production") {
565
569
  "inputWidth": PropTypes.number,
566
570
  "is": PropTypes.string,
567
571
  "isLoading": PropTypes.bool,
572
+ "isOptional": PropTypes.bool,
568
573
  "itemID": PropTypes.string,
569
574
  "itemProp": PropTypes.string,
570
575
  "itemRef": PropTypes.string,
@@ -55,6 +55,8 @@ export interface MultiSelectProps extends Omit<FormInputPropTypes, "defaultValue
55
55
  * Higher values make for smoother scrolling but may impact performance.
56
56
  * Only used if the `enableVirtualScroll` prop is set. */
57
57
  virtualScrollOverscan?: number;
58
+ /** Flag to configure component as optional. */
59
+ isOptional?: boolean;
58
60
  }
59
61
  export declare const MultiSelect: React.ForwardRefExoticComponent<MultiSelectProps & React.RefAttributes<unknown>>;
60
62
  export default MultiSelect;
@@ -55,6 +55,8 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
55
55
  inputRef,
56
56
  enableVirtualScroll,
57
57
  virtualScrollOverscan,
58
+ isOptional,
59
+ required,
58
60
  ...textboxProps
59
61
  }, ref) => {
60
62
  const [activeDescendantId, setActiveDescendantId] = useState();
@@ -404,6 +406,8 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
404
406
  onChange: handleTextboxChange,
405
407
  tooltipPosition,
406
408
  size,
409
+ required,
410
+ isOptional,
407
411
  inputRef,
408
412
  ...filterOutStyledSystemSpacingProps(textboxProps)
409
413
  };
@@ -574,6 +578,7 @@ if (process.env.NODE_ENV !== "production") {
574
578
  "inputWidth": PropTypes.number,
575
579
  "is": PropTypes.string,
576
580
  "isLoading": PropTypes.bool,
581
+ "isOptional": PropTypes.bool,
577
582
  "itemID": PropTypes.string,
578
583
  "itemProp": PropTypes.string,
579
584
  "itemRef": PropTypes.string,
@@ -59,6 +59,8 @@ export interface FormInputPropTypes extends ValidationProps, Omit<CommonTextboxP
59
59
  *
60
60
  */
61
61
  labelId?: string;
62
+ /** Flag to configure component as optional in Form */
63
+ isOptional?: boolean;
62
64
  }
63
65
  export interface SelectTextboxProps extends FormInputPropTypes {
64
66
  /** Id attribute of the select list */
@@ -37,6 +37,7 @@ const SelectTextbox = /*#__PURE__*/React.forwardRef(({
37
37
  onChange,
38
38
  selectedValue,
39
39
  required,
40
+ isOptional,
40
41
  textboxRef,
41
42
  hasTextCursor,
42
43
  transparent,
@@ -80,6 +81,7 @@ const SelectTextbox = /*#__PURE__*/React.forwardRef(({
80
81
  id,
81
82
  readOnly,
82
83
  required,
84
+ isOptional,
83
85
  onClick: handleTextboxClick,
84
86
  onFocus: handleTextboxFocus,
85
87
  onBlur: handleTextboxBlur,
@@ -234,6 +236,7 @@ if (process.env.NODE_ENV !== "production") {
234
236
  "inputWidth": PropTypes.number,
235
237
  "is": PropTypes.string,
236
238
  "isOpen": PropTypes.bool,
239
+ "isOptional": PropTypes.bool,
237
240
  "itemID": PropTypes.string,
238
241
  "itemProp": PropTypes.string,
239
242
  "itemRef": PropTypes.string,
@@ -61,6 +61,10 @@ export interface SimpleSelectProps extends Omit<FormInputPropTypes, "defaultValu
61
61
  * Higher values make for smoother scrolling but may impact performance.
62
62
  * Only used if the `enableVirtualScroll` prop is set. */
63
63
  virtualScrollOverscan?: number;
64
+ /** Flag to configure component as optional in Form */
65
+ isOptional?: boolean;
66
+ /** Flag to configure component as mandatory */
67
+ isRequired?: boolean;
64
68
  }
65
69
  export declare const SimpleSelect: React.ForwardRefExoticComponent<SimpleSelectProps & React.RefAttributes<unknown>>;
66
70
  export default SimpleSelect;
@@ -48,6 +48,8 @@ const SimpleSelect = /*#__PURE__*/React.forwardRef(({
48
48
  inputRef,
49
49
  enableVirtualScroll,
50
50
  virtualScrollOverscan,
51
+ isOptional,
52
+ required,
51
53
  ...props
52
54
  }, ref) => {
53
55
  const selectListId = useRef(guid());
@@ -314,6 +316,8 @@ const SimpleSelect = /*#__PURE__*/React.forwardRef(({
314
316
  onKeyDown: handleTextboxKeydown,
315
317
  onBlur: handleTextboxBlur,
316
318
  tooltipPosition,
319
+ required,
320
+ isOptional,
317
321
  transparent,
318
322
  inputRef,
319
323
  ...filterOutStyledSystemSpacingProps(props)
@@ -476,6 +480,8 @@ if (process.env.NODE_ENV !== "production") {
476
480
  "inputWidth": PropTypes.number,
477
481
  "is": PropTypes.string,
478
482
  "isLoading": PropTypes.bool,
483
+ "isOptional": PropTypes.bool,
484
+ "isRequired": PropTypes.bool,
479
485
  "itemID": PropTypes.string,
480
486
  "itemProp": PropTypes.string,
481
487
  "itemRef": PropTypes.string,
@@ -275,6 +275,7 @@ if (process.env.NODE_ENV !== "production") {
275
275
  })]),
276
276
  "inputWidth": PropTypes.number,
277
277
  "is": PropTypes.string,
278
+ "isOptional": PropTypes.bool,
278
279
  "itemID": PropTypes.string,
279
280
  "itemProp": PropTypes.string,
280
281
  "itemRef": PropTypes.string,
@@ -16,8 +16,10 @@ export interface TextEditorProps extends MarginProps {
16
16
  toolbarElements?: React.ReactNode;
17
17
  /** The value of the input, this is an EditorState immutable object */
18
18
  value: EditorState;
19
- /** Flag to configure component as mandatory */
19
+ /** Flag to configure component as mandatory. */
20
20
  required?: boolean;
21
+ /** Flag to configure component as optional. */
22
+ isOptional?: boolean;
21
23
  /** Message to be displayed when there is an error */
22
24
  error?: string;
23
25
  /** Message to be displayed when there is a warning */
@@ -1,3 +1,4 @@
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
1
2
  import React, { useCallback, useEffect, useRef, useState, useContext } from "react";
2
3
  import PropTypes from "prop-types";
3
4
  import { ContentState, EditorState, RichUtils, getDefaultKeyBinding, Modifier, Editor } from "draft-js";
@@ -33,6 +34,7 @@ const TextEditor = /*#__PURE__*/React.forwardRef(({
33
34
  previews,
34
35
  onLinkAdded,
35
36
  inputHint,
37
+ isOptional,
36
38
  ...rest
37
39
  }, ref) => {
38
40
  const {
@@ -43,6 +45,7 @@ const TextEditor = /*#__PURE__*/React.forwardRef(({
43
45
  const [activeInlines, setActiveInlines] = useState({});
44
46
  const [focusToolbar, setFocusToolbar] = useState(false);
45
47
  const editorRef = useRef(null);
48
+ const wrapper = useRef(null);
46
49
  const editor = ref || editorRef;
47
50
  const contentLength = getContent(value).getPlainText("").length;
48
51
  const moveCursor = useRef(contentLength > 0);
@@ -242,16 +245,26 @@ const TextEditor = /*#__PURE__*/React.forwardRef(({
242
245
  editor.current?.focus();
243
246
  }
244
247
  };
248
+ useEffect(() => {
249
+ if (required) {
250
+ const editableElement = wrapper.current?.querySelector("div[contenteditable='true']");
251
+ editableElement?.setAttribute("required", "");
252
+ editableElement?.setAttribute("aria-required", "true");
253
+ }
254
+ }, [required]);
245
255
  return /*#__PURE__*/React.createElement(EditorContext.Provider, {
246
256
  value: {
247
257
  onLinkAdded,
248
258
  editMode: true
249
259
  }
250
- }, /*#__PURE__*/React.createElement(StyledEditorWrapper, rest, /*#__PURE__*/React.createElement(LabelWrapper, {
260
+ }, /*#__PURE__*/React.createElement(StyledEditorWrapper, _extends({
261
+ ref: wrapper
262
+ }, rest), /*#__PURE__*/React.createElement(LabelWrapper, {
251
263
  onClick: () => handleEditorFocus(true)
252
264
  }, /*#__PURE__*/React.createElement(Label, {
253
265
  labelId: labelId,
254
- isRequired: required
266
+ isRequired: required,
267
+ optional: isOptional
255
268
  }, labelText)), inputHint && /*#__PURE__*/React.createElement(StyledHintText, {
256
269
  id: inputHintId.current
257
270
  }, inputHint), /*#__PURE__*/React.createElement(Box, {
@@ -313,6 +326,7 @@ if (process.env.NODE_ENV !== "production") {
313
326
  "error": PropTypes.string,
314
327
  "info": PropTypes.string,
315
328
  "inputHint": PropTypes.string,
329
+ "isOptional": PropTypes.bool,
316
330
  "labelText": PropTypes.string.isRequired,
317
331
  "m": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
318
332
  "__@toStringTag": PropTypes.string.isRequired,
@@ -79,8 +79,8 @@ export interface TextareaProps extends ValidationProps, MarginProps, Omit<Common
79
79
  placeholder?: string;
80
80
  /** Adds readOnly property */
81
81
  readOnly?: boolean;
82
- /** Flag to configure component as mandatory */
83
- required?: boolean;
82
+ /** Flag to configure component as optional */
83
+ isOptional?: boolean;
84
84
  /** The number of visible text lines for the control */
85
85
  rows?: number;
86
86
  /** One of type of size to apply to the textarea */
@@ -60,6 +60,8 @@ const Textarea = /*#__PURE__*/React.forwardRef(({
60
60
  inputRef,
61
61
  borderRadius,
62
62
  hideBorders = false,
63
+ required,
64
+ isOptional,
63
65
  ...rest
64
66
  }, ref) => {
65
67
  const {
@@ -185,7 +187,8 @@ const Textarea = /*#__PURE__*/React.forwardRef(({
185
187
  as: "textarea",
186
188
  inputRef: inputRef,
187
189
  validationIconId: validationRedesignOptIn ? undefined : validationId,
188
- inputBorderRadius: borderRadius
190
+ inputBorderRadius: borderRadius,
191
+ required: required
189
192
  }, rest)), children, /*#__PURE__*/React.createElement(InputIconToggle, {
190
193
  disabled: disabled,
191
194
  readOnly: readOnly,
@@ -222,7 +225,8 @@ const Textarea = /*#__PURE__*/React.forwardRef(({
222
225
  labelWidth: computeLabelPropValues(labelWidth),
223
226
  labelHelp: computeLabelPropValues(labelHelp),
224
227
  labelSpacing: labelSpacing,
225
- isRequired: rest.required,
228
+ isRequired: required,
229
+ isOptional: isOptional,
226
230
  useValidationIcon: computeLabelPropValues(validationOnLabel),
227
231
  adaptiveLabelBreakpoint: adaptiveLabelBreakpoint,
228
232
  validationRedesignOptIn: validationRedesignOptIn
@@ -349,6 +353,7 @@ if (process.env.NODE_ENV !== "production") {
349
353
  "inputRef": PropTypes.func,
350
354
  "inputWidth": PropTypes.number,
351
355
  "is": PropTypes.string,
356
+ "isOptional": PropTypes.bool,
352
357
  "itemID": PropTypes.string,
353
358
  "itemProp": PropTypes.string,
354
359
  "itemRef": PropTypes.string,
@@ -91,12 +91,12 @@ export interface CommonTextboxProps extends ValidationProps, MarginProps, Omit<C
91
91
  tooltipPosition?: "top" | "bottom" | "left" | "right";
92
92
  /** Aria label for rendered help component */
93
93
  helpAriaLabel?: string;
94
+ /** Flag to configure component as optional. */
95
+ isOptional?: boolean;
94
96
  }
95
97
  export interface TextboxProps extends CommonTextboxProps {
96
98
  /** Content to be rendered next to the input */
97
99
  children?: React.ReactNode;
98
- /** [Legacy] Flag to configure component as optional in Form */
99
- isOptional?: boolean;
100
100
  /** Container for DatePicker or SelectList components */
101
101
  positionedChildren?: React.ReactNode;
102
102
  /** Character limit of the textarea */
@@ -28,7 +28,7 @@ declare const StyledDeselectWrapper: import("styled-components").StyledComponent
28
28
  hasActionAdornment: boolean;
29
29
  }, never>;
30
30
  declare const StyledTileSelectFieldset: import("styled-components").StyledComponent<{
31
- ({ children, inline, legend, ...rest }: import("../fieldset").FieldsetProps): import("react").JSX.Element;
31
+ ({ children, inline, legend, required, isOptional, ...rest }: import("../fieldset").FieldsetProps): import("react").JSX.Element;
32
32
  displayName: string;
33
33
  }, any, {
34
34
  multiSelect: boolean;
@@ -27,6 +27,8 @@ export interface CommonCheckableInputProps extends ValidationProps, CommonHidden
27
27
  labelWidth?: number;
28
28
  /** Flag to configure component as mandatory */
29
29
  required?: boolean;
30
+ /** Flag to configure component as optional. */
31
+ isOptional?: boolean;
30
32
  /** If true the label switches position with the input */
31
33
  reverse?: boolean;
32
34
  /** Size of the component */
@@ -41,6 +41,7 @@ const CheckableInput = /*#__PURE__*/_react.default.forwardRef(({
41
41
  onChange,
42
42
  onFocus,
43
43
  required,
44
+ isOptional,
44
45
  reverse = false,
45
46
  validationOnLabel,
46
47
  warning,
@@ -62,7 +63,6 @@ const CheckableInput = /*#__PURE__*/_react.default.forwardRef(({
62
63
  label,
63
64
  fieldHelp
64
65
  });
65
- const isRadio = type === "radio";
66
66
  const formFieldProps = {
67
67
  disabled,
68
68
  loading,
@@ -83,7 +83,8 @@ const CheckableInput = /*#__PURE__*/_react.default.forwardRef(({
83
83
  validationIconId: validationId,
84
84
  // We don't want an asterisk on each radio control, only the legend
85
85
  // However, we still want the input element to receive the required prop
86
- isRequired: isRadio ? undefined : required,
86
+ isRequired: required,
87
+ isOptional,
87
88
  useValidationIcon: validationOnLabel
88
89
  };
89
90
  const inputProps = {
@@ -212,6 +213,7 @@ if (process.env.NODE_ENV !== "production") {
212
213
  "inputMode": _propTypes.default.oneOf(["decimal", "email", "none", "numeric", "search", "tel", "text", "url"]),
213
214
  "inputWidth": _propTypes.default.number,
214
215
  "is": _propTypes.default.string,
216
+ "isOptional": _propTypes.default.bool,
215
217
  "itemID": _propTypes.default.string,
216
218
  "itemProp": _propTypes.default.string,
217
219
  "itemRef": _propTypes.default.string,
@@ -35,11 +35,10 @@ const StyledLegendContent = exports.StyledLegendContent = _styledComponents.defa
35
35
  content: "*";
36
36
  line-height: 24px;
37
37
  color: var(--colorsSemanticNegative500);
38
- font-weight: 700;
39
- margin-left: var(--spacing100);
38
+ font-weight: var(--fontWeights700);
39
+ margin-left: var(--spacing050);
40
40
  position: relative;
41
41
  top: 1px;
42
- left: -4px;
43
42
  }
44
43
  `}
45
44
 
@@ -48,8 +47,9 @@ const StyledLegendContent = exports.StyledLegendContent = _styledComponents.defa
48
47
  }) => isOptional && (0, _styledComponents.css)`
49
48
  ::after {
50
49
  content: "(optional)";
51
- font-weight: 350; //TODO: (tokens) use token var(--fontWeights400) - FE-6022
52
- margin-left: 4px;
50
+ color: var(--colorsUtilityYin055);
51
+ font-weight: var(--fontWeights400);
52
+ margin-left: var(--spacing050);
53
53
  }
54
54
  `}
55
55
 
@@ -67,7 +67,8 @@ const StyledLegend = exports.StyledLegend = _styledComponents.default.legend`
67
67
  align-items: center;
68
68
  margin-bottom: var(--spacing100);
69
69
  padding: 0;
70
- font-weight: 600;
70
+ font-weight: var(--fontWeights700);
71
+ color: var(--colorsUtilityYin090);
71
72
  ${({
72
73
  inline,
73
74
  width,
@@ -53,7 +53,7 @@ export interface FormFieldProps extends CommonFormFieldProps, TagProps {
53
53
  fieldHelpInline?: boolean;
54
54
  /** Id of the element a label should be bound to */
55
55
  id: string;
56
- /** [Legacy] Flag to configure component as optional in Form */
56
+ /** Flag to configure component as optional in Form */
57
57
  isOptional?: boolean;
58
58
  /** Flag to configure component as mandatory */
59
59
  isRequired?: boolean;
@@ -59,6 +59,7 @@ const FormField = ({
59
59
  return Object.keys(validationProps).find(propName => validationProps[propName]);
60
60
  }, [error, warning, info, disabled]);
61
61
  !(invalidValidationProp === undefined) ? process.env.NODE_ENV !== "production" ? (0, _invariant.default)(false, `Prop \`${invalidValidationProp}\` cannot be used in conjunction with \`disabled\`. ` + "Use `readOnly` if you require users to see validations with a non-interactive field") : (0, _invariant.default)(false) : void 0;
62
+ !!(isRequired && isOptional) ? process.env.NODE_ENV !== "production" ? (0, _invariant.default)(false, "an input cannot be set to both required and optional at the same time") : (0, _invariant.default)(false) : void 0;
62
63
  const largeScreen = (0, _useIsAboveBreakpoint.default)(adaptiveLabelBreakpoint);
63
64
  let inlineLabel = labelInline;
64
65
  if (adaptiveLabelBreakpoint) {
@@ -10,7 +10,7 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
10
10
  const StyledLabel = _styledComponents.default.label`
11
11
  color: var(--colorsUtilityYin090);
12
12
  display: block;
13
- font-weight: 600; //TODO: (tokens) use token var(--fontWeights500)
13
+ font-weight: var(--fontWeights700);
14
14
 
15
15
  ${({
16
16
  isRequired
@@ -18,8 +18,8 @@ const StyledLabel = _styledComponents.default.label`
18
18
  ::after {
19
19
  content: "*";
20
20
  color: var(--colorsSemanticNegative500);
21
- font-weight: 700;
22
- margin-left: var(--spacing100);
21
+ font-weight: var(--fontWeights700);
22
+ margin-left: var(--spacing050);
23
23
  }
24
24
  `}
25
25
 
@@ -59,8 +59,9 @@ const StyledLabelContainer = exports.StyledLabelContainer = _styledComponents.de
59
59
  }) => optional && (0, _styledComponents.css)`
60
60
  ::after {
61
61
  content: "(optional)";
62
- font-weight: 350; //TODO: (tokens) use token var(--fontWeights400)
63
- margin-left: 4px;
62
+ font-weight: var(--fontWeights400);
63
+ margin-left: var(--spacing050);
64
+ color: var(--colorsUtilityYin055);
64
65
  }
65
66
  `}
66
67
  `;
@@ -20,6 +20,8 @@ export interface CheckboxGroupProps extends ValidationProps, MarginProps {
20
20
  labelSpacing?: 1 | 2;
21
21
  /** Flag to configure component as mandatory */
22
22
  required?: boolean;
23
+ /** Flag to configure component as optional. */
24
+ isOptional?: boolean;
23
25
  /** Overrides the default tooltip */
24
26
  tooltipPosition?: "top" | "bottom" | "left" | "right";
25
27
  /** When true, Checkboxes are in line */
@@ -32,6 +32,7 @@ const CheckboxGroup = props => {
32
32
  warning,
33
33
  info,
34
34
  required,
35
+ isOptional,
35
36
  legendInline,
36
37
  legendWidth,
37
38
  legendAlign,
@@ -49,7 +50,8 @@ const CheckboxGroup = props => {
49
50
  error: error,
50
51
  warning: warning,
51
52
  info: info,
52
- isRequired: required
53
+ isRequired: required,
54
+ isOptional: isOptional
53
55
  }, (0, _tags.default)("checkboxgroup", props), {
54
56
  blockGroupBehaviour: !(error || warning)
55
57
  }, (0, _utils.filterStyledSystemMarginProps)(props)), legendHelp && /*#__PURE__*/_react.default.createElement(_checkboxGroup.StyledHintText, null, legendHelp), /*#__PURE__*/_react.default.createElement(_box.default, {
@@ -82,7 +84,8 @@ const CheckboxGroup = props => {
82
84
  error: error,
83
85
  warning: warning,
84
86
  info: info,
85
- isRequired: required
87
+ isRequired: required,
88
+ isOptional: isOptional
86
89
  }, (0, _tags.default)("checkboxgroup", props), {
87
90
  blockGroupBehaviour: !(error || warning || info)
88
91
  }, (0, _utils.filterStyledSystemMarginProps)(props)), /*#__PURE__*/_react.default.createElement(_checkboxGroup.default, {
@@ -39,6 +39,7 @@ const Checkbox = exports.Checkbox = /*#__PURE__*/_react.default.forwardRef(({
39
39
  labelWidth,
40
40
  adaptiveSpacingBreakpoint,
41
41
  required,
42
+ isOptional,
42
43
  error,
43
44
  warning,
44
45
  info,
@@ -93,6 +94,7 @@ const Checkbox = exports.Checkbox = /*#__PURE__*/_react.default.forwardRef(({
93
94
  labelHelp,
94
95
  labelSpacing,
95
96
  required,
97
+ isOptional,
96
98
  fieldHelpInline,
97
99
  checked,
98
100
  disabled,
@@ -234,6 +236,7 @@ if (process.env.NODE_ENV !== "production") {
234
236
  })]),
235
237
  "inputWidth": _propTypes.default.number,
236
238
  "is": _propTypes.default.string,
239
+ "isOptional": _propTypes.default.bool,
237
240
  "itemID": _propTypes.default.string,
238
241
  "itemProp": _propTypes.default.string,
239
242
  "itemRef": _propTypes.default.string,
@@ -80,9 +80,13 @@ export interface DateRangeProps extends StyledDateRangeProps, MarginProps, TagPr
80
80
  validationOnLabel?: boolean;
81
81
  /** Overrides the default tooltip position */
82
82
  tooltipPosition?: "top" | "bottom" | "left" | "right";
83
+ /** Flag to configure component as mandatory. */
84
+ required?: boolean;
85
+ /** Flag to configure component as optional. */
86
+ isOptional?: boolean;
83
87
  }
84
88
  export declare const DateRange: {
85
- ({ endDateProps, id, labelsInline, name, onBlur, onChange, startDateProps, tooltipPosition, validationOnLabel, value, startRef, endRef, ...rest }: DateRangeProps): React.JSX.Element;
89
+ ({ endDateProps, id, labelsInline, name, onBlur, onChange, startDateProps, tooltipPosition, validationOnLabel, value, startRef, endRef, required, isOptional, ...rest }: DateRangeProps): React.JSX.Element;
86
90
  displayName: string;
87
91
  };
88
92
  export default DateRange;
@@ -33,6 +33,8 @@ const DateRange = ({
33
33
  value,
34
34
  startRef,
35
35
  endRef,
36
+ required,
37
+ isOptional,
36
38
  ...rest
37
39
  }) => {
38
40
  const l = (0, _useLocale.default)();
@@ -195,7 +197,9 @@ const DateRange = ({
195
197
  onBlur: handleOnBlur,
196
198
  onChange: onChangeCallback,
197
199
  onKeyDown: ev => handleOnKeyDown(ev, propsKey),
198
- ...props
200
+ ...props,
201
+ required,
202
+ isOptional
199
203
  };
200
204
  };
201
205
  return /*#__PURE__*/_react.default.createElement(_dateRange.default, _extends({}, (0, _tags.default)("date-range", rest), {
@@ -33,8 +33,6 @@ export interface DecimalProps extends Omit<CommonTextboxProps, "onChange" | "onB
33
33
  precision?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15;
34
34
  /** If true, the component will be read-only */
35
35
  readOnly?: boolean;
36
- /** Flag to configure component as mandatory */
37
- required?: boolean;
38
36
  /** The value of the input if it's used as a controlled component */
39
37
  value?: string;
40
38
  /** The locale string - default en */
@@ -29,7 +29,6 @@ const Decimal = exports.Decimal = /*#__PURE__*/_react.default.forwardRef(({
29
29
  id,
30
30
  name,
31
31
  allowEmptyValue = false,
32
- required,
33
32
  locale,
34
33
  value,
35
34
  inputRef,
@@ -186,7 +185,6 @@ const Decimal = exports.Decimal = /*#__PURE__*/_react.default.forwardRef(({
186
185
  onKeyPress: onKeyPress,
187
186
  align: align,
188
187
  readOnly: readOnly,
189
- required: required,
190
188
  inputWidth: inputWidth,
191
189
  onChange: handleOnChange,
192
190
  onBlur: handleOnBlur,
@@ -313,6 +311,7 @@ if (process.env.NODE_ENV !== "production") {
313
311
  "inputRef": _propTypes.default.func,
314
312
  "inputWidth": _propTypes.default.number,
315
313
  "is": _propTypes.default.string,
314
+ "isOptional": _propTypes.default.bool,
316
315
  "itemID": _propTypes.default.string,
317
316
  "itemProp": _propTypes.default.string,
318
317
  "itemRef": _propTypes.default.string,
@@ -1,14 +1,19 @@
1
1
  import React from "react";
2
2
  import { MarginProps } from "styled-system";
3
- import { StyledFieldsetProps } from "./fieldset.style";
4
- export interface FieldsetProps extends StyledFieldsetProps, MarginProps {
3
+ export interface FieldsetProps extends MarginProps {
4
+ /** When true, legend is placed in line with the children */
5
+ inline?: boolean;
5
6
  /** Child elements */
6
7
  children?: React.ReactNode;
7
8
  /** The text for the fieldsets legend element. */
8
9
  legend?: string;
10
+ /** Flag to configure fields as mandatory. */
11
+ required?: boolean;
12
+ /** Flag to configure fields as optional. */
13
+ isOptional?: boolean;
9
14
  }
10
15
  export declare const Fieldset: {
11
- ({ children, inline, legend, ...rest }: FieldsetProps): React.JSX.Element;
16
+ ({ children, inline, legend, required, isOptional, ...rest }: FieldsetProps): React.JSX.Element;
12
17
  displayName: string;
13
18
  };
14
19
  export default Fieldset;