@dxc-technology/halstack-react 0.0.0-9b45027 → 0.0.0-9bd9511

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 (294) hide show
  1. package/BackgroundColorContext.d.ts +2 -2
  2. package/BackgroundColorContext.js +1 -11
  3. package/HalstackContext.d.ts +13 -0
  4. package/HalstackContext.js +318 -0
  5. package/accordion/Accordion.d.ts +1 -1
  6. package/accordion/Accordion.js +124 -179
  7. package/accordion/Accordion.stories.tsx +115 -27
  8. package/accordion/Accordion.test.js +56 -0
  9. package/accordion/types.d.ts +12 -11
  10. package/accordion-group/AccordionGroup.d.ts +1 -1
  11. package/accordion-group/AccordionGroup.js +28 -77
  12. package/accordion-group/AccordionGroup.stories.tsx +28 -2
  13. package/accordion-group/AccordionGroup.test.js +108 -0
  14. package/accordion-group/types.d.ts +19 -12
  15. package/alert/Alert.js +18 -46
  16. package/alert/Alert.stories.tsx +28 -0
  17. package/alert/Alert.test.js +75 -0
  18. package/alert/types.d.ts +3 -3
  19. package/badge/Badge.d.ts +4 -0
  20. package/badge/Badge.js +6 -16
  21. package/badge/types.d.ts +5 -0
  22. package/bleed/Bleed.d.ts +2 -2
  23. package/bleed/Bleed.js +14 -55
  24. package/bleed/Bleed.stories.tsx +94 -95
  25. package/bleed/types.d.ts +26 -2
  26. package/box/Box.js +34 -63
  27. package/box/Box.stories.tsx +15 -0
  28. package/box/Box.test.js +13 -0
  29. package/box/types.d.ts +5 -4
  30. package/bulleted-list/BulletedList.d.ts +7 -0
  31. package/bulleted-list/BulletedList.js +98 -0
  32. package/bulleted-list/BulletedList.stories.tsx +200 -0
  33. package/bulleted-list/types.d.ts +11 -0
  34. package/bulleted-list/types.js +5 -0
  35. package/button/Button.js +61 -100
  36. package/button/Button.stories.tsx +159 -8
  37. package/button/Button.test.js +26 -0
  38. package/button/types.d.ts +8 -8
  39. package/card/Card.js +44 -70
  40. package/card/Card.test.js +39 -0
  41. package/card/types.d.ts +4 -3
  42. package/checkbox/Checkbox.d.ts +2 -2
  43. package/checkbox/Checkbox.js +115 -162
  44. package/checkbox/Checkbox.stories.tsx +198 -130
  45. package/checkbox/Checkbox.test.js +128 -0
  46. package/checkbox/types.d.ts +14 -6
  47. package/chip/Chip.d.ts +1 -1
  48. package/chip/Chip.js +29 -91
  49. package/chip/Chip.stories.tsx +98 -13
  50. package/chip/Chip.test.js +42 -0
  51. package/chip/types.d.ts +8 -16
  52. package/common/utils.js +1 -6
  53. package/common/variables.d.ts +1431 -0
  54. package/common/variables.js +480 -554
  55. package/date-input/Calendar.d.ts +4 -0
  56. package/date-input/Calendar.js +215 -0
  57. package/date-input/DateInput.js +164 -300
  58. package/date-input/DateInput.stories.tsx +199 -33
  59. package/date-input/DateInput.test.js +648 -0
  60. package/date-input/DatePicker.d.ts +4 -0
  61. package/date-input/DatePicker.js +116 -0
  62. package/date-input/Icons.d.ts +6 -0
  63. package/date-input/Icons.js +63 -0
  64. package/date-input/YearPicker.d.ts +4 -0
  65. package/date-input/YearPicker.js +101 -0
  66. package/date-input/types.d.ts +71 -13
  67. package/dialog/Dialog.js +52 -84
  68. package/dialog/Dialog.stories.tsx +99 -22
  69. package/dialog/Dialog.test.js +56 -0
  70. package/dialog/types.d.ts +4 -3
  71. package/dropdown/Dropdown.d.ts +1 -1
  72. package/dropdown/Dropdown.js +240 -323
  73. package/dropdown/Dropdown.stories.tsx +255 -64
  74. package/dropdown/Dropdown.test.js +479 -0
  75. package/dropdown/DropdownMenu.d.ts +4 -0
  76. package/dropdown/DropdownMenu.js +60 -0
  77. package/dropdown/DropdownMenuItem.d.ts +4 -0
  78. package/dropdown/DropdownMenuItem.js +70 -0
  79. package/dropdown/types.d.ts +30 -19
  80. package/file-input/FileInput.d.ts +2 -2
  81. package/file-input/FileInput.js +224 -351
  82. package/file-input/FileInput.stories.tsx +122 -11
  83. package/file-input/FileInput.test.js +445 -0
  84. package/file-input/FileItem.d.ts +4 -14
  85. package/file-input/FileItem.js +48 -97
  86. package/file-input/types.d.ts +24 -7
  87. package/flex/Flex.d.ts +4 -0
  88. package/flex/Flex.js +57 -0
  89. package/flex/Flex.stories.tsx +103 -0
  90. package/flex/types.d.ts +32 -0
  91. package/flex/types.js +5 -0
  92. package/footer/Footer.js +36 -143
  93. package/footer/Footer.stories.tsx +99 -1
  94. package/footer/Footer.test.js +92 -0
  95. package/footer/Icons.js +1 -5
  96. package/footer/types.d.ts +7 -6
  97. package/header/Header.js +112 -177
  98. package/header/Header.stories.tsx +189 -36
  99. package/header/Header.test.js +66 -0
  100. package/header/Icons.js +2 -6
  101. package/header/types.d.ts +4 -3
  102. package/heading/Heading.js +8 -29
  103. package/heading/Heading.test.js +169 -0
  104. package/heading/types.d.ts +3 -3
  105. package/inset/Inset.js +14 -55
  106. package/inset/Inset.stories.tsx +36 -36
  107. package/inset/types.d.ts +26 -2
  108. package/layout/ApplicationLayout.d.ts +16 -6
  109. package/layout/ApplicationLayout.js +71 -164
  110. package/layout/ApplicationLayout.stories.tsx +84 -93
  111. package/layout/Icons.d.ts +5 -0
  112. package/layout/Icons.js +11 -10
  113. package/layout/SidenavContext.d.ts +5 -0
  114. package/layout/SidenavContext.js +15 -0
  115. package/layout/types.d.ts +18 -33
  116. package/link/Link.d.ts +3 -2
  117. package/link/Link.js +61 -106
  118. package/link/Link.stories.tsx +159 -52
  119. package/link/Link.test.js +65 -0
  120. package/link/types.d.ts +9 -29
  121. package/main.d.ts +11 -15
  122. package/main.js +48 -121
  123. package/nav-tabs/NavTabs.d.ts +8 -0
  124. package/nav-tabs/NavTabs.js +95 -0
  125. package/nav-tabs/NavTabs.stories.tsx +260 -0
  126. package/nav-tabs/NavTabs.test.js +75 -0
  127. package/nav-tabs/Tab.d.ts +4 -0
  128. package/nav-tabs/Tab.js +120 -0
  129. package/nav-tabs/types.d.ts +53 -0
  130. package/nav-tabs/types.js +5 -0
  131. package/number-input/NumberInput.js +21 -38
  132. package/number-input/NumberInput.stories.tsx +5 -5
  133. package/number-input/NumberInput.test.js +406 -0
  134. package/number-input/NumberInputContext.js +0 -5
  135. package/number-input/numberInputContextTypes.d.ts +1 -1
  136. package/number-input/types.d.ts +21 -14
  137. package/package.json +22 -25
  138. package/paginator/Icons.d.ts +5 -0
  139. package/paginator/Icons.js +16 -38
  140. package/paginator/Paginator.js +31 -82
  141. package/paginator/Paginator.stories.tsx +24 -0
  142. package/paginator/Paginator.test.js +266 -0
  143. package/paginator/types.d.ts +1 -1
  144. package/paragraph/Paragraph.d.ts +6 -0
  145. package/paragraph/Paragraph.js +28 -0
  146. package/paragraph/Paragraph.stories.tsx +44 -0
  147. package/password-input/PasswordInput.js +28 -54
  148. package/password-input/PasswordInput.test.js +138 -0
  149. package/password-input/types.d.ts +18 -15
  150. package/progress-bar/ProgressBar.d.ts +2 -2
  151. package/progress-bar/ProgressBar.js +65 -84
  152. package/progress-bar/ProgressBar.stories.jsx +47 -12
  153. package/progress-bar/ProgressBar.test.js +93 -0
  154. package/progress-bar/types.d.ts +3 -4
  155. package/quick-nav/QuickNav.d.ts +4 -0
  156. package/quick-nav/QuickNav.js +95 -0
  157. package/quick-nav/QuickNav.stories.tsx +356 -0
  158. package/quick-nav/types.d.ts +21 -0
  159. package/quick-nav/types.js +5 -0
  160. package/radio-group/Radio.d.ts +1 -1
  161. package/radio-group/Radio.js +61 -66
  162. package/radio-group/RadioGroup.js +99 -129
  163. package/radio-group/RadioGroup.stories.tsx +171 -36
  164. package/radio-group/RadioGroup.test.js +620 -0
  165. package/radio-group/types.d.ts +85 -7
  166. package/resultsetTable/Icons.d.ts +7 -0
  167. package/resultsetTable/Icons.js +48 -0
  168. package/resultsetTable/ResultsetTable.js +66 -157
  169. package/resultsetTable/ResultsetTable.stories.tsx +50 -25
  170. package/resultsetTable/ResultsetTable.test.js +292 -0
  171. package/resultsetTable/types.d.ts +5 -5
  172. package/select/Icons.d.ts +10 -0
  173. package/select/Icons.js +90 -0
  174. package/select/Listbox.d.ts +4 -0
  175. package/select/Listbox.js +144 -0
  176. package/select/Option.d.ts +4 -0
  177. package/select/Option.js +81 -0
  178. package/select/Select.js +201 -485
  179. package/select/Select.stories.tsx +600 -201
  180. package/select/Select.test.js +1845 -0
  181. package/select/types.d.ts +62 -22
  182. package/sidenav/Sidenav.d.ts +6 -5
  183. package/sidenav/Sidenav.js +164 -74
  184. package/sidenav/Sidenav.stories.tsx +249 -149
  185. package/sidenav/Sidenav.test.js +37 -0
  186. package/sidenav/types.d.ts +50 -27
  187. package/slider/Slider.d.ts +2 -2
  188. package/slider/Slider.js +143 -164
  189. package/slider/Slider.stories.tsx +72 -9
  190. package/slider/Slider.test.js +222 -0
  191. package/slider/types.d.ts +11 -3
  192. package/spinner/Spinner.js +12 -41
  193. package/spinner/Spinner.stories.jsx +27 -1
  194. package/spinner/Spinner.test.js +55 -0
  195. package/spinner/types.d.ts +3 -3
  196. package/switch/Switch.d.ts +2 -2
  197. package/switch/Switch.js +148 -107
  198. package/switch/Switch.stories.tsx +53 -42
  199. package/switch/Switch.test.js +180 -0
  200. package/switch/types.d.ts +13 -5
  201. package/table/Table.js +5 -23
  202. package/table/Table.stories.jsx +80 -1
  203. package/table/Table.test.js +21 -0
  204. package/table/types.d.ts +3 -3
  205. package/tabs/Tab.d.ts +4 -0
  206. package/tabs/Tab.js +115 -0
  207. package/tabs/Tabs.d.ts +1 -1
  208. package/tabs/Tabs.js +318 -139
  209. package/tabs/Tabs.stories.tsx +119 -13
  210. package/tabs/Tabs.test.js +295 -0
  211. package/tabs/types.d.ts +21 -7
  212. package/tag/Tag.d.ts +1 -1
  213. package/tag/Tag.js +36 -75
  214. package/tag/Tag.stories.tsx +37 -27
  215. package/tag/Tag.test.js +49 -0
  216. package/tag/types.d.ts +25 -16
  217. package/text-input/Icons.d.ts +8 -0
  218. package/text-input/Icons.js +57 -0
  219. package/text-input/Suggestion.d.ts +4 -0
  220. package/text-input/Suggestion.js +68 -0
  221. package/text-input/Suggestions.d.ts +4 -0
  222. package/text-input/Suggestions.js +109 -0
  223. package/text-input/TextInput.js +232 -438
  224. package/text-input/TextInput.stories.tsx +310 -197
  225. package/text-input/TextInput.test.js +1404 -0
  226. package/text-input/types.d.ts +55 -17
  227. package/textarea/Textarea.js +53 -96
  228. package/textarea/Textarea.stories.jsx +93 -13
  229. package/textarea/Textarea.test.js +360 -0
  230. package/textarea/types.d.ts +22 -15
  231. package/toggle-group/ToggleGroup.d.ts +1 -1
  232. package/toggle-group/ToggleGroup.js +23 -57
  233. package/toggle-group/ToggleGroup.stories.tsx +46 -4
  234. package/toggle-group/ToggleGroup.test.js +124 -0
  235. package/toggle-group/types.d.ts +19 -11
  236. package/translatedLabelsType.d.ts +82 -0
  237. package/translatedLabelsType.js +5 -0
  238. package/typography/Typography.d.ts +4 -0
  239. package/typography/Typography.js +119 -0
  240. package/typography/Typography.stories.tsx +198 -0
  241. package/typography/types.d.ts +18 -0
  242. package/typography/types.js +5 -0
  243. package/useTheme.d.ts +1 -1
  244. package/useTheme.js +3 -9
  245. package/useTranslatedLabels.d.ts +3 -0
  246. package/useTranslatedLabels.js +15 -0
  247. package/wizard/Wizard.d.ts +1 -1
  248. package/wizard/Wizard.js +68 -98
  249. package/wizard/Wizard.stories.tsx +48 -19
  250. package/wizard/Wizard.test.js +114 -0
  251. package/wizard/types.d.ts +12 -7
  252. package/ThemeContext.d.ts +0 -15
  253. package/ThemeContext.js +0 -243
  254. package/V3Select/V3Select.js +0 -455
  255. package/V3Select/index.d.ts +0 -27
  256. package/V3Textarea/V3Textarea.js +0 -260
  257. package/V3Textarea/index.d.ts +0 -27
  258. package/common/RequiredComponent.js +0 -32
  259. package/date/Date.js +0 -373
  260. package/date/index.d.ts +0 -27
  261. package/input-text/Icons.js +0 -22
  262. package/input-text/InputText.js +0 -611
  263. package/input-text/index.d.ts +0 -36
  264. package/list/List.d.ts +0 -8
  265. package/list/List.js +0 -47
  266. package/list/List.stories.tsx +0 -95
  267. package/radio/Radio.d.ts +0 -4
  268. package/radio/Radio.js +0 -174
  269. package/radio/Radio.stories.tsx +0 -192
  270. package/radio/types.d.ts +0 -54
  271. package/row/Row.d.ts +0 -11
  272. package/row/Row.js +0 -127
  273. package/row/Row.stories.tsx +0 -239
  274. package/stack/Stack.d.ts +0 -10
  275. package/stack/Stack.js +0 -97
  276. package/stack/Stack.stories.tsx +0 -166
  277. package/text/Text.d.ts +0 -7
  278. package/text/Text.js +0 -30
  279. package/text/Text.stories.tsx +0 -19
  280. package/toggle/Toggle.js +0 -186
  281. package/toggle/index.d.ts +0 -21
  282. package/upload/Upload.js +0 -201
  283. package/upload/buttons-upload/ButtonsUpload.js +0 -111
  284. package/upload/buttons-upload/Icons.js +0 -40
  285. package/upload/dragAndDropArea/DragAndDropArea.js +0 -225
  286. package/upload/dragAndDropArea/Icons.js +0 -39
  287. package/upload/file-upload/FileToUpload.js +0 -115
  288. package/upload/file-upload/Icons.js +0 -66
  289. package/upload/files-upload/FilesToUpload.js +0 -109
  290. package/upload/index.d.ts +0 -15
  291. package/upload/transaction/Icons.js +0 -160
  292. package/upload/transaction/Transaction.js +0 -104
  293. package/upload/transactions/Transactions.js +0 -94
  294. /package/{radio → badge}/types.js +0 -0
@@ -1,13 +1,13 @@
1
1
  /// <reference types="react" />
2
- declare type Space = "xxsmall" | "xsmall" | "small" | "medium" | "large" | "xlarge" | "xxlarge";
3
- declare type Margin = {
2
+ type Space = "xxsmall" | "xsmall" | "small" | "medium" | "large" | "xlarge" | "xxlarge";
3
+ type Margin = {
4
4
  top?: Space;
5
5
  bottom?: Space;
6
6
  left?: Space;
7
7
  right?: Space;
8
8
  };
9
- declare type SVG = React.SVGProps<SVGSVGElement> | React.FunctionComponent<React.SVGProps<SVGSVGElement>>;
10
- declare type Action = {
9
+ type SVG = React.ReactNode & React.SVGProps<SVGSVGElement>;
10
+ type Action = {
11
11
  /**
12
12
  * This function will be called when the user clicks the action.
13
13
  */
@@ -21,7 +21,7 @@ declare type Action = {
21
21
  */
22
22
  title?: string;
23
23
  };
24
- declare type Props = {
24
+ type Props = {
25
25
  /**
26
26
  * Text to be placed above the input. This label will be used as the aria-label attribute of the list of suggestions.
27
27
  */
@@ -30,6 +30,10 @@ declare type Props = {
30
30
  * Name attribute of the input element.
31
31
  */
32
32
  name?: string;
33
+ /**
34
+ * Initial value of the input, only when it is uncontrolled.
35
+ */
36
+ defaultValue?: string;
33
37
  /**
34
38
  * Value of the input. If undefined, the component will be uncontrolled and the value will be managed internally by the component.
35
39
  */
@@ -74,26 +78,29 @@ declare type Props = {
74
78
  * This function will be called when the user types within the input
75
79
  * element of the component. An object including the current value and
76
80
  * the error (if the value entered is not valid) will be passed to this
77
- * function. If there is no error, error will be null.
81
+ * function. If there is no error, error will not be defined.
78
82
  */
79
83
  onChange?: (val: {
80
84
  value: string;
81
- error: string | null;
85
+ error?: string;
82
86
  }) => void;
83
87
  /**
84
88
  * This function will be called when the input element loses the focus.
85
89
  * An object including the input value and the error (if the value
86
90
  * entered is not valid) will be passed to this function. If there is no error,
87
- * error will be null.
91
+ * error will not be defined.
88
92
  */
89
93
  onBlur?: (val: {
90
94
  value: string;
91
- error: string | null;
95
+ error?: string;
92
96
  }) => void;
93
97
  /**
94
- * If it is defined, the component will change its appearance, showing
95
- * the error below the input component. If it is not defined, the error
96
- * messages will be managed internally, but never displayed on its own.
98
+ * If it is a defined value and also a truthy string, the component will
99
+ * change its appearance, showing the error below the input component. If
100
+ * the defined value is an empty string, it will reserve a space below
101
+ * the component for a future error, but it would not change its look. In
102
+ * case of being undefined or null, both the appearance and the space for
103
+ * the error message would not be modified.
97
104
  */
98
105
  error?: string;
99
106
  /**
@@ -110,7 +117,7 @@ declare type Props = {
110
117
  * pattern, the onBlur and onChange functions will be called with the
111
118
  * current value and an internal error informing that this value does not
112
119
  * match the pattern. If the pattern is met, the error parameter of both
113
- * events will be null.
120
+ * events will not be defined.
114
121
  */
115
122
  pattern?: string;
116
123
  /**
@@ -120,7 +127,7 @@ declare type Props = {
120
127
  * comply the minimum length, the onBlur and onChange functions will be called
121
128
  * with the current value and an internal error informing that the value
122
129
  * length does not comply the specified range. If a valid length is
123
- * reached, the error parameter of both events will be null.
130
+ * reached, the error parameter of both events will not be defined.
124
131
  */
125
132
  minLength?: number;
126
133
  /**
@@ -130,7 +137,7 @@ declare type Props = {
130
137
  * comply the maximum length, the onBlur and onChange functions will be called
131
138
  * with the current value and an internal error informing that the value
132
139
  * length does not comply the specified range. If a valid length is
133
- * reached, the error parameter of both events will be null.
140
+ * reached, the error parameter of both events will not be defined.
134
141
  */
135
142
  maxLength?: number;
136
143
  /**
@@ -144,7 +151,7 @@ declare type Props = {
144
151
  */
145
152
  margin?: Space | Margin;
146
153
  /**
147
- * Size of the component ('small' | 'medium' | 'large' | 'fillParent').
154
+ * Size of the component.
148
155
  */
149
156
  size?: "small" | "medium" | "large" | "fillParent";
150
157
  /**
@@ -152,8 +159,39 @@ declare type Props = {
152
159
  */
153
160
  tabIndex?: number;
154
161
  };
162
+ /**
163
+ * List of suggestions of an Text Input component.
164
+ */
165
+ export type SuggestionsProps = {
166
+ id: string;
167
+ value: string;
168
+ suggestions: string[];
169
+ visualFocusIndex: number;
170
+ highlightedSuggestions: boolean;
171
+ searchHasErrors: boolean;
172
+ isSearching: boolean;
173
+ suggestionOnClick: (suggestion: string) => void;
174
+ getTextInputWidth: () => number;
175
+ };
155
176
  /**
156
177
  * Reference to the component.
157
178
  */
158
- export declare type RefType = HTMLDivElement;
179
+ export type RefType = HTMLDivElement;
180
+ /**
181
+ * Single suggestion of an Text Input component.
182
+ */
183
+ export type SuggestionProps = {
184
+ id: string;
185
+ value: string;
186
+ onClick: (suggestion: string) => void;
187
+ suggestion: string;
188
+ isLast: boolean;
189
+ visuallyFocused: boolean;
190
+ highlighted: boolean;
191
+ };
192
+ export type AutosuggestWrapperProps = {
193
+ condition: boolean;
194
+ wrapper: (children: React.ReactNode) => JSX.Element;
195
+ children: React.ReactNode;
196
+ };
159
197
  export default Props;
@@ -1,145 +1,109 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  var _typeof3 = require("@babel/runtime/helpers/typeof");
6
-
7
5
  Object.defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
8
  exports["default"] = void 0;
11
-
12
9
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
13
-
14
10
  var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
15
-
16
11
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
17
-
18
12
  var _react = _interopRequireWildcard(require("react"));
19
-
20
13
  var _styledComponents = _interopRequireWildcard(require("styled-components"));
21
-
22
14
  var _utils = require("../common/utils.js");
23
-
24
15
  var _useTheme = _interopRequireDefault(require("../useTheme"));
25
-
26
- var _variables = require("../common/variables.js");
27
-
16
+ var _useTranslatedLabels = _interopRequireDefault(require("../useTranslatedLabels"));
17
+ var _variables = require("../common/variables");
28
18
  var _uuid = require("uuid");
29
-
30
19
  var _BackgroundColorContext = _interopRequireDefault(require("../BackgroundColorContext"));
31
-
32
20
  var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
33
-
34
21
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
35
-
36
22
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(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; }
37
-
38
- var getNotOptionalErrorMessage = function getNotOptionalErrorMessage() {
39
- return "This field is required. Please, enter a value.";
40
- };
41
-
42
- var getPatternErrorMessage = function getPatternErrorMessage() {
43
- return "Please match the format requested.";
44
- };
45
-
46
23
  var patternMatch = function patternMatch(pattern, value) {
47
24
  return new RegExp(pattern).test(value);
48
25
  };
49
-
50
26
  var DxcTextarea = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
51
27
  var label = _ref.label,
52
- _ref$name = _ref.name,
53
- name = _ref$name === void 0 ? "" : _ref$name,
54
- value = _ref.value,
55
- helperText = _ref.helperText,
56
- _ref$placeholder = _ref.placeholder,
57
- placeholder = _ref$placeholder === void 0 ? "" : _ref$placeholder,
58
- _ref$disabled = _ref.disabled,
59
- disabled = _ref$disabled === void 0 ? false : _ref$disabled,
60
- _ref$optional = _ref.optional,
61
- optional = _ref$optional === void 0 ? false : _ref$optional,
62
- _ref$verticalGrow = _ref.verticalGrow,
63
- verticalGrow = _ref$verticalGrow === void 0 ? "auto" : _ref$verticalGrow,
64
- _ref$rows = _ref.rows,
65
- rows = _ref$rows === void 0 ? 4 : _ref$rows,
66
- onChange = _ref.onChange,
67
- onBlur = _ref.onBlur,
68
- error = _ref.error,
69
- pattern = _ref.pattern,
70
- minLength = _ref.minLength,
71
- maxLength = _ref.maxLength,
72
- _ref$autocomplete = _ref.autocomplete,
73
- autocomplete = _ref$autocomplete === void 0 ? "off" : _ref$autocomplete,
74
- margin = _ref.margin,
75
- _ref$size = _ref.size,
76
- size = _ref$size === void 0 ? "medium" : _ref$size,
77
- _ref$tabIndex = _ref.tabIndex,
78
- tabIndex = _ref$tabIndex === void 0 ? 0 : _ref$tabIndex;
79
-
80
- var _useState = (0, _react.useState)(""),
81
- _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
82
- innerValue = _useState2[0],
83
- setInnerValue = _useState2[1];
84
-
28
+ _ref$name = _ref.name,
29
+ name = _ref$name === void 0 ? "" : _ref$name,
30
+ _ref$defaultValue = _ref.defaultValue,
31
+ defaultValue = _ref$defaultValue === void 0 ? "" : _ref$defaultValue,
32
+ value = _ref.value,
33
+ helperText = _ref.helperText,
34
+ _ref$placeholder = _ref.placeholder,
35
+ placeholder = _ref$placeholder === void 0 ? "" : _ref$placeholder,
36
+ _ref$disabled = _ref.disabled,
37
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled,
38
+ _ref$optional = _ref.optional,
39
+ optional = _ref$optional === void 0 ? false : _ref$optional,
40
+ _ref$verticalGrow = _ref.verticalGrow,
41
+ verticalGrow = _ref$verticalGrow === void 0 ? "auto" : _ref$verticalGrow,
42
+ _ref$rows = _ref.rows,
43
+ rows = _ref$rows === void 0 ? 4 : _ref$rows,
44
+ onChange = _ref.onChange,
45
+ onBlur = _ref.onBlur,
46
+ error = _ref.error,
47
+ pattern = _ref.pattern,
48
+ minLength = _ref.minLength,
49
+ maxLength = _ref.maxLength,
50
+ _ref$autocomplete = _ref.autocomplete,
51
+ autocomplete = _ref$autocomplete === void 0 ? "off" : _ref$autocomplete,
52
+ margin = _ref.margin,
53
+ _ref$size = _ref.size,
54
+ size = _ref$size === void 0 ? "medium" : _ref$size,
55
+ _ref$tabIndex = _ref.tabIndex,
56
+ tabIndex = _ref$tabIndex === void 0 ? 0 : _ref$tabIndex;
57
+ var _useState = (0, _react.useState)(defaultValue),
58
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
59
+ innerValue = _useState2[0],
60
+ setInnerValue = _useState2[1];
85
61
  var _useState3 = (0, _react.useState)("textarea-".concat((0, _uuid.v4)())),
86
- _useState4 = (0, _slicedToArray2["default"])(_useState3, 1),
87
- textareaId = _useState4[0];
88
-
62
+ _useState4 = (0, _slicedToArray2["default"])(_useState3, 1),
63
+ textareaId = _useState4[0];
89
64
  var colorsTheme = (0, _useTheme["default"])();
90
65
  var backgroundType = (0, _react.useContext)(_BackgroundColorContext["default"]);
66
+ var translatedLabels = (0, _useTranslatedLabels["default"])();
91
67
  var textareaRef = (0, _react.useRef)(null);
92
- var errorId = "error-message-".concat(textareaId);
93
-
94
- var getLengthErrorMessage = function getLengthErrorMessage() {
95
- return "Min length ".concat(minLength, ", max length ").concat(maxLength, ".");
96
- };
97
-
68
+ var errorId = "error-".concat(textareaId);
98
69
  var isNotOptional = function isNotOptional(value) {
99
70
  return value === "" && !optional;
100
71
  };
101
-
102
72
  var isLengthIncorrect = function isLengthIncorrect(value) {
103
73
  return value !== "" && minLength && maxLength && (value.length < minLength || value.length > maxLength);
104
74
  };
105
-
106
75
  var changeValue = function changeValue(newValue) {
107
76
  value !== null && value !== void 0 ? value : setInnerValue(newValue);
108
77
  if (isNotOptional(newValue)) onChange === null || onChange === void 0 ? void 0 : onChange({
109
78
  value: newValue,
110
- error: getNotOptionalErrorMessage()
79
+ error: translatedLabels.formFields.requiredValueErrorMessage
111
80
  });else if (isLengthIncorrect(newValue)) onChange === null || onChange === void 0 ? void 0 : onChange({
112
81
  value: newValue,
113
- error: getLengthErrorMessage()
82
+ error: translatedLabels.formFields.lengthErrorMessage(minLength, maxLength)
114
83
  });else if (newValue && pattern && !patternMatch(pattern, newValue)) onChange === null || onChange === void 0 ? void 0 : onChange({
115
84
  value: newValue,
116
- error: getPatternErrorMessage()
85
+ error: translatedLabels.formFields.formatRequestedErrorMessage
117
86
  });else onChange === null || onChange === void 0 ? void 0 : onChange({
118
- value: newValue,
119
- error: null
87
+ value: newValue
120
88
  });
121
89
  };
122
-
123
90
  var handleTOnBlur = function handleTOnBlur(event) {
124
91
  if (isNotOptional(event.target.value)) onBlur === null || onBlur === void 0 ? void 0 : onBlur({
125
92
  value: event.target.value,
126
- error: getNotOptionalErrorMessage()
93
+ error: translatedLabels.formFields.requiredValueErrorMessage
127
94
  });else if (isLengthIncorrect(event.target.value)) onBlur === null || onBlur === void 0 ? void 0 : onBlur({
128
95
  value: event.target.value,
129
- error: getLengthErrorMessage()
96
+ error: translatedLabels.formFields.lengthErrorMessage(minLength, maxLength)
130
97
  });else if (event.target.value && pattern && !patternMatch(pattern, event.target.value)) onBlur === null || onBlur === void 0 ? void 0 : onBlur({
131
98
  value: event.target.value,
132
- error: getPatternErrorMessage()
99
+ error: translatedLabels.formFields.formatRequestedErrorMessage
133
100
  });else onBlur === null || onBlur === void 0 ? void 0 : onBlur({
134
- value: event.target.value,
135
- error: null
101
+ value: event.target.value
136
102
  });
137
103
  };
138
-
139
104
  var handleTOnChange = function handleTOnChange(event) {
140
105
  changeValue(event.target.value);
141
106
  };
142
-
143
107
  (0, _react.useLayoutEffect)(function () {
144
108
  if (verticalGrow === "auto") {
145
109
  var textareaLineHeight = parseInt(window.getComputedStyle(textareaRef.current)["line-height"]);
@@ -150,7 +114,7 @@ var DxcTextarea = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref)
150
114
  }
151
115
  }, [value, verticalGrow, rows, innerValue]);
152
116
  return /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
153
- theme: colorsTheme.textarea
117
+ theme: colorsTheme["textarea"]
154
118
  }, /*#__PURE__*/_react["default"].createElement(TextareaContainer, {
155
119
  margin: margin,
156
120
  size: size,
@@ -160,7 +124,7 @@ var DxcTextarea = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref)
160
124
  disabled: disabled,
161
125
  backgroundType: backgroundType,
162
126
  helperText: helperText
163
- }, label, " ", optional && /*#__PURE__*/_react["default"].createElement(OptionalLabel, null, "(Optional)")), helperText && /*#__PURE__*/_react["default"].createElement(HelperText, {
127
+ }, label, " ", optional && /*#__PURE__*/_react["default"].createElement(OptionalLabel, null, translatedLabels.formFields.optionalLabel)), helperText && /*#__PURE__*/_react["default"].createElement(HelperText, {
164
128
  disabled: disabled,
165
129
  backgroundType: backgroundType
166
130
  }, helperText), /*#__PURE__*/_react["default"].createElement(Textarea, {
@@ -180,26 +144,25 @@ var DxcTextarea = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref)
180
144
  backgroundType: backgroundType,
181
145
  ref: textareaRef,
182
146
  tabIndex: tabIndex,
147
+ "aria-disabled": disabled,
183
148
  "aria-invalid": error ? "true" : "false",
184
- "aria-describedby": error ? errorId : undefined,
149
+ "aria-errormessage": error ? errorId : undefined,
185
150
  "aria-required": optional ? "false" : "true"
186
151
  }), !disabled && typeof error === "string" && /*#__PURE__*/_react["default"].createElement(Error, {
187
152
  id: errorId,
188
- backgroundType: backgroundType
153
+ backgroundType: backgroundType,
154
+ "aria-live": error ? "assertive" : "off"
189
155
  }, error)));
190
156
  });
191
-
192
157
  var sizes = {
193
158
  small: "240px",
194
159
  medium: "360px",
195
160
  large: "480px",
196
161
  fillParent: "100%"
197
162
  };
198
-
199
163
  var calculateWidth = function calculateWidth(margin, size) {
200
164
  return size === "fillParent" ? "calc(".concat(sizes[size], " - ").concat((0, _utils.getMargin)(margin, "left"), " - ").concat((0, _utils.getMargin)(margin, "right"), ")") : sizes[size];
201
165
  };
202
-
203
166
  var TextareaContainer = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-direction: column;\n\n width: ", ";\n margin: ", ";\n margin-top: ", ";\n margin-right: ", ";\n margin-bottom: ", ";\n margin-left: ", ";\n"])), function (props) {
204
167
  return calculateWidth(props.margin, props.size);
205
168
  }, function (props) {
@@ -213,7 +176,6 @@ var TextareaContainer = _styledComponents["default"].div(_templateObject || (_te
213
176
  }, function (props) {
214
177
  return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.left ? _variables.spaces[props.margin.left] : "";
215
178
  });
216
-
217
179
  var Label = _styledComponents["default"].label(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["\n color: ", ";\n\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n line-height: ", ";\n ", "\n"])), function (props) {
218
180
  return props.disabled ? props.backgroundType === "dark" ? props.theme.disabledLabelFontColorOnDark : props.theme.disabledLabelFontColor : props.backgroundType === "dark" ? props.theme.labelFontColorOnDark : props.theme.labelFontColor;
219
181
  }, function (props) {
@@ -229,11 +191,9 @@ var Label = _styledComponents["default"].label(_templateObject2 || (_templateObj
229
191
  }, function (props) {
230
192
  return !props.helperText && "margin-bottom: 0.25rem";
231
193
  });
232
-
233
194
  var OptionalLabel = _styledComponents["default"].span(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2["default"])(["\n font-weight: ", ";\n"])), function (props) {
234
195
  return props.theme.optionalLabelFontWeight;
235
196
  });
236
-
237
197
  var HelperText = _styledComponents["default"].span(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["\n color: ", ";\n\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n line-height: ", ";\n margin-bottom: 0.25rem;\n"])), function (props) {
238
198
  return props.disabled ? props.backgroundType === "dark" ? props.theme.disabledHelperTextFontColorOnDark : props.theme.disabledHelperTextFontColor : props.backgroundType === "dark" ? props.theme.helperTextFontColorOnDark : props.theme.helperTextFontColor;
239
199
  }, function (props) {
@@ -247,7 +207,6 @@ var HelperText = _styledComponents["default"].span(_templateObject4 || (_templat
247
207
  }, function (props) {
248
208
  return props.theme.helperTextLineHeight;
249
209
  });
250
-
251
210
  var Textarea = _styledComponents["default"].textarea(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2["default"])(["\n ", ";\n ", "\n\n padding: 0.5rem 1rem;\n box-shadow: 0 0 0 2px transparent;\n border-radius: 0.25rem;\n border: 1px solid\n ", ";\n ", "\n\n ", ";\n ", ";\n\n color: ", ";\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n line-height: 1.5em;\n\n ::placeholder {\n color: ", ";\n }\n"])), function (props) {
252
211
  if (props.verticalGrow === "none") return "resize: none;";else if (props.verticalGrow === "auto") return "resize: none; overflow: hidden;";else if (props.verticalGrow === "manual") return "resize: vertical;";else return "resize: none;";
253
212
  }, function (props) {
@@ -273,12 +232,10 @@ var Textarea = _styledComponents["default"].textarea(_templateObject5 || (_templ
273
232
  }, function (props) {
274
233
  return props.disabled ? props.backgroundType === "dark" ? props.theme.disabledPlaceholderFontColorOnDark : props.theme.disabledPlaceholderFontColor : props.backgroundType === "dark" ? props.theme.placeholderFontColorOnDark : props.theme.placeholderFontColor;
275
234
  });
276
-
277
235
  var Error = _styledComponents["default"].span(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteral2["default"])(["\n color: ", ";\n font-family: ", ";\n font-size: 0.75rem;\n font-weight: 400;\n min-height: 1.5em;\n line-height: 1.5em;\n margin-top: 0.25rem;\n"])), function (props) {
278
236
  return props.backgroundType === "dark" ? props.theme.errorMessageColorOnDark : props.theme.errorMessageColor;
279
237
  }, function (props) {
280
238
  return props.theme.fontFamily;
281
239
  });
282
-
283
240
  var _default = DxcTextarea;
284
241
  exports["default"] = _default;
@@ -4,12 +4,20 @@ import Title from "../../.storybook/components/Title";
4
4
  import ExampleContainer from "../../.storybook/components/ExampleContainer";
5
5
  import { BackgroundColorProvider } from "../BackgroundColorContext";
6
6
  import DarkContainer from "../../.storybook/components/DarkSection";
7
+ import { HalstackProvider } from "../HalstackContext";
7
8
 
8
9
  export default {
9
10
  title: "Textarea",
10
11
  component: DxcTextarea,
11
12
  };
12
13
 
14
+ const opinionatedTheme = {
15
+ textarea: {
16
+ fontColor: "#000000",
17
+ hoverBorderColor: "#a46ede",
18
+ },
19
+ };
20
+
13
21
  export const Chromatic = () => (
14
22
  <>
15
23
  <>
@@ -33,7 +41,7 @@ export const Chromatic = () => (
33
41
  </ExampleContainer>
34
42
  <ExampleContainer>
35
43
  <Title title="Disabled with value" theme="light" level={4} />
36
- <DxcTextarea label="Disabled" value="Example text" disabled />
44
+ <DxcTextarea label="Disabled" defaultValue="Example text" disabled />
37
45
  </ExampleContainer>
38
46
  <ExampleContainer>
39
47
  <Title title="With error" theme="light" level={4} />
@@ -41,12 +49,21 @@ export const Chromatic = () => (
41
49
  label="Textarea with error"
42
50
  helperText="Helper text"
43
51
  placeholder="Enter your text here..."
44
- error="Error message"
52
+ error="Error message."
53
+ />
54
+ </ExampleContainer>
55
+ <ExampleContainer pseudoState="pseudo-hover">
56
+ <Title title="Hovered with error" theme="light" level={4} />
57
+ <DxcTextarea
58
+ label="Hovered textarea with error"
59
+ helperText="Helper text"
60
+ placeholder="Enter your text here..."
61
+ error="Error message."
45
62
  />
46
63
  </ExampleContainer>
47
64
  <ExampleContainer>
48
65
  <Title title="Helper text and optional with value" theme="light" level={4} />
49
- <DxcTextarea label="Helper & optional" value="Some text" helperText="Sample text" optional />
66
+ <DxcTextarea label="Helper & optional" defaultValue="Some text" helperText="Sample text" optional />
50
67
  </ExampleContainer>
51
68
  <ExampleContainer>
52
69
  <Title title="Resizable" theme="light" level={4} />
@@ -57,36 +74,48 @@ export const Chromatic = () => (
57
74
  <DxcTextarea
58
75
  label="Manual vertical grow"
59
76
  verticalGrow="manual"
60
- value="Long textttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
77
+ defaultValue="Long textttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
61
78
  />
62
79
  </ExampleContainer>
63
80
  </>
64
81
  <BackgroundColorProvider color="#333333">
65
82
  <DarkContainer>
66
- <>
83
+ <ExampleContainer>
67
84
  <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
-
85
+ <DxcTextarea label="Helper & optional" defaultValue="Some text" helperText="Sample text" optional />
86
+ </ExampleContainer>
87
+ <ExampleContainer>
70
88
  <Title title="Disabled" theme="dark" level={4} />
71
89
  <DxcTextarea
72
90
  label="Disabled"
73
- margin="medium"
74
91
  optional
75
92
  helperText="Sample text"
76
93
  placeholder="Enter your text here..."
77
94
  disabled
78
95
  />
96
+ </ExampleContainer>
97
+ <ExampleContainer>
79
98
  <Title title="Disabled with value" theme="dark" level={4} />
80
- <DxcTextarea label="Disabled" margin="medium" value="Example text" disabled />
99
+ <DxcTextarea label="Disabled" defaultValue="Example text" disabled />
100
+ </ExampleContainer>
101
+ <ExampleContainer>
81
102
  <Title title="With error" theme="dark" level={4} />
82
103
  <DxcTextarea
83
104
  label="Textarea with error"
84
- margin="medium"
85
105
  helperText="Helper text"
86
106
  placeholder="Enter your text here..."
87
- error="Error message"
107
+ error="Error message."
108
+ />
109
+ </ExampleContainer>
110
+ <ExampleContainer pseudoState="pseudo-hover">
111
+ <Title title="Hovered with error" theme="dark" level={4} />
112
+ <DxcTextarea
113
+ label="Hovered textarea with error"
114
+ helperText="Helper text"
115
+ placeholder="Enter your text here..."
116
+ error="Error message."
88
117
  />
89
- </>
118
+ </ExampleContainer>
90
119
  </DarkContainer>
91
120
  </BackgroundColorProvider>
92
121
  <Title title="Sizes" theme="light" level={2} />
@@ -130,7 +159,58 @@ export const Chromatic = () => (
130
159
  <ExampleContainer>
131
160
  <Title title="Xxlarge margin" theme="light" level={4} />
132
161
  <DxcTextarea label="Xxlarge" margin="xxlarge" />
133
- <hr />
162
+ </ExampleContainer>
163
+ <Title title="Opinionated theme" theme="light" level={2} />
164
+ <ExampleContainer pseudoState="pseudo-hover">
165
+ <Title title="Hovered" theme="light" level={4} />
166
+ <HalstackProvider theme={opinionatedTheme}>
167
+ <DxcTextarea label="Hovered" helperText="Sample text" placeholder="Placeholder" />
168
+ </HalstackProvider>
169
+ </ExampleContainer>
170
+ <ExampleContainer pseudoState="pseudo-focus">
171
+ <Title title="Focused" theme="light" level={4} />
172
+ <HalstackProvider theme={opinionatedTheme}>
173
+ <DxcTextarea label="Focused" helperText="Sample text" />
174
+ </HalstackProvider>
175
+ </ExampleContainer>
176
+ <ExampleContainer>
177
+ <Title title="Disabled" theme="light" level={4} />
178
+ <HalstackProvider theme={opinionatedTheme}>
179
+ <DxcTextarea
180
+ label="Disabled"
181
+ optional
182
+ helperText="Sample text"
183
+ placeholder="Enter your text here..."
184
+ disabled
185
+ />
186
+ </HalstackProvider>
187
+ </ExampleContainer>
188
+ <ExampleContainer>
189
+ <Title title="Disabled with value" theme="light" level={4} />
190
+ <HalstackProvider theme={opinionatedTheme}>
191
+ <DxcTextarea label="Disabled" helperText="Sample text" defaultValue="Example text" disabled />
192
+ </HalstackProvider>
193
+ </ExampleContainer>
194
+ <ExampleContainer>
195
+ <Title title="With error" theme="light" level={4} />
196
+ <HalstackProvider theme={opinionatedTheme}>
197
+ <DxcTextarea
198
+ label="Textarea with error"
199
+ helperText="Helper text"
200
+ placeholder="Enter your text here..."
201
+ error="Error message."
202
+ />
203
+ </HalstackProvider>
204
+ </ExampleContainer>
205
+ <ExampleContainer>
206
+ <Title title="Grow manual" theme="light" level={4} />{" "}
207
+ <HalstackProvider theme={opinionatedTheme}>
208
+ <DxcTextarea
209
+ label="Manual vertical grow"
210
+ verticalGrow="manual"
211
+ defaultValue="Long textttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
212
+ />
213
+ </HalstackProvider>
134
214
  </ExampleContainer>
135
215
  </>
136
216
  );