@dxc-technology/halstack-react 0.0.0-d3554d7 → 0.0.0-d3ac293

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 (267) hide show
  1. package/BackgroundColorContext.d.ts +2 -2
  2. package/BackgroundColorContext.js +1 -1
  3. package/HalstackContext.d.ts +1336 -0
  4. package/HalstackContext.js +335 -0
  5. package/accordion/Accordion.d.ts +1 -1
  6. package/accordion/Accordion.js +118 -126
  7. package/accordion/Accordion.stories.tsx +115 -27
  8. package/accordion/Accordion.test.js +26 -12
  9. package/accordion/types.d.ts +9 -4
  10. package/accordion-group/AccordionGroup.d.ts +1 -1
  11. package/accordion-group/AccordionGroup.js +17 -38
  12. package/accordion-group/AccordionGroup.stories.tsx +28 -2
  13. package/accordion-group/AccordionGroup.test.js +31 -38
  14. package/accordion-group/types.d.ts +14 -3
  15. package/alert/Alert.js +7 -4
  16. package/alert/Alert.stories.tsx +28 -0
  17. package/alert/Alert.test.js +1 -1
  18. package/badge/Badge.d.ts +1 -1
  19. package/badge/Badge.js +5 -3
  20. package/badge/types.d.ts +1 -0
  21. package/bleed/Bleed.js +1 -34
  22. package/bleed/Bleed.stories.tsx +94 -95
  23. package/bleed/types.d.ts +25 -1
  24. package/box/Box.js +25 -37
  25. package/box/Box.stories.tsx +15 -0
  26. package/box/Box.test.js +1 -1
  27. package/box/types.d.ts +1 -0
  28. package/bulleted-list/BulletedList.d.ts +7 -0
  29. package/bulleted-list/BulletedList.js +123 -0
  30. package/bulleted-list/BulletedList.stories.tsx +200 -0
  31. package/bulleted-list/types.d.ts +11 -0
  32. package/button/Button.js +52 -69
  33. package/button/Button.stories.tsx +159 -8
  34. package/button/Button.test.js +1 -1
  35. package/button/types.d.ts +7 -7
  36. package/card/Card.js +25 -28
  37. package/card/Card.test.js +1 -1
  38. package/card/types.d.ts +1 -0
  39. package/checkbox/Checkbox.d.ts +2 -2
  40. package/checkbox/Checkbox.js +107 -110
  41. package/checkbox/Checkbox.stories.tsx +198 -130
  42. package/checkbox/Checkbox.test.js +101 -11
  43. package/checkbox/types.d.ts +13 -5
  44. package/chip/Chip.js +18 -24
  45. package/chip/Chip.stories.tsx +96 -9
  46. package/chip/Chip.test.js +3 -5
  47. package/chip/types.d.ts +1 -1
  48. package/common/utils.d.ts +1 -0
  49. package/common/utils.js +4 -4
  50. package/common/variables.d.ts +1625 -0
  51. package/common/variables.js +483 -352
  52. package/date-input/Calendar.d.ts +4 -0
  53. package/date-input/Calendar.js +258 -0
  54. package/date-input/DateInput.js +169 -258
  55. package/date-input/DateInput.stories.tsx +199 -33
  56. package/date-input/DateInput.test.js +521 -155
  57. package/date-input/DatePicker.d.ts +4 -0
  58. package/date-input/DatePicker.js +146 -0
  59. package/date-input/Icons.d.ts +6 -0
  60. package/date-input/Icons.js +75 -0
  61. package/date-input/YearPicker.d.ts +4 -0
  62. package/date-input/YearPicker.js +126 -0
  63. package/date-input/types.d.ts +67 -9
  64. package/dialog/Dialog.js +76 -93
  65. package/dialog/Dialog.stories.tsx +230 -123
  66. package/dialog/Dialog.test.js +334 -5
  67. package/dialog/types.d.ts +3 -2
  68. package/dropdown/Dropdown.d.ts +1 -1
  69. package/dropdown/Dropdown.js +246 -253
  70. package/dropdown/Dropdown.stories.tsx +245 -56
  71. package/dropdown/Dropdown.test.js +507 -110
  72. package/dropdown/DropdownMenu.d.ts +4 -0
  73. package/dropdown/DropdownMenu.js +70 -0
  74. package/dropdown/DropdownMenuItem.d.ts +4 -0
  75. package/dropdown/DropdownMenuItem.js +81 -0
  76. package/dropdown/types.d.ts +25 -5
  77. package/file-input/FileInput.d.ts +2 -2
  78. package/file-input/FileInput.js +181 -223
  79. package/file-input/FileInput.stories.tsx +122 -11
  80. package/file-input/FileInput.test.js +14 -14
  81. package/file-input/FileItem.d.ts +4 -14
  82. package/file-input/FileItem.js +44 -66
  83. package/file-input/types.d.ts +17 -0
  84. package/flex/Flex.d.ts +4 -0
  85. package/flex/Flex.js +69 -0
  86. package/flex/Flex.stories.tsx +103 -0
  87. package/flex/types.d.ts +32 -0
  88. package/footer/Footer.js +16 -89
  89. package/footer/Footer.stories.tsx +99 -1
  90. package/footer/Footer.test.js +14 -26
  91. package/footer/Icons.js +1 -1
  92. package/footer/types.d.ts +2 -1
  93. package/header/Header.js +108 -129
  94. package/header/Header.stories.tsx +189 -36
  95. package/header/Header.test.js +20 -4
  96. package/header/Icons.js +2 -2
  97. package/header/types.d.ts +3 -2
  98. package/heading/Heading.js +1 -1
  99. package/heading/Heading.test.js +1 -1
  100. package/inset/Inset.js +1 -34
  101. package/inset/Inset.stories.tsx +36 -36
  102. package/inset/types.d.ts +25 -1
  103. package/layout/ApplicationLayout.d.ts +16 -6
  104. package/layout/ApplicationLayout.js +72 -132
  105. package/layout/ApplicationLayout.stories.tsx +84 -93
  106. package/layout/Icons.d.ts +5 -0
  107. package/layout/Icons.js +13 -2
  108. package/layout/SidenavContext.d.ts +5 -0
  109. package/layout/SidenavContext.js +19 -0
  110. package/layout/types.d.ts +18 -33
  111. package/link/Link.d.ts +3 -2
  112. package/link/Link.js +59 -76
  113. package/link/Link.stories.tsx +155 -53
  114. package/link/Link.test.js +9 -19
  115. package/link/types.d.ts +7 -23
  116. package/main.d.ts +8 -10
  117. package/main.js +46 -56
  118. package/nav-tabs/NavTabs.d.ts +8 -0
  119. package/nav-tabs/NavTabs.js +125 -0
  120. package/nav-tabs/NavTabs.stories.tsx +260 -0
  121. package/nav-tabs/NavTabs.test.js +82 -0
  122. package/nav-tabs/Tab.d.ts +4 -0
  123. package/nav-tabs/Tab.js +150 -0
  124. package/nav-tabs/types.d.ts +53 -0
  125. package/number-input/NumberInput.js +11 -18
  126. package/number-input/NumberInput.stories.tsx +5 -5
  127. package/number-input/NumberInput.test.js +46 -12
  128. package/number-input/types.d.ts +17 -10
  129. package/package.json +20 -23
  130. package/paginator/Icons.d.ts +5 -0
  131. package/paginator/Icons.js +16 -28
  132. package/paginator/Paginator.js +19 -46
  133. package/paginator/Paginator.stories.tsx +24 -0
  134. package/paginator/Paginator.test.js +78 -39
  135. package/paragraph/Paragraph.d.ts +6 -0
  136. package/paragraph/Paragraph.js +38 -0
  137. package/paragraph/Paragraph.stories.tsx +44 -0
  138. package/password-input/PasswordInput.js +7 -4
  139. package/password-input/PasswordInput.test.js +17 -19
  140. package/password-input/types.d.ts +14 -11
  141. package/progress-bar/ProgressBar.d.ts +2 -2
  142. package/progress-bar/ProgressBar.js +61 -55
  143. package/progress-bar/ProgressBar.stories.jsx +47 -12
  144. package/progress-bar/ProgressBar.test.js +68 -23
  145. package/progress-bar/types.d.ts +3 -4
  146. package/quick-nav/QuickNav.d.ts +4 -0
  147. package/quick-nav/QuickNav.js +117 -0
  148. package/quick-nav/QuickNav.stories.tsx +356 -0
  149. package/quick-nav/types.d.ts +21 -0
  150. package/radio-group/Radio.d.ts +1 -1
  151. package/radio-group/Radio.js +43 -28
  152. package/radio-group/RadioGroup.js +32 -28
  153. package/radio-group/RadioGroup.stories.tsx +135 -17
  154. package/radio-group/RadioGroup.test.js +145 -117
  155. package/radio-group/types.d.ts +79 -2
  156. package/resultsetTable/Icons.d.ts +7 -0
  157. package/resultsetTable/Icons.js +51 -0
  158. package/resultsetTable/ResultsetTable.js +49 -108
  159. package/resultsetTable/ResultsetTable.stories.tsx +50 -25
  160. package/resultsetTable/ResultsetTable.test.js +61 -42
  161. package/resultsetTable/types.d.ts +2 -2
  162. package/select/Icons.d.ts +10 -0
  163. package/select/Icons.js +93 -0
  164. package/select/Listbox.d.ts +4 -0
  165. package/select/Listbox.js +169 -0
  166. package/select/Option.d.ts +4 -0
  167. package/select/Option.js +97 -0
  168. package/select/Select.js +179 -384
  169. package/select/Select.stories.tsx +531 -142
  170. package/select/Select.test.js +652 -324
  171. package/select/types.d.ts +53 -13
  172. package/sidenav/Sidenav.d.ts +6 -5
  173. package/sidenav/Sidenav.js +183 -53
  174. package/sidenav/Sidenav.stories.tsx +249 -149
  175. package/sidenav/Sidenav.test.js +25 -37
  176. package/sidenav/types.d.ts +50 -27
  177. package/slider/Slider.d.ts +2 -2
  178. package/slider/Slider.js +124 -98
  179. package/slider/Slider.stories.tsx +72 -9
  180. package/slider/Slider.test.js +143 -22
  181. package/slider/types.d.ts +10 -2
  182. package/spinner/Spinner.js +4 -4
  183. package/spinner/Spinner.stories.jsx +27 -1
  184. package/spinner/Spinner.test.js +1 -1
  185. package/switch/Switch.d.ts +2 -2
  186. package/switch/Switch.js +152 -69
  187. package/switch/Switch.stories.tsx +53 -42
  188. package/switch/Switch.test.js +156 -4
  189. package/switch/types.d.ts +12 -4
  190. package/table/Table.js +3 -3
  191. package/table/Table.stories.jsx +80 -1
  192. package/table/Table.test.js +2 -2
  193. package/tabs/Tab.d.ts +4 -0
  194. package/tabs/Tab.js +133 -0
  195. package/tabs/Tabs.d.ts +1 -1
  196. package/tabs/Tabs.js +363 -109
  197. package/tabs/Tabs.stories.tsx +119 -13
  198. package/tabs/Tabs.test.js +241 -14
  199. package/tabs/types.d.ts +19 -5
  200. package/tag/Tag.js +17 -22
  201. package/tag/Tag.stories.tsx +25 -8
  202. package/tag/Tag.test.js +1 -1
  203. package/tag/types.d.ts +1 -1
  204. package/text-input/Icons.d.ts +8 -0
  205. package/text-input/Icons.js +60 -0
  206. package/text-input/Suggestion.d.ts +4 -0
  207. package/text-input/Suggestion.js +84 -0
  208. package/text-input/Suggestions.d.ts +4 -0
  209. package/text-input/Suggestions.js +134 -0
  210. package/text-input/TextInput.js +221 -344
  211. package/text-input/TextInput.stories.tsx +290 -195
  212. package/text-input/TextInput.test.js +763 -731
  213. package/text-input/types.d.ts +50 -12
  214. package/textarea/Textarea.js +17 -26
  215. package/textarea/Textarea.stories.jsx +65 -6
  216. package/textarea/Textarea.test.js +38 -37
  217. package/textarea/types.d.ts +18 -11
  218. package/toggle-group/ToggleGroup.d.ts +1 -1
  219. package/toggle-group/ToggleGroup.js +6 -5
  220. package/toggle-group/ToggleGroup.stories.tsx +46 -4
  221. package/toggle-group/ToggleGroup.test.js +36 -5
  222. package/toggle-group/types.d.ts +9 -1
  223. package/typography/Typography.d.ts +4 -0
  224. package/typography/Typography.js +32 -0
  225. package/typography/Typography.stories.tsx +198 -0
  226. package/typography/types.d.ts +18 -0
  227. package/typography/types.js +5 -0
  228. package/useTheme.d.ts +1234 -1
  229. package/useTheme.js +3 -3
  230. package/useTranslatedLabels.d.ts +85 -0
  231. package/useTranslatedLabels.js +20 -0
  232. package/utils/BaseTypography.d.ts +21 -0
  233. package/utils/BaseTypography.js +108 -0
  234. package/utils/FocusLock.d.ts +13 -0
  235. package/utils/FocusLock.js +139 -0
  236. package/wizard/Wizard.d.ts +1 -1
  237. package/wizard/Wizard.js +59 -55
  238. package/wizard/Wizard.stories.tsx +48 -19
  239. package/wizard/Wizard.test.js +37 -24
  240. package/wizard/types.d.ts +10 -5
  241. package/ThemeContext.d.ts +0 -10
  242. package/ThemeContext.js +0 -243
  243. package/common/RequiredComponent.js +0 -32
  244. package/list/List.d.ts +0 -4
  245. package/list/List.js +0 -47
  246. package/list/List.stories.tsx +0 -95
  247. package/list/types.d.ts +0 -7
  248. package/radio/Radio.d.ts +0 -4
  249. package/radio/Radio.js +0 -174
  250. package/radio/Radio.stories.tsx +0 -192
  251. package/radio/Radio.test.js +0 -71
  252. package/radio/types.d.ts +0 -54
  253. package/row/Row.d.ts +0 -3
  254. package/row/Row.js +0 -127
  255. package/row/Row.stories.tsx +0 -237
  256. package/row/types.d.ts +0 -10
  257. package/stack/Stack.d.ts +0 -3
  258. package/stack/Stack.js +0 -97
  259. package/stack/Stack.stories.tsx +0 -164
  260. package/stack/types.d.ts +0 -9
  261. package/text/Text.d.ts +0 -7
  262. package/text/Text.js +0 -30
  263. package/text/Text.stories.tsx +0 -19
  264. /package/{list → bulleted-list}/types.js +0 -0
  265. /package/{radio → flex}/types.js +0 -0
  266. /package/{row → nav-tabs}/types.js +0 -0
  267. /package/{stack → quick-nav}/types.js +0 -0
@@ -14,6 +14,10 @@ declare type Props = {
14
14
  * Name attribute of the textarea element.
15
15
  */
16
16
  name?: string;
17
+ /**
18
+ * Initial value of the textarea, only when it is uncontrolled.
19
+ */
20
+ defaultValue?: string;
17
21
  /**
18
22
  * Value of the textarea. If undefined, the component will be uncontrolled and the value will be managed internally.
19
23
  */
@@ -52,26 +56,29 @@ declare type Props = {
52
56
  * This function will be called when the user types within the textarea.
53
57
  * An object including the current value and the error (if the value
54
58
  * entered is not valid) will be passed to this function.
55
- * If there is no error, error will be null.
59
+ * If there is no error, error will not be defined.
56
60
  */
57
61
  onChange?: (val: {
58
62
  value: string;
59
- error: string | null;
63
+ error?: string;
60
64
  }) => void;
61
65
  /**
62
66
  * This function will be called when the textarea loses the focus. An
63
67
  * object including the textarea value and the error (if the value entered
64
68
  * is not valid) will be passed to this function. If there is no error,
65
- * error will be null.
69
+ * error will not be defined.
66
70
  */
67
71
  onBlur?: (val: {
68
72
  value: string;
69
- error: string | null;
73
+ error?: string;
70
74
  }) => void;
71
75
  /**
72
- * If it is defined, the component will change its appearance, showing
73
- * the error below the textarea. If it is not defined, the error
74
- * messages will be managed internally, but never displayed on its own.
76
+ * If it is a defined value and also a truthy string, the component will
77
+ * change its appearance, showing the error below the textarea. If the
78
+ * defined value is an empty string, it will reserve a space below the
79
+ * component for a future error, but it would not change its look. In
80
+ * case of being undefined or null, both the appearance and the space for
81
+ * the error message would not be modified.
75
82
  */
76
83
  error?: string;
77
84
  /**
@@ -81,7 +88,7 @@ declare type Props = {
81
88
  * pattern, the onBlur and onChange functions will be called with the
82
89
  * current value and an internal error informing that this value does not
83
90
  * match the pattern. If the pattern is met, the error parameter of both
84
- * events will be null.
91
+ * events will not be defined.
85
92
  */
86
93
  pattern?: string;
87
94
  /**
@@ -91,7 +98,7 @@ declare type Props = {
91
98
  * comply the minimum length, the onBlur and onChange functions will be called
92
99
  * with the current value and an internal error informing that the value
93
100
  * length does not comply the specified range. If a valid length is
94
- * reached, the error parameter of both events will be null.
101
+ * reached, the error parameter of both events will not be defined.
95
102
  */
96
103
  minLength?: number;
97
104
  /**
@@ -101,7 +108,7 @@ declare type Props = {
101
108
  * comply the maximum length, the onBlur and onChange functions will be called
102
109
  * with the current value and an internal error informing that the value
103
110
  * length does not comply the specified range. If a valid length is
104
- * reached, the error parameter of both events will be null.
111
+ * reached, the error parameter of both events will not be defined.
105
112
  */
106
113
  maxLength?: number;
107
114
  /**
@@ -115,7 +122,7 @@ declare type Props = {
115
122
  */
116
123
  margin?: Space | Margin;
117
124
  /**
118
- * Size of the component ('small' | 'medium' | 'large' | 'fillParent').
125
+ * Size of the component.
119
126
  */
120
127
  size?: "small" | "medium" | "large" | "fillParent";
121
128
  /**
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
2
  import ToogleGroupPropsType from "./types";
3
- declare const DxcToggleGroup: ({ label, helperText, value, onChange, disabled, options, margin, multiple, tabIndex, }: ToogleGroupPropsType) => JSX.Element;
3
+ declare const DxcToggleGroup: ({ label, helperText, defaultValue, value, onChange, disabled, options, margin, multiple, tabIndex, }: ToogleGroupPropsType) => JSX.Element;
4
4
  export default DxcToggleGroup;
@@ -21,7 +21,7 @@ var _styledComponents = _interopRequireWildcard(require("styled-components"));
21
21
 
22
22
  var _uuid = require("uuid");
23
23
 
24
- var _variables = require("../common/variables.js");
24
+ var _variables = require("../common/variables");
25
25
 
26
26
  var _useTheme = _interopRequireDefault(require("../useTheme"));
27
27
 
@@ -34,6 +34,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
34
34
  var DxcToggleGroup = function DxcToggleGroup(_ref) {
35
35
  var label = _ref.label,
36
36
  helperText = _ref.helperText,
37
+ defaultValue = _ref.defaultValue,
37
38
  value = _ref.value,
38
39
  onChange = _ref.onChange,
39
40
  _ref$disabled = _ref.disabled,
@@ -46,7 +47,7 @@ var DxcToggleGroup = function DxcToggleGroup(_ref) {
46
47
  tabIndex = _ref$tabIndex === void 0 ? 0 : _ref$tabIndex;
47
48
  var colorsTheme = (0, _useTheme["default"])();
48
49
 
49
- var _useState = (0, _react.useState)(multiple ? [] : -1),
50
+ var _useState = (0, _react.useState)(defaultValue !== null && defaultValue !== void 0 ? defaultValue : multiple ? [] : -1),
50
51
  _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
51
52
  selectedValue = _useState2[0],
52
53
  setSelectedValue = _useState2[1];
@@ -108,9 +109,9 @@ var DxcToggleGroup = function DxcToggleGroup(_ref) {
108
109
  role: multiple ? "group" : "radiogroup"
109
110
  }, options.map(function (option, i) {
110
111
  return /*#__PURE__*/_react["default"].createElement(ToggleContainer, {
111
- selected: multiple && Array.isArray(value) ? value ? value.includes(option.value) : Array.isArray(selectedValue) && selectedValue.includes(option.value) : value ? option.value === value : option.value === selectedValue,
112
+ selected: multiple ? value ? Array.isArray(value) && value.includes(option.value) : Array.isArray(selectedValue) && selectedValue.includes(option.value) : value ? option.value === value : option.value === selectedValue,
112
113
  role: multiple ? "switch" : "radio",
113
- "aria-checked": multiple && Array.isArray(value) ? value ? value.includes(option.value) : Array.isArray(selectedValue) && selectedValue.includes(option.value) : value ? option.value === value : option.value === selectedValue,
114
+ "aria-checked": multiple ? value ? Array.isArray(value) && value.includes(option.value) : Array.isArray(selectedValue) && selectedValue.includes(option.value) : value ? option.value === value : option.value === selectedValue,
114
115
  tabIndex: !disabled ? tabIndex : -1,
115
116
  onClick: function onClick() {
116
117
  return !disabled && handleToggleChange(option.value);
@@ -172,7 +173,7 @@ var ToggleGroup = _styledComponents["default"].div(_templateObject3 || (_templat
172
173
  return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.left ? _variables.spaces[props.margin.left] : "";
173
174
  });
174
175
 
175
- var OptionsContainer = _styledComponents["default"].div(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-direction: row;\n opacity: 1;\n height: calc(48px - 4px - 4px);\n border-width: ", ";\n border-style: ", ";\n border-radius: ", ";\n border-color: ", ";\n background-color: ", ";\n padding: 4px;\n margin-top: ", ";\n"])), function (props) {
176
+ var OptionsContainer = _styledComponents["default"].div(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-direction: row;\n width: max-content;\n opacity: 1;\n height: calc(48px - 4px - 4px);\n border-width: ", ";\n border-style: ", ";\n border-radius: ", ";\n border-color: ", ";\n background-color: ", ";\n padding: 4px;\n margin-top: ", ";\n"])), function (props) {
176
177
  return props.theme.containerBorderThickness;
177
178
  }, function (props) {
178
179
  return props.theme.containerBorderStyle;
@@ -3,6 +3,7 @@ import { userEvent, within } from "@storybook/testing-library";
3
3
  import DxcToggleGroup from "./ToggleGroup";
4
4
  import Title from "../../.storybook/components/Title";
5
5
  import ExampleContainer from "../../.storybook/components/ExampleContainer";
6
+ import { HalstackProvider } from "../HalstackContext";
6
7
 
7
8
  export default {
8
9
  title: "ToggleGroup",
@@ -89,6 +90,16 @@ const twoOptions = [
89
90
  label: "Twitter",
90
91
  },
91
92
  ];
93
+
94
+ const opinionatedTheme = {
95
+ toggleGroup: {
96
+ selectedBaseColor: "#5f249f",
97
+ selectedFontColor: "#ffffff",
98
+ unselectedBaseColor: "#e6e6e6",
99
+ unselectedFontColor: "#000000",
100
+ },
101
+ };
102
+
92
103
  export const Chromatic = () => (
93
104
  <>
94
105
  <ExampleContainer>
@@ -97,7 +108,7 @@ export const Chromatic = () => (
97
108
  </ExampleContainer>
98
109
  <ExampleContainer>
99
110
  <Title title="Selected" theme="light" level={4} />
100
- <DxcToggleGroup label="Selected" helperText="HelperText" value={2} options={options} />
111
+ <DxcToggleGroup label="Selected" helperText="HelperText" defaultValue={2} options={options} />
101
112
  </ExampleContainer>
102
113
  <ExampleContainer>
103
114
  <Title title="Icons toggle group" theme="light" level={4} />
@@ -109,11 +120,11 @@ export const Chromatic = () => (
109
120
  </ExampleContainer>
110
121
  <ExampleContainer>
111
122
  <Title title="Disabled" theme="light" level={4} />
112
- <DxcToggleGroup label="Disabled" value={2} options={options} disabled />
123
+ <DxcToggleGroup label="Disabled" defaultValue={2} options={options} disabled />
113
124
  </ExampleContainer>
114
125
  <ExampleContainer pseudoState="pseudo-hover">
115
126
  <Title title="Hovered" theme="light" level={4} />
116
- <DxcToggleGroup label="Hovered" options={twoOptions} value={2} />
127
+ <DxcToggleGroup label="Hovered" options={twoOptions} defaultValue={2} />
117
128
  </ExampleContainer>
118
129
  <ExampleContainer>
119
130
  <Title title="Multiple toggleGroup" theme="light" level={4} />
@@ -121,7 +132,7 @@ export const Chromatic = () => (
121
132
  label="Toggle group"
122
133
  helperText="Please select one or more"
123
134
  options={options}
124
- value={[1, 3]}
135
+ defaultValue={[1, 3]}
125
136
  multiple
126
137
  ></DxcToggleGroup>
127
138
  </ExampleContainer>
@@ -154,6 +165,37 @@ export const Chromatic = () => (
154
165
  <Title title="xxLarge" theme="light" level={4} />
155
166
  <DxcToggleGroup label="xxLarge margin" options={options} margin="xxlarge" />
156
167
  </ExampleContainer>
168
+ <Title title="Opinionated theme" theme="light" level={2} />
169
+ <ExampleContainer>
170
+ <HalstackProvider theme={opinionatedTheme}>
171
+ <Title title="Selected" theme="light" level={4} />
172
+ <DxcToggleGroup label="Selected" helperText="HelperText" defaultValue={2} options={options} />
173
+ </HalstackProvider>
174
+ </ExampleContainer>
175
+ <ExampleContainer>
176
+ <HalstackProvider theme={opinionatedTheme}>
177
+ <Title title="Icons & label toggle group" theme="light" level={4} />
178
+ <DxcToggleGroup label="Icons & label" options={optionsWithIconAndLabel} />
179
+ </HalstackProvider>
180
+ </ExampleContainer>
181
+ <ExampleContainer>
182
+ <HalstackProvider theme={opinionatedTheme}>
183
+ <Title title="Disabled" theme="light" level={4} />
184
+ <DxcToggleGroup label="Disabled" defaultValue={2} options={options} disabled />
185
+ </HalstackProvider>
186
+ </ExampleContainer>
187
+ <ExampleContainer pseudoState="pseudo-hover">
188
+ <Title title="Hovered" theme="light" level={4} />
189
+ <HalstackProvider theme={opinionatedTheme}>
190
+ <DxcToggleGroup label="Hovered" options={twoOptions} defaultValue={2} />
191
+ </HalstackProvider>
192
+ </ExampleContainer>
193
+ <ExampleContainer pseudoState="pseudo-active">
194
+ <Title title="Actived" theme="light" level={4} />
195
+ <HalstackProvider theme={opinionatedTheme}>
196
+ <DxcToggleGroup label="Actived" options={twoOptions} defaultValue={2} />
197
+ </HalstackProvider>
198
+ </ExampleContainer>
157
199
  </>
158
200
  );
159
201
  const OptionSelected = () => <DxcToggleGroup label="Toggle group" helperText="HelperText" options={options} />;
@@ -6,7 +6,7 @@ var _react = _interopRequireDefault(require("react"));
6
6
 
7
7
  var _react2 = require("@testing-library/react");
8
8
 
9
- var _ToggleGroup = _interopRequireDefault(require("./ToggleGroup"));
9
+ var _ToggleGroup = _interopRequireDefault(require("./ToggleGroup.tsx"));
10
10
 
11
11
  var options = [{
12
12
  value: 1,
@@ -92,13 +92,22 @@ describe("Toggle group component tests", function () {
92
92
  onChange: onChange,
93
93
  multiple: true
94
94
  })),
95
- getByText = _render5.getByText;
95
+ getAllByRole = _render5.getAllByRole;
96
96
 
97
- var option = getByText("Ebay");
97
+ var toggleOptions = getAllByRole("switch");
98
98
 
99
- _react2.fireEvent.click(option);
99
+ _react2.fireEvent.click(toggleOptions[0]);
100
+
101
+ expect(onChange).toHaveBeenCalledWith([1]);
102
+
103
+ _react2.fireEvent.click(toggleOptions[1]);
100
104
 
101
- expect(onChange).toHaveBeenCalledWith([2]);
105
+ _react2.fireEvent.click(toggleOptions[3]);
106
+
107
+ expect(onChange).toHaveBeenCalledWith([1, 2, 4]);
108
+ expect(toggleOptions[0].getAttribute("aria-checked")).toBe("true");
109
+ expect(toggleOptions[1].getAttribute("aria-checked")).toBe("true");
110
+ expect(toggleOptions[3].getAttribute("aria-checked")).toBe("true");
102
111
  });
103
112
  test("Controlled multiple toggle returns always same values", function () {
104
113
  var onChange = jest.fn();
@@ -122,4 +131,26 @@ describe("Toggle group component tests", function () {
122
131
 
123
132
  expect(onChange).toHaveBeenNthCalledWith(2, [1, 4]);
124
133
  });
134
+ test("Single selection: Renders with correct default value", function () {
135
+ var _render7 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_ToggleGroup["default"], {
136
+ options: options,
137
+ defaultValue: 2
138
+ })),
139
+ getAllByRole = _render7.getAllByRole;
140
+
141
+ var toggleOptions = getAllByRole("radio");
142
+ expect(toggleOptions[1].getAttribute("aria-checked")).toBe("true");
143
+ });
144
+ test("Multiple selection: Renders with correct default value", function () {
145
+ var _render8 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_ToggleGroup["default"], {
146
+ options: options,
147
+ defaultValue: [2, 4],
148
+ multiple: true
149
+ })),
150
+ getAllByRole = _render8.getAllByRole;
151
+
152
+ var toggleOptions = getAllByRole("switch");
153
+ expect(toggleOptions[1].getAttribute("aria-checked")).toBe("true");
154
+ expect(toggleOptions[3].getAttribute("aria-checked")).toBe("true");
155
+ });
125
156
  });
@@ -6,7 +6,7 @@ declare type Margin = {
6
6
  left?: Space;
7
7
  right?: Space;
8
8
  };
9
- declare type SVG = React.SVGProps<SVGSVGElement>;
9
+ declare type SVG = React.ReactNode & React.SVGProps<SVGSVGElement>;
10
10
  declare type OptionCommons = {
11
11
  /**
12
12
  * Number with the option inner value.
@@ -66,6 +66,10 @@ declare type SingleSelectionToggle = CommonProps & {
66
66
  * 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.
67
67
  */
68
68
  multiple?: false;
69
+ /**
70
+ * The key of the initially selected value.
71
+ */
72
+ defaultValue?: number;
69
73
  /**
70
74
  * The key of the selected value. If the component allows multiple selection, value must be an array.
71
75
  * If undefined, the component will be uncontrolled and the value will be managed internally by the component.
@@ -82,6 +86,10 @@ declare type MultipleSelectionToggle = CommonProps & {
82
86
  * 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.
83
87
  */
84
88
  multiple: true;
89
+ /**
90
+ * The array of keys with the initially selected values.
91
+ */
92
+ defaultValue?: number[];
85
93
  /**
86
94
  * An array with the keys of the selected values.
87
95
  * If undefined, the component will be uncontrolled and the value will be managed internally by the component.
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import TypographyPropsTypes from "./types";
3
+ declare const DxcTypography: ({ textOverflow, whiteSpace, children, ...props }: TypographyPropsTypes) => JSX.Element;
4
+ export default DxcTypography;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+
12
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
+
14
+ var _react = _interopRequireDefault(require("react"));
15
+
16
+ var _BaseTypography = _interopRequireDefault(require("../utils/BaseTypography"));
17
+
18
+ var _excluded = ["textOverflow", "whiteSpace", "children"];
19
+
20
+ var DxcTypography = function DxcTypography(_ref) {
21
+ var textOverflow = _ref.textOverflow,
22
+ whiteSpace = _ref.whiteSpace,
23
+ children = _ref.children,
24
+ props = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
25
+ return /*#__PURE__*/_react["default"].createElement(_BaseTypography["default"], (0, _extends2["default"])({
26
+ textOverflow: textOverflow,
27
+ whiteSpace: whiteSpace == null && textOverflow != null && textOverflow !== "unset" ? "nowrap" : whiteSpace
28
+ }, props), children);
29
+ };
30
+
31
+ var _default = DxcTypography;
32
+ exports["default"] = _default;
@@ -0,0 +1,198 @@
1
+ import React from "react";
2
+ import Title from "../../.storybook/components/Title";
3
+ import ExampleContainer from "../../.storybook/components/ExampleContainer";
4
+ import DxcTypography from "./Typography";
5
+
6
+ export default {
7
+ title: "Typography",
8
+ component: DxcTypography,
9
+ };
10
+
11
+ export const Chromatic = () => (
12
+ <>
13
+ <ExampleContainer>
14
+ <Title title="Default Typography" theme="light" level={4} />
15
+ <DxcTypography>Default typography.</DxcTypography>
16
+ </ExampleContainer>
17
+ <ExampleContainer>
18
+ <Title title="Typography font sizes" theme="light" level={4} />
19
+ <DxcTypography display="block" fontSize="3.75rem">
20
+ 3.75rem.
21
+ </DxcTypography>
22
+ <DxcTypography display="block" fontSize="3rem">
23
+ 3rem.
24
+ </DxcTypography>
25
+ <DxcTypography display="block" fontSize="2rem">
26
+ 2rem.
27
+ </DxcTypography>
28
+ <DxcTypography display="block" fontSize="1.5rem">
29
+ 1.5rem.
30
+ </DxcTypography>
31
+ <DxcTypography display="block" fontSize="1.25rem">
32
+ 1.25rem.
33
+ </DxcTypography>
34
+ <DxcTypography display="block" fontSize="1rem">
35
+ 1rem.
36
+ </DxcTypography>
37
+ <DxcTypography display="block" fontSize="0.875rem">
38
+ 0.875rem.
39
+ </DxcTypography>
40
+ <DxcTypography display="block" fontSize="0.75rem">
41
+ 0.75rem.
42
+ </DxcTypography>
43
+ </ExampleContainer>
44
+ <ExampleContainer>
45
+ <Title title="Typography letter spacing" theme="light" level={4} />
46
+ <DxcTypography display="block" letterSpacing="-0.025em">
47
+ -0.025em.
48
+ </DxcTypography>
49
+ <DxcTypography display="block" letterSpacing="-0.0125em">
50
+ -0.0125em.
51
+ </DxcTypography>
52
+ <DxcTypography display="block" letterSpacing="0em">
53
+ 0em.
54
+ </DxcTypography>
55
+ <DxcTypography display="block" letterSpacing="0.025em">
56
+ 0.025em.
57
+ </DxcTypography>
58
+ <DxcTypography display="block" letterSpacing="0.05em">
59
+ 0.05em.
60
+ </DxcTypography>
61
+ <DxcTypography display="block" letterSpacing="0.1em">
62
+ 0.1em.
63
+ </DxcTypography>{" "}
64
+ </ExampleContainer>
65
+ <ExampleContainer>
66
+ <Title title="Typography line height" theme="light" level={4} />
67
+ <DxcTypography display="block" lineHeight="1em">
68
+ 1em.
69
+ </DxcTypography>
70
+ <DxcTypography display="block" lineHeight="1.25em">
71
+ 1.25em.
72
+ </DxcTypography>
73
+ <DxcTypography display="block" lineHeight="1.365em">
74
+ 1.365em.
75
+ </DxcTypography>
76
+ <DxcTypography display="block" lineHeight="1.5em">
77
+ 1.5em.
78
+ </DxcTypography>
79
+ <DxcTypography display="block" lineHeight="1.715em">
80
+ 1.715em.
81
+ </DxcTypography>
82
+ <DxcTypography display="block" lineHeight="2em">
83
+ 2em.
84
+ </DxcTypography>
85
+ </ExampleContainer>
86
+ <ExampleContainer>
87
+ <Title title="Typography font weight" theme="light" level={4} />
88
+ <DxcTypography display="block" fontWeight="300">
89
+ 300.
90
+ </DxcTypography>
91
+ <DxcTypography display="block" fontWeight="400">
92
+ 400.
93
+ </DxcTypography>
94
+ <DxcTypography display="block" fontWeight="600">
95
+ 600.
96
+ </DxcTypography>
97
+ <DxcTypography display="block" fontWeight="700">
98
+ 700.
99
+ </DxcTypography>
100
+ </ExampleContainer>
101
+ <ExampleContainer>
102
+ <Title title="Typography decoration" theme="light" level={4} />
103
+ <DxcTypography display="block" textDecoration="underline">
104
+ Underline.
105
+ </DxcTypography>
106
+ <DxcTypography display="block" textDecoration="line-through">
107
+ Line-through.
108
+ </DxcTypography>
109
+ </ExampleContainer>
110
+ <ExampleContainer>
111
+ <Title title="Typography font family" theme="light" level={4} />
112
+ <DxcTypography display="block" fontFamily="Open Sans, sans-serif">
113
+ Open Sans, sans-serif.
114
+ </DxcTypography>
115
+ <DxcTypography display="block" fontFamily="Source Code Pro, monospace">
116
+ Source Code Pro, monospace.
117
+ </DxcTypography>
118
+ </ExampleContainer>
119
+ <ExampleContainer>
120
+ <Title title="Typography font style" theme="light" level={4} />
121
+ <DxcTypography display="block" fontStyle="italic">
122
+ Italic.
123
+ </DxcTypography>
124
+ <DxcTypography display="block" fontStyle="normal">
125
+ Normal.
126
+ </DxcTypography>
127
+ </ExampleContainer>
128
+ <ExampleContainer>
129
+ <Title title="Typography align" theme="light" level={4} />
130
+ <DxcTypography display="block" textAlign="left">
131
+ Left.
132
+ </DxcTypography>
133
+ <DxcTypography display="block" textAlign="center">
134
+ Center.
135
+ </DxcTypography>
136
+ <DxcTypography display="block" textAlign="right">
137
+ Right.
138
+ </DxcTypography>
139
+ </ExampleContainer>
140
+ <ExampleContainer>
141
+ <Title title="Typography whitespace" theme="light" level={4} />
142
+ <div style={{ margin: "50px", border: "1px solid red", width: "125px" }}>
143
+ <DxcTypography fontSize="2rem">
144
+ {" "} Normal: A bunch of words you see.
145
+ </DxcTypography>
146
+ </div>
147
+ <div style={{ margin: "50px", border: "1px solid red", width: "125px" }}>
148
+ <DxcTypography whiteSpace="nowrap" fontSize="2rem">
149
+ {" "}No-wrap: A bunch of words you see.
150
+ </DxcTypography>
151
+ </div>
152
+ <div style={{ margin: "50px", border: "1px solid red", width: "125px" }}>
153
+ <DxcTypography whiteSpace="pre" fontSize="2rem">
154
+ {" "} pre: A bunch of words you see.
155
+ </DxcTypography>
156
+ </div>
157
+ <div style={{ margin: "50px", border: "1px solid red", width: "125px" }}>
158
+ <DxcTypography whiteSpace="pre-line" fontSize="2rem">
159
+ {" "}pre-line: A bunch of words you see.
160
+ </DxcTypography>
161
+ </div>
162
+ <div style={{ margin: "50px", border: "1px solid red", width: "125px" }}>
163
+ <DxcTypography whiteSpace="pre-wrap" fontSize="2rem">
164
+ {" "} pre-wrap: A bunch of words you see.
165
+ </DxcTypography>
166
+ </div>
167
+ </ExampleContainer>{" "}
168
+ <ExampleContainer>
169
+ <Title title="Typography display" theme="light" level={4} />
170
+ <DxcTypography display="block" textAlign="left">
171
+ Display Block.
172
+ <DxcTypography>A different text.</DxcTypography>
173
+ </DxcTypography>
174
+ <DxcTypography display="inline" textAlign="left">
175
+ Display Inline.
176
+ <DxcTypography>A different text.</DxcTypography>
177
+ </DxcTypography>
178
+ </ExampleContainer>
179
+ <ExampleContainer>
180
+ <Title title="Typography text-overflow" theme="light" level={4} />
181
+ <div style={{ width: "75px" }}>
182
+ <DxcTypography display="block" textOverflow="clip">
183
+ Overflow clip.
184
+ </DxcTypography>
185
+ </div>
186
+ <div style={{ width: "75px" }}>
187
+ <DxcTypography display="block" textOverflow="ellipsis">
188
+ Overflow ellipsis.
189
+ </DxcTypography>
190
+ </div>
191
+ <div style={{ width: "75px" }}>
192
+ <DxcTypography display="block" textOverflow="unset">
193
+ Overflow unset.
194
+ </DxcTypography>
195
+ </div>
196
+ </ExampleContainer>
197
+ </>
198
+ );
@@ -0,0 +1,18 @@
1
+ /// <reference types="react" />
2
+ declare type Props = {
3
+ as?: keyof HTMLElementTagNameMap;
4
+ display?: "inline" | "block";
5
+ fontFamily?: "Open Sans, sans-serif" | "Source Code Pro, monospace";
6
+ fontSize?: "0.75rem" | "0.875rem" | "1rem" | "1.25rem" | "1.5rem" | "2rem" | "3rem" | "3.75rem";
7
+ fontStyle?: "italic" | "normal";
8
+ fontWeight?: "300" | "400" | "600" | "700";
9
+ letterSpacing?: "-0.025em" | "-0.0125em" | "0em" | "0.025em" | "0.05em" | "0.1em";
10
+ lineHeight?: "1em" | "1.25em" | "1.365em" | "1.5em" | "1.715em" | "2em";
11
+ textAlign?: "left" | "center" | "right";
12
+ color?: string;
13
+ textDecoration?: "none" | "underline" | "line-through";
14
+ textOverflow?: "clip" | "ellipsis" | "unset";
15
+ whiteSpace?: "normal" | "nowrap" | "pre" | "pre-line" | "pre-wrap";
16
+ children: React.ReactNode;
17
+ };
18
+ export default Props;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });