@dxc-technology/halstack-react 0.0.0-8b5e703 → 0.0.0-8b61ced

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 (193) hide show
  1. package/HalstackContext.js +7 -11
  2. package/accordion/Accordion.js +122 -103
  3. package/accordion/Accordion.stories.tsx +2 -3
  4. package/accordion/Accordion.test.js +9 -10
  5. package/accordion/types.d.ts +5 -4
  6. package/accordion-group/AccordionGroup.js +2 -21
  7. package/accordion-group/AccordionGroup.stories.tsx +27 -1
  8. package/accordion-group/AccordionGroup.test.js +20 -45
  9. package/accordion-group/types.d.ts +10 -3
  10. package/alert/Alert.js +1 -1
  11. package/bleed/Bleed.js +1 -34
  12. package/bleed/Bleed.stories.tsx +94 -95
  13. package/bleed/types.d.ts +1 -1
  14. package/box/Box.js +23 -33
  15. package/box/types.d.ts +1 -0
  16. package/bulleted-list/BulletedList.d.ts +7 -0
  17. package/bulleted-list/BulletedList.js +123 -0
  18. package/bulleted-list/BulletedList.stories.tsx +200 -0
  19. package/bulleted-list/types.d.ts +11 -0
  20. package/{list → bulleted-list}/types.js +0 -0
  21. package/button/Button.js +43 -61
  22. package/button/Button.stories.tsx +9 -0
  23. package/button/types.d.ts +7 -7
  24. package/card/Card.js +34 -36
  25. package/card/types.d.ts +1 -0
  26. package/checkbox/Checkbox.d.ts +2 -2
  27. package/checkbox/Checkbox.js +92 -99
  28. package/checkbox/Checkbox.stories.tsx +79 -59
  29. package/checkbox/Checkbox.test.js +93 -16
  30. package/checkbox/types.d.ts +6 -2
  31. package/chip/types.d.ts +1 -1
  32. package/common/variables.js +75 -48
  33. package/date-input/Calendar.d.ts +4 -0
  34. package/date-input/Calendar.js +258 -0
  35. package/date-input/DateInput.js +77 -222
  36. package/date-input/DateInput.stories.tsx +30 -17
  37. package/date-input/DateInput.test.js +411 -138
  38. package/date-input/DatePicker.d.ts +4 -0
  39. package/date-input/DatePicker.js +160 -0
  40. package/date-input/YearPicker.d.ts +4 -0
  41. package/date-input/YearPicker.js +115 -0
  42. package/date-input/types.d.ts +53 -0
  43. package/dialog/Dialog.js +52 -28
  44. package/dialog/Dialog.stories.tsx +57 -2
  45. package/dialog/Dialog.test.js +34 -4
  46. package/dialog/types.d.ts +3 -2
  47. package/dropdown/Dropdown.d.ts +1 -1
  48. package/dropdown/Dropdown.js +247 -247
  49. package/dropdown/Dropdown.stories.tsx +126 -63
  50. package/dropdown/Dropdown.test.js +504 -108
  51. package/dropdown/DropdownMenu.d.ts +4 -0
  52. package/dropdown/DropdownMenu.js +80 -0
  53. package/dropdown/DropdownMenuItem.d.ts +4 -0
  54. package/dropdown/DropdownMenuItem.js +92 -0
  55. package/dropdown/types.d.ts +25 -5
  56. package/file-input/FileInput.d.ts +2 -2
  57. package/file-input/FileInput.js +177 -219
  58. package/file-input/FileInput.stories.tsx +38 -10
  59. package/file-input/FileInput.test.js +53 -12
  60. package/file-input/FileItem.d.ts +4 -14
  61. package/file-input/FileItem.js +38 -63
  62. package/file-input/types.d.ts +17 -0
  63. package/flex/Flex.d.ts +4 -0
  64. package/flex/Flex.js +69 -0
  65. package/flex/Flex.stories.tsx +103 -0
  66. package/flex/types.d.ts +32 -0
  67. package/{radio → flex}/types.js +0 -0
  68. package/footer/Footer.stories.tsx +8 -1
  69. package/footer/Icons.js +1 -1
  70. package/footer/types.d.ts +2 -1
  71. package/header/Header.js +74 -72
  72. package/header/Header.stories.tsx +4 -4
  73. package/header/Icons.js +2 -2
  74. package/header/types.d.ts +3 -2
  75. package/inset/Inset.js +1 -34
  76. package/inset/Inset.stories.tsx +36 -36
  77. package/inset/types.d.ts +1 -1
  78. package/layout/ApplicationLayout.d.ts +16 -6
  79. package/layout/ApplicationLayout.js +70 -117
  80. package/layout/ApplicationLayout.stories.tsx +84 -93
  81. package/layout/Icons.d.ts +5 -0
  82. package/layout/Icons.js +13 -2
  83. package/layout/SidenavContext.d.ts +5 -0
  84. package/layout/SidenavContext.js +19 -0
  85. package/layout/types.d.ts +18 -33
  86. package/link/Link.js +12 -5
  87. package/link/Link.stories.tsx +13 -6
  88. package/link/types.d.ts +1 -1
  89. package/main.d.ts +5 -9
  90. package/main.js +28 -60
  91. package/number-input/NumberInput.test.js +43 -7
  92. package/package.json +16 -20
  93. package/paginator/Paginator.js +2 -2
  94. package/paginator/Paginator.test.js +43 -1
  95. package/paragraph/Paragraph.d.ts +6 -0
  96. package/paragraph/Paragraph.js +38 -0
  97. package/paragraph/Paragraph.stories.tsx +44 -0
  98. package/password-input/PasswordInput.test.js +13 -12
  99. package/progress-bar/ProgressBar.d.ts +2 -2
  100. package/progress-bar/ProgressBar.js +56 -50
  101. package/progress-bar/ProgressBar.stories.jsx +3 -1
  102. package/progress-bar/ProgressBar.test.js +67 -22
  103. package/progress-bar/types.d.ts +3 -4
  104. package/quick-nav/QuickNav.js +25 -20
  105. package/quick-nav/QuickNav.stories.tsx +131 -26
  106. package/radio-group/Radio.d.ts +1 -1
  107. package/radio-group/Radio.js +43 -28
  108. package/radio-group/RadioGroup.js +23 -22
  109. package/radio-group/RadioGroup.stories.tsx +1 -0
  110. package/radio-group/RadioGroup.test.js +123 -96
  111. package/radio-group/types.d.ts +2 -2
  112. package/resultsetTable/Icons.d.ts +7 -0
  113. package/resultsetTable/Icons.js +51 -0
  114. package/resultsetTable/ResultsetTable.js +48 -107
  115. package/resultsetTable/ResultsetTable.stories.tsx +50 -25
  116. package/resultsetTable/ResultsetTable.test.js +65 -41
  117. package/resultsetTable/types.d.ts +2 -2
  118. package/select/Listbox.d.ts +1 -1
  119. package/select/Listbox.js +53 -7
  120. package/select/Select.js +43 -43
  121. package/select/Select.stories.tsx +133 -103
  122. package/select/Select.test.js +363 -250
  123. package/select/types.d.ts +2 -5
  124. package/sidenav/Sidenav.d.ts +6 -5
  125. package/sidenav/Sidenav.js +184 -52
  126. package/sidenav/Sidenav.stories.tsx +154 -156
  127. package/sidenav/Sidenav.test.js +25 -37
  128. package/sidenav/types.d.ts +50 -27
  129. package/slider/Slider.d.ts +2 -2
  130. package/slider/Slider.js +120 -95
  131. package/slider/Slider.stories.tsx +7 -1
  132. package/slider/Slider.test.js +121 -21
  133. package/slider/types.d.ts +6 -2
  134. package/spinner/Spinner.js +2 -2
  135. package/switch/Switch.d.ts +2 -2
  136. package/switch/Switch.js +135 -68
  137. package/switch/Switch.stories.tsx +8 -30
  138. package/switch/Switch.test.js +144 -17
  139. package/switch/types.d.ts +6 -2
  140. package/table/Table.js +1 -1
  141. package/table/Table.test.js +1 -1
  142. package/tabs/Tab.d.ts +4 -0
  143. package/tabs/Tab.js +135 -0
  144. package/tabs/Tabs.js +360 -104
  145. package/tabs/Tabs.stories.tsx +74 -1
  146. package/tabs/Tabs.test.js +217 -6
  147. package/tabs/types.d.ts +15 -5
  148. package/tabs-nav/NavTabs.d.ts +2 -1
  149. package/tabs-nav/NavTabs.js +40 -21
  150. package/tabs-nav/Tab.js +29 -16
  151. package/tabs-nav/types.d.ts +7 -5
  152. package/tag/Tag.js +1 -1
  153. package/tag/types.d.ts +1 -1
  154. package/text-input/Icons.d.ts +8 -0
  155. package/text-input/Icons.js +60 -0
  156. package/text-input/Suggestion.js +38 -9
  157. package/text-input/Suggestions.d.ts +4 -0
  158. package/text-input/Suggestions.js +134 -0
  159. package/text-input/TextInput.js +189 -282
  160. package/text-input/TextInput.stories.tsx +194 -182
  161. package/text-input/TextInput.test.js +737 -725
  162. package/text-input/types.d.ts +22 -3
  163. package/toggle-group/types.d.ts +1 -1
  164. package/typography/Typography.d.ts +4 -0
  165. package/typography/Typography.js +131 -0
  166. package/typography/Typography.stories.tsx +198 -0
  167. package/typography/types.d.ts +18 -0
  168. package/{row → typography}/types.js +0 -0
  169. package/wizard/Wizard.js +9 -16
  170. package/wizard/Wizard.stories.tsx +20 -1
  171. package/wizard/types.d.ts +5 -4
  172. package/common/RequiredComponent.js +0 -32
  173. package/list/List.d.ts +0 -4
  174. package/list/List.js +0 -47
  175. package/list/List.stories.tsx +0 -95
  176. package/list/types.d.ts +0 -7
  177. package/radio/Radio.d.ts +0 -4
  178. package/radio/Radio.js +0 -173
  179. package/radio/Radio.stories.tsx +0 -192
  180. package/radio/Radio.test.js +0 -71
  181. package/radio/types.d.ts +0 -54
  182. package/row/Row.d.ts +0 -3
  183. package/row/Row.js +0 -127
  184. package/row/Row.stories.tsx +0 -237
  185. package/row/types.d.ts +0 -28
  186. package/stack/Stack.d.ts +0 -3
  187. package/stack/Stack.js +0 -97
  188. package/stack/Stack.stories.tsx +0 -164
  189. package/stack/types.d.ts +0 -24
  190. package/stack/types.js +0 -5
  191. package/text/Text.d.ts +0 -7
  192. package/text/Text.js +0 -30
  193. package/text/Text.stories.tsx +0 -19
@@ -1,5 +1,6 @@
1
1
  import React from "react";
2
2
  import DxcButton from "./Button";
3
+ import DxcFlex from "./../flex/Flex";
3
4
  import { BackgroundColorProvider } from "../BackgroundColorContext";
4
5
  import Title from "../../.storybook/components/Title";
5
6
  import ExampleContainer from "../../.storybook/components/ExampleContainer";
@@ -270,5 +271,13 @@ export const Chromatic = () => (
270
271
  <Title title="Xxlarge margin" theme="light" level={4} />
271
272
  <DxcButton label="Xxlarge margin" margin="xxlarge" />
272
273
  </ExampleContainer>
274
+ <Title title="Inside a flex" theme="light" level={2} />
275
+ <ExampleContainer>
276
+ <DxcFlex direction="column" gap="0.75rem">
277
+ <DxcButton label="Button" />
278
+ <DxcButton label="Button" />
279
+ <DxcButton label="Button" />
280
+ </DxcFlex>
281
+ </ExampleContainer>
273
282
  </>
274
283
  );
package/button/types.d.ts CHANGED
@@ -1,19 +1,19 @@
1
1
  /// <reference types="react" />
2
- declare type Space = "xxsmall" | "xsmall" | "small" | "medium" | "large" | "xlarge" | "xxlarge";
3
- declare type Margin = {
2
+ export declare type Space = "xxsmall" | "xsmall" | "small" | "medium" | "large" | "xlarge" | "xxlarge";
3
+ export declare 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>;
9
+ export declare type SVG = React.ReactNode & React.SVGProps<SVGSVGElement>;
10
10
  declare type Props = {
11
11
  /**
12
- * Text to be placed next to the button.
12
+ * Text to be placed in the button.
13
13
  */
14
14
  label?: string;
15
15
  /**
16
- * Uses one of the available button modes.
16
+ * The available button modes.
17
17
  */
18
18
  mode?: "primary" | "secondary" | "text";
19
19
  /**
@@ -25,11 +25,11 @@ declare type Props = {
25
25
  */
26
26
  iconPosition?: "before" | "after";
27
27
  /**
28
- * This prop corresponds to the 'type' prop of the button in html.
28
+ * 'type' html prop of the button.
29
29
  */
30
30
  type?: "button" | "reset" | "submit";
31
31
  /**
32
- * Element or path used as the icon that will be placed next to the button label.
32
+ * Element or path used as the icon that will be placed next to the label.
33
33
  */
34
34
  icon?: string | SVG;
35
35
  /**
package/card/Card.js CHANGED
@@ -25,7 +25,7 @@ var _useTheme = _interopRequireDefault(require("../useTheme"));
25
25
 
26
26
  var _Box = _interopRequireDefault(require("../box/Box"));
27
27
 
28
- var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
28
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
29
29
 
30
30
  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); }
31
31
 
@@ -64,17 +64,6 @@ var DxcCard = function DxcCard(_ref) {
64
64
  src: imageSrc
65
65
  }));
66
66
 
67
- var tagContent = /*#__PURE__*/_react["default"].createElement(_Box["default"], {
68
- shadowDepth: !outlined ? 0 : isHovered && (onClick || linkHref) ? 2 : 1
69
- }, /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
70
- theme: colorsTheme.card
71
- }, /*#__PURE__*/_react["default"].createElement(CardContainer, {
72
- hasAction: onClick || linkHref,
73
- imagePosition: imagePosition
74
- }, imageSrc && imagePosition === "before" && imageComponent, /*#__PURE__*/_react["default"].createElement(CardContent, {
75
- contentPadding: contentPadding
76
- }, children), imageSrc && imagePosition === "after" && imageComponent)));
77
-
78
67
  return /*#__PURE__*/_react["default"].createElement(StyledDxcCard, {
79
68
  margin: margin,
80
69
  onMouseEnter: function onMouseEnter() {
@@ -84,15 +73,23 @@ var DxcCard = function DxcCard(_ref) {
84
73
  return changeIsHovered(false);
85
74
  },
86
75
  onClick: onClick,
87
- hasAction: onClick,
88
- tabIndex: typeof onClick === "function" && !linkHref ? tabIndex : -1
89
- }, linkHref && /*#__PURE__*/_react["default"].createElement(StyledLink, {
90
- tabIndex: tabIndex,
76
+ hasAction: onClick || linkHref,
77
+ tabIndex: onClick || linkHref ? tabIndex : -1,
78
+ as: linkHref && "a",
91
79
  href: linkHref
92
- }, tagContent) || tagContent);
80
+ }, /*#__PURE__*/_react["default"].createElement(_Box["default"], {
81
+ shadowDepth: !outlined ? 0 : isHovered && (onClick || linkHref) ? 2 : 1
82
+ }, /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
83
+ theme: colorsTheme.card
84
+ }, /*#__PURE__*/_react["default"].createElement(CardContainer, {
85
+ hasAction: onClick || linkHref,
86
+ imagePosition: imagePosition
87
+ }, imageSrc && imagePosition === "before" && imageComponent, /*#__PURE__*/_react["default"].createElement(CardContent, {
88
+ contentPadding: contentPadding
89
+ }, children), imageSrc && imagePosition === "after" && imageComponent))));
93
90
  };
94
91
 
95
- var StyledDxcCard = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n display: inline-flex;\n cursor: ", ";\n outline: ", ";\n margin: ", ";\n margin-top: ", ";\n margin-right: ", ";\n margin-bottom: ", ";\n margin-left: ", ";\n\n :focus {\n outline: #0095ff auto 1px;\n }\n"])), function (_ref2) {
92
+ var StyledDxcCard = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n display: inline-flex;\n cursor: ", ";\n outline: ", ";\n margin: ", ";\n margin-top: ", ";\n margin-right: ", ";\n margin-bottom: ", ";\n margin-left: ", ";\n text-decoration: none;\n\n ", "\n"])), function (_ref2) {
96
93
  var hasAction = _ref2.hasAction;
97
94
  return hasAction && "pointer" || "unset";
98
95
  }, function (_ref3) {
@@ -113,49 +110,50 @@ var StyledDxcCard = _styledComponents["default"].div(_templateObject || (_templa
113
110
  }, function (_ref8) {
114
111
  var margin = _ref8.margin;
115
112
  return margin && margin.left ? _variables.spaces[margin.left] : "";
113
+ }, function (_ref9) {
114
+ var hasAction = _ref9.hasAction;
115
+ return hasAction && ":focus {\n outline: #0095ff auto 1px;\n }";
116
116
  });
117
117
 
118
118
  var CardContainer = _styledComponents["default"].div(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["\n display: inline-flex;\n height: ", ";\n width: ", ";\n &:hover {\n border-color: ", ";\n }\n"])), function (props) {
119
119
  return props.theme.height;
120
120
  }, function (props) {
121
121
  return props.theme.width;
122
- }, function (_ref9) {
123
- var hasAction = _ref9.hasAction;
122
+ }, function (_ref10) {
123
+ var hasAction = _ref10.hasAction;
124
124
  return hasAction ? "" : "unset";
125
125
  });
126
126
 
127
- var StyledLink = _styledComponents["default"].a(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2["default"])(["\n cursor: pointer;\n text-decoration: none;\n\n :focus {\n outline-color: #0095ff;\n }\n"])));
128
-
129
- var TagImage = _styledComponents["default"].img(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["\n height: ", ";\n width: ", ";\n object-fit: ", ";\n"])), function (_ref10) {
130
- var imagePadding = _ref10.imagePadding;
131
- return !imagePadding ? "100%" : "calc(100% - ".concat(_variables.spaces[imagePadding], " - ").concat(_variables.spaces[imagePadding], ")");
132
- }, function (_ref11) {
127
+ var TagImage = _styledComponents["default"].img(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2["default"])(["\n height: ", ";\n width: ", ";\n object-fit: ", ";\n"])), function (_ref11) {
133
128
  var imagePadding = _ref11.imagePadding;
134
129
  return !imagePadding ? "100%" : "calc(100% - ".concat(_variables.spaces[imagePadding], " - ").concat(_variables.spaces[imagePadding], ")");
135
130
  }, function (_ref12) {
136
- var cover = _ref12.cover;
131
+ var imagePadding = _ref12.imagePadding;
132
+ return !imagePadding ? "100%" : "calc(100% - ".concat(_variables.spaces[imagePadding], " - ").concat(_variables.spaces[imagePadding], ")");
133
+ }, function (_ref13) {
134
+ var cover = _ref13.cover;
137
135
  return cover ? "cover" : "contain";
138
136
  });
139
137
 
140
- var ImageContainer = _styledComponents["default"].div(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2["default"])(["\n width: 35%;\n height: 100%;\n flex-shrink: 0;\n background: ", ";\n justify-content: center;\n align-items: center;\n display: inline-flex;\n"])), function (_ref13) {
141
- var imageBgColor = _ref13.imageBgColor;
138
+ var ImageContainer = _styledComponents["default"].div(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["\n width: 35%;\n height: 100%;\n flex-shrink: 0;\n background: ", ";\n justify-content: center;\n align-items: center;\n display: inline-flex;\n"])), function (_ref14) {
139
+ var imageBgColor = _ref14.imageBgColor;
142
140
  return imageBgColor;
143
141
  });
144
142
 
145
- var CardContent = _styledComponents["default"].div(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteral2["default"])(["\n flex-grow: 1;\n padding: ", ";\n padding-top: ", ";\n padding-right: ", ";\n padding-bottom: ", ";\n padding-left: ", ";\n overflow: hidden;\n"])), function (_ref14) {
146
- var contentPadding = _ref14.contentPadding;
147
- return contentPadding && (0, _typeof2["default"])(contentPadding) !== "object" ? _variables.spaces[contentPadding] : "0px";
148
- }, function (_ref15) {
143
+ var CardContent = _styledComponents["default"].div(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2["default"])(["\n flex-grow: 1;\n padding: ", ";\n padding-top: ", ";\n padding-right: ", ";\n padding-bottom: ", ";\n padding-left: ", ";\n overflow: hidden;\n"])), function (_ref15) {
149
144
  var contentPadding = _ref15.contentPadding;
150
- return contentPadding && (0, _typeof2["default"])(contentPadding) === "object" && contentPadding.top ? _variables.spaces[contentPadding.top] : "";
145
+ return contentPadding && (0, _typeof2["default"])(contentPadding) !== "object" ? _variables.spaces[contentPadding] : "0px";
151
146
  }, function (_ref16) {
152
147
  var contentPadding = _ref16.contentPadding;
153
- return contentPadding && (0, _typeof2["default"])(contentPadding) === "object" && contentPadding.right ? _variables.spaces[contentPadding.right] : "";
148
+ return contentPadding && (0, _typeof2["default"])(contentPadding) === "object" && contentPadding.top ? _variables.spaces[contentPadding.top] : "";
154
149
  }, function (_ref17) {
155
150
  var contentPadding = _ref17.contentPadding;
156
- return contentPadding && (0, _typeof2["default"])(contentPadding) === "object" && contentPadding.bottom ? _variables.spaces[contentPadding.bottom] : "";
151
+ return contentPadding && (0, _typeof2["default"])(contentPadding) === "object" && contentPadding.right ? _variables.spaces[contentPadding.right] : "";
157
152
  }, function (_ref18) {
158
153
  var contentPadding = _ref18.contentPadding;
154
+ return contentPadding && (0, _typeof2["default"])(contentPadding) === "object" && contentPadding.bottom ? _variables.spaces[contentPadding.bottom] : "";
155
+ }, function (_ref19) {
156
+ var contentPadding = _ref19.contentPadding;
159
157
  return contentPadding && (0, _typeof2["default"])(contentPadding) === "object" && contentPadding.left ? _variables.spaces[contentPadding.left] : "";
160
158
  });
161
159
 
package/card/types.d.ts CHANGED
@@ -47,6 +47,7 @@ declare type Props = {
47
47
  */
48
48
  margin?: Space | Size;
49
49
  /**
50
+ * @deprecated This prop will be removed shortly, consider using the Inset component for this purpose.
50
51
  * Size of the padding to be applied to the content area ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
51
52
  * You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different padding sizes.
52
53
  */
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import React from "react";
2
2
  import CheckboxPropsType from "./types";
3
- declare const DxcCheckbox: ({ checked, defaultChecked, value, label, labelPosition, name, disabled, optional, onChange, margin, size, tabIndex, }: CheckboxPropsType) => JSX.Element;
3
+ declare const DxcCheckbox: React.ForwardRefExoticComponent<CheckboxPropsType & React.RefAttributes<HTMLDivElement>>;
4
4
  export default DxcCheckbox;
@@ -19,8 +19,6 @@ var _react = _interopRequireWildcard(require("react"));
19
19
 
20
20
  var _styledComponents = _interopRequireWildcard(require("styled-components"));
21
21
 
22
- var _Checkbox = _interopRequireDefault(require("@material-ui/core/Checkbox"));
23
-
24
22
  var _variables = require("../common/variables.js");
25
23
 
26
24
  var _utils = require("../common/utils.js");
@@ -33,13 +31,22 @@ var _useTranslatedLabels = _interopRequireDefault(require("../useTranslatedLabel
33
31
 
34
32
  var _BackgroundColorContext = _interopRequireDefault(require("../BackgroundColorContext"));
35
33
 
36
- var _templateObject, _templateObject2, _templateObject3;
34
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
37
35
 
38
36
  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); }
39
37
 
40
38
  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; }
41
39
 
42
- var DxcCheckbox = function DxcCheckbox(_ref) {
40
+ var checkedIcon = /*#__PURE__*/_react["default"].createElement("svg", {
41
+ fill: "currentColor",
42
+ focusable: "false",
43
+ "aria-hidden": "true",
44
+ viewBox: "0 0 24 24"
45
+ }, /*#__PURE__*/_react["default"].createElement("path", {
46
+ d: "M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"
47
+ }));
48
+
49
+ var DxcCheckbox = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
43
50
  var checked = _ref.checked,
44
51
  _ref$defaultChecked = _ref.defaultChecked,
45
52
  defaultChecked = _ref$defaultChecked === void 0 ? false : _ref$defaultChecked,
@@ -61,96 +68,86 @@ var DxcCheckbox = function DxcCheckbox(_ref) {
61
68
  _ref$tabIndex = _ref.tabIndex,
62
69
  tabIndex = _ref$tabIndex === void 0 ? 0 : _ref$tabIndex;
63
70
 
64
- var _useState = (0, _react.useState)("checkbox-".concat((0, _uuid.v4)())),
71
+ var _useState = (0, _react.useState)("label-checkbox-".concat((0, _uuid.v4)())),
65
72
  _useState2 = (0, _slicedToArray2["default"])(_useState, 1),
66
- switchId = _useState2[0];
67
-
68
- var labelId = "label-".concat(switchId);
73
+ labelId = _useState2[0];
69
74
 
70
75
  var _useState3 = (0, _react.useState)(defaultChecked),
71
76
  _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
72
77
  innerChecked = _useState4[0],
73
78
  setInnerChecked = _useState4[1];
74
79
 
75
- var _useState5 = (0, _react.useState)(false),
76
- _useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
77
- isLabelHovered = _useState6[0],
78
- setIsLabelHovered = _useState6[1];
79
-
80
+ var checkboxRef = (0, _react.useRef)(null);
80
81
  var colorsTheme = (0, _useTheme["default"])();
81
82
  var backgroundType = (0, _react.useContext)(_BackgroundColorContext["default"]);
82
83
  var translatedLabels = (0, _useTranslatedLabels["default"])();
83
84
 
84
- var handlerCheckboxChange = function handlerCheckboxChange(checkboxValue) {
85
- if (checked === undefined) {
86
- var isChecked = checkboxValue.target.checked === undefined ? !innerChecked : checkboxValue.target.checked;
87
- setInnerChecked(isChecked);
88
-
89
- if (typeof onChange === "function") {
90
- onChange(isChecked);
91
- }
92
- } else {
93
- if (typeof onChange === "function") {
94
- onChange(!checked);
95
- }
96
- }
97
- };
85
+ var handleCheckboxChange = function handleCheckboxChange() {
86
+ var _checkboxRef$current;
98
87
 
99
- var handleLabelHover = function handleLabelHover() {
100
- setIsLabelHovered(!isLabelHovered);
88
+ document.activeElement !== (checkboxRef === null || checkboxRef === void 0 ? void 0 : checkboxRef.current) && (checkboxRef === null || checkboxRef === void 0 ? void 0 : (_checkboxRef$current = checkboxRef.current) === null || _checkboxRef$current === void 0 ? void 0 : _checkboxRef$current.focus());
89
+ var newChecked = checked !== null && checked !== void 0 ? checked : innerChecked;
90
+ checked !== null && checked !== void 0 ? checked : setInnerChecked(function (innerChecked) {
91
+ return !innerChecked;
92
+ });
93
+ onChange === null || onChange === void 0 ? void 0 : onChange(!newChecked);
101
94
  };
102
95
 
103
- var labelComponent = /*#__PURE__*/_react["default"].createElement(LabelContainer, {
104
- id: labelId,
105
- labelPosition: labelPosition,
106
- onClick: disabled === true ? function () {} : handlerCheckboxChange,
107
- disabled: disabled,
108
- className: "labelContainer",
109
- backgroundType: backgroundType,
110
- onMouseOver: handleLabelHover,
111
- onMouseOut: handleLabelHover
112
- }, labelPosition === "before" ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, label, " ", optional && /*#__PURE__*/_react["default"].createElement("span", null, translatedLabels.formFields.optionalLabel)) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, optional && /*#__PURE__*/_react["default"].createElement("span", null, "(Optional)"), " ", label));
96
+ var handleKeyboard = function handleKeyboard(event) {
97
+ switch (event.key) {
98
+ case " ":
99
+ event.preventDefault();
100
+ handleCheckboxChange();
101
+ }
102
+ };
113
103
 
114
104
  return /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
115
105
  theme: colorsTheme.checkbox
116
- }, /*#__PURE__*/_react["default"].createElement(CheckboxContainer, {
117
- id: name,
118
- brightness: _variables.componentTokens,
119
- label: label,
120
- labelPosition: labelPosition,
106
+ }, /*#__PURE__*/_react["default"].createElement(MainContainer, {
121
107
  disabled: disabled,
108
+ onClick: disabled ? undefined : handleCheckboxChange,
122
109
  margin: margin,
123
110
  size: size,
111
+ checked: checked !== null && checked !== void 0 ? checked : innerChecked,
124
112
  backgroundType: backgroundType,
125
- isLabelHovered: isLabelHovered
126
- }, label && labelPosition === "before" && labelComponent, /*#__PURE__*/_react["default"].createElement(_Checkbox["default"], {
113
+ ref: ref
114
+ }, label && labelPosition === "before" && /*#__PURE__*/_react["default"].createElement(LabelContainer, {
115
+ id: labelId,
116
+ disabled: disabled,
117
+ backgroundType: backgroundType
118
+ }, label, optional && " ".concat(translatedLabels.formFields.optionalLabel)), /*#__PURE__*/_react["default"].createElement(ValueInput, {
119
+ type: "checkbox",
127
120
  checked: checked !== null && checked !== void 0 ? checked : innerChecked,
128
- inputProps: {
129
- name: name,
130
- "aria-labelledby": labelId,
131
- role: "checkbox",
132
- "aria-checked": checked !== null && checked !== void 0 ? checked : innerChecked
133
- },
134
- onChange: handlerCheckboxChange,
121
+ name: name,
122
+ "aria-hidden": "true",
135
123
  value: value,
136
124
  disabled: disabled,
137
- disableRipple: true,
138
- className: "test",
139
- tabIndex: tabIndex
140
- }), /*#__PURE__*/_react["default"].createElement(CheckboxBlackBack, {
141
- labelPosition: labelPosition,
142
- disabled: disabled,
125
+ readOnly: true
126
+ }), /*#__PURE__*/_react["default"].createElement(CheckboxContainer, null, /*#__PURE__*/_react["default"].createElement(Checkbox, {
127
+ onKeyDown: handleKeyboard,
128
+ role: "checkbox",
129
+ tabIndex: disabled ? -1 : tabIndex,
130
+ "aria-checked": checked !== null && checked !== void 0 ? checked : innerChecked,
131
+ "aria-disabled": disabled,
132
+ "aria-required": !disabled && !optional,
133
+ "aria-labelledby": labelId,
134
+ backgroundType: backgroundType,
143
135
  checked: checked !== null && checked !== void 0 ? checked : innerChecked,
136
+ disabled: disabled,
137
+ ref: checkboxRef
138
+ }, (checked !== null && checked !== void 0 ? checked : innerChecked) && checkedIcon)), label && labelPosition === "after" && /*#__PURE__*/_react["default"].createElement(LabelContainer, {
139
+ id: labelId,
140
+ disabled: disabled,
144
141
  backgroundType: backgroundType
145
- }), label && labelPosition === "after" && labelComponent));
146
- };
142
+ }, optional && "".concat(translatedLabels.formFields.optionalLabel, " "), label)));
143
+ });
147
144
 
148
145
  var sizes = {
149
146
  small: "120px",
150
147
  medium: "240px",
151
148
  large: "480px",
152
149
  fillParent: "100%",
153
- fitContent: "unset"
150
+ fitContent: "fit-content"
154
151
  };
155
152
 
156
153
  var calculateWidth = function calculateWidth(margin, size) {
@@ -177,7 +174,7 @@ var getDisabledColor = function getDisabledColor(props, element) {
177
174
  }
178
175
  };
179
176
 
180
- var getNotDisabledColor = function getNotDisabledColor(props, element) {
177
+ var getEnabledColor = function getEnabledColor(props, element) {
181
178
  switch (element) {
182
179
  case "check":
183
180
  return props.backgroundType && props.backgroundType === "dark" ? props.theme.checkColorOnDark : props.theme.checkColor;
@@ -185,72 +182,68 @@ var getNotDisabledColor = function getNotDisabledColor(props, element) {
185
182
  case "background":
186
183
  return props.backgroundType && props.backgroundType === "dark" ? props.theme.backgroundColorCheckedOnDark : props.theme.backgroundColorChecked;
187
184
 
185
+ case "hoverBackground":
186
+ return props.backgroundType && props.backgroundType === "dark" ? props.theme.hoverBackgroundColorCheckedOnDark : props.theme.hoverBackgroundColorChecked;
187
+
188
188
  case "border":
189
189
  return props.backgroundType && props.backgroundType === "dark" ? props.theme.borderColorOnDark : props.theme.borderColor;
190
190
 
191
+ case "hoverBorder":
192
+ return props.backgroundType && props.backgroundType === "dark" ? props.theme.hoverBorderColorOnDark : props.theme.hoverBorderColor;
193
+
191
194
  case "label":
192
195
  return props.backgroundType && props.backgroundType === "dark" ? props.theme.fontColorOnDark : props.theme.fontColor;
193
196
  }
194
197
  };
195
198
 
196
- var LabelContainer = _styledComponents["default"].span(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n color: ", ";\n font-family: ", ";\n font-size: ", ";\n font-weight: ", ";\n cursor: ", ";\n"])), function (props) {
197
- return props.disabled ? getDisabledColor(props, "label") : getNotDisabledColor(props, "label");
199
+ var LabelContainer = _styledComponents["default"].span(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n color: ", ";\n font-family: ", ";\n font-size: ", ";\n font-weight: ", ";\n"])), function (props) {
200
+ return props.disabled ? getDisabledColor(props, "label") : getEnabledColor(props, "label");
198
201
  }, function (props) {
199
202
  return props.theme.fontFamily;
200
203
  }, function (props) {
201
204
  return props.theme.fontSize;
202
205
  }, function (props) {
203
206
  return props.theme.fontWeight;
204
- }, function (props) {
205
- return props.disabled ? "not-allowed" : "pointer";
206
207
  });
207
208
 
208
- var CheckboxContainer = _styledComponents["default"].span(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["\n margin: ", ";\n margin-top: ", ";\n margin-right: ", ";\n margin-bottom: ", ";\n margin-left: ", ";\n width: ", ";\n display: inline-flex;\n align-items: center;\n cursor: ", ";\n position: relative;\n .MuiCheckbox-colorSecondary {\n .MuiIconButton-label {\n & > .MuiSvgIcon-root {\n color: ", ";\n }\n }\n &.Mui-disabled {\n .MuiIconButton-label {\n & > .MuiSvgIcon-root {\n color: ", ";\n opacity: 0.34;\n }\n }\n }\n &.Mui-checked {\n .MuiIconButton-label {\n & > .MuiSvgIcon-root {\n color: ", ";\n }\n }\n\n &:hover {\n background-color: transparent;\n .MuiIconButton-label {\n & > .MuiSvgIcon-root {\n background-color: transparent;\n color: ", ";\n }\n }\n }\n }\n .MuiIconButton-label {\n & > .MuiSvgIcon-root {\n width: 24px;\n height: 24px;\n }\n }\n }\n\n .MuiIconButton-colorSecondary {\n &:hover {\n background-color: transparent;\n }\n }\n .MuiButtonBase-root {\n &:hover {\n .MuiIconButton-label {\n & > .MuiSvgIcon-root {\n color: ", ";\n }\n }\n }\n\n &.Mui-focusVisible {\n .MuiIconButton-label {\n border-radius: 2px;\n outline: 2px solid\n ", ";\n outline-offset: -1px;\n }\n }\n z-index: 1;\n margin-left: ", ";\n margin-right: ", ";\n padding: 0px;\n left: ", ";\n right: ", ";\n }\n"])), function (props) {
209
- return props.margin && (0, _typeof2["default"])(props.margin) !== "object" ? _variables.spaces[props.margin] : "0px";
209
+ var ValueInput = _styledComponents["default"].input(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["\n display: none;\n"])));
210
+
211
+ var CheckboxContainer = _styledComponents["default"].span(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n align-items: center;\n justify-content: center;\n height: 24px;\n width: 24px;\n"])));
212
+
213
+ var Checkbox = _styledComponents["default"].span(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["\n position: relative;\n box-sizing: border-box;\n display: flex;\n align-items: center;\n justify-content: center;\n height: 18px;\n width: 18px;\n border: 2px solid\n ", ";\n border-radius: 2px;\n background-color: ", ";\n color: ", ";\n\n &:focus {\n outline: 2px solid\n ", ";\n outline-offset: 2px;\n }\n svg {\n position: absolute;\n width: 22px;\n height: 22px;\n }\n ", "\n"])), function (props) {
214
+ return props.disabled ? getDisabledColor(props, "border") : getEnabledColor(props, "border");
210
215
  }, function (props) {
211
- return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.top ? _variables.spaces[props.margin.top] : "";
216
+ return props.checked ? props.disabled ? getDisabledColor(props, "check") : getEnabledColor(props, "check") : "transparent";
212
217
  }, function (props) {
213
- return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.right ? _variables.spaces[props.margin.right] : "";
218
+ return props.disabled ? getDisabledColor(props, "background") : getEnabledColor(props, "background");
214
219
  }, function (props) {
215
- return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.bottom ? _variables.spaces[props.margin.bottom] : "";
220
+ return props.backgroundType === "dark" ? props.theme.focusColorOnDark : props.theme.focusColor;
216
221
  }, function (props) {
217
- return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.left ? _variables.spaces[props.margin.left] : "";
222
+ return props.disabled && "pointer-events: none;";
223
+ });
224
+
225
+ var MainContainer = _styledComponents["default"].div(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2["default"])(["\n display: inline-flex;\n align-items: center;\n gap: ", ";\n width: ", ";\n margin: ", ";\n margin-top: ", ";\n margin-right: ", ";\n margin-bottom: ", ";\n margin-left: ", ";\n\n cursor: ", ";\n\n &:hover ", " {\n border: 2px solid\n ", ";\n background-color: ", ";\n color: ", ";\n }\n"])), function (props) {
226
+ return props.theme.checkLabelSpacing;
218
227
  }, function (props) {
219
228
  return calculateWidth(props.margin, props.size);
220
229
  }, function (props) {
221
- return props.disabled ? "not-allowed" : "pointer";
222
- }, function (props) {
223
- return props.isLabelHovered ? props.backgroundType === "dark" ? props.theme.hoverBorderColorOnDark : props.theme.hoverBorderColor : getNotDisabledColor(props, "border");
224
- }, function (props) {
225
- return getDisabledColor(props, "border");
226
- }, function (props) {
227
- return props.disabled ? getDisabledColor(props, "background") : getNotDisabledColor(props, "background");
228
- }, function (props) {
229
- return props.backgroundType === "dark" ? props.theme.hoverBackgroundColorCheckedOnDark : props.theme.hoverBackgroundColorChecked;
230
- }, function (props) {
231
- return props.backgroundType === "dark" ? props.theme.hoverBorderColorOnDark : props.theme.hoverBorderColor;
232
- }, function (props) {
233
- return props.backgroundType === "dark" ? props.theme.focusColorOnDark : props.theme.focusColor;
234
- }, function (props) {
235
- return props.labelPosition === "before" && props.label ? props.theme.checkLabelSpacing : "0";
230
+ return props.margin && (0, _typeof2["default"])(props.margin) !== "object" ? _variables.spaces[props.margin] : "0px";
236
231
  }, function (props) {
237
- return props.labelPosition === "after" && props.label ? props.theme.checkLabelSpacing : "0";
232
+ return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.top ? _variables.spaces[props.margin.top] : "";
238
233
  }, function (props) {
239
- return props.labelPosition === "before" ? "unset" : "1px";
234
+ return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.right ? _variables.spaces[props.margin.right] : "";
240
235
  }, function (props) {
241
- return props.labelPosition === "before" ? "1px" : "unset";
242
- });
243
-
244
- var CheckboxBlackBack = _styledComponents["default"].span(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2["default"])(["\n background-color: ", ";\n width: 16px;\n height: 16px;\n position: absolute;\n left: ", ";\n right: ", ";\n z-index: 0;\n margin-left: ", ";\n margin-right: ", ";\n"])), function (props) {
245
- return !props.checked ? "transparent" : props.disabled ? getDisabledColor(props, "check") : getNotDisabledColor(props, "check");
236
+ return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.bottom ? _variables.spaces[props.margin.bottom] : "";
246
237
  }, function (props) {
247
- return props.labelPosition === "before" ? "unset" : "5px";
238
+ return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.left ? _variables.spaces[props.margin.left] : "";
248
239
  }, function (props) {
249
- return props.labelPosition === "before" ? "5px" : "unset";
240
+ return props.disabled ? "not-allowed" : "pointer";
241
+ }, Checkbox, function (props) {
242
+ return props.disabled ? getDisabledColor(props, "border") : getEnabledColor(props, "hoverBorder");
250
243
  }, function (props) {
251
- return props.labelPosition === "after" ? "0px" : "";
244
+ return props.checked ? props.disabled ? getDisabledColor(props, "check") : getEnabledColor(props, "check") : "transparent";
252
245
  }, function (props) {
253
- return props.labelPosition === "before" ? "0px" : "";
246
+ return props.disabled ? getDisabledColor(props, "background") : getEnabledColor(props, "hoverBackground");
254
247
  });
255
248
 
256
249
  var _default = DxcCheckbox;