@dxc-technology/halstack-react 0.0.0-e628009 → 0.0.0-e690193

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 (136) hide show
  1. package/README.md +27 -47
  2. package/dist/index.d.mts +3923 -0
  3. package/dist/index.d.ts +3923 -0
  4. package/dist/index.js +14133 -0
  5. package/dist/index.mjs +14045 -0
  6. package/package.json +92 -68
  7. package/babel.config.js +0 -8
  8. package/dist/BackgroundColorContext.js +0 -46
  9. package/dist/ThemeContext.js +0 -248
  10. package/dist/V3Textarea/V3Textarea.js +0 -264
  11. package/dist/accordion/Accordion.js +0 -353
  12. package/dist/accordion-group/AccordionGroup.js +0 -186
  13. package/dist/alert/Alert.js +0 -403
  14. package/dist/alert/index.d.ts +0 -51
  15. package/dist/badge/Badge.js +0 -63
  16. package/dist/box/Box.js +0 -156
  17. package/dist/button/Button.js +0 -238
  18. package/dist/card/Card.js +0 -254
  19. package/dist/checkbox/Checkbox.js +0 -300
  20. package/dist/chip/Chip.js +0 -265
  21. package/dist/common/OpenSans.css +0 -81
  22. package/dist/common/RequiredComponent.js +0 -40
  23. package/dist/common/fonts/OpenSans-Bold.ttf +0 -0
  24. package/dist/common/fonts/OpenSans-BoldItalic.ttf +0 -0
  25. package/dist/common/fonts/OpenSans-ExtraBold.ttf +0 -0
  26. package/dist/common/fonts/OpenSans-ExtraBoldItalic.ttf +0 -0
  27. package/dist/common/fonts/OpenSans-Italic.ttf +0 -0
  28. package/dist/common/fonts/OpenSans-Light.ttf +0 -0
  29. package/dist/common/fonts/OpenSans-LightItalic.ttf +0 -0
  30. package/dist/common/fonts/OpenSans-Regular.ttf +0 -0
  31. package/dist/common/fonts/OpenSans-SemiBold.ttf +0 -0
  32. package/dist/common/fonts/OpenSans-SemiBoldItalic.ttf +0 -0
  33. package/dist/common/utils.js +0 -22
  34. package/dist/common/variables.js +0 -1569
  35. package/dist/date/Date.js +0 -379
  36. package/dist/date-input/DateInput.js +0 -400
  37. package/dist/date-input/index.d.ts +0 -95
  38. package/dist/dialog/Dialog.js +0 -218
  39. package/dist/dropdown/Dropdown.js +0 -544
  40. package/dist/file-input/FileInput.js +0 -644
  41. package/dist/file-input/FileItem.js +0 -280
  42. package/dist/file-input/index.d.ts +0 -81
  43. package/dist/footer/Footer.js +0 -421
  44. package/dist/footer/Icons.js +0 -77
  45. package/dist/header/Header.js +0 -434
  46. package/dist/header/Icons.js +0 -59
  47. package/dist/heading/Heading.js +0 -230
  48. package/dist/input-text/Icons.js +0 -22
  49. package/dist/input-text/InputText.js +0 -705
  50. package/dist/layout/ApplicationLayout.js +0 -327
  51. package/dist/layout/Icons.js +0 -55
  52. package/dist/link/Link.js +0 -237
  53. package/dist/main.d.ts +0 -8
  54. package/dist/main.js +0 -367
  55. package/dist/new-select/NewSelect.js +0 -836
  56. package/dist/new-select/index.d.ts +0 -53
  57. package/dist/number-input/NumberInput.js +0 -136
  58. package/dist/number-input/NumberInputContext.js +0 -16
  59. package/dist/number-input/index.d.ts +0 -113
  60. package/dist/paginator/Icons.js +0 -66
  61. package/dist/paginator/Paginator.js +0 -283
  62. package/dist/password-input/PasswordInput.js +0 -198
  63. package/dist/password-input/index.d.ts +0 -94
  64. package/dist/progress-bar/ProgressBar.js +0 -242
  65. package/dist/radio/Radio.js +0 -209
  66. package/dist/resultsetTable/ResultsetTable.js +0 -358
  67. package/dist/select/Select.js +0 -549
  68. package/dist/sidenav/Sidenav.js +0 -179
  69. package/dist/slider/Slider.js +0 -404
  70. package/dist/spinner/Spinner.js +0 -381
  71. package/dist/switch/Switch.js +0 -222
  72. package/dist/table/Table.js +0 -132
  73. package/dist/tabs/Tabs.js +0 -343
  74. package/dist/tabs-for-sections/TabsForSections.js +0 -92
  75. package/dist/tag/Tag.js +0 -282
  76. package/dist/text-input/TextInput.js +0 -971
  77. package/dist/text-input/index.d.ts +0 -135
  78. package/dist/textarea/Textarea.js +0 -369
  79. package/dist/textarea/index.d.ts +0 -117
  80. package/dist/toggle/Toggle.js +0 -220
  81. package/dist/toggle-group/ToggleGroup.js +0 -327
  82. package/dist/upload/Upload.js +0 -205
  83. package/dist/upload/buttons-upload/ButtonsUpload.js +0 -135
  84. package/dist/upload/buttons-upload/Icons.js +0 -40
  85. package/dist/upload/dragAndDropArea/DragAndDropArea.js +0 -329
  86. package/dist/upload/dragAndDropArea/Icons.js +0 -39
  87. package/dist/upload/file-upload/FileToUpload.js +0 -189
  88. package/dist/upload/file-upload/Icons.js +0 -66
  89. package/dist/upload/files-upload/FilesToUpload.js +0 -123
  90. package/dist/upload/transaction/Icons.js +0 -160
  91. package/dist/upload/transaction/Transaction.js +0 -148
  92. package/dist/upload/transactions/Transactions.js +0 -138
  93. package/dist/useTheme.js +0 -22
  94. package/dist/wizard/Icons.js +0 -65
  95. package/dist/wizard/Wizard.js +0 -405
  96. package/test/Accordion.test.js +0 -33
  97. package/test/AccordionGroup.test.js +0 -125
  98. package/test/Alert.test.js +0 -53
  99. package/test/Box.test.js +0 -10
  100. package/test/Button.test.js +0 -18
  101. package/test/Card.test.js +0 -30
  102. package/test/Checkbox.test.js +0 -45
  103. package/test/Chip.test.js +0 -25
  104. package/test/Date.test.js +0 -397
  105. package/test/DateInput.test.js +0 -242
  106. package/test/Dialog.test.js +0 -23
  107. package/test/Dropdown.test.js +0 -145
  108. package/test/FileInput.test.js +0 -201
  109. package/test/Footer.test.js +0 -94
  110. package/test/Header.test.js +0 -34
  111. package/test/Heading.test.js +0 -83
  112. package/test/InputText.test.js +0 -248
  113. package/test/Link.test.js +0 -43
  114. package/test/NumberInput.test.js +0 -259
  115. package/test/Paginator.test.js +0 -177
  116. package/test/PasswordInput.test.js +0 -83
  117. package/test/ProgressBar.test.js +0 -35
  118. package/test/Radio.test.js +0 -37
  119. package/test/ResultsetTable.test.js +0 -329
  120. package/test/Select.test.js +0 -212
  121. package/test/Sidenav.test.js +0 -45
  122. package/test/Slider.test.js +0 -74
  123. package/test/Spinner.test.js +0 -32
  124. package/test/Switch.test.js +0 -45
  125. package/test/Table.test.js +0 -36
  126. package/test/Tabs.test.js +0 -109
  127. package/test/TabsForSections.test.js +0 -34
  128. package/test/Tag.test.js +0 -32
  129. package/test/TextInput.test.js +0 -732
  130. package/test/Textarea.test.js +0 -193
  131. package/test/ToggleGroup.test.js +0 -85
  132. package/test/Upload.test.js +0 -60
  133. package/test/V3TextArea.test.js +0 -51
  134. package/test/Wizard.test.js +0 -130
  135. package/test/mocks/pngMock.js +0 -1
  136. package/test/mocks/svgMock.js +0 -1
@@ -1,220 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
-
5
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
-
7
- Object.defineProperty(exports, "__esModule", {
8
- value: true
9
- });
10
- exports["default"] = void 0;
11
-
12
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
-
14
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
15
-
16
- var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
17
-
18
- var _react = _interopRequireDefault(require("react"));
19
-
20
- var _lab = require("@material-ui/lab");
21
-
22
- var _propTypes = _interopRequireDefault(require("prop-types"));
23
-
24
- var _styledComponents = _interopRequireWildcard(require("styled-components"));
25
-
26
- var _utils = require("../common/utils.js");
27
-
28
- var _useTheme = _interopRequireDefault(require("../useTheme.js"));
29
-
30
- function _templateObject4() {
31
- var data = (0, _taggedTemplateLiteral2["default"])([""]);
32
-
33
- _templateObject4 = function _templateObject4() {
34
- return data;
35
- };
36
-
37
- return data;
38
- }
39
-
40
- function _templateObject3() {
41
- var data = (0, _taggedTemplateLiteral2["default"])(["\n width: 20px;\n height: 20px;\n line-height: 1;\n margin-right: ", ";\n margin-left: ", ";\n"]);
42
-
43
- _templateObject3 = function _templateObject3() {
44
- return data;
45
- };
46
-
47
- return data;
48
- }
49
-
50
- function _templateObject2() {
51
- var data = (0, _taggedTemplateLiteral2["default"])(["\n line-height: 1;\n display: flex;\n align-items: center;\n flex-direction: ", ";\n"]);
52
-
53
- _templateObject2 = function _templateObject2() {
54
- return data;
55
- };
56
-
57
- return data;
58
- }
59
-
60
- function _templateObject() {
61
- var data = (0, _taggedTemplateLiteral2["default"])(["\n & {\n margin: ", ";\n margin-top: ", ";\n margin-right: ", ";\n margin-bottom: ", ";\n margin-left: ", ";\n\n opacity: ", ";\n cursor: ", ";\n display: inline-block;\n width: ", ";\n }\n\n .MuiToggleButton-label {\n font-size: 14px;\n font-family: ", ";\n color: ", ";\n }\n .MuiButtonBase-root {\n width: ", ";\n min-height: ", ";\n background-color: ", ";\n &:hover {\n background-color: ", ";\n .MuiToggleButton-label {\n color: ", ";\n }\n }\n }\n\n .MuiToggleButton-root {\n min-width: 42px;\n height: 43px;\n border: ", ";\n\n border-radius: 4px !important;\n }\n\n .MuiToggleButton-root.Mui-selected {\n background-color: ", ";\n &:hover {\n background-color: ", ";\n .MuiToggleButton-label {\n color: ", ";\n }\n }\n }\n\n .MuiToggleButton-root:last-child,\n .MuiToggleButton-root:first-child,\n .MuiToggleButton-root:not(:first-child) {\n padding: ", ";\n }\n\n .MuiTouchRipple-child {\n background-color: ", ";\n }\n"]);
62
-
63
- _templateObject = function _templateObject() {
64
- return data;
65
- };
66
-
67
- return data;
68
- }
69
-
70
- var DxcToggle = function DxcToggle(_ref) {
71
- var _ref$label = _ref.label,
72
- label = _ref$label === void 0 ? "" : _ref$label,
73
- _ref$iconSrc = _ref.iconSrc,
74
- iconSrc = _ref$iconSrc === void 0 ? "" : _ref$iconSrc,
75
- _ref$mode = _ref.mode,
76
- mode = _ref$mode === void 0 ? "basic" : _ref$mode,
77
- _ref$theme = _ref.theme,
78
- theme = _ref$theme === void 0 ? "light" : _ref$theme,
79
- _ref$disableRipple = _ref.disableRipple,
80
- disableRipple = _ref$disableRipple === void 0 ? false : _ref$disableRipple,
81
- _ref$iconPosition = _ref.iconPosition,
82
- iconPosition = _ref$iconPosition === void 0 ? "before" : _ref$iconPosition,
83
- _ref$disabled = _ref.disabled,
84
- disabled = _ref$disabled === void 0 ? false : _ref$disabled,
85
- onClick = _ref.onClick,
86
- _ref$selected = _ref.selected,
87
- selected = _ref$selected === void 0 ? false : _ref$selected,
88
- margin = _ref.margin,
89
- _ref$size = _ref.size,
90
- size = _ref$size === void 0 ? "fitContent" : _ref$size;
91
- var colorsTheme = (0, _useTheme["default"])();
92
-
93
- var handlerToggleClick = function handlerToggleClick() {
94
- if (!disabled && typeof onClick === "function") {
95
- onClick(!selected);
96
- }
97
- };
98
-
99
- return _react["default"].createElement(_styledComponents.ThemeProvider, {
100
- theme: colorsTheme
101
- }, _react["default"].createElement(DxcToggleContainer, {
102
- margin: margin,
103
- brightness: theme,
104
- disabled: disabled,
105
- disableRipple: disableRipple,
106
- selected: selected,
107
- label: label,
108
- mode: mode,
109
- iconPosition: iconPosition,
110
- value: true,
111
- size: size,
112
- onClick: handlerToggleClick
113
- }, _react["default"].createElement(_lab.ToggleButton, {
114
- disabled: disabled,
115
- disableRipple: disableRipple,
116
- selected: selected,
117
- label: label,
118
- value: true
119
- }, _react["default"].createElement(ContentContainer, {
120
- iconPosition: iconPosition,
121
- label: label,
122
- iconSrc: iconSrc
123
- }, iconSrc !== "" && _react["default"].createElement(IconContainer, {
124
- iconPosition: iconPosition,
125
- label: label,
126
- src: iconSrc
127
- }), label !== "" && _react["default"].createElement(LabelContainer, null, label)))));
128
- };
129
-
130
- var sizes = {
131
- small: "42px",
132
- medium: "120px",
133
- large: "240px",
134
- fillParent: "100%",
135
- fitContent: "unset"
136
- };
137
-
138
- var calculateWidth = function calculateWidth(margin, size) {
139
- if (size === "fillParent") {
140
- return "calc(".concat(sizes[size], " - ").concat((0, _utils.getMargin)(margin, "left"), " - ").concat((0, _utils.getMargin)(margin, "right"), ")");
141
- }
142
-
143
- return sizes[size];
144
- };
145
-
146
- var DxcToggleContainer = _styledComponents["default"].div(_templateObject(), function (props) {
147
- return props.margin && (0, _typeof2["default"])(props.margin) !== "object" ? spaces[props.margin] : "0px";
148
- }, function (props) {
149
- return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.top ? spaces[props.margin.top] : "";
150
- }, function (props) {
151
- return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.right ? spaces[props.margin.right] : "";
152
- }, function (props) {
153
- return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.bottom ? spaces[props.margin.bottom] : "";
154
- }, function (props) {
155
- return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.left ? spaces[props.margin.left] : "";
156
- }, function (props) {
157
- return props.disabled ? "0.5" : "1";
158
- }, function (props) {
159
- return props.disabled ? "not-allowed" : "pointer";
160
- }, function (props) {
161
- return calculateWidth(props.margin, props.size);
162
- }, function (props) {
163
- return props.theme.fontFamily;
164
- }, function (props) {
165
- return props.brightness === "dark" && props.mode === "outlined" ? props.theme.white : props.theme.black;
166
- }, function (props) {
167
- return calculateWidth(props.margin, props.size);
168
- }, function (props) {
169
- return props.mode === "outlined" ? "41px" : "43px";
170
- }, function (props) {
171
- return props.mode !== "outlined" ? props.theme.darkWhite : "transparent";
172
- }, function (props) {
173
- return props.mode === "basic" ? props.theme.lightGrey : props.brightness === "dark" ? props.theme.darkGrey : props.theme.darkWhite;
174
- }, function (props) {
175
- return props.brightness === "dark" && props.mode === "outlined" ? props.theme.white : props.theme.black;
176
- }, function (props) {
177
- return props.mode === "basic" ? "none !important" : props.brightness === "dark" && !props.selected ? "2px solid ".concat(props.theme.white, " !important") : props.brightness === "dark" && props.selected ? "2px solid ".concat(props.theme.yellow, " !important") : "2px solid ".concat(props.theme.black, " !important");
178
- }, function (props) {
179
- return props.mode === "outlined" ? props.brightness === "light" ? props.theme.darkWhite : "transparent" : props.theme.yellow;
180
- }, function (props) {
181
- return props.mode === "basic" && props.brightness === "light" ? props.theme.black : props.mode === "basic" && props.brightness === "dark" ? props.theme.lightBlack : props.brightness === "light" ? props.theme.lightGrey : props.theme.darkGrey;
182
- }, function (props) {
183
- return props.mode === "basic" ? props.theme.yellow : props.brightness === "dark" && props.mode === "outlined" ? props.theme.white : props.theme.black;
184
- }, function (props) {
185
- return props.label !== "" && props.size !== "small" ? props.mode === "outlined" ? "8px 30px " : "12px 30px" : props.mode === "outlined" ? "8px 10px " : "12px 10px";
186
- }, function (props) {
187
- return props.mode === "basic" ? props.selected === false ? props.theme.yellow : props.theme.darkWhite : props.selected === false ? props.theme.lightGrey : props.theme.white;
188
- });
189
-
190
- var ContentContainer = _styledComponents["default"].span(_templateObject2(), function (props) {
191
- return props.iconPosition === "after" ? "row-reverse" : "row";
192
- });
193
-
194
- var IconContainer = _styledComponents["default"].img(_templateObject3(), function (props) {
195
- return props.label !== "" && props.iconPosition === "before" ? "10px" : "";
196
- }, function (props) {
197
- return props.label !== "" && props.iconPosition === "after" ? "10px" : "";
198
- });
199
-
200
- var LabelContainer = _styledComponents["default"].span(_templateObject4());
201
-
202
- DxcToggle.propTypes = {
203
- size: _propTypes["default"].oneOf((0, _toConsumableArray2["default"])(Object.keys(sizes))),
204
- theme: _propTypes["default"].oneOf(["light", "dark", ""]),
205
- mode: _propTypes["default"].oneOf(["basic", "outlined", ""]),
206
- iconPosition: _propTypes["default"].oneOf(["before", "after", ""]),
207
- iconSrc: _propTypes["default"].string,
208
- selected: _propTypes["default"].bool,
209
- disabled: _propTypes["default"].bool,
210
- disableRipple: _propTypes["default"].bool,
211
- onClick: _propTypes["default"].func,
212
- margin: _propTypes["default"].oneOfType([_propTypes["default"].shape({
213
- top: _propTypes["default"].oneOf(Object.keys(spaces)),
214
- bottom: _propTypes["default"].oneOf(Object.keys(spaces)),
215
- left: _propTypes["default"].oneOf(Object.keys(spaces)),
216
- right: _propTypes["default"].oneOf(Object.keys(spaces))
217
- }), _propTypes["default"].oneOf((0, _toConsumableArray2["default"])(Object.keys(spaces)))])
218
- };
219
- var _default = DxcToggle;
220
- exports["default"] = _default;
@@ -1,327 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
-
5
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
-
7
- Object.defineProperty(exports, "__esModule", {
8
- value: true
9
- });
10
- exports["default"] = void 0;
11
-
12
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
-
14
- var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
15
-
16
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
17
-
18
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
19
-
20
- var _react = _interopRequireWildcard(require("react"));
21
-
22
- var _styledComponents = _interopRequireWildcard(require("styled-components"));
23
-
24
- var _uuid = require("uuid");
25
-
26
- var _propTypes = _interopRequireDefault(require("prop-types"));
27
-
28
- var _variables = require("../common/variables.js");
29
-
30
- var _useTheme = _interopRequireDefault(require("../useTheme.js"));
31
-
32
- function _templateObject9() {
33
- var data = (0, _taggedTemplateLiteral2["default"])(["\n margin-right: ", ";\n height: 24px;\n width: 24px;\n overflow: hidden;\n display: flex;\n img,\n svg {\n height: 100%;\n width: 100%;\n }\n"]);
34
-
35
- _templateObject9 = function _templateObject9() {
36
- return data;
37
- };
38
-
39
- return data;
40
- }
41
-
42
- function _templateObject8() {
43
- var data = (0, _taggedTemplateLiteral2["default"])(["\n height: 24px;\n width: 24px;\n margin-right: ", ";\n"]);
44
-
45
- _templateObject8 = function _templateObject8() {
46
- return data;
47
- };
48
-
49
- return data;
50
- }
51
-
52
- function _templateObject7() {
53
- var data = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-direction: row;\n"]);
54
-
55
- _templateObject7 = function _templateObject7() {
56
- return data;
57
- };
58
-
59
- return data;
60
- }
61
-
62
- function _templateObject6() {
63
- var data = (0, _taggedTemplateLiteral2["default"])(["\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n"]);
64
-
65
- _templateObject6 = function _templateObject6() {
66
- return data;
67
- };
68
-
69
- return data;
70
- }
71
-
72
- function _templateObject5() {
73
- var data = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-direction: column;\n justify-content: center;\n margin-right: ", ";\n\n ", "\n"]);
74
-
75
- _templateObject5 = function _templateObject5() {
76
- return data;
77
- };
78
-
79
- return data;
80
- }
81
-
82
- function _templateObject4() {
83
- var data = (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"]);
84
-
85
- _templateObject4 = function _templateObject4() {
86
- return data;
87
- };
88
-
89
- return data;
90
- }
91
-
92
- function _templateObject3() {
93
- var data = (0, _taggedTemplateLiteral2["default"])(["\n display: inline-flex;\n flex-direction: column;\n margin: ", ";\n margin-top: ", ";\n margin-right: ", ";\n margin-bottom: ", ";\n margin-left: ", ";\n"]);
94
-
95
- _templateObject3 = function _templateObject3() {
96
- return data;
97
- };
98
-
99
- return data;
100
- }
101
-
102
- function _templateObject2() {
103
- var data = (0, _taggedTemplateLiteral2["default"])(["\n color: ", ";\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n line-height: ", ";\n"]);
104
-
105
- _templateObject2 = function _templateObject2() {
106
- return data;
107
- };
108
-
109
- return data;
110
- }
111
-
112
- function _templateObject() {
113
- var data = (0, _taggedTemplateLiteral2["default"])(["\n color: ", ";\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n line-height: ", ";\n"]);
114
-
115
- _templateObject = function _templateObject() {
116
- return data;
117
- };
118
-
119
- return data;
120
- }
121
-
122
- var DxcToggleGroup = function DxcToggleGroup(_ref) {
123
- var label = _ref.label,
124
- helperText = _ref.helperText,
125
- value = _ref.value,
126
- onChange = _ref.onChange,
127
- _ref$disabled = _ref.disabled,
128
- disabled = _ref$disabled === void 0 ? false : _ref$disabled,
129
- _ref$options = _ref.options,
130
- options = _ref$options === void 0 ? [] : _ref$options,
131
- margin = _ref.margin,
132
- _ref$multiple = _ref.multiple,
133
- multiple = _ref$multiple === void 0 ? false : _ref$multiple,
134
- _ref$tabIndex = _ref.tabIndex,
135
- tabIndex = _ref$tabIndex === void 0 ? 0 : _ref$tabIndex;
136
- var colorsTheme = (0, _useTheme["default"])();
137
-
138
- var _useState = (0, _react.useState)(multiple ? [] : null),
139
- _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
140
- selectedValue = _useState2[0],
141
- setSelectedValue = _useState2[1];
142
-
143
- var _useState3 = (0, _react.useState)("toggle-group-".concat((0, _uuid.v4)())),
144
- _useState4 = (0, _slicedToArray2["default"])(_useState3, 1),
145
- toggleGroupId = _useState4[0];
146
-
147
- var handleToggleChange = function handleToggleChange(selectedOption) {
148
- var newSelectedOptions;
149
-
150
- if (value == null) {
151
- if (multiple) {
152
- newSelectedOptions = selectedValue.map(function (value) {
153
- return value;
154
- });
155
-
156
- if (newSelectedOptions.includes(selectedOption)) {
157
- var index = newSelectedOptions.indexOf(selectedOption);
158
- newSelectedOptions.splice(index, 1);
159
- } else {
160
- newSelectedOptions.push(selectedOption);
161
- }
162
-
163
- setSelectedValue(newSelectedOptions);
164
- } else setSelectedValue(selectedOption === selectedValue ? null : selectedOption);
165
- } else if (multiple) {
166
- newSelectedOptions = value.map(function (v) {
167
- return v;
168
- });
169
-
170
- if (newSelectedOptions.includes(selectedOption)) {
171
- var _index = newSelectedOptions.indexOf(selectedOption);
172
-
173
- newSelectedOptions.splice(_index, 1);
174
- } else newSelectedOptions.push(selectedOption);
175
- }
176
-
177
- typeof onChange === "function" && onChange(multiple ? newSelectedOptions : selectedOption);
178
- };
179
-
180
- var handleKeyPress = function handleKeyPress(event, optionValue) {
181
- event.preventDefault();
182
- if (!disabled && (event.nativeEvent.code === "Enter" || event.nativeEvent.code === "Space")) handleToggleChange(optionValue);
183
- };
184
-
185
- return _react["default"].createElement(_styledComponents.ThemeProvider, {
186
- theme: colorsTheme.toggleGroup
187
- }, _react["default"].createElement(ToggleGroup, {
188
- margin: margin,
189
- disabled: disabled
190
- }, _react["default"].createElement(Label, {
191
- htmlFor: toggleGroupId,
192
- disabled: disabled
193
- }, label), _react["default"].createElement(HelperText, {
194
- disabled: disabled
195
- }, helperText), _react["default"].createElement(OptionsContainer, {
196
- id: toggleGroupId,
197
- role: multiple ? "group" : "radiogroup"
198
- }, options.map(function (option, i) {
199
- return _react["default"].createElement(ToggleContainer, {
200
- selected: multiple ? value ? value.includes(option.value) : selectedValue.includes(option.value) : value ? option.value === value : option.value === selectedValue,
201
- role: multiple ? "switch" : "radio",
202
- "aria-checked": multiple ? value ? value.includes(option.value) : selectedValue.includes(option.value) : value ? option.value === value : option.value === selectedValue,
203
- tabIndex: !disabled ? tabIndex : -1,
204
- onClick: function onClick() {
205
- return !disabled && handleToggleChange(option.value);
206
- },
207
- isFirst: i === 0,
208
- isLast: i === options.length - 1,
209
- isIcon: option.iconSrc || option.icon,
210
- optionLabel: option.label,
211
- disabled: disabled,
212
- onKeyPress: function onKeyPress(event) {
213
- handleKeyPress(event, option.value);
214
- },
215
- key: "toggle-".concat(i, "-").concat(option.label)
216
- }, _react["default"].createElement(OptionContent, null, option.icon && _react["default"].createElement(IconContainer, {
217
- optionLabel: option.label
218
- }, (0, _typeof2["default"])(option.icon) === "object" ? option.icon : _react["default"].createElement(option.icon)), option.iconSrc && _react["default"].createElement(Icon, {
219
- src: option.iconSrc,
220
- optionLabel: option.label
221
- }), option.label && _react["default"].createElement(LabelContainer, null, option.label)));
222
- }))));
223
- };
224
-
225
- var Label = _styledComponents["default"].label(_templateObject(), function (props) {
226
- return props.disabled ? props.theme.disabledLabelFontColor : props.theme.labelFontColor;
227
- }, function (props) {
228
- return props.theme.labelFontFamily;
229
- }, function (props) {
230
- return props.theme.labelFontSize;
231
- }, function (props) {
232
- return props.theme.labelFontStyle;
233
- }, function (props) {
234
- return props.theme.labelFontWeight;
235
- }, function (props) {
236
- return props.theme.labelLineHeight;
237
- });
238
-
239
- var HelperText = _styledComponents["default"].span(_templateObject2(), function (props) {
240
- return props.disabled ? props.theme.disabledHelperTextFontcolor : props.theme.helperTextFontColor;
241
- }, function (props) {
242
- return props.theme.helperTextFontFamily;
243
- }, function (props) {
244
- return props.theme.helperTextFontSize;
245
- }, function (props) {
246
- return props.theme.helperTextFontStyle;
247
- }, function (props) {
248
- return props.theme.helperTextFontWeight;
249
- }, function (props) {
250
- return props.theme.helperTextLineHeight;
251
- });
252
-
253
- var ToggleGroup = _styledComponents["default"].div(_templateObject3(), function (props) {
254
- return props.margin && (0, _typeof2["default"])(props.margin) !== "object" ? _variables.spaces[props.margin] : "0px";
255
- }, function (props) {
256
- return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.top ? _variables.spaces[props.margin.top] : "";
257
- }, function (props) {
258
- return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.right ? _variables.spaces[props.margin.right] : "";
259
- }, function (props) {
260
- return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.bottom ? _variables.spaces[props.margin.bottom] : "";
261
- }, function (props) {
262
- return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.left ? _variables.spaces[props.margin.left] : "";
263
- });
264
-
265
- var OptionsContainer = _styledComponents["default"].div(_templateObject4(), function (props) {
266
- return props.theme.containerBorderThickness;
267
- }, function (props) {
268
- return props.theme.containerBorderStyle;
269
- }, function (props) {
270
- return props.theme.containerBorderRadius;
271
- }, function (props) {
272
- return props.theme.containerBorderColor;
273
- }, function (props) {
274
- return props.theme.containerBackgroundColor;
275
- }, function (props) {
276
- return props.theme.containerMarginTop;
277
- });
278
-
279
- var ToggleContainer = _styledComponents["default"].div(_templateObject5(), function (props) {
280
- return !props.isLast && "4px";
281
- }, function (props) {
282
- return "\n background-color: ".concat(props.selected ? props.disabled ? props.theme.selectedDisabledBackgroundColor : props.theme.selectedBackgroundColor : props.disabled ? props.theme.unselectedDisabledBackgroundColor : props.theme.unselectedBackgroundColor, ";\n border-width: ").concat(props.theme.optionBorderThickness, ";\n border-style: ").concat(props.theme.optionBorderStyle, ";\n border-radius: ").concat(props.theme.optionBorderRadius, ";\n padding-left: ").concat(props.optionLabel && props.isIcon || props.optionLabel && !props.isIcon ? props.theme.labelPaddingLeft : props.theme.iconPaddingLeft, ";\n padding-right: ").concat(props.optionLabel && props.isIcon || props.optionLabel && !props.isIcon ? props.theme.labelPaddingRight : props.theme.iconPaddingRight, ";\n ").concat(!props.disabled ? ":hover {\n background-color: ".concat(props.selected ? props.theme.selectedHoverBackgroundColor : props.theme.unselectedHoverBackgroundColor, ";\n }\n :active {\n background-color: ").concat(props.selected ? props.theme.selectedActiveBackgroundColor : props.theme.unselectedActiveBackgroundColor, ";\n color: #ffffff;\n } \n :focus {\n border-color: transparent;\n box-shadow: 0 0 0 ").concat(props.theme.optionFocusBorderThickness, " ").concat(props.backgroundType === "dark" ? props.theme.focusColorOnDark : props.theme.focusColor, ";\n }\n &:focus-visible {\n outline: none;\n }\n cursor: pointer;\n color: ").concat(props.selected ? props.theme.selectedFontColor : props.theme.unselectedFontColor, ";\n") : "color: ".concat(props.selected ? props.theme.selectedDisabledFontColor : props.theme.unselectedDisabledFontColor, ";\n cursor: not-allowed;"), "\n ");
283
- });
284
-
285
- var LabelContainer = _styledComponents["default"].span(_templateObject6(), function (props) {
286
- return props.theme.optionLabelFontFamily;
287
- }, function (props) {
288
- return props.theme.optionLabelFontSize;
289
- }, function (props) {
290
- return props.theme.optionLabelFontStyle;
291
- }, function (props) {
292
- return props.theme.optionLabelFontWeight;
293
- });
294
-
295
- var OptionContent = _styledComponents["default"].div(_templateObject7());
296
-
297
- var Icon = _styledComponents["default"].img(_templateObject8(), function (props) {
298
- return props.optionLabel && props.theme.iconMarginRight;
299
- });
300
-
301
- var IconContainer = _styledComponents["default"].div(_templateObject9(), function (props) {
302
- return props.optionLabel && props.theme.iconMarginRight;
303
- });
304
-
305
- DxcToggleGroup.propTypes = {
306
- label: _propTypes["default"].string,
307
- helperText: _propTypes["default"].string,
308
- value: _propTypes["default"].any,
309
- onChange: _propTypes["default"].func,
310
- disabled: _propTypes["default"].bool,
311
- multiple: _propTypes["default"].bool,
312
- options: _propTypes["default"].arrayOf(_propTypes["default"].shape({
313
- value: _propTypes["default"].any.isRequired,
314
- label: _propTypes["default"].string,
315
- icon: _propTypes["default"].oneOfType([_propTypes["default"].element, _propTypes["default"].func]),
316
- iconSrc: _propTypes["default"].string
317
- })),
318
- margin: _propTypes["default"].oneOfType([_propTypes["default"].shape({
319
- top: _propTypes["default"].oneOf(Object.keys(_variables.spaces)),
320
- bottom: _propTypes["default"].oneOf(Object.keys(_variables.spaces)),
321
- left: _propTypes["default"].oneOf(Object.keys(_variables.spaces)),
322
- right: _propTypes["default"].oneOf(Object.keys(_variables.spaces))
323
- }), _propTypes["default"].oneOf((0, _toConsumableArray2["default"])(Object.keys(_variables.spaces)))]),
324
- tabIndex: _propTypes["default"].number
325
- };
326
- var _default = DxcToggleGroup;
327
- exports["default"] = _default;