@dxc-technology/halstack-react 0.0.0-c680086 → 0.0.0-c6bd008

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 (202) hide show
  1. package/HalstackContext.d.ts +12 -0
  2. package/HalstackContext.js +295 -0
  3. package/accordion/Accordion.d.ts +1 -1
  4. package/accordion/Accordion.js +7 -28
  5. package/accordion/Accordion.stories.tsx +11 -11
  6. package/accordion/Accordion.test.js +72 -0
  7. package/accordion/types.d.ts +4 -0
  8. package/accordion-group/AccordionGroup.d.ts +1 -1
  9. package/accordion-group/AccordionGroup.js +14 -15
  10. package/accordion-group/AccordionGroup.stories.tsx +1 -1
  11. package/accordion-group/AccordionGroup.test.js +151 -0
  12. package/accordion-group/types.d.ts +4 -0
  13. package/alert/Alert.js +4 -1
  14. package/alert/Alert.test.js +92 -0
  15. package/badge/Badge.d.ts +4 -0
  16. package/badge/Badge.js +5 -3
  17. package/badge/types.d.ts +5 -0
  18. package/{radio → badge}/types.js +0 -0
  19. package/bleed/Bleed.js +1 -34
  20. package/bleed/Bleed.stories.tsx +62 -63
  21. package/bleed/types.d.ts +25 -1
  22. package/box/Box.js +22 -32
  23. package/box/Box.test.js +18 -0
  24. package/button/Button.js +14 -11
  25. package/button/Button.test.js +35 -0
  26. package/card/Card.js +24 -27
  27. package/card/Card.test.js +50 -0
  28. package/checkbox/Checkbox.d.ts +1 -1
  29. package/checkbox/Checkbox.js +43 -39
  30. package/checkbox/Checkbox.stories.tsx +124 -128
  31. package/checkbox/Checkbox.test.js +78 -0
  32. package/checkbox/types.d.ts +7 -3
  33. package/chip/Chip.test.js +56 -0
  34. package/common/variables.js +181 -322
  35. package/date-input/DateInput.js +53 -39
  36. package/date-input/DateInput.stories.tsx +7 -7
  37. package/date-input/DateInput.test.js +479 -0
  38. package/date-input/types.d.ts +16 -9
  39. package/dialog/Dialog.js +4 -32
  40. package/dialog/Dialog.test.js +40 -0
  41. package/dropdown/Dropdown.js +13 -17
  42. package/dropdown/Dropdown.test.js +189 -0
  43. package/file-input/FileInput.js +9 -6
  44. package/file-input/FileInput.test.js +457 -0
  45. package/file-input/FileItem.js +7 -5
  46. package/footer/Footer.js +15 -88
  47. package/footer/Footer.test.js +109 -0
  48. package/footer/Icons.js +1 -1
  49. package/header/Header.js +27 -48
  50. package/header/Header.stories.tsx +46 -36
  51. package/header/Header.test.js +79 -0
  52. package/heading/Heading.test.js +186 -0
  53. package/inline/Inline.d.ts +4 -0
  54. package/inline/Inline.js +56 -0
  55. package/inline/Inline.stories.tsx +264 -0
  56. package/inline/types.d.ts +32 -0
  57. package/inline/types.js +5 -0
  58. package/inset/Inset.js +1 -34
  59. package/inset/Inset.stories.tsx +33 -33
  60. package/inset/types.d.ts +25 -1
  61. package/layout/ApplicationLayout.d.ts +4 -3
  62. package/layout/ApplicationLayout.js +84 -110
  63. package/layout/ApplicationLayout.stories.tsx +14 -59
  64. package/layout/Icons.d.ts +5 -0
  65. package/layout/Icons.js +13 -2
  66. package/layout/SidenavContext.d.ts +5 -0
  67. package/layout/SidenavContext.js +19 -0
  68. package/layout/types.d.ts +5 -10
  69. package/link/Link.d.ts +3 -2
  70. package/link/Link.js +57 -74
  71. package/link/Link.stories.tsx +87 -52
  72. package/link/Link.test.js +83 -0
  73. package/link/types.d.ts +7 -23
  74. package/list/List.js +1 -1
  75. package/list/List.stories.tsx +16 -22
  76. package/list/types.d.ts +1 -1
  77. package/main.d.ts +7 -8
  78. package/main.js +39 -41
  79. package/number-input/NumberInput.js +11 -18
  80. package/number-input/NumberInput.stories.tsx +5 -5
  81. package/number-input/NumberInput.test.js +506 -0
  82. package/number-input/types.d.ts +17 -10
  83. package/package.json +7 -5
  84. package/paginator/Paginator.js +17 -38
  85. package/paginator/Paginator.test.js +308 -0
  86. package/password-input/PasswordInput.js +7 -4
  87. package/password-input/PasswordInput.test.js +180 -0
  88. package/password-input/types.d.ts +14 -11
  89. package/progress-bar/ProgressBar.js +1 -1
  90. package/progress-bar/ProgressBar.stories.jsx +11 -11
  91. package/progress-bar/ProgressBar.test.js +65 -0
  92. package/quick-nav/QuickNav.d.ts +4 -0
  93. package/quick-nav/QuickNav.js +116 -0
  94. package/quick-nav/QuickNav.stories.tsx +237 -0
  95. package/quick-nav/types.d.ts +21 -0
  96. package/quick-nav/types.js +5 -0
  97. package/radio-group/Radio.d.ts +1 -1
  98. package/radio-group/Radio.js +25 -24
  99. package/radio-group/RadioGroup.js +46 -37
  100. package/radio-group/RadioGroup.stories.tsx +60 -39
  101. package/radio-group/RadioGroup.test.js +530 -83
  102. package/radio-group/types.d.ts +80 -2
  103. package/resultsetTable/ResultsetTable.test.js +348 -0
  104. package/row/types.d.ts +18 -0
  105. package/select/Icons.d.ts +10 -0
  106. package/select/Icons.js +93 -0
  107. package/select/Listbox.d.ts +4 -0
  108. package/select/Listbox.js +175 -0
  109. package/select/Option.d.ts +4 -0
  110. package/select/Option.js +110 -0
  111. package/select/Select.js +148 -351
  112. package/select/Select.stories.tsx +230 -176
  113. package/select/Select.test.js +2162 -0
  114. package/select/types.d.ts +53 -11
  115. package/sidenav/Sidenav.d.ts +1 -1
  116. package/sidenav/Sidenav.js +20 -9
  117. package/sidenav/Sidenav.test.js +56 -0
  118. package/slider/Slider.d.ts +1 -1
  119. package/slider/Slider.js +2 -1
  120. package/slider/Slider.stories.tsx +8 -8
  121. package/slider/Slider.test.js +150 -0
  122. package/slider/types.d.ts +4 -0
  123. package/spinner/Spinner.js +1 -1
  124. package/spinner/Spinner.test.js +64 -0
  125. package/stack/Stack.d.ts +2 -1
  126. package/stack/Stack.js +26 -71
  127. package/stack/Stack.stories.tsx +139 -78
  128. package/stack/types.d.ts +23 -4
  129. package/switch/Switch.d.ts +1 -1
  130. package/switch/Switch.js +35 -19
  131. package/switch/Switch.stories.tsx +14 -14
  132. package/switch/Switch.test.js +98 -0
  133. package/switch/types.d.ts +6 -2
  134. package/table/Table.test.js +26 -0
  135. package/tabs/Tabs.d.ts +1 -1
  136. package/tabs/Tabs.js +9 -11
  137. package/tabs/Tabs.stories.tsx +0 -8
  138. package/tabs/Tabs.test.js +140 -0
  139. package/tabs/types.d.ts +4 -0
  140. package/tabs-nav/NavTabs.d.ts +8 -0
  141. package/tabs-nav/NavTabs.js +125 -0
  142. package/tabs-nav/NavTabs.stories.tsx +170 -0
  143. package/tabs-nav/NavTabs.test.js +82 -0
  144. package/tabs-nav/Tab.d.ts +4 -0
  145. package/tabs-nav/Tab.js +132 -0
  146. package/tabs-nav/types.d.ts +53 -0
  147. package/tabs-nav/types.js +5 -0
  148. package/tag/Tag.js +14 -19
  149. package/tag/Tag.stories.tsx +12 -8
  150. package/tag/Tag.test.js +60 -0
  151. package/text-input/Suggestion.d.ts +4 -0
  152. package/text-input/Suggestion.js +55 -0
  153. package/text-input/TextInput.js +56 -80
  154. package/text-input/TextInput.stories.tsx +30 -12
  155. package/text-input/TextInput.test.js +1712 -0
  156. package/text-input/types.d.ts +31 -12
  157. package/textarea/Textarea.js +20 -27
  158. package/textarea/Textarea.stories.jsx +33 -12
  159. package/textarea/Textarea.test.js +437 -0
  160. package/textarea/types.d.ts +18 -11
  161. package/toggle-group/ToggleGroup.d.ts +1 -1
  162. package/toggle-group/ToggleGroup.js +5 -4
  163. package/toggle-group/ToggleGroup.stories.tsx +4 -4
  164. package/toggle-group/ToggleGroup.test.js +156 -0
  165. package/toggle-group/types.d.ts +8 -0
  166. package/useTheme.js +2 -2
  167. package/useTranslatedLabels.d.ts +2 -0
  168. package/useTranslatedLabels.js +20 -0
  169. package/wizard/Wizard.d.ts +1 -1
  170. package/wizard/Wizard.js +55 -44
  171. package/wizard/Wizard.stories.tsx +13 -23
  172. package/wizard/Wizard.test.js +141 -0
  173. package/wizard/types.d.ts +6 -2
  174. package/ThemeContext.d.ts +0 -15
  175. package/ThemeContext.js +0 -243
  176. package/V3Select/V3Select.js +0 -455
  177. package/V3Select/index.d.ts +0 -27
  178. package/V3Textarea/V3Textarea.js +0 -260
  179. package/V3Textarea/index.d.ts +0 -27
  180. package/date/Date.js +0 -373
  181. package/date/index.d.ts +0 -27
  182. package/input-text/Icons.js +0 -22
  183. package/input-text/InputText.js +0 -611
  184. package/input-text/index.d.ts +0 -36
  185. package/radio/Radio.d.ts +0 -4
  186. package/radio/Radio.js +0 -174
  187. package/radio/Radio.stories.tsx +0 -192
  188. package/radio/types.d.ts +0 -54
  189. package/toggle/Toggle.js +0 -186
  190. package/toggle/index.d.ts +0 -21
  191. package/upload/Upload.js +0 -201
  192. package/upload/buttons-upload/ButtonsUpload.js +0 -111
  193. package/upload/buttons-upload/Icons.js +0 -40
  194. package/upload/dragAndDropArea/DragAndDropArea.js +0 -225
  195. package/upload/dragAndDropArea/Icons.js +0 -39
  196. package/upload/file-upload/FileToUpload.js +0 -115
  197. package/upload/file-upload/Icons.js +0 -66
  198. package/upload/files-upload/FilesToUpload.js +0 -109
  199. package/upload/index.d.ts +0 -15
  200. package/upload/transaction/Icons.js +0 -160
  201. package/upload/transaction/Transaction.js +0 -104
  202. package/upload/transactions/Transactions.js +0 -94
@@ -28,14 +28,16 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
28
28
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
29
 
30
30
  var DxcRadio = function DxcRadio(_ref) {
31
+ var _option$disabled;
32
+
31
33
  var option = _ref.option,
32
34
  currentValue = _ref.currentValue,
33
- _onClick = _ref.onClick,
34
- onFocus = _ref.onFocus,
35
+ onClick = _ref.onClick,
35
36
  error = _ref.error,
36
37
  disabled = _ref.disabled,
37
38
  focused = _ref.focused,
38
- readonly = _ref.readonly;
39
+ readonly = _ref.readonly,
40
+ tabIndex = _ref.tabIndex;
39
41
 
40
42
  var _useState = (0, _react.useState)("radio-".concat((0, _uuid.v4)())),
41
43
  _useState2 = (0, _slicedToArray2["default"])(_useState, 1),
@@ -43,7 +45,13 @@ var DxcRadio = function DxcRadio(_ref) {
43
45
 
44
46
  var ref = (0, _react.useRef)(null);
45
47
  var colorsTheme = (0, _useTheme["default"])();
46
- var checked = option.value === currentValue;
48
+
49
+ var handleOnClick = function handleOnClick() {
50
+ var _ref$current;
51
+
52
+ onClick();
53
+ focused && document.activeElement !== (ref === null || ref === void 0 ? void 0 : ref.current) && (ref === null || ref === void 0 ? void 0 : (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus());
54
+ };
47
55
 
48
56
  var _useState3 = (0, _react.useState)(true),
49
57
  _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
@@ -51,7 +59,7 @@ var DxcRadio = function DxcRadio(_ref) {
51
59
  setFirstUpdate = _useState4[1];
52
60
 
53
61
  (0, _react.useLayoutEffect)(function () {
54
- var _ref$current;
62
+ var _ref$current2;
55
63
 
56
64
  // Don't apply in the first render
57
65
  if (firstUpdate) {
@@ -59,7 +67,7 @@ var DxcRadio = function DxcRadio(_ref) {
59
67
  return;
60
68
  }
61
69
 
62
- focused && (ref === null || ref === void 0 ? void 0 : (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus());
70
+ focused && (ref === null || ref === void 0 ? void 0 : (_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.focus());
63
71
  }, [focused]);
64
72
  return /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
65
73
  theme: colorsTheme.radioGroup
@@ -68,28 +76,21 @@ var DxcRadio = function DxcRadio(_ref) {
68
76
  disabled: disabled,
69
77
  readonly: readonly,
70
78
  onMouseDown: function onMouseDown(event) {
71
- // Prevents div's onclick from stealing the radio button's focus
79
+ // Prevents div's onClick from stealing the radio input's focus
72
80
  event.preventDefault();
73
81
  },
74
- onClick: function onClick() {
75
- var _ref$current2;
76
-
77
- ref === null || ref === void 0 ? void 0 : (_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.focus();
78
-
79
- _onClick();
80
- }
82
+ onClick: handleOnClick
81
83
  }, /*#__PURE__*/_react["default"].createElement(RadioInputContainer, null, /*#__PURE__*/_react["default"].createElement(RadioInput, {
82
84
  error: error,
83
85
  disabled: disabled,
84
86
  readonly: readonly,
85
- onFocus: onFocus,
86
87
  role: "radio",
87
- "aria-checked": checked,
88
- "aria-disabled": option.disabled,
88
+ "aria-checked": option.value === currentValue,
89
+ "aria-disabled": (_option$disabled = option.disabled) !== null && _option$disabled !== void 0 ? _option$disabled : false,
89
90
  "aria-labelledby": radioLabelId,
90
- tabIndex: disabled ? -1 : focused ? 0 : -1,
91
+ tabIndex: disabled ? -1 : focused ? tabIndex : -1,
91
92
  ref: ref
92
- }, checked && /*#__PURE__*/_react["default"].createElement(Dot, {
93
+ }, option.value === currentValue && /*#__PURE__*/_react["default"].createElement(Dot, {
93
94
  disabled: disabled,
94
95
  readonly: readonly,
95
96
  error: error
@@ -101,18 +102,18 @@ var DxcRadio = function DxcRadio(_ref) {
101
102
 
102
103
  var RadioMainContainer = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n"])));
103
104
 
104
- var RadioContainer = _styledComponents["default"].span(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["\n display: inline-flex;\n align-items: center;\n cursor: ", ";\n \n ", "\n"])), function (props) {
105
+ var RadioContainer = _styledComponents["default"].span(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["\n display: inline-flex;\n align-items: center;\n cursor: ", ";\n\n ", "\n"])), function (props) {
105
106
  return props.disabled ? "not-allowed" : props.readonly ? "default" : "pointer";
106
107
  }, function (props) {
107
- return !props.disabled && "\n &:hover {\n & > div > div { \n border-color: ".concat(props.error ? props.theme.hoverErrorRadioInputColor : props.readonly ? props.theme.hoverReadonlyRadioInputColor : props.theme.hoverRadioInputColor, ";\n & > span {\n background-color: ").concat(props.error ? props.theme.hoverErrorRadioInputColor : props.readonly ? props.theme.hoverReadonlyRadioInputColor : props.theme.hoverRadioInputColor, ";\n }\n };\n }\n &:active {\n & > div > div {\n border-color: ").concat(props.error ? props.theme.activeErrorRadioInputColor : props.readonly ? props.theme.activeReadonlyRadioInputColor : props.theme.activeRadioInputColor, ";\n & > span {\n background-color: ").concat(props.error ? props.theme.activeErrorRadioInputColor : props.readonly ? props.theme.activeReadonlyRadioInputColor : props.theme.activeRadioInputColor, ";\n }\n }\n }\n ");
108
+ return !props.disabled ? "\n &:hover {\n & > div > div { \n border-color: ".concat(props.error ? props.theme.hoverErrorRadioInputColor : props.readonly ? props.theme.hoverReadonlyRadioInputColor : props.theme.hoverRadioInputColor, ";\n & > span {\n background-color: ").concat(props.error ? props.theme.hoverErrorRadioInputColor : props.readonly ? props.theme.hoverReadonlyRadioInputColor : props.theme.hoverRadioInputColor, ";\n }\n };\n }\n &:active {\n & > div > div {\n border-color: ").concat(props.error ? props.theme.activeErrorRadioInputColor : props.readonly ? props.theme.activeReadonlyRadioInputColor : props.theme.activeRadioInputColor, ";\n & > span {\n background-color: ").concat(props.error ? props.theme.activeErrorRadioInputColor : props.readonly ? props.theme.activeReadonlyRadioInputColor : props.theme.activeRadioInputColor, ";\n }\n }\n }\n ") : "pointer-events: none;";
108
109
  });
109
110
 
110
111
  var RadioInputContainer = _styledComponents["default"].div(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n align-items: center;\n justify-content: center;\n height: 24px;\n width: 24px;\n"])));
111
112
 
112
- var RadioInput = _styledComponents["default"].div(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n align-items: center;\n justify-content: center;\n box-sizing: border-box;\n width: 18px;\n height: 18px;\n border: 2px solid\n ", ";\n border-radius: 50%;\n box-shadow: 0 0 0 2px transparent;\n\n ", "\n"])), function (props) {
113
+ var RadioInput = _styledComponents["default"].div(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n align-items: center;\n justify-content: center;\n box-sizing: border-box;\n width: 18px;\n height: 18px;\n border: 2px solid\n ", ";\n border-radius: 50%;\n\n ", "\n"])), function (props) {
113
114
  if (props.disabled) return props.theme.disabledRadioInputColor;else if (props.error) return props.theme.errorRadioInputColor;else if (props.readonly) return props.theme.readonlyRadioInputColor;else return props.theme.radioInputColor;
114
115
  }, function (props) {
115
- return !props.disabled ? "&:focus {\n outline: 2px solid ".concat(props.theme.focusBorderColor, ";\n outline-offset: 1px;\n }\n &:focus-visible {\n outline: 2px solid ").concat(props.theme.focusBorderColor, ";\n outline-offset: 1px;\n }\n ") : "\n pointer-events: none;\n :focus-visible {\n outline: none;\n }\n ";
116
+ return !props.disabled ? "&:focus {\n outline: 2px solid ".concat(props.theme.focusBorderColor, ";\n outline-offset: 1px;\n }\n &:focus-visible {\n outline: 2px solid ").concat(props.theme.focusBorderColor, ";\n outline-offset: 1px;\n }\n ") : "\n :focus-visible {\n outline: none;\n }\n ";
116
117
  });
117
118
 
118
119
  var Dot = _styledComponents["default"].span(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2["default"])(["\n height: 10px;\n width: 10px;\n border-radius: 50%;\n background-color: ", ";\n"])), function (props) {
@@ -132,7 +133,7 @@ var Label = _styledComponents["default"].span(_templateObject6 || (_templateObje
132
133
  }, function (props) {
133
134
  return props.theme.radioInputLabelLineHeight;
134
135
  }, function (props) {
135
- return props.disabled && "color: ".concat(props.theme.disabledRadioInputLabelFontColor, "; pointer-events: none;");
136
+ return props.disabled ? "color: ".concat(props.theme.disabledRadioInputLabelFontColor, "; pointer-events: none;") : "color: ".concat(props.theme.radioInputLabelFontColor);
136
137
  });
137
138
 
138
139
  var _default = /*#__PURE__*/_react["default"].memo(DxcRadio);
@@ -23,6 +23,8 @@ var _uuid = require("uuid");
23
23
 
24
24
  var _useTheme = _interopRequireDefault(require("../useTheme"));
25
25
 
26
+ var _useTranslatedLabels = _interopRequireDefault(require("../useTranslatedLabels"));
27
+
26
28
  var _Radio = _interopRequireDefault(require("./Radio"));
27
29
 
28
30
  var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7;
@@ -47,8 +49,7 @@ var DxcRadioGroup = /*#__PURE__*/_react["default"].forwardRef(function (_ref, re
47
49
  disabled = _ref$disabled === void 0 ? false : _ref$disabled,
48
50
  _ref$optional = _ref.optional,
49
51
  optional = _ref$optional === void 0 ? false : _ref$optional,
50
- _ref$optionalItemLabe = _ref.optionalItemLabel,
51
- optionalItemLabel = _ref$optionalItemLabe === void 0 ? "N/A" : _ref$optionalItemLabe,
52
+ optionalItemLabel = _ref.optionalItemLabel,
52
53
  _ref$readonly = _ref.readonly,
53
54
  readonly = _ref$readonly === void 0 ? false : _ref$readonly,
54
55
  _ref$stacking = _ref.stacking,
@@ -57,7 +58,9 @@ var DxcRadioGroup = /*#__PURE__*/_react["default"].forwardRef(function (_ref, re
57
58
  value = _ref.value,
58
59
  onChange = _ref.onChange,
59
60
  onBlur = _ref.onBlur,
60
- error = _ref.error;
61
+ error = _ref.error,
62
+ _ref$tabIndex = _ref.tabIndex,
63
+ tabIndex = _ref$tabIndex === void 0 ? 0 : _ref$tabIndex;
61
64
 
62
65
  var _useState = (0, _react.useState)("radio-group-".concat((0, _uuid.v4)())),
63
66
  _useState2 = (0, _slicedToArray2["default"])(_useState, 1),
@@ -76,8 +79,10 @@ var DxcRadioGroup = /*#__PURE__*/_react["default"].forwardRef(function (_ref, re
76
79
  firstTimeFocus = _useState6[0],
77
80
  setFirstTimeFocus = _useState6[1];
78
81
 
82
+ var colorsTheme = (0, _useTheme["default"])();
83
+ var translatedLabels = (0, _useTranslatedLabels["default"])();
79
84
  var optionalItem = {
80
- label: optionalItemLabel,
85
+ label: optionalItemLabel || translatedLabels.radioGroup.optionalItemLabelDefault,
81
86
  value: "",
82
87
  disabled: disabled
83
88
  };
@@ -90,7 +95,6 @@ var DxcRadioGroup = /*#__PURE__*/_react["default"].forwardRef(function (_ref, re
90
95
  currentFocusIndex = _useState8[0],
91
96
  setCurrentFocusIndex = _useState8[1];
92
97
 
93
- var colorsTheme = (0, _useTheme["default"])();
94
98
  var handleOnChange = (0, _react.useCallback)(function (newValue) {
95
99
  var currentValue = value !== null && value !== void 0 ? value : innerValue;
96
100
 
@@ -102,42 +106,46 @@ var DxcRadioGroup = /*#__PURE__*/_react["default"].forwardRef(function (_ref, re
102
106
 
103
107
  var handleOnBlur = function handleOnBlur(e) {
104
108
  // If the radio group loses the focus to an element not contained inside it...
105
- !e.currentTarget.contains(e.relatedTarget) && setFirstTimeFocus(true);
106
- var currentValue = value !== null && value !== void 0 ? value : innerValue;
107
- !optional && !Boolean(currentValue) ? onBlur === null || onBlur === void 0 ? void 0 : onBlur({
108
- value: currentValue,
109
- error: "This field is required. Please, choose an option."
110
- }) : onBlur === null || onBlur === void 0 ? void 0 : onBlur({
111
- value: currentValue
112
- });
109
+ if (!e.currentTarget.contains(e.relatedTarget)) {
110
+ setFirstTimeFocus(true);
111
+ var currentValue = value !== null && value !== void 0 ? value : innerValue;
112
+ !optional && !Boolean(currentValue) ? onBlur === null || onBlur === void 0 ? void 0 : onBlur({
113
+ value: currentValue,
114
+ error: translatedLabels.formFields.requiredSelectionErrorMessage
115
+ }) : onBlur === null || onBlur === void 0 ? void 0 : onBlur({
116
+ value: currentValue
117
+ });
118
+ }
119
+ };
120
+
121
+ var handleOnFocus = function handleOnFocus() {
122
+ firstTimeFocus && setFirstTimeFocus(false);
113
123
  };
114
124
 
115
125
  var setPreviousRadioChecked = function setPreviousRadioChecked() {
116
- if (!disabled) {
117
- setCurrentFocusIndex(function (currentFocusIndex) {
118
- var index = currentFocusIndex === 0 ? innerOptions.length - 1 : currentFocusIndex - 1;
126
+ setCurrentFocusIndex(function (currentFocusIndex) {
127
+ var index = currentFocusIndex === 0 ? innerOptions.length - 1 : currentFocusIndex - 1;
119
128
 
120
- while (innerOptions[index].disabled) {
121
- index = index === 0 ? innerOptions.length - 1 : index - 1;
122
- }
129
+ while (innerOptions[index].disabled) {
130
+ index = index === 0 ? innerOptions.length - 1 : index - 1;
131
+ }
123
132
 
124
- return index;
125
- });
126
- }
133
+ handleOnChange(innerOptions[index].value);
134
+ return index;
135
+ });
127
136
  };
128
137
 
129
138
  var setNextRadioChecked = function setNextRadioChecked() {
130
- if (!disabled) {
131
- setCurrentFocusIndex(function (currentFocusIndex) {
132
- var index = currentFocusIndex === innerOptions.length - 1 ? 0 : currentFocusIndex + 1;
139
+ setCurrentFocusIndex(function (currentFocusIndex) {
140
+ var index = currentFocusIndex === innerOptions.length - 1 ? 0 : currentFocusIndex + 1;
133
141
 
134
- while (innerOptions[index].disabled) {
135
- index = index === innerOptions.length - 1 ? 0 : index + 1;
136
- }
142
+ while (innerOptions[index].disabled) {
143
+ index = index === innerOptions.length - 1 ? 0 : index + 1;
144
+ }
137
145
 
138
- return index;
139
- });
140
- }
146
+ handleOnChange(innerOptions[index].value);
147
+ return index;
148
+ });
141
149
  };
142
150
 
143
151
  var handleOnKeyDown = function handleOnKeyDown(event) {
@@ -176,10 +184,11 @@ var DxcRadioGroup = /*#__PURE__*/_react["default"].forwardRef(function (_ref, re
176
184
  id: radioGroupLabelId,
177
185
  helperText: helperText,
178
186
  disabled: disabled
179
- }, label, " ", optional && /*#__PURE__*/_react["default"].createElement(OptionalLabel, null, "(Optional)")), helperText && /*#__PURE__*/_react["default"].createElement(HelperText, {
187
+ }, label, " ", optional && /*#__PURE__*/_react["default"].createElement(OptionalLabel, null, translatedLabels.formFields.optionalLabel)), helperText && /*#__PURE__*/_react["default"].createElement(HelperText, {
180
188
  disabled: disabled
181
189
  }, helperText), /*#__PURE__*/_react["default"].createElement(RadioGroup, {
182
190
  onBlur: handleOnBlur,
191
+ onFocus: handleOnFocus,
183
192
  onKeyDown: handleOnKeyDown,
184
193
  stacking: stacking,
185
194
  role: "radiogroup",
@@ -187,7 +196,9 @@ var DxcRadioGroup = /*#__PURE__*/_react["default"].forwardRef(function (_ref, re
187
196
  "aria-labelledby": radioGroupLabelId,
188
197
  "aria-invalid": error ? "true" : "false",
189
198
  "aria-errormessage": error ? errorId : undefined,
190
- "aria-required": !optional
199
+ "aria-required": !disabled && !readonly && !optional,
200
+ "aria-readonly": readonly,
201
+ "aria-orientation": stacking === "column" ? "vertical" : "horizontal"
191
202
  }, /*#__PURE__*/_react["default"].createElement(ValueInput, {
192
203
  name: name,
193
204
  value: value !== null && value !== void 0 ? value : innerValue,
@@ -201,13 +212,11 @@ var DxcRadioGroup = /*#__PURE__*/_react["default"].forwardRef(function (_ref, re
201
212
  handleOnChange(option.value);
202
213
  setCurrentFocusIndex(index);
203
214
  },
204
- onFocus: function onFocus() {
205
- !firstTimeFocus ? handleOnChange(option.value) : setFirstTimeFocus(false);
206
- },
207
215
  error: error,
208
216
  disabled: option.disabled || disabled,
209
217
  focused: currentFocusIndex === index,
210
- readonly: readonly
218
+ readonly: readonly,
219
+ tabIndex: tabIndex
211
220
  });
212
221
  })), !disabled && typeof error === "string" && /*#__PURE__*/_react["default"].createElement(Error, {
213
222
  id: errorId,
@@ -7,6 +7,8 @@ export default {
7
7
  component: DxcRadioGroup,
8
8
  };
9
9
 
10
+ const single_option = [{ label: "Option A", value: "A" }];
11
+
10
12
  const options = [
11
13
  { label: "Option 1", value: "1" },
12
14
  { label: "Option 2", value: "2" },
@@ -14,66 +16,85 @@ const options = [
14
16
  { label: "Option 4", value: "4" },
15
17
  ];
16
18
 
17
- const single_disabled_options = [
18
- { label: "Option 1", value: "1" },
19
- { label: "Option 2", value: "2", disabled: true },
20
- { label: "Option 3", value: "3" },
21
- ];
19
+ const single_disabled_options = [{ label: "Option A", value: "A", disabled: true }];
22
20
 
23
21
  export const Chromatic = () => (
24
22
  <>
23
+ <Title title="Radio input states" theme="light" level={2} />
24
+ <ExampleContainer>
25
+ <Title title="Enabled" theme="light" level={4} />
26
+ <DxcRadioGroup label="Example" defaultValue="A" options={single_option} />
27
+ </ExampleContainer>
28
+ <ExampleContainer pseudoState="pseudo-hover">
29
+ <Title title="Hovered" theme="light" level={4} />
30
+ <DxcRadioGroup label="Example" defaultValue="A" options={single_option} />
31
+ </ExampleContainer>
32
+ <ExampleContainer pseudoState="pseudo-active">
33
+ <Title title="Active" theme="light" level={4} />
34
+ <DxcRadioGroup label="Example" defaultValue="A" options={single_option} />
35
+ </ExampleContainer>
36
+ <ExampleContainer pseudoState="pseudo-focus">
37
+ <Title title="Focused" theme="light" level={4} />
38
+ <DxcRadioGroup label="Example" defaultValue="A" options={single_option} />
39
+ </ExampleContainer>
40
+ <ExampleContainer>
41
+ <Title title="Disabled" theme="light" level={4} />
42
+ <DxcRadioGroup label="Example" options={single_disabled_options} defaultValue="A" />
43
+ </ExampleContainer>
44
+ <Title title="Readonly radio input sub-states" theme="light" level={3} />
45
+ <ExampleContainer>
46
+ <Title title="Enabled" theme="light" level={4} />
47
+ <DxcRadioGroup label="Example" options={single_option} defaultValue="A" readonly />
48
+ </ExampleContainer>
49
+ <ExampleContainer pseudoState="pseudo-hover">
50
+ <Title title="Hovered" theme="light" level={4} />
51
+ <DxcRadioGroup label="Example" options={single_option} defaultValue="A" readonly />
52
+ </ExampleContainer>
53
+ <ExampleContainer pseudoState="pseudo-active">
54
+ <Title title="Active" theme="light" level={4} />
55
+ <DxcRadioGroup label="Example" options={single_option} defaultValue="A" readonly />
56
+ </ExampleContainer>
57
+ <Title title="Error radio input sub-states" theme="light" level={3} />
25
58
  <ExampleContainer>
26
- <Title title="Label only" theme="light" level={4} />
27
- <DxcRadioGroup label="Example of a label only" options={options} />
59
+ <Title title="Enabled" theme="light" level={4} />
60
+ <DxcRadioGroup label="Example" options={single_option} defaultValue="A" error="Error message" />
61
+ </ExampleContainer>
62
+ <ExampleContainer pseudoState="pseudo-hover">
63
+ <Title title="Hovered" theme="light" level={4} />
64
+ <DxcRadioGroup label="Example" options={single_option} defaultValue="A" readonly error="Error message" />
28
65
  </ExampleContainer>
66
+ <ExampleContainer pseudoState="pseudo-active">
67
+ <Title title="Active" theme="light" level={4} />
68
+ <DxcRadioGroup label="Example" options={single_option} defaultValue="A" readonly error="Error message" />
69
+ </ExampleContainer>
70
+ <Title title="Variants" theme="light" level={2} />
29
71
  <ExampleContainer>
30
72
  <Title title="Column" theme="light" level={4} />
31
- <DxcRadioGroup label="Example" helperText="Helper text" options={options} defaultValue="3" />
73
+ <DxcRadioGroup label="Example" helperText="Helper text" options={options} />
32
74
  </ExampleContainer>
33
75
  <ExampleContainer>
34
76
  <Title title="Row" theme="light" level={4} />
35
77
  <DxcRadioGroup label="Example" helperText="Helper text" options={options} stacking="row" />
36
78
  </ExampleContainer>
37
79
  <ExampleContainer>
38
- <Title title="Disabled" theme="light" level={4} />
39
- <DxcRadioGroup
40
- label="Disabled"
41
- error="Error message"
42
- helperText="Helper text"
43
- options={options}
44
- disabled
45
- optional
46
- defaultValue="2"
47
- />
80
+ <Title title="Optional" theme="light" level={4} />
81
+ <DxcRadioGroup label="Example" optional helperText="Helper text" options={options} stacking="row" />
48
82
  </ExampleContainer>
49
83
  <ExampleContainer>
50
- <Title title="Single disabled" theme="light" level={4} />
51
- <DxcRadioGroup label="Disabled" helperText="Helper text" options={single_disabled_options} defaultValue="3" />
84
+ <Title title="Disabled" theme="light" level={4} />
85
+ <DxcRadioGroup label="Example" helperText="Helper text" options={options} disabled />
52
86
  </ExampleContainer>
53
87
  <ExampleContainer>
54
- <Title title="Optional" theme="light" level={4} />
55
- <DxcRadioGroup
56
- label="Example"
57
- optionalItemLabel="No selection"
58
- optional
59
- helperText="Helper text"
60
- options={options}
61
- stacking="row"
62
- />
88
+ <Title title="Readonly" theme="light" level={4} />
89
+ <DxcRadioGroup label="Example" readonly helperText="Helper text" options={options} />
63
90
  </ExampleContainer>
64
91
  <ExampleContainer>
65
- <Title title="Error" theme="light" level={4} />
66
- <DxcRadioGroup
67
- label="Example"
68
- error="Error message"
69
- helperText="Helper text"
70
- options={options}
71
- defaultValue="2"
72
- />
92
+ <Title title="Error space reserved" theme="light" level={4} />
93
+ <DxcRadioGroup label="Example" error="" helperText="Helper text" options={options} />
73
94
  </ExampleContainer>
74
95
  <ExampleContainer>
75
- <Title title="Readonly" theme="light" level={4} />
76
- <DxcRadioGroup label="Example" readonly helperText="Helper text" options={options} defaultValue="2" />
96
+ <Title title="Error" theme="light" level={4} />
97
+ <DxcRadioGroup label="Example" error="Error message" helperText="Helper text" options={options} />
77
98
  </ExampleContainer>
78
99
  </>
79
100
  );