@dxc-technology/halstack-react 0.0.0-df9dd3c → 0.0.0-dfb16f5
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.d.ts +1 -1
- package/accordion/Accordion.js +122 -135
- package/accordion/Accordion.stories.tsx +20 -14
- package/accordion/Accordion.test.js +71 -0
- package/accordion/types.d.ts +11 -10
- package/accordion-group/AccordionGroup.d.ts +1 -1
- package/accordion-group/AccordionGroup.js +15 -36
- package/accordion-group/AccordionGroup.stories.tsx +28 -2
- package/accordion-group/AccordionGroup.test.js +126 -0
- package/accordion-group/types.d.ts +16 -9
- package/alert/Alert.js +5 -2
- package/alert/Alert.test.js +92 -0
- package/badge/Badge.d.ts +4 -0
- package/badge/Badge.js +5 -3
- package/badge/types.d.ts +5 -0
- package/{radio → badge}/types.js +0 -0
- package/bleed/Bleed.d.ts +3 -0
- package/bleed/Bleed.js +51 -0
- package/bleed/Bleed.stories.tsx +341 -0
- package/bleed/types.d.ts +37 -0
- package/bleed/types.js +5 -0
- package/box/Box.js +23 -33
- package/box/Box.test.js +18 -0
- package/box/types.d.ts +1 -0
- 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/bulleted-list/types.js +5 -0
- package/button/Button.d.ts +1 -1
- package/button/Button.js +57 -80
- package/button/Button.stories.tsx +15 -8
- package/button/Button.test.js +35 -0
- package/button/types.d.ts +8 -12
- package/card/Card.js +24 -27
- package/card/Card.stories.tsx +1 -1
- package/card/Card.test.js +50 -0
- package/card/types.d.ts +1 -0
- package/checkbox/Checkbox.d.ts +2 -2
- package/checkbox/Checkbox.js +106 -109
- package/checkbox/Checkbox.stories.tsx +146 -130
- package/checkbox/Checkbox.test.js +155 -0
- package/checkbox/types.d.ts +13 -5
- package/chip/Chip.d.ts +1 -1
- package/chip/Chip.js +14 -52
- package/chip/Chip.stories.tsx +6 -8
- package/chip/Chip.test.js +56 -0
- package/chip/types.d.ts +5 -13
- package/common/variables.js +250 -346
- package/date-input/DateInput.js +62 -48
- package/date-input/DateInput.stories.tsx +7 -7
- package/date-input/DateInput.test.js +479 -0
- package/date-input/types.d.ts +16 -9
- package/dialog/Dialog.js +46 -50
- package/dialog/Dialog.stories.tsx +57 -2
- package/dialog/Dialog.test.js +70 -0
- package/dialog/types.d.ts +3 -2
- package/dropdown/Dropdown.d.ts +1 -1
- package/dropdown/Dropdown.js +247 -273
- package/dropdown/Dropdown.stories.tsx +144 -79
- package/dropdown/Dropdown.test.js +585 -0
- 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 +29 -18
- package/file-input/FileInput.d.ts +2 -2
- package/file-input/FileInput.js +179 -220
- package/file-input/FileInput.stories.tsx +39 -10
- package/file-input/FileInput.test.js +498 -0
- package/file-input/FileItem.d.ts +4 -14
- package/file-input/FileItem.js +43 -66
- package/file-input/types.d.ts +17 -0
- package/flex/Flex.d.ts +4 -0
- package/flex/Flex.js +69 -0
- package/flex/Flex.stories.tsx +103 -0
- package/flex/types.d.ts +32 -0
- package/flex/types.js +5 -0
- package/footer/Footer.js +24 -99
- package/footer/Footer.stories.tsx +8 -1
- package/footer/Footer.test.js +109 -0
- package/footer/Icons.js +1 -1
- package/footer/types.d.ts +2 -1
- package/header/Header.js +95 -114
- package/header/Header.stories.tsx +46 -36
- package/header/Header.test.js +79 -0
- package/header/Icons.js +2 -2
- package/header/types.d.ts +3 -2
- package/heading/Heading.stories.tsx +3 -2
- package/heading/Heading.test.js +186 -0
- package/inset/Inset.d.ts +3 -0
- package/inset/Inset.js +51 -0
- package/inset/Inset.stories.tsx +229 -0
- package/inset/types.d.ts +37 -0
- package/inset/types.js +5 -0
- package/layout/ApplicationLayout.d.ts +16 -6
- package/layout/ApplicationLayout.js +71 -125
- package/layout/ApplicationLayout.stories.tsx +84 -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 +60 -85
- package/link/Link.stories.tsx +99 -52
- package/link/Link.test.js +83 -0
- package/link/types.d.ts +9 -29
- package/main.d.ts +11 -15
- package/main.js +53 -79
- package/number-input/NumberInput.js +11 -18
- package/number-input/NumberInput.stories.tsx +5 -5
- package/number-input/NumberInput.test.js +543 -0
- package/number-input/types.d.ts +17 -10
- package/package.json +14 -12
- package/paginator/Paginator.js +17 -38
- package/paginator/Paginator.test.js +308 -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.stories.tsx +3 -3
- package/password-input/PasswordInput.test.js +181 -0
- 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 +110 -0
- package/progress-bar/types.d.ts +3 -4
- package/quick-nav/QuickNav.d.ts +4 -0
- package/quick-nav/QuickNav.js +117 -0
- package/quick-nav/QuickNav.stories.tsx +342 -0
- package/quick-nav/types.d.ts +21 -0
- package/quick-nav/types.js +5 -0
- package/radio-group/Radio.d.ts +1 -1
- package/radio-group/Radio.js +79 -32
- package/radio-group/RadioGroup.js +153 -36
- package/radio-group/RadioGroup.stories.tsx +64 -19
- package/radio-group/RadioGroup.test.js +722 -0
- package/radio-group/types.d.ts +90 -13
- package/resultsetTable/ResultsetTable.js +6 -5
- package/resultsetTable/ResultsetTable.stories.tsx +7 -8
- package/resultsetTable/ResultsetTable.test.js +348 -0
- package/select/Icons.d.ts +10 -0
- package/select/Icons.js +93 -0
- package/select/Listbox.d.ts +4 -0
- package/select/Listbox.js +198 -0
- package/select/Option.d.ts +4 -0
- package/select/Option.js +110 -0
- package/select/Select.js +147 -365
- package/select/Select.stories.tsx +231 -176
- package/select/Select.test.js +2233 -0
- package/select/types.d.ts +52 -12
- package/sidenav/Sidenav.d.ts +6 -5
- package/sidenav/Sidenav.js +184 -52
- package/sidenav/Sidenav.stories.tsx +154 -139
- package/sidenav/Sidenav.test.js +44 -0
- package/sidenav/types.d.ts +50 -27
- package/slider/Slider.d.ts +2 -2
- package/slider/Slider.js +122 -96
- package/slider/Slider.stories.tsx +15 -9
- package/slider/Slider.test.js +250 -0
- package/slider/types.d.ts +10 -2
- package/spinner/Spinner.js +1 -1
- package/spinner/Spinner.stories.jsx +1 -0
- package/spinner/Spinner.test.js +64 -0
- package/switch/Switch.d.ts +2 -2
- package/switch/Switch.js +150 -67
- package/switch/Switch.stories.tsx +21 -43
- package/switch/Switch.test.js +225 -0
- package/switch/types.d.ts +12 -4
- package/table/Table.js +1 -1
- package/table/Table.stories.jsx +2 -1
- package/table/Table.test.js +26 -0
- package/tabs/Tab.d.ts +4 -0
- package/tabs/Tab.js +135 -0
- package/tabs/Tabs.d.ts +1 -1
- package/tabs/Tabs.js +364 -110
- package/tabs/Tabs.stories.tsx +81 -16
- package/tabs/Tabs.test.js +351 -0
- package/tabs/types.d.ts +39 -17
- 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/tabs-nav/types.js +5 -0
- package/tag/Tag.d.ts +1 -1
- package/tag/Tag.js +18 -28
- package/tag/Tag.stories.tsx +26 -29
- package/tag/Tag.test.js +60 -0
- package/tag/types.d.ts +23 -14
- package/text-input/Icons.d.ts +8 -0
- package/text-input/Icons.js +60 -0
- package/text-input/Suggestion.d.ts +4 -0
- package/text-input/Suggestion.js +57 -0
- package/text-input/Suggestions.d.ts +4 -0
- package/text-input/Suggestions.js +134 -0
- package/text-input/TextInput.js +213 -322
- package/text-input/TextInput.stories.tsx +218 -193
- package/text-input/TextInput.test.js +1771 -0
- package/text-input/types.d.ts +51 -13
- package/textarea/Textarea.js +20 -27
- package/textarea/Textarea.stories.jsx +37 -15
- package/textarea/Textarea.test.js +437 -0
- package/textarea/types.d.ts +18 -11
- 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 +156 -0
- 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/typography/types.js +5 -0
- package/useTheme.js +2 -2
- package/useTranslatedLabels.d.ts +2 -0
- package/useTranslatedLabels.js +20 -0
- package/wizard/Wizard.d.ts +1 -1
- package/wizard/Wizard.js +58 -54
- package/wizard/Wizard.stories.tsx +33 -24
- package/wizard/Wizard.test.js +141 -0
- package/wizard/types.d.ts +10 -5
- package/ThemeContext.d.ts +0 -15
- package/ThemeContext.js +0 -243
- package/V3Select/V3Select.js +0 -455
- package/V3Select/index.d.ts +0 -27
- package/V3Textarea/V3Textarea.js +0 -260
- package/V3Textarea/index.d.ts +0 -27
- package/date/Date.js +0 -373
- package/date/index.d.ts +0 -27
- package/input-text/Icons.js +0 -22
- package/input-text/InputText.js +0 -611
- package/input-text/index.d.ts +0 -36
- package/list/List.d.ts +0 -8
- package/list/List.js +0 -47
- package/list/List.stories.tsx +0 -85
- package/radio/Radio.d.ts +0 -4
- package/radio/Radio.js +0 -174
- package/radio/Radio.stories.tsx +0 -192
- package/radio/types.d.ts +0 -54
- package/row/Row.d.ts +0 -11
- package/row/Row.js +0 -124
- package/row/Row.stories.tsx +0 -223
- package/stack/Stack.d.ts +0 -10
- package/stack/Stack.js +0 -94
- package/stack/Stack.stories.tsx +0 -150
- package/text/Text.d.ts +0 -7
- package/text/Text.js +0 -30
- package/text/Text.stories.tsx +0 -19
- package/toggle/Toggle.js +0 -186
- package/toggle/index.d.ts +0 -21
- package/upload/Upload.js +0 -201
- package/upload/buttons-upload/ButtonsUpload.js +0 -111
- package/upload/buttons-upload/Icons.js +0 -40
- package/upload/dragAndDropArea/DragAndDropArea.js +0 -225
- package/upload/dragAndDropArea/Icons.js +0 -39
- package/upload/file-upload/FileToUpload.js +0 -115
- package/upload/file-upload/Icons.js +0 -66
- package/upload/files-upload/FilesToUpload.js +0 -109
- package/upload/index.d.ts +0 -15
- package/upload/transaction/Icons.js +0 -160
- package/upload/transaction/Transaction.js +0 -104
- package/upload/transactions/Transactions.js +0 -94
package/switch/Switch.js
CHANGED
|
@@ -19,9 +19,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
19
19
|
|
|
20
20
|
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
21
21
|
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
var _RequiredComponent = _interopRequireDefault(require("../common/RequiredComponent"));
|
|
22
|
+
var _uuid = require("uuid");
|
|
25
23
|
|
|
26
24
|
var _variables = require("../common/variables.js");
|
|
27
25
|
|
|
@@ -29,16 +27,19 @@ var _utils = require("../common/utils.js");
|
|
|
29
27
|
|
|
30
28
|
var _useTheme = _interopRequireDefault(require("../useTheme"));
|
|
31
29
|
|
|
30
|
+
var _useTranslatedLabels = _interopRequireDefault(require("../useTranslatedLabels"));
|
|
31
|
+
|
|
32
32
|
var _BackgroundColorContext = _interopRequireDefault(require("../BackgroundColorContext"));
|
|
33
33
|
|
|
34
|
-
var _templateObject, _templateObject2;
|
|
34
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
|
|
35
35
|
|
|
36
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); }
|
|
37
37
|
|
|
38
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; }
|
|
39
39
|
|
|
40
|
-
var DxcSwitch = function
|
|
41
|
-
var
|
|
40
|
+
var DxcSwitch = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
41
|
+
var defaultChecked = _ref.defaultChecked,
|
|
42
|
+
checked = _ref.checked,
|
|
42
43
|
value = _ref.value,
|
|
43
44
|
_ref$label = _ref.label,
|
|
44
45
|
label = _ref$label === void 0 ? "" : _ref$label,
|
|
@@ -48,75 +49,159 @@ var DxcSwitch = function DxcSwitch(_ref) {
|
|
|
48
49
|
name = _ref$name === void 0 ? "" : _ref$name,
|
|
49
50
|
_ref$disabled = _ref.disabled,
|
|
50
51
|
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
52
|
+
_ref$optional = _ref.optional,
|
|
53
|
+
optional = _ref$optional === void 0 ? false : _ref$optional,
|
|
51
54
|
onChange = _ref.onChange,
|
|
52
|
-
_ref$required = _ref.required,
|
|
53
|
-
required = _ref$required === void 0 ? false : _ref$required,
|
|
54
55
|
margin = _ref.margin,
|
|
55
56
|
_ref$size = _ref.size,
|
|
56
57
|
size = _ref$size === void 0 ? "fitContent" : _ref$size,
|
|
57
58
|
_ref$tabIndex = _ref.tabIndex,
|
|
58
59
|
tabIndex = _ref$tabIndex === void 0 ? 0 : _ref$tabIndex;
|
|
59
60
|
|
|
60
|
-
var _useState = (0, _react.useState)(
|
|
61
|
-
_useState2 = (0, _slicedToArray2["default"])(_useState,
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
var _useState = (0, _react.useState)("switch-".concat((0, _uuid.v4)())),
|
|
62
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 1),
|
|
63
|
+
switchId = _useState2[0];
|
|
64
|
+
|
|
65
|
+
var labelId = "label-".concat(switchId);
|
|
66
|
+
|
|
67
|
+
var _useState3 = (0, _react.useState)(defaultChecked !== null && defaultChecked !== void 0 ? defaultChecked : false),
|
|
68
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
69
|
+
innerChecked = _useState4[0],
|
|
70
|
+
setInnerChecked = _useState4[1];
|
|
64
71
|
|
|
65
72
|
var colorsTheme = (0, _useTheme["default"])();
|
|
73
|
+
var translatedLabels = (0, _useTranslatedLabels["default"])();
|
|
66
74
|
var backgroundType = (0, _react.useContext)(_BackgroundColorContext["default"]);
|
|
75
|
+
var refTrack = (0, _react.useRef)(null);
|
|
67
76
|
|
|
68
|
-
var
|
|
69
|
-
|
|
70
|
-
|
|
77
|
+
var handleOnKeyDown = function handleOnKeyDown(event) {
|
|
78
|
+
switch (event.key) {
|
|
79
|
+
case "Enter":
|
|
80
|
+
case " ":
|
|
81
|
+
//Space
|
|
82
|
+
event.preventDefault();
|
|
83
|
+
refTrack.current.focus();
|
|
84
|
+
var isChecked = !(checked !== null && checked !== void 0 ? checked : innerChecked);
|
|
85
|
+
setInnerChecked(isChecked);
|
|
86
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(isChecked);
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
71
90
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
91
|
+
var handlerSwitchChange = function handlerSwitchChange(event) {
|
|
92
|
+
checked !== null && checked !== void 0 ? checked : setInnerChecked(function (innerChecked) {
|
|
93
|
+
return !innerChecked;
|
|
94
|
+
});
|
|
95
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(checked ? !checked : !innerChecked);
|
|
76
96
|
};
|
|
77
97
|
|
|
78
98
|
return /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
|
|
79
99
|
theme: colorsTheme["switch"]
|
|
80
100
|
}, /*#__PURE__*/_react["default"].createElement(SwitchContainer, {
|
|
81
101
|
margin: margin,
|
|
102
|
+
size: size,
|
|
103
|
+
onKeyDown: handleOnKeyDown,
|
|
82
104
|
disabled: disabled,
|
|
105
|
+
onClick: !disabled ? handlerSwitchChange : undefined,
|
|
106
|
+
ref: ref
|
|
107
|
+
}, labelPosition === "before" && label && /*#__PURE__*/_react["default"].createElement(LabelContainer, {
|
|
108
|
+
id: labelId,
|
|
83
109
|
labelPosition: labelPosition,
|
|
84
|
-
|
|
85
|
-
backgroundType: backgroundType
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
},
|
|
92
|
-
onChange: handlerSwitchChange,
|
|
110
|
+
disabled: disabled,
|
|
111
|
+
backgroundType: backgroundType,
|
|
112
|
+
label: label
|
|
113
|
+
}, label, " ", optional && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, translatedLabels.formFields.optionalLabel)), /*#__PURE__*/_react["default"].createElement(ValueInput, {
|
|
114
|
+
type: "checkbox",
|
|
115
|
+
name: name,
|
|
116
|
+
"aria-hidden": true,
|
|
93
117
|
value: value,
|
|
94
118
|
disabled: disabled,
|
|
95
|
-
|
|
96
|
-
|
|
119
|
+
checked: checked !== null && checked !== void 0 ? checked : innerChecked,
|
|
120
|
+
readOnly: true
|
|
121
|
+
}), /*#__PURE__*/_react["default"].createElement(SwitchBase, null, /*#__PURE__*/_react["default"].createElement(SwitchTrack, {
|
|
122
|
+
role: "switch",
|
|
123
|
+
backgroundType: backgroundType,
|
|
124
|
+
"aria-checked": checked !== null && checked !== void 0 ? checked : innerChecked,
|
|
125
|
+
"aria-disabled": disabled,
|
|
126
|
+
disabled: disabled,
|
|
127
|
+
"aria-labelledby": labelId,
|
|
128
|
+
tabIndex: !disabled ? tabIndex : -1,
|
|
129
|
+
ref: refTrack
|
|
130
|
+
})), labelPosition === "after" && label && /*#__PURE__*/_react["default"].createElement(LabelContainer, {
|
|
131
|
+
id: labelId,
|
|
97
132
|
labelPosition: labelPosition,
|
|
98
|
-
onClick: !disabled && handlerSwitchChange,
|
|
99
133
|
disabled: disabled,
|
|
100
|
-
backgroundType: backgroundType
|
|
101
|
-
|
|
102
|
-
};
|
|
134
|
+
backgroundType: backgroundType,
|
|
135
|
+
label: label
|
|
136
|
+
}, optional && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, translatedLabels.formFields.optionalLabel), " ", label)));
|
|
137
|
+
});
|
|
103
138
|
|
|
104
139
|
var sizes = {
|
|
105
140
|
small: "60px",
|
|
106
141
|
medium: "240px",
|
|
107
142
|
large: "480px",
|
|
108
143
|
fillParent: "100%",
|
|
109
|
-
fitContent: "
|
|
144
|
+
fitContent: "fit-content"
|
|
110
145
|
};
|
|
111
146
|
|
|
112
147
|
var calculateWidth = function calculateWidth(margin, size) {
|
|
113
148
|
return size === "fillParent" ? "calc(".concat(sizes[size], " - ").concat((0, _utils.getMargin)(margin, "left"), " - ").concat((0, _utils.getMargin)(margin, "right"), ")") : sizes[size];
|
|
114
149
|
};
|
|
115
150
|
|
|
116
|
-
var
|
|
151
|
+
var getDisabledColor = function getDisabledColor(props, element, subelement) {
|
|
152
|
+
switch (element) {
|
|
153
|
+
case "track":
|
|
154
|
+
switch (subelement) {
|
|
155
|
+
case "check":
|
|
156
|
+
return props.backgroundType && props.backgroundType === "dark" ? props.theme.disabledCheckedTrackBackgroundColorOnDark : props.theme.disabledCheckedTrackBackgroundColor;
|
|
157
|
+
|
|
158
|
+
case "uncheck":
|
|
159
|
+
return props.backgroundType && props.backgroundType === "dark" ? props.theme.disabledUncheckedTrackBackgroundColorOnDark : props.theme.disabledUncheckedTrackBackgroundColor;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
case "thumb":
|
|
163
|
+
switch (subelement) {
|
|
164
|
+
case "check":
|
|
165
|
+
return props.backgroundType && props.backgroundType === "dark" ? props.theme.disabledCheckedThumbBackgroundColorOnDark : props.theme.disabledCheckedThumbBackgroundColor;
|
|
166
|
+
|
|
167
|
+
case "uncheck":
|
|
168
|
+
return props.backgroundType && props.backgroundType === "dark" ? props.theme.disabledUncheckedThumbBackgroundColorOnDark : props.theme.disabledUncheckedThumbBackgroundColor;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
case "label":
|
|
172
|
+
return props.backgroundType && props.backgroundType === "dark" ? props.theme.disabledLabelFontColorOnDark : props.theme.disabledLabelFontColor;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
var getNotDisabledColor = function getNotDisabledColor(props, element, subelement) {
|
|
177
|
+
switch (element) {
|
|
178
|
+
case "track":
|
|
179
|
+
switch (subelement) {
|
|
180
|
+
case "check":
|
|
181
|
+
return props.backgroundType && props.backgroundType === "dark" ? props.theme.checkedTrackBackgroundColorOnDark : props.theme.checkedTrackBackgroundColor;
|
|
182
|
+
|
|
183
|
+
case "uncheck":
|
|
184
|
+
return props.backgroundType && props.backgroundType === "dark" ? props.theme.uncheckedTrackBackgroundColorOnDark : props.theme.uncheckedTrackBackgroundColor;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
case "thumb":
|
|
188
|
+
switch (subelement) {
|
|
189
|
+
case "check":
|
|
190
|
+
return props.backgroundType && props.backgroundType === "dark" ? props.theme.checkedThumbBackgroundColorOnDark : props.theme.checkedThumbBackgroundColor;
|
|
191
|
+
|
|
192
|
+
case "uncheck":
|
|
193
|
+
return props.backgroundType && props.backgroundType === "dark" ? props.theme.uncheckedThumbBackgroundColorOnDark : props.theme.uncheckedThumbBackgroundColor;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
case "label":
|
|
197
|
+
return props.backgroundType && props.backgroundType === "dark" ? props.theme.labelFontColorOnDark : props.theme.labelFontColor;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
var SwitchContainer = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n display: inline-flex;\n align-items: center;\n width: ", ";\n height: 40px;\n cursor: ", ";\n\n margin: ", ";\n margin-top: ", ";\n margin-right: ", ";\n margin-bottom: ", ";\n margin-left: ", ";\n"])), function (props) {
|
|
117
202
|
return calculateWidth(props.margin, props.size);
|
|
118
203
|
}, function (props) {
|
|
119
|
-
return props.
|
|
204
|
+
return props.disabled === true ? "not-allowed" : "pointer";
|
|
120
205
|
}, function (props) {
|
|
121
206
|
return props.margin && (0, _typeof2["default"])(props.margin) !== "object" ? _variables.spaces[props.margin] : "0px";
|
|
122
207
|
}, function (props) {
|
|
@@ -127,52 +212,50 @@ var SwitchContainer = _styledComponents["default"].div(_templateObject || (_temp
|
|
|
127
212
|
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.bottom ? _variables.spaces[props.margin.bottom] : "";
|
|
128
213
|
}, function (props) {
|
|
129
214
|
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.left ? _variables.spaces[props.margin.left] : "";
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
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\n ", ";\n\n ", "\n"])), function (props) {
|
|
218
|
+
return props.disabled ? getDisabledColor(props, "label") : getNotDisabledColor(props, "label");
|
|
130
219
|
}, function (props) {
|
|
131
|
-
return props.
|
|
132
|
-
}, function (props) {
|
|
133
|
-
return props.theme.trackWidth;
|
|
134
|
-
}, function (props) {
|
|
135
|
-
return "".concat(props.backgroundType === "dark" ? props.theme.thumbFocusColorOnDark : props.theme.thumbFocusColor, " solid 2px");
|
|
136
|
-
}, function (props) {
|
|
137
|
-
return props.backgroundType === "dark" ? props.theme.uncheckedTrackBackgroundColorOnDark : props.theme.uncheckedTrackBackgroundColor;
|
|
138
|
-
}, function (props) {
|
|
139
|
-
return props.theme.trackHeight;
|
|
140
|
-
}, function (props) {
|
|
141
|
-
return props.theme.thumbWidth;
|
|
220
|
+
return props.theme.labelFontFamily;
|
|
142
221
|
}, function (props) {
|
|
143
|
-
return props.theme.
|
|
222
|
+
return props.theme.labelFontSize;
|
|
144
223
|
}, function (props) {
|
|
145
|
-
return props.
|
|
224
|
+
return props.disabled ? props.theme.disabledLabelFontStyle : props.theme.labelFontStyle;
|
|
146
225
|
}, function (props) {
|
|
147
|
-
return props.
|
|
226
|
+
return props.theme.labelFontWeight;
|
|
148
227
|
}, function (props) {
|
|
149
|
-
return props.
|
|
228
|
+
return !props.label ? "margin: 0px;" : props.labelPosition === "after" ? "margin-left: ".concat(props.theme.spaceBetweenLabelSwitch, ";") : "margin-right: ".concat(props.theme.spaceBetweenLabelSwitch, ";");
|
|
150
229
|
}, function (props) {
|
|
151
|
-
return props.
|
|
230
|
+
return props.labelPosition === "before" && "order: -1";
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
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: 0px 12px;\n"])));
|
|
234
|
+
|
|
235
|
+
var ValueInput = _styledComponents["default"].input(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["\n display: none;\n"])));
|
|
236
|
+
|
|
237
|
+
var SwitchTrack = _styledComponents["default"].span(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2["default"])(["\n border-radius: 15px;\n width: ", ";\n height: ", ";\n position: relative;\n cursor: ", ";\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 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 &[aria-checked=\"true\"] {\n background-color: ", ";\n ::before {\n transform: translateX(", ");\n background-color: ", ";\n }\n }\n"])), function (props) {
|
|
238
|
+
return props.theme.trackWidth;
|
|
152
239
|
}, function (props) {
|
|
153
|
-
return props.
|
|
240
|
+
return props.theme.trackHeight;
|
|
154
241
|
}, function (props) {
|
|
155
|
-
return props.
|
|
242
|
+
return props.disabled ? "not-allowed" : "pointer";
|
|
156
243
|
}, function (props) {
|
|
157
|
-
return props.theme.
|
|
244
|
+
return "".concat(props.backgroundType === "dark" ? props.theme.thumbFocusColorOnDark : props.theme.thumbFocusColor, " solid 2px");
|
|
158
245
|
}, function (props) {
|
|
159
|
-
return props.
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
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"])), function (props) {
|
|
163
|
-
return props.disabled ? props.backgroundType === "dark" ? props.theme.disabledLabelFontColorOnDark : props.theme.disabledLabelFontColor : props.backgroundType === "dark" ? props.theme.labelFontColorOnDark : props.theme.labelFontColor;
|
|
246
|
+
return props.theme.thumbWidth;
|
|
164
247
|
}, function (props) {
|
|
165
|
-
return props.theme.
|
|
248
|
+
return props.theme.thumbHeight;
|
|
166
249
|
}, function (props) {
|
|
167
|
-
return props.
|
|
250
|
+
return props.disabled ? getDisabledColor(props, "thumb", "uncheck") : getNotDisabledColor(props, "thumb", "uncheck");
|
|
168
251
|
}, function (props) {
|
|
169
|
-
return props.disabled ? props
|
|
252
|
+
return props.disabled ? getDisabledColor(props, "track", "uncheck") : getNotDisabledColor(props, "track", "uncheck");
|
|
170
253
|
}, function (props) {
|
|
171
|
-
return props.
|
|
254
|
+
return props.disabled ? getDisabledColor(props, "track", "check") : getNotDisabledColor(props, "track", "check");
|
|
172
255
|
}, function (props) {
|
|
173
|
-
return props.
|
|
256
|
+
return props.theme.thumbShift;
|
|
174
257
|
}, function (props) {
|
|
175
|
-
return props.
|
|
258
|
+
return props.disabled ? getDisabledColor(props, "thumb", "check") : getNotDisabledColor(props, "thumb", "check");
|
|
176
259
|
});
|
|
177
260
|
|
|
178
261
|
var _default = DxcSwitch;
|
|
@@ -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,25 +20,29 @@ 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
|
-
<DxcSwitch label="Switch"
|
|
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} />
|
|
42
|
-
<DxcSwitch label="Switch" disabled
|
|
45
|
+
<DxcSwitch label="Switch" disabled defaultChecked labelPosition="after" />
|
|
43
46
|
</ExampleContainer>
|
|
44
47
|
<BackgroundColorProvider color="#333333">
|
|
45
48
|
<DarkContainer>
|
|
@@ -47,32 +50,36 @@ 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
|
-
<DxcSwitch label="Switch"
|
|
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} />
|
|
68
|
-
<DxcSwitch label="Switch" disabled
|
|
75
|
+
<DxcSwitch label="Switch" disabled defaultChecked labelPosition="after" />
|
|
69
76
|
</ExampleContainer>
|
|
70
77
|
</DarkContainer>
|
|
71
78
|
</BackgroundColorProvider>
|
|
72
79
|
<Title title="Margins" theme="light" level={2} />
|
|
73
80
|
<ExampleContainer>
|
|
74
81
|
<Title title="Xxsmall margin" theme="light" level={4} />
|
|
75
|
-
<DxcSwitch label="
|
|
82
|
+
<DxcSwitch label="Xxsmall" margin="xxsmall" />
|
|
76
83
|
</ExampleContainer>
|
|
77
84
|
<ExampleContainer>
|
|
78
85
|
<Title title="Xsmall margin" theme="light" 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("checkbox").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("checkbox").focus();
|
|
160
|
-
};
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _react = _interopRequireDefault(require("react"));
|
|
6
|
+
|
|
7
|
+
var _react2 = require("@testing-library/react");
|
|
8
|
+
|
|
9
|
+
var _Switch = _interopRequireDefault(require("./Switch"));
|
|
10
|
+
|
|
11
|
+
describe("Switch component tests", function () {
|
|
12
|
+
test("Switch renders with correct text", function () {
|
|
13
|
+
var onChange = jest.fn(function (returnedValue) {
|
|
14
|
+
expect(returnedValue).toBe(true);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
var _render = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
18
|
+
label: "SwitchComponent",
|
|
19
|
+
checked: false,
|
|
20
|
+
onChange: onChange
|
|
21
|
+
})),
|
|
22
|
+
getByText = _render.getByText;
|
|
23
|
+
|
|
24
|
+
expect(getByText("SwitchComponent")).toBeTruthy();
|
|
25
|
+
});
|
|
26
|
+
test("Calls correct function on click", function () {
|
|
27
|
+
var onChange = jest.fn();
|
|
28
|
+
|
|
29
|
+
var _render2 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
30
|
+
label: "SwitchComponent",
|
|
31
|
+
checked: false,
|
|
32
|
+
onChange: onChange
|
|
33
|
+
})),
|
|
34
|
+
getByText = _render2.getByText;
|
|
35
|
+
|
|
36
|
+
_react2.fireEvent.click(getByText("SwitchComponent"));
|
|
37
|
+
|
|
38
|
+
expect(onChange).toHaveBeenCalled();
|
|
39
|
+
});
|
|
40
|
+
test("Calls correct function on key down", function () {
|
|
41
|
+
var onChange = jest.fn();
|
|
42
|
+
|
|
43
|
+
var _render3 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
44
|
+
label: "SwitchComponent",
|
|
45
|
+
checked: false,
|
|
46
|
+
onChange: onChange
|
|
47
|
+
})),
|
|
48
|
+
getByText = _render3.getByText;
|
|
49
|
+
|
|
50
|
+
_react2.fireEvent.focus(getByText("SwitchComponent"));
|
|
51
|
+
|
|
52
|
+
_react2.fireEvent.keyDown(getByText("SwitchComponent"), {
|
|
53
|
+
key: "Enter"
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
expect(onChange).toHaveBeenCalled();
|
|
57
|
+
|
|
58
|
+
_react2.fireEvent.keyDown(getByText("SwitchComponent"), {
|
|
59
|
+
key: " "
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
expect(onChange).toHaveBeenCalled();
|
|
63
|
+
});
|
|
64
|
+
test("Everytime the user clicks the component the onchange function is called with the correct value CONTROLLED COMPONENT", function () {
|
|
65
|
+
var onChange = jest.fn();
|
|
66
|
+
|
|
67
|
+
var _render4 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
68
|
+
label: "SwitchComponent",
|
|
69
|
+
checked: false,
|
|
70
|
+
onChange: onChange
|
|
71
|
+
})),
|
|
72
|
+
getByText = _render4.getByText;
|
|
73
|
+
|
|
74
|
+
_react2.fireEvent.click(getByText("SwitchComponent"));
|
|
75
|
+
|
|
76
|
+
_react2.fireEvent.click(getByText("SwitchComponent"));
|
|
77
|
+
|
|
78
|
+
expect(onChange.mock.calls[0][0]).toBe(true);
|
|
79
|
+
expect(onChange.mock.calls[1][0]).toBe(true);
|
|
80
|
+
});
|
|
81
|
+
test("Everytime the user use enter in the component, the onchange function is called with the correct value CONTROLLED COMPONENT", function () {
|
|
82
|
+
var onChange = jest.fn();
|
|
83
|
+
|
|
84
|
+
var _render5 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
85
|
+
label: "SwitchComponent",
|
|
86
|
+
checked: false,
|
|
87
|
+
onChange: onChange
|
|
88
|
+
})),
|
|
89
|
+
getByText = _render5.getByText;
|
|
90
|
+
|
|
91
|
+
_react2.fireEvent.focus(getByText("SwitchComponent"));
|
|
92
|
+
|
|
93
|
+
_react2.fireEvent.keyDown(getByText("SwitchComponent"), {
|
|
94
|
+
key: "Enter"
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
_react2.fireEvent.keyDown(getByText("SwitchComponent"), {
|
|
98
|
+
key: "Enter"
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
expect(onChange.mock.calls[0][0]).toBe(true);
|
|
102
|
+
expect(onChange.mock.calls[1][0]).toBe(true);
|
|
103
|
+
});
|
|
104
|
+
test("Everytime the user use space in the component, the onchange function is called with the correct value CONTROLLED COMPONENT", function () {
|
|
105
|
+
var onChange = jest.fn();
|
|
106
|
+
|
|
107
|
+
var _render6 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
108
|
+
label: "SwitchComponent",
|
|
109
|
+
checked: false,
|
|
110
|
+
onChange: onChange
|
|
111
|
+
})),
|
|
112
|
+
getByText = _render6.getByText;
|
|
113
|
+
|
|
114
|
+
_react2.fireEvent.focus(getByText("SwitchComponent"));
|
|
115
|
+
|
|
116
|
+
_react2.fireEvent.keyDown(getByText("SwitchComponent"), {
|
|
117
|
+
key: " "
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
_react2.fireEvent.keyDown(getByText("SwitchComponent"), {
|
|
121
|
+
key: " "
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
expect(onChange.mock.calls[0][0]).toBe(true);
|
|
125
|
+
expect(onChange.mock.calls[1][0]).toBe(true);
|
|
126
|
+
});
|
|
127
|
+
test("Everytime the user clicks the component the onchange function is called with the correct value UNCONTROLLED COMPONENT", function () {
|
|
128
|
+
var onChange = jest.fn();
|
|
129
|
+
|
|
130
|
+
var _render7 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
131
|
+
label: "SwitchComponent",
|
|
132
|
+
onChange: onChange
|
|
133
|
+
})),
|
|
134
|
+
getByText = _render7.getByText;
|
|
135
|
+
|
|
136
|
+
_react2.fireEvent.click(getByText("SwitchComponent"));
|
|
137
|
+
|
|
138
|
+
_react2.fireEvent.click(getByText("SwitchComponent"));
|
|
139
|
+
|
|
140
|
+
expect(onChange.mock.calls[0][0]).toBe(true);
|
|
141
|
+
expect(onChange.mock.calls[1][0]).toBe(false);
|
|
142
|
+
});
|
|
143
|
+
test("Everytime the user use enter in the component, the onchange function is called with the correct value UNCONTROLLED COMPONENT", function () {
|
|
144
|
+
var onChange = jest.fn();
|
|
145
|
+
|
|
146
|
+
var _render8 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
147
|
+
label: "SwitchComponent",
|
|
148
|
+
onChange: onChange
|
|
149
|
+
})),
|
|
150
|
+
getByText = _render8.getByText;
|
|
151
|
+
|
|
152
|
+
_react2.fireEvent.focus(getByText("SwitchComponent"));
|
|
153
|
+
|
|
154
|
+
_react2.fireEvent.keyDown(getByText("SwitchComponent"), {
|
|
155
|
+
key: "Enter"
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
_react2.fireEvent.keyDown(getByText("SwitchComponent"), {
|
|
159
|
+
key: "Enter"
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
expect(onChange.mock.calls[0][0]).toBe(true);
|
|
163
|
+
expect(onChange.mock.calls[1][0]).toBe(false);
|
|
164
|
+
});
|
|
165
|
+
test("Everytime the user use space in the component, the onchange function is called with the correct value UNCONTROLLED COMPONENT", function () {
|
|
166
|
+
var onChange = jest.fn();
|
|
167
|
+
|
|
168
|
+
var _render9 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
169
|
+
label: "SwitchComponent",
|
|
170
|
+
onChange: onChange
|
|
171
|
+
})),
|
|
172
|
+
getByText = _render9.getByText;
|
|
173
|
+
|
|
174
|
+
_react2.fireEvent.focus(getByText("SwitchComponent"));
|
|
175
|
+
|
|
176
|
+
_react2.fireEvent.keyDown(getByText("SwitchComponent"), {
|
|
177
|
+
key: " "
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
_react2.fireEvent.keyDown(getByText("SwitchComponent"), {
|
|
181
|
+
key: " "
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
expect(onChange.mock.calls[0][0]).toBe(true);
|
|
185
|
+
expect(onChange.mock.calls[1][0]).toBe(false);
|
|
186
|
+
});
|
|
187
|
+
test("Renders with correct initial value and initial state when it is uncontrolled", function () {
|
|
188
|
+
var component = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
189
|
+
label: "Default label",
|
|
190
|
+
defaultChecked: true,
|
|
191
|
+
value: "test-defaultChecked",
|
|
192
|
+
name: "test"
|
|
193
|
+
}));
|
|
194
|
+
var switchEl = component.getByRole("switch");
|
|
195
|
+
var inputEl = component.container.querySelector("input[name=\"test\"]");
|
|
196
|
+
expect(inputEl.value).toBe("test-defaultChecked");
|
|
197
|
+
expect(switchEl.getAttribute("aria-checked")).toBe("true");
|
|
198
|
+
});
|
|
199
|
+
test("Renders with correct aria attributes", function () {
|
|
200
|
+
var _render10 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
201
|
+
label: "Default label"
|
|
202
|
+
})),
|
|
203
|
+
getByText = _render10.getByText,
|
|
204
|
+
getByRole = _render10.getByRole;
|
|
205
|
+
|
|
206
|
+
var switchEl = getByRole("switch");
|
|
207
|
+
var label = getByText("Default label");
|
|
208
|
+
expect(switchEl.getAttribute("aria-labelledby")).toBe(label.id);
|
|
209
|
+
expect(switchEl.getAttribute("aria-checked")).toBe("false");
|
|
210
|
+
});
|
|
211
|
+
test("Renders disabled switch correctly", function () {
|
|
212
|
+
var _render11 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
213
|
+
label: "Default label",
|
|
214
|
+
disabled: true
|
|
215
|
+
})),
|
|
216
|
+
getByText = _render11.getByText,
|
|
217
|
+
getByRole = _render11.getByRole;
|
|
218
|
+
|
|
219
|
+
var switchEl = getByRole("switch");
|
|
220
|
+
var label = getByText("Default label");
|
|
221
|
+
expect(switchEl.getAttribute("aria-labelledby")).toBe(label.id);
|
|
222
|
+
expect(switchEl.getAttribute("aria-checked")).toBe("false");
|
|
223
|
+
expect(switchEl.getAttribute("aria-disabled")).toBe("true");
|
|
224
|
+
});
|
|
225
|
+
});
|