@dxc-technology/halstack-react 0.0.0-4254e6c → 0.0.0-4299a60

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 (206) hide show
  1. package/BackgroundColorContext.d.ts +10 -0
  2. package/BackgroundColorContext.js +1 -3
  3. package/ThemeContext.d.ts +15 -0
  4. package/ThemeContext.js +5 -8
  5. package/V3Select/V3Select.js +2 -2
  6. package/V3Textarea/V3Textarea.js +2 -2
  7. package/accordion/Accordion.d.ts +4 -0
  8. package/accordion/Accordion.js +14 -45
  9. package/accordion/types.d.ts +68 -0
  10. package/accordion/types.js +5 -0
  11. package/accordion-group/AccordionGroup.d.ts +7 -0
  12. package/accordion-group/AccordionGroup.js +59 -73
  13. package/accordion-group/AccordionGroup.stories.tsx +225 -0
  14. package/accordion-group/types.d.ts +72 -0
  15. package/accordion-group/types.js +5 -0
  16. package/alert/Alert.js +2 -2
  17. package/alert/Alert.stories.tsx +170 -0
  18. package/alert/types.d.ts +1 -1
  19. package/badge/Badge.js +1 -1
  20. package/box/Box.d.ts +4 -0
  21. package/box/Box.js +6 -32
  22. package/box/Box.stories.tsx +132 -0
  23. package/box/types.d.ts +43 -0
  24. package/box/types.js +5 -0
  25. package/button/Button.d.ts +1 -1
  26. package/button/Button.js +9 -12
  27. package/button/Button.stories.tsx +217 -234
  28. package/button/types.d.ts +11 -11
  29. package/card/Card.d.ts +4 -0
  30. package/card/Card.js +17 -53
  31. package/card/Card.stories.tsx +201 -0
  32. package/card/ice-cream.jpg +0 -0
  33. package/card/types.d.ts +67 -0
  34. package/card/types.js +5 -0
  35. package/checkbox/Checkbox.js +2 -2
  36. package/checkbox/Checkbox.stories.tsx +192 -0
  37. package/checkbox/types.d.ts +3 -4
  38. package/chip/Chip.d.ts +4 -0
  39. package/chip/Chip.js +1 -23
  40. package/chip/Chip.stories.tsx +121 -0
  41. package/chip/types.d.ts +53 -0
  42. package/chip/types.js +5 -0
  43. package/common/variables.js +33 -24
  44. package/date/Date.js +1 -1
  45. package/date-input/DateInput.js +1 -1
  46. package/date-input/DateInput.stories.tsx +138 -0
  47. package/dialog/Dialog.d.ts +4 -0
  48. package/dialog/Dialog.js +6 -25
  49. package/dialog/Dialog.stories.tsx +212 -0
  50. package/dialog/types.d.ts +43 -0
  51. package/dialog/types.js +5 -0
  52. package/dropdown/Dropdown.d.ts +4 -0
  53. package/dropdown/Dropdown.js +8 -41
  54. package/dropdown/types.d.ts +89 -0
  55. package/dropdown/types.js +5 -0
  56. package/file-input/FileInput.d.ts +4 -0
  57. package/file-input/FileInput.js +30 -51
  58. package/file-input/FileItem.d.ts +14 -0
  59. package/file-input/FileItem.js +10 -19
  60. package/file-input/types.d.ts +87 -0
  61. package/file-input/types.js +5 -0
  62. package/footer/Footer.d.ts +4 -0
  63. package/footer/Footer.js +6 -37
  64. package/footer/Footer.stories.jsx +151 -0
  65. package/footer/types.d.ts +69 -0
  66. package/footer/types.js +5 -0
  67. package/header/Header.d.ts +7 -0
  68. package/header/Header.js +28 -30
  69. package/header/Header.stories.tsx +162 -0
  70. package/header/Icons.js +2 -27
  71. package/header/types.d.ts +47 -0
  72. package/header/types.js +5 -0
  73. package/heading/Heading.d.ts +4 -0
  74. package/heading/Heading.js +7 -24
  75. package/heading/Heading.stories.tsx +53 -0
  76. package/heading/types.d.ts +33 -0
  77. package/heading/types.js +5 -0
  78. package/input-text/InputText.js +2 -2
  79. package/layout/ApplicationLayout.d.ts +10 -0
  80. package/layout/ApplicationLayout.js +8 -18
  81. package/layout/ApplicationLayout.stories.tsx +171 -0
  82. package/layout/types.d.ts +57 -0
  83. package/layout/types.js +5 -0
  84. package/link/Link.d.ts +3 -0
  85. package/link/Link.js +4 -26
  86. package/link/Link.stories.tsx +146 -0
  87. package/link/types.d.ts +74 -0
  88. package/link/types.js +5 -0
  89. package/main.d.ts +2 -2
  90. package/main.js +2 -2
  91. package/number-input/NumberInput.d.ts +4 -0
  92. package/number-input/NumberInput.js +2 -44
  93. package/number-input/NumberInput.stories.tsx +115 -0
  94. package/number-input/NumberInputContext.d.ts +4 -0
  95. package/number-input/NumberInputContext.js +5 -2
  96. package/number-input/numberInputContextTypes.d.ts +19 -0
  97. package/number-input/numberInputContextTypes.js +5 -0
  98. package/number-input/types.d.ts +117 -0
  99. package/number-input/types.js +5 -0
  100. package/package.json +1 -1
  101. package/paginator/Paginator.js +2 -2
  102. package/paginator/Paginator.stories.tsx +63 -0
  103. package/password-input/PasswordInput.d.ts +4 -0
  104. package/password-input/PasswordInput.js +7 -42
  105. package/password-input/{PasswordInput.stories.jsx → PasswordInput.stories.tsx} +1 -1
  106. package/password-input/types.d.ts +107 -0
  107. package/password-input/types.js +5 -0
  108. package/progress-bar/ProgressBar.d.ts +4 -0
  109. package/progress-bar/ProgressBar.js +5 -23
  110. package/progress-bar/ProgressBar.stories.jsx +58 -0
  111. package/progress-bar/types.d.ts +37 -0
  112. package/progress-bar/types.js +5 -0
  113. package/radio/Radio.js +2 -2
  114. package/radio/Radio.stories.tsx +192 -0
  115. package/radio/types.d.ts +2 -2
  116. package/resultsetTable/ResultsetTable.d.ts +4 -0
  117. package/resultsetTable/ResultsetTable.js +4 -27
  118. package/resultsetTable/types.d.ts +67 -0
  119. package/resultsetTable/types.js +5 -0
  120. package/select/Select.js +2 -2
  121. package/select/Select.stories.tsx +572 -0
  122. package/select/index.d.ts +4 -4
  123. package/sidenav/Sidenav.d.ts +9 -0
  124. package/sidenav/Sidenav.js +6 -15
  125. package/sidenav/Sidenav.stories.tsx +165 -0
  126. package/sidenav/types.d.ts +50 -0
  127. package/sidenav/types.js +5 -0
  128. package/slider/Slider.d.ts +4 -0
  129. package/slider/Slider.js +61 -84
  130. package/slider/Slider.stories.tsx +177 -0
  131. package/slider/types.d.ts +78 -0
  132. package/slider/types.js +5 -0
  133. package/spinner/Spinner.d.ts +4 -0
  134. package/spinner/Spinner.js +8 -25
  135. package/spinner/Spinner.stories.jsx +102 -0
  136. package/spinner/types.d.ts +32 -0
  137. package/spinner/types.js +5 -0
  138. package/switch/Switch.js +4 -4
  139. package/switch/Switch.stories.tsx +160 -0
  140. package/table/Table.d.ts +4 -0
  141. package/table/Table.js +3 -3
  142. package/table/Table.stories.jsx +276 -0
  143. package/table/types.d.ts +21 -0
  144. package/table/types.js +5 -0
  145. package/tabs/Tabs.d.ts +4 -0
  146. package/tabs/Tabs.js +9 -55
  147. package/tabs/Tabs.stories.tsx +121 -0
  148. package/tabs/types.d.ts +70 -0
  149. package/tabs/types.js +5 -0
  150. package/tag/Tag.d.ts +4 -0
  151. package/tag/Tag.js +21 -36
  152. package/tag/Tag.stories.tsx +145 -0
  153. package/tag/types.d.ts +60 -0
  154. package/tag/types.js +5 -0
  155. package/text-input/TextInput.d.ts +4 -0
  156. package/text-input/TextInput.js +28 -65
  157. package/text-input/TextInput.stories.tsx +456 -0
  158. package/text-input/types.d.ts +159 -0
  159. package/text-input/types.js +5 -0
  160. package/textarea/Textarea.js +15 -16
  161. package/textarea/Textarea.stories.jsx +135 -0
  162. package/textarea/index.d.ts +18 -8
  163. package/toggle/Toggle.js +1 -1
  164. package/toggle-group/ToggleGroup.d.ts +4 -0
  165. package/toggle-group/ToggleGroup.js +6 -32
  166. package/toggle-group/ToggleGroup.stories.tsx +178 -0
  167. package/toggle-group/types.d.ts +84 -0
  168. package/toggle-group/types.js +5 -0
  169. package/upload/buttons-upload/ButtonsUpload.js +2 -2
  170. package/upload/dragAndDropArea/DragAndDropArea.js +2 -2
  171. package/upload/file-upload/FileToUpload.js +1 -1
  172. package/upload/files-upload/FilesToUpload.js +1 -1
  173. package/upload/transaction/Transaction.js +2 -2
  174. package/upload/transactions/Transactions.js +1 -1
  175. package/useTheme.d.ts +2 -0
  176. package/useTheme.js +1 -1
  177. package/wizard/Wizard.d.ts +4 -0
  178. package/wizard/Wizard.js +12 -52
  179. package/wizard/Wizard.stories.jsx +224 -0
  180. package/wizard/types.d.ts +64 -0
  181. package/wizard/types.js +5 -0
  182. package/accordion/index.d.ts +0 -28
  183. package/accordion-group/index.d.ts +0 -16
  184. package/box/index.d.ts +0 -25
  185. package/card/index.d.ts +0 -22
  186. package/chip/index.d.ts +0 -22
  187. package/dialog/index.d.ts +0 -18
  188. package/dropdown/index.d.ts +0 -26
  189. package/file-input/index.d.ts +0 -81
  190. package/footer/index.d.ts +0 -25
  191. package/header/index.d.ts +0 -25
  192. package/heading/index.d.ts +0 -17
  193. package/link/index.d.ts +0 -23
  194. package/number-input/index.d.ts +0 -113
  195. package/password-input/index.d.ts +0 -94
  196. package/progress-bar/index.d.ts +0 -18
  197. package/resultsetTable/index.d.ts +0 -19
  198. package/sidenav/index.d.ts +0 -13
  199. package/slider/index.d.ts +0 -29
  200. package/spinner/index.d.ts +0 -17
  201. package/table/index.d.ts +0 -13
  202. package/tabs/index.d.ts +0 -19
  203. package/tag/index.d.ts +0 -24
  204. package/text-input/index.d.ts +0 -135
  205. package/toggle-group/index.d.ts +0 -21
  206. package/wizard/index.d.ts +0 -18
@@ -23,7 +23,7 @@ var _styledComponents = _interopRequireWildcard(require("styled-components"));
23
23
 
24
24
  var _utils = require("../common/utils.js");
25
25
 
26
- var _useTheme = _interopRequireDefault(require("../useTheme.js"));
26
+ var _useTheme = _interopRequireDefault(require("../useTheme"));
27
27
 
28
28
  var _propTypes = _interopRequireDefault(require("prop-types"));
29
29
 
@@ -31,7 +31,7 @@ var _variables = require("../common/variables.js");
31
31
 
32
32
  var _uuid = require("uuid");
33
33
 
34
- var _BackgroundColorContext = _interopRequireDefault(require("../BackgroundColorContext.js"));
34
+ var _BackgroundColorContext = _interopRequireDefault(require("../BackgroundColorContext"));
35
35
 
36
36
  var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
37
37
 
@@ -43,10 +43,6 @@ var getNotOptionalErrorMessage = function getNotOptionalErrorMessage() {
43
43
  return "This field is required. Please, enter a value.";
44
44
  };
45
45
 
46
- var getLengthErrorMessage = function getLengthErrorMessage(length) {
47
- return "Min length ".concat(length.min, ", max length ").concat(length.max, ".");
48
- };
49
-
50
46
  var getPatternErrorMessage = function getPatternErrorMessage() {
51
47
  return "Please match the format requested.";
52
48
  };
@@ -78,7 +74,8 @@ var DxcTextarea = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref)
78
74
  _ref$error = _ref.error,
79
75
  error = _ref$error === void 0 ? "" : _ref$error,
80
76
  pattern = _ref.pattern,
81
- length = _ref.length,
77
+ minLength = _ref.minLength,
78
+ maxLength = _ref.maxLength,
82
79
  _ref$autocomplete = _ref.autocomplete,
83
80
  autocomplete = _ref$autocomplete === void 0 ? "off" : _ref$autocomplete,
84
81
  margin = _ref.margin,
@@ -101,12 +98,16 @@ var DxcTextarea = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref)
101
98
  var textareaRef = (0, _react.useRef)(null);
102
99
  var errorId = "error-message-".concat(textareaId);
103
100
 
101
+ var getLengthErrorMessage = function getLengthErrorMessage() {
102
+ return "Min length ".concat(minLength, ", max length ").concat(maxLength, ".");
103
+ };
104
+
104
105
  var isNotOptional = function isNotOptional(value) {
105
106
  return value === "" && !optional;
106
107
  };
107
108
 
108
109
  var isLengthIncorrect = function isLengthIncorrect(value) {
109
- return value !== "" && length && length.min && length.max && (value.length < length.min || value.length > length.max);
110
+ return value !== "" && minLength && maxLength && (value.length < minLength || value.length > maxLength);
110
111
  };
111
112
 
112
113
  var changeValue = function changeValue(newValue) {
@@ -116,7 +117,7 @@ var DxcTextarea = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref)
116
117
  error: getNotOptionalErrorMessage()
117
118
  });else if (isLengthIncorrect(newValue)) onChange === null || onChange === void 0 ? void 0 : onChange({
118
119
  value: newValue,
119
- error: getLengthErrorMessage(length)
120
+ error: getLengthErrorMessage()
120
121
  });else if (newValue && pattern && !patternMatch(pattern, newValue)) onChange === null || onChange === void 0 ? void 0 : onChange({
121
122
  value: newValue,
122
123
  error: getPatternErrorMessage()
@@ -132,7 +133,7 @@ var DxcTextarea = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref)
132
133
  error: getNotOptionalErrorMessage()
133
134
  });else if (isLengthIncorrect(event.target.value)) onBlur === null || onBlur === void 0 ? void 0 : onBlur({
134
135
  value: event.target.value,
135
- error: getLengthErrorMessage(length)
136
+ error: getLengthErrorMessage()
136
137
  });else if (event.target.value && pattern && !patternMatch(pattern, event.target.value)) onBlur === null || onBlur === void 0 ? void 0 : onBlur({
137
138
  value: event.target.value,
138
139
  error: getPatternErrorMessage()
@@ -179,8 +180,8 @@ var DxcTextarea = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref)
179
180
  onBlur: handleTOnBlur,
180
181
  disabled: disabled,
181
182
  error: error,
182
- minLength: length === null || length === void 0 ? void 0 : length.min,
183
- maxLength: length === null || length === void 0 ? void 0 : length.max,
183
+ minLength: minLength,
184
+ maxLength: maxLength,
184
185
  autoComplete: autocomplete,
185
186
  backgroundType: backgroundType,
186
187
  ref: textareaRef,
@@ -293,10 +294,8 @@ DxcTextarea.propTypes = {
293
294
  placeholder: _propTypes["default"].string,
294
295
  verticalGrow: _propTypes["default"].oneOf(["auto", "none", "manual"]),
295
296
  rows: _propTypes["default"].number,
296
- length: _propTypes["default"].shape({
297
- min: _propTypes["default"].number,
298
- max: _propTypes["default"].number
299
- }),
297
+ minLength: _propTypes["default"].number,
298
+ maxLength: _propTypes["default"].number,
300
299
  pattern: _propTypes["default"].string,
301
300
  disabled: _propTypes["default"].bool,
302
301
  optional: _propTypes["default"].bool,
@@ -0,0 +1,135 @@
1
+ import React from "react";
2
+ import DxcTextarea from "./Textarea";
3
+ import Title from "../../.storybook/components/Title";
4
+ import ExampleContainer from "../../.storybook/components/ExampleContainer";
5
+ import { BackgroundColorProvider } from "../BackgroundColorContext";
6
+ import DarkContainer from "../../.storybook/components/DarkSection";
7
+
8
+ export default {
9
+ title: "Textarea",
10
+ component: DxcTextarea,
11
+ };
12
+
13
+ export const Chromatic = () => (
14
+ <>
15
+ <>
16
+ <ExampleContainer pseudoState="pseudo-hover">
17
+ <Title title="Hovered" theme="light" level={4} />
18
+ <DxcTextarea label="Hovered" />
19
+ </ExampleContainer>
20
+ <ExampleContainer pseudoState="pseudo-focus">
21
+ <Title title="Focused" theme="light" level={4} />
22
+ <DxcTextarea label="Focused" />
23
+ </ExampleContainer>
24
+ <ExampleContainer>
25
+ <Title title="Disabled" theme="light" level={4} />
26
+ <DxcTextarea
27
+ label="Disabled"
28
+ optional
29
+ helperText="Sample text"
30
+ placeholder="Enter your text here..."
31
+ disabled
32
+ />
33
+ </ExampleContainer>
34
+ <ExampleContainer>
35
+ <Title title="Disabled with value" theme="light" level={4} />
36
+ <DxcTextarea label="Disabled" value="Example text" disabled />
37
+ </ExampleContainer>
38
+ <ExampleContainer>
39
+ <Title title="With error" theme="light" level={4} />
40
+ <DxcTextarea
41
+ label="Textarea with error"
42
+ helperText="Helper text"
43
+ placeholder="Enter your text here..."
44
+ error="Error message"
45
+ />
46
+ </ExampleContainer>
47
+ <ExampleContainer>
48
+ <Title title="Helper text and optional with value" theme="light" level={4} />
49
+ <DxcTextarea label="Helper & optional" value="Some text" helperText="Sample text" optional />
50
+ </ExampleContainer>
51
+ <ExampleContainer>
52
+ <Title title="Resizable" theme="light" level={4} />
53
+ <DxcTextarea label="With resizer" helperText="Helper text" verticalGrow="manual" />
54
+ </ExampleContainer>
55
+ <ExampleContainer>
56
+ <Title title="Grow manual" theme="light" level={4} />
57
+ <DxcTextarea
58
+ label="Manual vertical grow"
59
+ verticalGrow="manual"
60
+ value="Long textttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
61
+ />
62
+ </ExampleContainer>
63
+ </>
64
+ <BackgroundColorProvider color="#333333">
65
+ <DarkContainer>
66
+ <>
67
+ <Title title="Helper text and optional with value" theme="dark" level={4} />
68
+ <DxcTextarea label="Helper & optional" value="Some text" margin="medium" helperText="Sample text" optional />
69
+
70
+ <Title title="Disabled" theme="dark" level={4} />
71
+ <DxcTextarea
72
+ label="Disabled"
73
+ margin="medium"
74
+ optional
75
+ helperText="Sample text"
76
+ placeholder="Enter your text here..."
77
+ disabled
78
+ />
79
+ <Title title="Disabled with value" theme="dark" level={4} />
80
+ <DxcTextarea label="Disabled" margin="medium" value="Example text" disabled />
81
+ <Title title="With error" theme="dark" level={4} />
82
+ <DxcTextarea
83
+ label="Textarea with error"
84
+ margin="medium"
85
+ helperText="Helper text"
86
+ placeholder="Enter your text here..."
87
+ error="Error message"
88
+ />
89
+ </>
90
+ </DarkContainer>
91
+ </BackgroundColorProvider>
92
+ <Title title="Sizes" theme="light" level={2} />
93
+ <ExampleContainer>
94
+ <DxcTextarea label="Small" size="small" />
95
+ </ExampleContainer>
96
+ <ExampleContainer>
97
+ <DxcTextarea label="Medium" size="medium" />
98
+ </ExampleContainer>
99
+ <ExampleContainer>
100
+ <DxcTextarea label="Large" size="large" />
101
+ </ExampleContainer>
102
+ <ExampleContainer>
103
+ <DxcTextarea label="Fill parent" size="fillParent" />
104
+ </ExampleContainer>
105
+ <Title title="Margins" theme="light" level={2} />
106
+ <ExampleContainer>
107
+ <Title title="Xxsmall margin" theme="light" level={4} />
108
+ <DxcTextarea label="Xxsmmall" margin="xxsmall" />
109
+ </ExampleContainer>
110
+ <ExampleContainer>
111
+ <Title title="Xsmall margin" theme="light" level={4} />
112
+ <DxcTextarea label="xsmmall" margin="xsmall" />
113
+ </ExampleContainer>
114
+ <ExampleContainer>
115
+ <Title title="Small margin" theme="light" level={4} />
116
+ <DxcTextarea label="smmall" margin="small" />
117
+ </ExampleContainer>
118
+ <ExampleContainer>
119
+ <Title title="Medium margin" theme="light" level={4} />
120
+ <DxcTextarea label="medium" margin="medium" />
121
+ </ExampleContainer>
122
+ <ExampleContainer>
123
+ <Title title="Large margin" theme="light" level={4} />
124
+ <DxcTextarea label="Large" margin="large" />
125
+ </ExampleContainer>
126
+ <ExampleContainer>
127
+ <Title title="Xlarge margin" theme="light" level={4} />
128
+ <DxcTextarea label="Xlarge" margin="xlarge" />
129
+ </ExampleContainer>
130
+ <ExampleContainer>
131
+ <Title title="Xxlarge margin" theme="light" level={4} />
132
+ <DxcTextarea label="Xxlarge" margin="xxlarge" />
133
+ </ExampleContainer>
134
+ </>
135
+ );
@@ -33,9 +33,9 @@ type Props = {
33
33
  */
34
34
  disabled?: boolean;
35
35
  /**
36
- * If true, the textarea will be optional, showing '(Optional)'
37
- * next to the label. Otherwise, the field will be considered required
38
- * and an error will be passed as a parameter to the OnBlur and onChange functions
36
+ * If true, the textarea will be optional, showing '(Optional)'
37
+ * next to the label. Otherwise, the field will be considered required
38
+ * and an error will be passed as a parameter to the OnBlur and onChange functions
39
39
  * when it has not been filled.
40
40
  */
41
41
  optional?: boolean;
@@ -53,14 +53,14 @@ type Props = {
53
53
  /**
54
54
  * This function will be called when the user types within the textarea.
55
55
  * An object including the current value and the error (if the value
56
- * entered is not valid) will be passed to this function.
56
+ * entered is not valid) will be passed to this function.
57
57
  * If there is no error, error will be null.
58
58
  */
59
59
  onChange?: (val: { value: string; error: string }) => void;
60
60
  /**
61
61
  * This function will be called when the textarea loses the focus. An
62
62
  * object including the textarea value and the error (if the value entered
63
- * is not valid) will be passed to this function. If there is no error,
63
+ * is not valid) will be passed to this function. If there is no error,
64
64
  * error will be null.
65
65
  */
66
66
  onBlur?: (val: { value: string; error: string }) => void;
@@ -81,15 +81,25 @@ type Props = {
81
81
  */
82
82
  pattern?: string;
83
83
  /**
84
- * Specifies the minimun and maximum length allowed by the textarea.
84
+ * Specifies the minimun length allowed by the textarea.
85
85
  * This will be checked both when the textarea loses the
86
86
  * focus and while typing within it. If the string entered does not
87
- * comply the length, the onBlur and onChange functions will be called
87
+ * comply the minimum length, the onBlur and onChange functions will be called
88
88
  * with the current value and an internal error informing that the value
89
89
  * length does not comply the specified range. If a valid length is
90
90
  * reached, the error parameter of both events will be null.
91
91
  */
92
- length?: { min: number; max: number };
92
+ minLength?: number;
93
+ /**
94
+ * Specifies the maximum length allowed by the textarea.
95
+ * This will be checked both when the textarea loses the
96
+ * focus and while typing within it. If the string entered does not
97
+ * comply the maximum length, the onBlur and onChange functions will be called
98
+ * with the current value and an internal error informing that the value
99
+ * length does not comply the specified range. If a valid length is
100
+ * reached, the error parameter of both events will be null.
101
+ */
102
+ maxLength?: number;
93
103
  /**
94
104
  * HTML autocomplete attribute. Lets the user specify if any permission the user agent has to provide automated assistance in filling out the textarea value.
95
105
  * Its value must be one of all the possible values of the HTML autocomplete attribute: 'on', 'off', 'email', 'username', 'new-password', ...
package/toggle/Toggle.js CHANGED
@@ -25,7 +25,7 @@ var _styledComponents = _interopRequireWildcard(require("styled-components"));
25
25
 
26
26
  var _utils = require("../common/utils.js");
27
27
 
28
- var _useTheme = _interopRequireDefault(require("../useTheme.js"));
28
+ var _useTheme = _interopRequireDefault(require("../useTheme"));
29
29
 
30
30
  var _templateObject, _templateObject2, _templateObject3, _templateObject4;
31
31
 
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import ToogleGroupPropsType from "./types";
3
+ declare const DxcToggleGroup: ({ label, helperText, value, onChange, disabled, options, margin, multiple, tabIndex, }: ToogleGroupPropsType) => JSX.Element;
4
+ export default DxcToggleGroup;
@@ -9,8 +9,6 @@ Object.defineProperty(exports, "__esModule", {
9
9
  });
10
10
  exports["default"] = void 0;
11
11
 
12
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
-
14
12
  var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
15
13
 
16
14
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
@@ -23,11 +21,9 @@ var _styledComponents = _interopRequireWildcard(require("styled-components"));
23
21
 
24
22
  var _uuid = require("uuid");
25
23
 
26
- var _propTypes = _interopRequireDefault(require("prop-types"));
27
-
28
24
  var _variables = require("../common/variables.js");
29
25
 
30
- var _useTheme = _interopRequireDefault(require("../useTheme.js"));
26
+ var _useTheme = _interopRequireDefault(require("../useTheme"));
31
27
 
32
28
  var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9;
33
29
 
@@ -42,8 +38,7 @@ var DxcToggleGroup = function DxcToggleGroup(_ref) {
42
38
  onChange = _ref.onChange,
43
39
  _ref$disabled = _ref.disabled,
44
40
  disabled = _ref$disabled === void 0 ? false : _ref$disabled,
45
- _ref$options = _ref.options,
46
- options = _ref$options === void 0 ? [] : _ref$options,
41
+ options = _ref.options,
47
42
  margin = _ref.margin,
48
43
  _ref$multiple = _ref.multiple,
49
44
  multiple = _ref$multiple === void 0 ? false : _ref$multiple,
@@ -51,7 +46,7 @@ var DxcToggleGroup = function DxcToggleGroup(_ref) {
51
46
  tabIndex = _ref$tabIndex === void 0 ? 0 : _ref$tabIndex;
52
47
  var colorsTheme = (0, _useTheme["default"])();
53
48
 
54
- var _useState = (0, _react.useState)(multiple ? [] : null),
49
+ var _useState = (0, _react.useState)(multiple ? [] : ""),
55
50
  _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
56
51
  selectedValue = _useState2[0],
57
52
  setSelectedValue = _useState2[1];
@@ -64,7 +59,7 @@ var DxcToggleGroup = function DxcToggleGroup(_ref) {
64
59
  var newSelectedOptions;
65
60
 
66
61
  if (value == null) {
67
- if (multiple) {
62
+ if (multiple && Array.isArray(selectedValue)) {
68
63
  newSelectedOptions = selectedValue.map(function (value) {
69
64
  return value;
70
65
  });
@@ -79,9 +74,9 @@ var DxcToggleGroup = function DxcToggleGroup(_ref) {
79
74
  setSelectedValue(newSelectedOptions);
80
75
  } else setSelectedValue(selectedOption === selectedValue ? null : selectedOption);
81
76
  } else if (multiple) {
82
- newSelectedOptions = value.map(function (v) {
77
+ newSelectedOptions = Array.isArray(value) ? value.map(function (v) {
83
78
  return v;
84
- });
79
+ }) : value;
85
80
 
86
81
  if (newSelectedOptions.includes(selectedOption)) {
87
82
  var _index = newSelectedOptions.indexOf(selectedOption);
@@ -218,26 +213,5 @@ var IconContainer = _styledComponents["default"].div(_templateObject9 || (_templ
218
213
  return props.optionLabel && props.theme.iconMarginRight;
219
214
  });
220
215
 
221
- DxcToggleGroup.propTypes = {
222
- label: _propTypes["default"].string,
223
- helperText: _propTypes["default"].string,
224
- value: _propTypes["default"].any,
225
- onChange: _propTypes["default"].func,
226
- disabled: _propTypes["default"].bool,
227
- multiple: _propTypes["default"].bool,
228
- options: _propTypes["default"].arrayOf(_propTypes["default"].shape({
229
- value: _propTypes["default"].any.isRequired,
230
- label: _propTypes["default"].string,
231
- icon: _propTypes["default"].oneOfType([_propTypes["default"].element, _propTypes["default"].func]),
232
- iconSrc: _propTypes["default"].string
233
- })),
234
- margin: _propTypes["default"].oneOfType([_propTypes["default"].shape({
235
- top: _propTypes["default"].oneOf(Object.keys(_variables.spaces)),
236
- bottom: _propTypes["default"].oneOf(Object.keys(_variables.spaces)),
237
- left: _propTypes["default"].oneOf(Object.keys(_variables.spaces)),
238
- right: _propTypes["default"].oneOf(Object.keys(_variables.spaces))
239
- }), _propTypes["default"].oneOf((0, _toConsumableArray2["default"])(Object.keys(_variables.spaces)))]),
240
- tabIndex: _propTypes["default"].number
241
- };
242
216
  var _default = DxcToggleGroup;
243
217
  exports["default"] = _default;
@@ -0,0 +1,178 @@
1
+ import React from "react";
2
+ import { userEvent, within } from "@storybook/testing-library";
3
+ import DxcToggleGroup from "./ToggleGroup";
4
+ import Title from "../../.storybook/components/Title";
5
+ import ExampleContainer from "../../.storybook/components/ExampleContainer";
6
+
7
+ export default {
8
+ title: "ToggleGroup",
9
+ component: DxcToggleGroup,
10
+ };
11
+
12
+ const ethernetSVG = () => {
13
+ return (
14
+ <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
15
+ <path d="M0 0h24v24H0V0z" fill="none" />
16
+ <path d="M7.77 6.76L6.23 5.48.82 12l5.41 6.52 1.54-1.28L3.42 12l4.35-5.24zM7 13h2v-2H7v2zm10-2h-2v2h2v-2zm-6 2h2v-2h-2v2zm6.77-7.52l-1.54 1.28L20.58 12l-4.35 5.24 1.54 1.28L23.18 12l-5.41-6.52z" />
17
+ </svg>
18
+ );
19
+ };
20
+ const gMobileSVG = () => {
21
+ return (
22
+ <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
23
+ <g>
24
+ <path d="M0,0h24v24H0V0z" fill="none" />
25
+ </g>
26
+ <g>
27
+ <g>
28
+ <path d="M3,7v2h5v2H4v2h4v2H3v2h5c1.1,0,2-0.9,2-2v-1.5c0-0.83-0.67-1.5-1.5-1.5c0.83,0,1.5-0.67,1.5-1.5V9c0-1.1-0.9-2-2-2H3z M21,11v4c0,1.1-0.9,2-2,2h-5c-1.1,0-2-0.9-2-2V9c0-1.1,0.9-2,2-2h5c1.1,0,2,0.9,2,2h-7v6h5v-2h-2.5v-2H21z" />
29
+ </g>
30
+ </g>
31
+ </svg>
32
+ );
33
+ };
34
+ const wifiSVG = () => {
35
+ return (
36
+ <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
37
+ <path d="M0 0h24v24H0V0zm0 0h24v24H0V0z" fill="none" />
38
+ <path d="M1 9l2 2c4.97-4.97 13.03-4.97 18 0l2-2C16.93 2.93 7.08 2.93 1 9zm8 8l3 3 3-3c-1.65-1.66-4.34-1.66-6 0zm-4-4l2 2c2.76-2.76 7.24-2.76 10 0l2-2C15.14 9.14 8.87 9.14 5 13z" />
39
+ </svg>
40
+ );
41
+ };
42
+ const options = [
43
+ {
44
+ value: 1,
45
+ label: "Facebook",
46
+ },
47
+ {
48
+ value: 2,
49
+ label: "Twitter",
50
+ },
51
+ {
52
+ value: 3,
53
+ label: "Linkedin",
54
+ },
55
+ ];
56
+ const optionsWithIcon = [
57
+ {
58
+ value: 1,
59
+ icon: wifiSVG,
60
+ },
61
+ {
62
+ value: 2,
63
+ icon: ethernetSVG,
64
+ },
65
+ {
66
+ value: 3,
67
+ icon: gMobileSVG,
68
+ },
69
+ ];
70
+ const optionsWithIconAndLabel = [
71
+ {
72
+ value: 1,
73
+ label: "Wi-fi",
74
+ icon: wifiSVG,
75
+ },
76
+ {
77
+ value: 2,
78
+ label: "Ethernet",
79
+ icon: ethernetSVG,
80
+ },
81
+ {
82
+ value: 3,
83
+ label: "3G Mobile",
84
+ icon: gMobileSVG,
85
+ },
86
+ ];
87
+ const twoOptions = [
88
+ {
89
+ value: 1,
90
+ label: "Facebook",
91
+ },
92
+ {
93
+ value: 2,
94
+ label: "Twitter",
95
+ },
96
+ ];
97
+ export const Chromatic = () => (
98
+ <>
99
+ <ExampleContainer>
100
+ <Title title="Basic toggle group" theme="light" level={4} />
101
+ <DxcToggleGroup label="Toggle group" helperText="HelperText" options={options} />
102
+ </ExampleContainer>
103
+ <ExampleContainer>
104
+ <Title title="Selected" theme="light" level={4} />
105
+ <DxcToggleGroup label="Selected" helperText="HelperText" value={2} options={options} />
106
+ </ExampleContainer>
107
+ <ExampleContainer>
108
+ <Title title="Icons toggle group" theme="light" level={4} />
109
+ <DxcToggleGroup label="Icons group" options={optionsWithIcon} />
110
+ </ExampleContainer>
111
+ <ExampleContainer>
112
+ <Title title="Icons & label toggle group" theme="light" level={4} />
113
+ <DxcToggleGroup label="Icons & label" options={optionsWithIconAndLabel} />
114
+ </ExampleContainer>
115
+ <ExampleContainer>
116
+ <Title title="Disabled" theme="light" level={4} />
117
+ <DxcToggleGroup label="Disabled" value={2} options={options} disabled />
118
+ </ExampleContainer>
119
+ <ExampleContainer pseudoState="pseudo-hover">
120
+ <Title title="Hovered" theme="light" level={4} />
121
+ <DxcToggleGroup label="Hovered" options={twoOptions} value={2} />
122
+ </ExampleContainer>
123
+ <ExampleContainer>
124
+ <Title title="Multiple toggleGroup" theme="light" level={4} />
125
+ <DxcToggleGroup
126
+ label="Toggle group"
127
+ helperText="Please select one or more"
128
+ options={options}
129
+ value={[1, 3]}
130
+ multiple
131
+ ></DxcToggleGroup>
132
+ </ExampleContainer>
133
+ <Title title="Margins" theme="light" level={2} />
134
+ <ExampleContainer>
135
+ <Title title="xxSmall" theme="light" level={4} />
136
+ <DxcToggleGroup label="xxSmall margin" options={options} margin="xxsmall" />
137
+ </ExampleContainer>
138
+ <ExampleContainer>
139
+ <Title title="xSmall" theme="light" level={4} />
140
+ <DxcToggleGroup label="xSmall margin" options={options} margin="xsmall" />
141
+ </ExampleContainer>
142
+ <ExampleContainer>
143
+ <Title title="Small" theme="light" level={4} />
144
+ <DxcToggleGroup label="Small margin" options={options} margin="small" />
145
+ </ExampleContainer>
146
+ <ExampleContainer>
147
+ <Title title="Medium" theme="light" level={4} />
148
+ <DxcToggleGroup label="Medium margin" options={options} margin="medium" />
149
+ </ExampleContainer>
150
+ <ExampleContainer>
151
+ <Title title="Large" theme="light" level={4} />
152
+ <DxcToggleGroup label="Large margin" options={options} margin="large" />
153
+ </ExampleContainer>
154
+ <ExampleContainer>
155
+ <Title title="xLarge" theme="light" level={4} />
156
+ <DxcToggleGroup label="xLarge margin" options={options} margin="xlarge" />
157
+ </ExampleContainer>
158
+ <ExampleContainer>
159
+ <Title title="xxLarge" theme="light" level={4} />
160
+ <DxcToggleGroup label="xxLarge margin" options={options} margin="xxlarge" />
161
+ </ExampleContainer>
162
+ </>
163
+ );
164
+ const OptionSelected = () => <DxcToggleGroup label="Toggle group" helperText="HelperText" options={options} />;
165
+
166
+ export const ToggleGroupSelectedActived = OptionSelected.bind({});
167
+ ToggleGroupSelectedActived.play = async ({ canvasElement }) => {
168
+ const canvas = within(canvasElement);
169
+ const option = canvas.getByText("Linkedin");
170
+ await userEvent.click(option);
171
+ };
172
+ export const ToggleGroupUnselectedActived = OptionSelected.bind({});
173
+ ToggleGroupUnselectedActived.play = async ({ canvasElement }) => {
174
+ const canvas = within(canvasElement);
175
+ const option = canvas.getByText("Twitter");
176
+ await userEvent.click(option);
177
+ userEvent.tab();
178
+ };
@@ -0,0 +1,84 @@
1
+ /// <reference types="react" />
2
+ declare type Space = "xxsmall" | "xsmall" | "small" | "medium" | "large" | "xlarge" | "xxlarge";
3
+ declare type Margin = {
4
+ top?: Space;
5
+ bottom?: Space;
6
+ left?: Space;
7
+ right?: Space;
8
+ };
9
+ declare type SVG = React.SVGProps<SVGSVGElement> | React.FunctionComponent<React.SVGProps<SVGSVGElement>>;
10
+ declare type OptionCommons = {
11
+ /**
12
+ * Number with the option inner value.
13
+ */
14
+ value: string;
15
+ /**
16
+ * @deprecated URL of the icon that will be placed. IconSrc and label can't be used at same time.
17
+ */
18
+ iconSrc?: string;
19
+ };
20
+ declare type OptionIcon = OptionCommons & {
21
+ /**
22
+ * String with the option display value.
23
+ */
24
+ label?: string;
25
+ /**
26
+ * Element used as the icon. Icon and label can't be used at same time.
27
+ */
28
+ icon: SVG;
29
+ };
30
+ declare type OptionLabel = OptionCommons & {
31
+ /**
32
+ * String with the option display value.
33
+ */
34
+ label: string;
35
+ /**
36
+ * Element used as the icon. Icon and label can't be used at same time.
37
+ */
38
+ icon?: SVG;
39
+ };
40
+ declare type Option = OptionIcon | OptionLabel;
41
+ declare type Props = {
42
+ /**
43
+ * Text to be placed above the component.
44
+ */
45
+ label?: string;
46
+ /**
47
+ * Helper text to be placed above the component.
48
+ */
49
+ helperText?: string;
50
+ /**
51
+ * The key(s) of the selected value(s). If the toggle group component doesn't allow multiple selection,
52
+ * it must be one unique value. If the component allows multiple selection, value must be an array.
53
+ * If undefined, the component will be uncontrolled and the value will be managed internally by the component.
54
+ */
55
+ value?: string | string[];
56
+ /**
57
+ * This function will be called every time the selection changes. The number with the key of the selected
58
+ * value will be passed as a parameter to this function.
59
+ * If multiple selection is allowed, an array of keys will be passed.
60
+ */
61
+ onChange?: (optionIndex: number | number[]) => void;
62
+ /**
63
+ * If true, the component will be disabled.
64
+ */
65
+ disabled?: boolean;
66
+ /**
67
+ * An array of objects representing the selectable options.
68
+ */
69
+ options: Option[];
70
+ /**
71
+ * If true, the toggle group will support multiple selection. In that case, value must be an array of numbers with the keys of the selected values.
72
+ */
73
+ multiple?: boolean;
74
+ /**
75
+ * Size of the margin to be applied to the component ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
76
+ * You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different margin sizes.
77
+ */
78
+ margin?: Space | Margin;
79
+ /**
80
+ * Value of the tabindex.
81
+ */
82
+ tabIndex?: number;
83
+ };
84
+ export default Props;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });