@dxc-technology/halstack-react 0.0.0-fdc49d2 → 0.0.0-feed711
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.
- package/HalstackContext.d.ts +12 -0
- package/HalstackContext.js +295 -0
- package/accordion/Accordion.js +5 -27
- package/accordion/Accordion.stories.tsx +4 -4
- package/accordion/types.d.ts +1 -1
- package/accordion-group/AccordionGroup.d.ts +1 -1
- package/accordion-group/AccordionGroup.js +14 -15
- package/accordion-group/AccordionGroup.stories.tsx +1 -1
- package/accordion-group/AccordionGroup.test.js +24 -6
- package/accordion-group/types.d.ts +5 -1
- package/alert/Alert.js +4 -1
- package/badge/Badge.d.ts +1 -1
- package/badge/Badge.js +5 -3
- package/badge/types.d.ts +1 -0
- package/bleed/Bleed.js +1 -34
- package/bleed/Bleed.stories.tsx +94 -95
- package/bleed/types.d.ts +1 -1
- package/box/Box.js +22 -32
- package/bulleted-list/BulletedList.d.ts +7 -0
- package/bulleted-list/BulletedList.js +123 -0
- package/bulleted-list/BulletedList.stories.tsx +200 -0
- package/bulleted-list/types.d.ts +11 -0
- package/{list → bulleted-list}/types.js +0 -0
- package/button/Button.js +53 -68
- package/button/Button.stories.tsx +9 -0
- package/button/types.d.ts +7 -7
- package/card/Card.js +24 -27
- package/checkbox/Checkbox.d.ts +1 -1
- package/checkbox/Checkbox.js +38 -28
- package/checkbox/Checkbox.stories.tsx +124 -128
- package/checkbox/types.d.ts +3 -3
- package/chip/types.d.ts +1 -1
- package/common/variables.js +229 -98
- package/date-input/DateInput.js +41 -23
- package/date-input/DateInput.test.js +9 -22
- package/date-input/types.d.ts +12 -9
- package/dialog/Dialog.js +46 -50
- package/dialog/Dialog.stories.tsx +1 -2
- package/dialog/Dialog.test.js +34 -4
- package/dialog/types.d.ts +2 -2
- package/dropdown/Dropdown.d.ts +1 -1
- package/dropdown/Dropdown.js +242 -250
- package/dropdown/Dropdown.stories.tsx +126 -63
- package/dropdown/Dropdown.test.js +510 -108
- package/dropdown/DropdownMenu.d.ts +4 -0
- package/dropdown/DropdownMenu.js +80 -0
- package/dropdown/DropdownMenuItem.d.ts +4 -0
- package/dropdown/DropdownMenuItem.js +92 -0
- package/dropdown/types.d.ts +25 -5
- package/file-input/FileInput.js +9 -6
- package/file-input/FileItem.js +7 -5
- package/flex/Flex.d.ts +4 -0
- package/flex/Flex.js +57 -0
- package/flex/Flex.stories.tsx +103 -0
- package/flex/types.d.ts +21 -0
- package/{radio → flex}/types.js +0 -0
- package/footer/Footer.js +15 -88
- package/footer/Icons.js +1 -1
- package/footer/types.d.ts +1 -1
- package/header/Header.js +95 -114
- package/header/Header.stories.tsx +46 -36
- package/header/Header.test.js +18 -2
- package/header/Icons.js +2 -2
- package/header/types.d.ts +2 -2
- package/inset/Inset.js +1 -34
- package/inset/Inset.stories.tsx +36 -36
- package/inset/types.d.ts +25 -1
- package/layout/ApplicationLayout.d.ts +16 -6
- package/layout/ApplicationLayout.js +71 -131
- package/layout/ApplicationLayout.stories.tsx +83 -93
- package/layout/Icons.d.ts +5 -0
- package/layout/Icons.js +13 -2
- package/layout/SidenavContext.d.ts +5 -0
- package/layout/SidenavContext.js +19 -0
- package/layout/types.d.ts +18 -33
- package/link/Link.d.ts +3 -2
- package/link/Link.js +57 -74
- package/link/Link.stories.tsx +95 -53
- package/link/Link.test.js +7 -15
- package/link/types.d.ts +7 -23
- package/main.d.ts +7 -10
- package/main.js +43 -61
- package/number-input/NumberInput.test.js +2 -4
- package/number-input/types.d.ts +13 -10
- package/package.json +14 -12
- package/paginator/Paginator.js +17 -38
- package/paginator/Paginator.test.js +42 -0
- package/paragraph/Paragraph.d.ts +6 -0
- package/paragraph/Paragraph.js +38 -0
- package/paragraph/Paragraph.stories.tsx +44 -0
- package/password-input/PasswordInput.js +7 -4
- package/password-input/PasswordInput.test.js +3 -6
- package/password-input/types.d.ts +14 -11
- package/progress-bar/ProgressBar.d.ts +2 -2
- package/progress-bar/ProgressBar.js +57 -51
- package/progress-bar/ProgressBar.stories.jsx +13 -11
- package/progress-bar/ProgressBar.test.js +67 -22
- package/progress-bar/types.d.ts +3 -4
- package/quick-nav/QuickNav.js +83 -25
- package/quick-nav/QuickNav.stories.tsx +43 -16
- package/quick-nav/types.d.ts +4 -8
- package/radio-group/Radio.js +1 -1
- package/radio-group/RadioGroup.js +21 -20
- package/resultsetTable/ResultsetTable.test.js +42 -0
- package/select/Listbox.d.ts +4 -0
- package/select/Listbox.js +199 -0
- package/select/Option.js +1 -1
- package/select/Select.js +102 -199
- package/select/Select.stories.tsx +145 -100
- package/select/Select.test.js +440 -281
- package/select/types.d.ts +31 -12
- package/sidenav/Sidenav.d.ts +6 -5
- package/sidenav/Sidenav.js +184 -52
- package/sidenav/Sidenav.stories.tsx +154 -156
- package/sidenav/Sidenav.test.js +25 -37
- package/sidenav/types.d.ts +50 -27
- package/slider/Slider.d.ts +1 -1
- package/slider/Slider.js +5 -4
- package/slider/Slider.stories.tsx +8 -8
- package/slider/Slider.test.js +68 -10
- package/slider/types.d.ts +4 -0
- package/spinner/Spinner.js +1 -1
- package/switch/Switch.d.ts +2 -2
- package/switch/Switch.js +113 -54
- package/switch/Switch.stories.tsx +16 -38
- package/switch/Switch.test.js +122 -8
- package/switch/types.d.ts +5 -6
- package/tabs/Tabs.d.ts +1 -1
- package/tabs/Tabs.js +9 -11
- package/tabs/Tabs.stories.tsx +0 -8
- package/tabs/Tabs.test.js +26 -9
- package/tabs/types.d.ts +5 -1
- package/tabs-nav/NavTabs.d.ts +8 -0
- package/tabs-nav/NavTabs.js +125 -0
- package/tabs-nav/NavTabs.stories.tsx +170 -0
- package/tabs-nav/NavTabs.test.js +82 -0
- package/tabs-nav/Tab.d.ts +4 -0
- package/tabs-nav/Tab.js +130 -0
- package/tabs-nav/types.d.ts +53 -0
- package/{row → tabs-nav}/types.js +0 -0
- package/tag/Tag.js +5 -8
- package/tag/types.d.ts +1 -1
- package/text-input/Suggestion.d.ts +4 -0
- package/text-input/Suggestion.js +55 -0
- package/text-input/TextInput.js +60 -97
- package/text-input/TextInput.stories.tsx +1 -2
- package/text-input/TextInput.test.js +22 -35
- package/text-input/types.d.ts +27 -12
- package/textarea/Textarea.js +10 -19
- package/textarea/types.d.ts +10 -7
- package/toggle-group/ToggleGroup.d.ts +1 -1
- package/toggle-group/ToggleGroup.js +5 -4
- package/toggle-group/ToggleGroup.stories.tsx +4 -4
- package/toggle-group/ToggleGroup.test.js +35 -4
- package/toggle-group/types.d.ts +9 -1
- package/typography/Typography.d.ts +4 -0
- package/typography/Typography.js +131 -0
- package/typography/Typography.stories.tsx +198 -0
- package/typography/types.d.ts +18 -0
- package/{stack → typography}/types.js +0 -0
- package/useTheme.js +2 -2
- package/useTranslatedLabels.d.ts +2 -0
- package/useTranslatedLabels.js +20 -0
- package/wizard/Wizard.js +43 -44
- package/wizard/Wizard.stories.tsx +20 -1
- package/wizard/types.d.ts +5 -4
- package/ThemeContext.d.ts +0 -10
- package/ThemeContext.js +0 -243
- package/list/List.d.ts +0 -4
- package/list/List.js +0 -47
- package/list/List.stories.tsx +0 -95
- package/list/types.d.ts +0 -7
- package/radio/Radio.d.ts +0 -4
- package/radio/Radio.js +0 -174
- package/radio/Radio.stories.tsx +0 -192
- package/radio/Radio.test.js +0 -71
- package/radio/types.d.ts +0 -54
- package/row/Row.d.ts +0 -3
- package/row/Row.js +0 -127
- package/row/Row.stories.tsx +0 -237
- package/row/types.d.ts +0 -28
- package/stack/Stack.d.ts +0 -3
- package/stack/Stack.js +0 -97
- package/stack/Stack.stories.tsx +0 -164
- package/stack/types.d.ts +0 -24
- package/text/Text.d.ts +0 -7
- package/text/Text.js +0 -30
- package/text/Text.stories.tsx +0 -19
package/slider/Slider.test.js
CHANGED
|
@@ -6,6 +6,8 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
6
6
|
|
|
7
7
|
var _react2 = require("@testing-library/react");
|
|
8
8
|
|
|
9
|
+
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
10
|
+
|
|
9
11
|
var _Slider = _interopRequireDefault(require("./Slider"));
|
|
10
12
|
|
|
11
13
|
describe("Slider component tests", function () {
|
|
@@ -20,10 +22,25 @@ describe("Slider component tests", function () {
|
|
|
20
22
|
expect(getByText("0")).toBeTruthy();
|
|
21
23
|
expect(getByText("100")).toBeTruthy();
|
|
22
24
|
});
|
|
25
|
+
test("Slider renders with correct initial value when it is uncontrolled", function () {
|
|
26
|
+
var _render2 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Slider["default"], {
|
|
27
|
+
defaultValue: 30,
|
|
28
|
+
minValue: 0,
|
|
29
|
+
maxValue: 100,
|
|
30
|
+
showLimitsValues: true,
|
|
31
|
+
showInput: true
|
|
32
|
+
})),
|
|
33
|
+
getByRole = _render2.getByRole;
|
|
34
|
+
|
|
35
|
+
var slider = getByRole("slider");
|
|
36
|
+
var input = getByRole("textbox");
|
|
37
|
+
expect(slider.getAttribute("aria-valuenow")).toBe("30");
|
|
38
|
+
expect(input.value).toBe("30");
|
|
39
|
+
});
|
|
23
40
|
test("Calls correct function onChange in controlled slider", function () {
|
|
24
41
|
var onChange = jest.fn();
|
|
25
42
|
|
|
26
|
-
var
|
|
43
|
+
var _render3 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Slider["default"], {
|
|
27
44
|
minValue: 0,
|
|
28
45
|
maxValue: 100,
|
|
29
46
|
onChange: onChange,
|
|
@@ -31,8 +48,10 @@ describe("Slider component tests", function () {
|
|
|
31
48
|
value: 13,
|
|
32
49
|
showInput: true
|
|
33
50
|
})),
|
|
34
|
-
getByRole =
|
|
51
|
+
getByRole = _render3.getByRole;
|
|
35
52
|
|
|
53
|
+
expect(getByRole("slider").getAttribute("aria-valuenow")).toBe("13");
|
|
54
|
+
expect(getByRole("textbox").value).toBe("13");
|
|
36
55
|
(0, _react2.act)(function () {
|
|
37
56
|
_react2.fireEvent.change(getByRole("textbox"), {
|
|
38
57
|
target: {
|
|
@@ -41,18 +60,20 @@ describe("Slider component tests", function () {
|
|
|
41
60
|
});
|
|
42
61
|
});
|
|
43
62
|
expect(onChange).toHaveBeenCalledWith(25);
|
|
63
|
+
expect(getByRole("slider").getAttribute("aria-valuenow")).toBe("13");
|
|
64
|
+
expect(getByRole("textbox").value).toBe("13");
|
|
44
65
|
});
|
|
45
66
|
test("Calls correct function onChange in uncontrolled slider", function () {
|
|
46
67
|
var onChange = jest.fn();
|
|
47
68
|
|
|
48
|
-
var
|
|
69
|
+
var _render4 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Slider["default"], {
|
|
49
70
|
minValue: 0,
|
|
50
71
|
maxValue: 100,
|
|
51
72
|
onChange: onChange,
|
|
52
73
|
showLimitsValues: true,
|
|
53
74
|
showInput: true
|
|
54
75
|
})),
|
|
55
|
-
getByRole =
|
|
76
|
+
getByRole = _render4.getByRole;
|
|
56
77
|
|
|
57
78
|
(0, _react2.act)(function () {
|
|
58
79
|
_react2.fireEvent.change(getByRole("textbox"), {
|
|
@@ -62,11 +83,13 @@ describe("Slider component tests", function () {
|
|
|
62
83
|
});
|
|
63
84
|
});
|
|
64
85
|
expect(onChange).toHaveBeenCalledWith(25);
|
|
86
|
+
expect(getByRole("slider").getAttribute("aria-valuenow")).toBe("25");
|
|
87
|
+
expect(getByRole("textbox").value).toBe("25");
|
|
65
88
|
});
|
|
66
89
|
test("Disabled slider have disabled input", function () {
|
|
67
90
|
var onChange = jest.fn();
|
|
68
91
|
|
|
69
|
-
var
|
|
92
|
+
var _render5 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Slider["default"], {
|
|
70
93
|
minValue: 0,
|
|
71
94
|
maxValue: 100,
|
|
72
95
|
onChange: onChange,
|
|
@@ -75,7 +98,7 @@ describe("Slider component tests", function () {
|
|
|
75
98
|
showInput: true,
|
|
76
99
|
value: 13
|
|
77
100
|
})),
|
|
78
|
-
getByRole =
|
|
101
|
+
getByRole = _render5.getByRole;
|
|
79
102
|
|
|
80
103
|
(0, _react2.act)(function () {
|
|
81
104
|
_react2.fireEvent.change(getByRole("textbox"), {
|
|
@@ -90,7 +113,7 @@ describe("Slider component tests", function () {
|
|
|
90
113
|
test("Calls correct function onDragEnd", function () {
|
|
91
114
|
var onDragEnd = jest.fn();
|
|
92
115
|
|
|
93
|
-
var
|
|
116
|
+
var _render6 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Slider["default"], {
|
|
94
117
|
minValue: 0,
|
|
95
118
|
maxValue: 100,
|
|
96
119
|
showLimitsValues: true,
|
|
@@ -98,7 +121,7 @@ describe("Slider component tests", function () {
|
|
|
98
121
|
onDragEnd: onDragEnd,
|
|
99
122
|
value: 25
|
|
100
123
|
})),
|
|
101
|
-
getByRole =
|
|
124
|
+
getByRole = _render6.getByRole;
|
|
102
125
|
|
|
103
126
|
(0, _react2.act)(function () {
|
|
104
127
|
_react2.fireEvent.mouseDown(getByRole("slider"));
|
|
@@ -112,7 +135,7 @@ describe("Slider component tests", function () {
|
|
|
112
135
|
return "".concat(x, "$");
|
|
113
136
|
});
|
|
114
137
|
|
|
115
|
-
var
|
|
138
|
+
var _render7 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Slider["default"], {
|
|
116
139
|
minValue: 0,
|
|
117
140
|
maxValue: 100,
|
|
118
141
|
showLimitsValues: true,
|
|
@@ -120,10 +143,45 @@ describe("Slider component tests", function () {
|
|
|
120
143
|
value: 25,
|
|
121
144
|
labelFormatCallback: labelFormatCallback
|
|
122
145
|
})),
|
|
123
|
-
getByText =
|
|
146
|
+
getByText = _render7.getByText;
|
|
124
147
|
|
|
125
148
|
expect(getByText("0$")).toBeTruthy();
|
|
126
149
|
expect(getByText("100$")).toBeTruthy();
|
|
127
150
|
expect(labelFormatCallback).toHaveBeenCalledTimes(2);
|
|
128
151
|
});
|
|
152
|
+
test("Change value correctly to 0 from external function", function () {
|
|
153
|
+
var onChange = jest.fn();
|
|
154
|
+
|
|
155
|
+
var _render8 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Slider["default"], {
|
|
156
|
+
minValue: 0,
|
|
157
|
+
maxValue: 100,
|
|
158
|
+
onChange: onChange,
|
|
159
|
+
showLimitsValues: true,
|
|
160
|
+
value: 13,
|
|
161
|
+
showInput: true
|
|
162
|
+
})),
|
|
163
|
+
rerender = _render8.rerender,
|
|
164
|
+
getByRole = _render8.getByRole;
|
|
165
|
+
|
|
166
|
+
var slider = getByRole("slider");
|
|
167
|
+
|
|
168
|
+
_userEvent["default"].tab();
|
|
169
|
+
|
|
170
|
+
_react2.fireEvent.keyDown(slider, {
|
|
171
|
+
key: "ArrowRight",
|
|
172
|
+
code: "ArrowRight",
|
|
173
|
+
keyCode: 39,
|
|
174
|
+
charCode: 39
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
rerender( /*#__PURE__*/_react["default"].createElement(_Slider["default"], {
|
|
178
|
+
minValue: 0,
|
|
179
|
+
maxValue: 100,
|
|
180
|
+
onChange: onChange,
|
|
181
|
+
showLimitsValues: true,
|
|
182
|
+
value: 0,
|
|
183
|
+
showInput: true
|
|
184
|
+
}));
|
|
185
|
+
expect(slider.getAttribute("aria-valuenow")).toBe("0");
|
|
186
|
+
});
|
|
129
187
|
});
|
package/slider/types.d.ts
CHANGED
|
@@ -14,6 +14,10 @@ declare type Props = {
|
|
|
14
14
|
* Name attribute of the input element.
|
|
15
15
|
*/
|
|
16
16
|
name?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Initial value of the slider, only when it is uncontrolled.
|
|
19
|
+
*/
|
|
20
|
+
defaultValue?: number;
|
|
17
21
|
/**
|
|
18
22
|
* The selected value. If undefined, the component will be uncontrolled and the value will be managed internally by the component.
|
|
19
23
|
*/
|
package/spinner/Spinner.js
CHANGED
|
@@ -199,7 +199,7 @@ var SVGSpinner = _styledComponents["default"].svg(_templateObject8 || (_template
|
|
|
199
199
|
var CircleSpinner = _styledComponents["default"].circle(_templateObject9 || (_templateObject9 = (0, _taggedTemplateLiteral2["default"])(["\n fill: transparent;\n stroke-linecap: initial;\n vector-effect: non-scaling-stroke;\n animation: ", ";\n stroke: ", ";\n transform-origin: ", ";\n stroke-dasharray: ", ";\n stroke-width: ", ";\n stroke-dashoffset: ", ";\n"])), function (props) {
|
|
200
200
|
return props.isDeterminated ? "none" : props.mode !== "small" ? "1.4s ease-in-out infinite both svg-circle-large" : "1.4s ease-in-out infinite both svg-circle-small";
|
|
201
201
|
}, function (props) {
|
|
202
|
-
return props.backgroundType === "dark" ? props.theme.
|
|
202
|
+
return props.backgroundType === "dark" || props.mode === "overlay" ? props.theme.trackCircleColorOverlay : props.theme.trackCircleColor;
|
|
203
203
|
}, function (props) {
|
|
204
204
|
return !props.isDeterminated ? "50% 50%" : "";
|
|
205
205
|
}, function (props) {
|
package/switch/Switch.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import SwitchPropsType from "./types";
|
|
3
|
-
declare const DxcSwitch: ({ defaultChecked, checked, value, label, labelPosition, name, disabled,
|
|
2
|
+
import { SwitchPropsType } from "./types";
|
|
3
|
+
declare const DxcSwitch: ({ defaultChecked, checked, value, label, labelPosition, name, disabled, optional, onChange, margin, size, tabIndex, }: SwitchPropsType) => JSX.Element;
|
|
4
4
|
export default DxcSwitch;
|
package/switch/Switch.js
CHANGED
|
@@ -19,10 +19,6 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
19
19
|
|
|
20
20
|
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
21
21
|
|
|
22
|
-
var _core = require("@material-ui/core");
|
|
23
|
-
|
|
24
|
-
var _RequiredComponent = _interopRequireDefault(require("../common/RequiredComponent"));
|
|
25
|
-
|
|
26
22
|
var _uuid = require("uuid");
|
|
27
23
|
|
|
28
24
|
var _variables = require("../common/variables.js");
|
|
@@ -31,15 +27,19 @@ var _utils = require("../common/utils.js");
|
|
|
31
27
|
|
|
32
28
|
var _useTheme = _interopRequireDefault(require("../useTheme"));
|
|
33
29
|
|
|
30
|
+
var _useTranslatedLabels = _interopRequireDefault(require("../useTranslatedLabels"));
|
|
31
|
+
|
|
34
32
|
var _BackgroundColorContext = _interopRequireDefault(require("../BackgroundColorContext"));
|
|
35
33
|
|
|
36
|
-
var _templateObject, _templateObject2;
|
|
34
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
|
|
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
40
|
var DxcSwitch = function DxcSwitch(_ref) {
|
|
41
|
+
var _ref2;
|
|
42
|
+
|
|
43
43
|
var defaultChecked = _ref.defaultChecked,
|
|
44
44
|
checked = _ref.checked,
|
|
45
45
|
value = _ref.value,
|
|
@@ -51,9 +51,9 @@ var DxcSwitch = function DxcSwitch(_ref) {
|
|
|
51
51
|
name = _ref$name === void 0 ? "" : _ref$name,
|
|
52
52
|
_ref$disabled = _ref.disabled,
|
|
53
53
|
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
54
|
+
_ref$optional = _ref.optional,
|
|
55
|
+
optional = _ref$optional === void 0 ? false : _ref$optional,
|
|
54
56
|
onChange = _ref.onChange,
|
|
55
|
-
_ref$required = _ref.required,
|
|
56
|
-
required = _ref$required === void 0 ? false : _ref$required,
|
|
57
57
|
margin = _ref.margin,
|
|
58
58
|
_ref$size = _ref.size,
|
|
59
59
|
size = _ref$size === void 0 ? "fitContent" : _ref$size,
|
|
@@ -71,8 +71,32 @@ var DxcSwitch = function DxcSwitch(_ref) {
|
|
|
71
71
|
innerChecked = _useState4[0],
|
|
72
72
|
setInnerChecked = _useState4[1];
|
|
73
73
|
|
|
74
|
+
var _useState5 = (0, _react.useState)((_ref2 = label !== "" && label !== null && label !== undefined) !== null && _ref2 !== void 0 ? _ref2 : false),
|
|
75
|
+
_useState6 = (0, _slicedToArray2["default"])(_useState5, 1),
|
|
76
|
+
hasLabel = _useState6[0];
|
|
77
|
+
|
|
74
78
|
var colorsTheme = (0, _useTheme["default"])();
|
|
79
|
+
var translatedLabels = (0, _useTranslatedLabels["default"])();
|
|
75
80
|
var backgroundType = (0, _react.useContext)(_BackgroundColorContext["default"]);
|
|
81
|
+
var refTrack = (0, _react.useRef)(null);
|
|
82
|
+
|
|
83
|
+
var handleOnKeyDown = function handleOnKeyDown(event) {
|
|
84
|
+
switch (event.key) {
|
|
85
|
+
case "Enter":
|
|
86
|
+
case " ":
|
|
87
|
+
//Space
|
|
88
|
+
event.preventDefault();
|
|
89
|
+
refTrack.current.focus();
|
|
90
|
+
var isChecked = !(checked !== null && checked !== void 0 ? checked : innerChecked);
|
|
91
|
+
setInnerChecked(isChecked);
|
|
92
|
+
|
|
93
|
+
if (typeof onChange === "function") {
|
|
94
|
+
onChange(isChecked);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
76
100
|
|
|
77
101
|
var handlerSwitchChange = function handlerSwitchChange(event) {
|
|
78
102
|
if (checked === undefined) {
|
|
@@ -80,38 +104,64 @@ var DxcSwitch = function DxcSwitch(_ref) {
|
|
|
80
104
|
|
|
81
105
|
var isChecked = (_event$target$checked = event.target.checked) !== null && _event$target$checked !== void 0 ? _event$target$checked : !innerChecked;
|
|
82
106
|
setInnerChecked(isChecked);
|
|
83
|
-
|
|
84
|
-
|
|
107
|
+
|
|
108
|
+
if (typeof onChange === "function") {
|
|
109
|
+
onChange(isChecked);
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
if (typeof onChange === "function") {
|
|
113
|
+
onChange(!checked);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
85
116
|
};
|
|
86
117
|
|
|
87
118
|
return /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
|
|
88
119
|
theme: colorsTheme["switch"]
|
|
89
120
|
}, /*#__PURE__*/_react["default"].createElement(SwitchContainer, {
|
|
90
121
|
margin: margin,
|
|
122
|
+
size: size,
|
|
123
|
+
onKeyDown: handleOnKeyDown
|
|
124
|
+
}, labelPosition === "before" && hasLabel && /*#__PURE__*/_react["default"].createElement(LabelContainer, {
|
|
125
|
+
id: labelId,
|
|
126
|
+
labelPosition: labelPosition,
|
|
127
|
+
onClick: !disabled ? handlerSwitchChange : undefined,
|
|
91
128
|
disabled: disabled,
|
|
129
|
+
backgroundType: backgroundType,
|
|
130
|
+
hasLabel: hasLabel
|
|
131
|
+
}, label, " ", optional && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, translatedLabels.formFields.optionalLabel)), /*#__PURE__*/_react["default"].createElement(SwitchBase, {
|
|
92
132
|
labelPosition: labelPosition,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
"aria-checked": checked !== null && checked !== void 0 ? checked : innerChecked,
|
|
102
|
-
tabIndex: tabIndex
|
|
103
|
-
},
|
|
104
|
-
onChange: handlerSwitchChange,
|
|
105
|
-
value: value,
|
|
133
|
+
hasLabel: hasLabel,
|
|
134
|
+
htmlFor: labelId,
|
|
135
|
+
onClick: disabled === true ? function () {} : handlerSwitchChange
|
|
136
|
+
}, /*#__PURE__*/_react["default"].createElement(SwitchInput, {
|
|
137
|
+
type: "checkbox",
|
|
138
|
+
role: "switch",
|
|
139
|
+
name: name,
|
|
140
|
+
id: labelId,
|
|
106
141
|
disabled: disabled,
|
|
107
|
-
|
|
108
|
-
|
|
142
|
+
value: value,
|
|
143
|
+
"aria-labelledby": labelId,
|
|
144
|
+
"aria-label": hasLabel ? label : undefined,
|
|
145
|
+
"aria-checked": checked !== null && checked !== void 0 ? checked : innerChecked,
|
|
146
|
+
defaultChecked: defaultChecked !== null && defaultChecked !== void 0 ? defaultChecked : undefined,
|
|
147
|
+
tabIndex: -1
|
|
148
|
+
}), disabled ? /*#__PURE__*/_react["default"].createElement(DisabledSwitchTrack, {
|
|
149
|
+
backgroundType: backgroundType,
|
|
150
|
+
"data-checked": checked !== null && checked !== void 0 ? checked : innerChecked ? innerChecked : undefined,
|
|
151
|
+
tabIndex: -1
|
|
152
|
+
}) : /*#__PURE__*/_react["default"].createElement(SwitchTrack, {
|
|
153
|
+
backgroundType: backgroundType,
|
|
154
|
+
"data-checked": checked !== null && checked !== void 0 ? checked : innerChecked ? innerChecked : undefined,
|
|
155
|
+
tabIndex: tabIndex,
|
|
156
|
+
ref: refTrack
|
|
157
|
+
})), labelPosition === "after" && hasLabel && /*#__PURE__*/_react["default"].createElement(LabelContainer, {
|
|
109
158
|
id: labelId,
|
|
110
159
|
labelPosition: labelPosition,
|
|
111
|
-
onClick: !disabled
|
|
160
|
+
onClick: !disabled ? handlerSwitchChange : undefined,
|
|
112
161
|
disabled: disabled,
|
|
113
|
-
backgroundType: backgroundType
|
|
114
|
-
|
|
162
|
+
backgroundType: backgroundType,
|
|
163
|
+
hasLabel: hasLabel
|
|
164
|
+
}, optional && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, translatedLabels.formFields.optionalLabel), " ", label)));
|
|
115
165
|
};
|
|
116
166
|
|
|
117
167
|
var sizes = {
|
|
@@ -126,10 +176,8 @@ var calculateWidth = function calculateWidth(margin, size) {
|
|
|
126
176
|
return size === "fillParent" ? "calc(".concat(sizes[size], " - ").concat((0, _utils.getMargin)(margin, "left"), " - ").concat((0, _utils.getMargin)(margin, "right"), ")") : sizes[size];
|
|
127
177
|
};
|
|
128
178
|
|
|
129
|
-
var SwitchContainer = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n
|
|
179
|
+
var SwitchContainer = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n display: inline-flex;\n align-items: center;\n width: ", ";\n height: 40px;\n\n margin: ", ";\n margin-top: ", ";\n margin-right: ", ";\n margin-bottom: ", ";\n margin-left: ", ";\n"])), function (props) {
|
|
130
180
|
return calculateWidth(props.margin, props.size);
|
|
131
|
-
}, function (props) {
|
|
132
|
-
return props.labelPosition === "after" ? "row" : "row-reverse";
|
|
133
181
|
}, function (props) {
|
|
134
182
|
return props.margin && (0, _typeof2["default"])(props.margin) !== "object" ? _variables.spaces[props.margin] : "0px";
|
|
135
183
|
}, function (props) {
|
|
@@ -140,16 +188,38 @@ var SwitchContainer = _styledComponents["default"].div(_templateObject || (_temp
|
|
|
140
188
|
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.bottom ? _variables.spaces[props.margin.bottom] : "";
|
|
141
189
|
}, function (props) {
|
|
142
190
|
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.left ? _variables.spaces[props.margin.left] : "";
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
var LabelContainer = _styledComponents["default"].span(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n color: ", ";\n opacity: 1;\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n cursor: ", ";\n\n ", ";\n\n ", "\n"])), function (props) {
|
|
194
|
+
return props.disabled ? props.backgroundType === "dark" ? props.theme.disabledLabelFontColorOnDark : props.theme.disabledLabelFontColor : props.backgroundType === "dark" ? props.theme.labelFontColorOnDark : props.theme.labelFontColor;
|
|
143
195
|
}, function (props) {
|
|
144
|
-
return props.
|
|
196
|
+
return props.theme.labelFontFamily;
|
|
145
197
|
}, function (props) {
|
|
146
|
-
return props.theme.
|
|
198
|
+
return props.theme.labelFontSize;
|
|
147
199
|
}, function (props) {
|
|
148
|
-
return
|
|
200
|
+
return props.disabled ? props.theme.disabledLabelFontStyle : props.theme.labelFontStyle;
|
|
149
201
|
}, function (props) {
|
|
150
|
-
return props.
|
|
202
|
+
return props.theme.labelFontWeight;
|
|
203
|
+
}, function (props) {
|
|
204
|
+
return props.disabled === true ? "not-allowed" : "pointer";
|
|
205
|
+
}, function (props) {
|
|
206
|
+
return !props.hasLabel ? "margin: 0px;" : props.labelPosition === "after" ? "margin-left: ".concat(props.theme.spaceBetweenLabelSwitch, ";") : "margin-right: ".concat(props.theme.spaceBetweenLabelSwitch, ";");
|
|
207
|
+
}, function (props) {
|
|
208
|
+
return props.labelPosition === "before" && "order: -1";
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
var SwitchBase = _styledComponents["default"].label(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n align-items: center;\n justify-content: space-between;\n cursor: pointer;\n margin: ", ";\n"])), function (props) {
|
|
212
|
+
return !props.hasLabel ? "0px 4px" : props.labelPosition === "before" ? "0 4px 0 12px" : "0 12px 0 4px";
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
var SwitchInput = _styledComponents["default"].input(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["\n opacity: 0;\n width: 0;\n height: 0;\n margin: 0px;\n"])));
|
|
216
|
+
|
|
217
|
+
var SwitchTrack = _styledComponents["default"].span(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2["default"])(["\n border-radius: 15px;\n width: ", ";\n height: ", ";\n position: relative;\n transition: transform 0.2s ease;\n\n &:focus-visible {\n outline: none;\n ::before {\n outline: ", ";\n outline-offset: 6px;\n }\n }\n\n /* Thumb element */\n ::before {\n content: \"\";\n transform: initial;\n transition: transform 0.2s ease;\n position: absolute;\n width: ", ";\n height: ", ";\n border-radius: 50%;\n z-index: 1;\n box-shadow: 0px 2px 1px -1px rgb(0 0 0 / 20%), 0px 1px 1px 0px rgb(0 0 0 / 14%), 0px 1px 3px 0px rgb(0 0 0 / 12%);\n bottom: -6px;\n left: -4px;\n transform: translateX(0px);\n background-color: ", ";\n }\n\n /* Unchecked */\n background-color: ", ";\n\n /* Checked */\n &[data-checked=\"true\"] {\n background-color: ", ";\n ::before {\n transform: translateX(", ");\n background-color: ", ";\n }\n }\n"])), function (props) {
|
|
218
|
+
return props.theme.trackWidth;
|
|
151
219
|
}, function (props) {
|
|
152
220
|
return props.theme.trackHeight;
|
|
221
|
+
}, function (props) {
|
|
222
|
+
return "".concat(props.backgroundType === "dark" ? props.theme.thumbFocusColorOnDark : props.theme.thumbFocusColor, " solid 2px");
|
|
153
223
|
}, function (props) {
|
|
154
224
|
return props.theme.thumbWidth;
|
|
155
225
|
}, function (props) {
|
|
@@ -157,36 +227,25 @@ var SwitchContainer = _styledComponents["default"].div(_templateObject || (_temp
|
|
|
157
227
|
}, function (props) {
|
|
158
228
|
return props.backgroundType === "dark" ? props.theme.uncheckedThumbBackgroundColorOnDark : props.theme.uncheckedThumbBackgroundColor;
|
|
159
229
|
}, function (props) {
|
|
160
|
-
return props.backgroundType === "dark" ? props.theme.
|
|
161
|
-
}, function (props) {
|
|
162
|
-
return props.backgroundType === "dark" ? props.theme.disabledUncheckedTrackBackgroundColorOnDark : props.theme.disabledUncheckedTrackBackgroundColor;
|
|
163
|
-
}, function (props) {
|
|
164
|
-
return props.backgroundType === "dark" ? props.theme.disabledCheckedThumbBackgroundColorOnDark : props.theme.disabledCheckedThumbBackgroundColor;
|
|
165
|
-
}, function (props) {
|
|
166
|
-
return props.backgroundType === "dark" ? props.theme.disabledCheckedTrackBackgroundColorOnDark : props.theme.disabledCheckedTrackBackgroundColor;
|
|
230
|
+
return props.backgroundType === "dark" ? props.theme.uncheckedTrackBackgroundColorOnDark : props.theme.uncheckedTrackBackgroundColor;
|
|
167
231
|
}, function (props) {
|
|
168
|
-
return props.backgroundType === "dark" ? props.theme.
|
|
232
|
+
return props.backgroundType === "dark" ? props.theme.checkedTrackBackgroundColorOnDark : props.theme.checkedTrackBackgroundColor;
|
|
169
233
|
}, function (props) {
|
|
170
234
|
return props.theme.thumbShift;
|
|
171
235
|
}, function (props) {
|
|
172
|
-
return props.backgroundType === "dark" ? props.theme.
|
|
236
|
+
return props.backgroundType === "dark" ? props.theme.checkedThumbBackgroundColorOnDark : props.theme.checkedThumbBackgroundColor;
|
|
173
237
|
});
|
|
174
238
|
|
|
175
|
-
var
|
|
176
|
-
return props.
|
|
177
|
-
}, function (props) {
|
|
178
|
-
return props.theme.labelFontFamily;
|
|
179
|
-
}, function (props) {
|
|
180
|
-
return props.theme.labelFontSize;
|
|
239
|
+
var DisabledSwitchTrack = (0, _styledComponents["default"])(SwitchTrack)(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteral2["default"])(["\n cursor: not-allowed;\n\n /* Unchecked */\n background-color: ", ";\n\n ::before {\n background-color: ", ";\n }\n\n /* Checked */\n &[data-checked=\"true\"] {\n background-color: ", ";\n\n ::before {\n transform: translateX(", ");\n background-color: ", ";\n }\n }\n"])), function (props) {
|
|
240
|
+
return props.backgroundType === "dark" ? props.theme.disabledUncheckedTrackBackgroundColorOnDark : props.theme.disabledUncheckedTrackBackgroundColor;
|
|
181
241
|
}, function (props) {
|
|
182
|
-
return props.
|
|
242
|
+
return props.backgroundType === "dark" ? props.theme.disabledUncheckedThumbBackgroundColorOnDark : props.theme.disabledUncheckedThumbBackgroundColor;
|
|
183
243
|
}, function (props) {
|
|
184
|
-
return props.theme.
|
|
244
|
+
return props.backgroundType === "dark" ? props.theme.disabledCheckedTrackBackgroundColorOnDark : props.theme.disabledCheckedTrackBackgroundColor;
|
|
185
245
|
}, function (props) {
|
|
186
|
-
return props.
|
|
246
|
+
return props.theme.thumbShift;
|
|
187
247
|
}, function (props) {
|
|
188
|
-
return props.
|
|
248
|
+
return props.backgroundType === "dark" ? props.theme.disabledCheckedThumbBackgroundColorOnDark : props.theme.disabledCheckedThumbBackgroundColor;
|
|
189
249
|
});
|
|
190
|
-
|
|
191
250
|
var _default = DxcSwitch;
|
|
192
251
|
exports["default"] = _default;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { userEvent, within } from "@storybook/testing-library";
|
|
3
2
|
import DxcSwitch from "./Switch";
|
|
4
3
|
import { BackgroundColorProvider } from "../BackgroundColorContext";
|
|
5
4
|
import Title from "../../.storybook/components/Title";
|
|
@@ -21,21 +20,25 @@ export const Chromatic = () => (
|
|
|
21
20
|
<Title title="Without label" theme="light" level={4} />
|
|
22
21
|
<DxcSwitch />
|
|
23
22
|
</ExampleContainer>
|
|
23
|
+
<ExampleContainer pseudoState="pseudo-focus-visible">
|
|
24
|
+
<Title title="Focused" theme="light" level={4} />
|
|
25
|
+
<DxcSwitch label="Switch" labelPosition="after" />
|
|
26
|
+
</ExampleContainer>
|
|
24
27
|
<ExampleContainer>
|
|
25
28
|
<Title title="Checked" theme="light" level={4} />
|
|
26
29
|
<DxcSwitch label="Switch" defaultChecked />
|
|
27
30
|
</ExampleContainer>
|
|
28
31
|
<ExampleContainer>
|
|
29
|
-
<Title title="
|
|
30
|
-
<DxcSwitch label="Switch"
|
|
32
|
+
<Title title="Optional" theme="light" level={4} />
|
|
33
|
+
<DxcSwitch label="Switch" optional />
|
|
31
34
|
</ExampleContainer>
|
|
32
35
|
<ExampleContainer>
|
|
33
36
|
<Title title="Disabled" theme="light" level={4} />
|
|
34
37
|
<DxcSwitch label="Switch" disabled />
|
|
35
38
|
</ExampleContainer>
|
|
36
39
|
<ExampleContainer>
|
|
37
|
-
<Title title="Disabled
|
|
38
|
-
<DxcSwitch label="Switch" disabled
|
|
40
|
+
<Title title="Disabled optional" theme="light" level={4} />
|
|
41
|
+
<DxcSwitch label="Switch" disabled optional labelPosition="after" />
|
|
39
42
|
</ExampleContainer>
|
|
40
43
|
<ExampleContainer>
|
|
41
44
|
<Title title="Disabled checked" theme="light" level={4} />
|
|
@@ -47,21 +50,25 @@ export const Chromatic = () => (
|
|
|
47
50
|
<Title title="With label" theme="dark" level={4} />
|
|
48
51
|
<DxcSwitch label="Switch" />
|
|
49
52
|
</ExampleContainer>
|
|
53
|
+
<ExampleContainer pseudoState="pseudo-focus-visible">
|
|
54
|
+
<Title title="Focused" theme="dark" level={4} />
|
|
55
|
+
<DxcSwitch label="Switch" labelPosition="after" />
|
|
56
|
+
</ExampleContainer>
|
|
50
57
|
<ExampleContainer>
|
|
51
58
|
<Title title="Checked" theme="dark" level={4} />
|
|
52
59
|
<DxcSwitch label="Switch" defaultChecked />
|
|
53
60
|
</ExampleContainer>
|
|
54
61
|
<ExampleContainer>
|
|
55
|
-
<Title title="
|
|
56
|
-
<DxcSwitch label="Switch"
|
|
62
|
+
<Title title="Optional" theme="dark" level={4} />
|
|
63
|
+
<DxcSwitch label="Switch" optional />
|
|
57
64
|
</ExampleContainer>
|
|
58
65
|
<ExampleContainer>
|
|
59
66
|
<Title title="Disabled" theme="dark" level={4} />
|
|
60
67
|
<DxcSwitch label="Switch" disabled />
|
|
61
68
|
</ExampleContainer>
|
|
62
69
|
<ExampleContainer>
|
|
63
|
-
<Title title="Disabled
|
|
64
|
-
<DxcSwitch label="Switch" disabled
|
|
70
|
+
<Title title="Disabled optional" theme="dark" level={4} />
|
|
71
|
+
<DxcSwitch label="Switch" disabled optional labelPosition="after" />
|
|
65
72
|
</ExampleContainer>
|
|
66
73
|
<ExampleContainer>
|
|
67
74
|
<Title title="Disabled checked" theme="dark" level={4} />
|
|
@@ -129,32 +136,3 @@ export const Chromatic = () => (
|
|
|
129
136
|
</ExampleContainer>
|
|
130
137
|
</>
|
|
131
138
|
);
|
|
132
|
-
|
|
133
|
-
const Switch = () => (
|
|
134
|
-
<ExampleContainer>
|
|
135
|
-
<Title title="Focused" theme="light" level={4} />
|
|
136
|
-
<DxcSwitch label="Switch" />
|
|
137
|
-
</ExampleContainer>
|
|
138
|
-
);
|
|
139
|
-
export const FocusedSwitch = Switch.bind({});
|
|
140
|
-
FocusedSwitch.play = async ({ canvasElement }) => {
|
|
141
|
-
const canvas = within(canvasElement);
|
|
142
|
-
canvas.getByRole("switch").focus();
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const DarkSwitch = () => (
|
|
146
|
-
<BackgroundColorProvider color="#333333">
|
|
147
|
-
<DarkContainer>
|
|
148
|
-
<ExampleContainer>
|
|
149
|
-
<Title title="Focused" theme="dark" level={4} />
|
|
150
|
-
<DxcSwitch label="Switch" />
|
|
151
|
-
</ExampleContainer>
|
|
152
|
-
</DarkContainer>
|
|
153
|
-
</BackgroundColorProvider>
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
export const FocusedSwitchOnDark = DarkSwitch.bind({});
|
|
157
|
-
FocusedSwitchOnDark.play = async ({ canvasElement }) => {
|
|
158
|
-
const canvas = within(canvasElement);
|
|
159
|
-
canvas.getByRole("switch").focus();
|
|
160
|
-
};
|