@dxc-technology/halstack-react 0.0.0-8d998c7 → 0.0.0-8f4e799
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/BackgroundColorContext.d.ts +10 -0
- package/BackgroundColorContext.js +1 -4
- package/HalstackContext.d.ts +12 -0
- package/HalstackContext.js +295 -0
- package/accordion/Accordion.d.ts +1 -1
- package/accordion/Accordion.js +124 -137
- package/accordion/Accordion.stories.tsx +306 -0
- package/accordion/Accordion.test.js +71 -0
- package/accordion/types.d.ts +11 -11
- package/accordion-group/AccordionGroup.d.ts +1 -1
- package/accordion-group/AccordionGroup.js +16 -37
- package/accordion-group/AccordionGroup.stories.tsx +251 -0
- package/accordion-group/AccordionGroup.test.js +126 -0
- package/accordion-group/types.d.ts +16 -10
- package/alert/Alert.js +7 -4
- package/alert/Alert.stories.tsx +170 -0
- package/alert/Alert.test.js +92 -0
- package/alert/types.d.ts +1 -1
- package/badge/Badge.d.ts +4 -0
- package/badge/Badge.js +6 -4
- 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.d.ts +4 -0
- package/box/Box.js +29 -65
- package/box/{Box.stories.jsx → Box.stories.tsx} +0 -0
- package/box/Box.test.js +18 -0
- package/box/types.d.ts +43 -0
- package/box/types.js +5 -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 +61 -87
- package/button/Button.stories.tsx +232 -242
- package/button/Button.test.js +35 -0
- package/button/types.d.ts +14 -18
- package/card/Card.js +26 -30
- package/card/Card.stories.tsx +201 -0
- package/card/Card.test.js +50 -0
- package/card/ice-cream.jpg +0 -0
- package/card/types.d.ts +4 -6
- package/checkbox/Checkbox.d.ts +1 -1
- package/checkbox/Checkbox.js +104 -108
- package/checkbox/Checkbox.stories.tsx +188 -0
- package/checkbox/Checkbox.test.js +155 -0
- package/checkbox/types.d.ts +11 -7
- package/chip/Chip.d.ts +4 -0
- package/chip/Chip.js +16 -76
- package/chip/Chip.stories.tsx +119 -0
- package/chip/Chip.test.js +56 -0
- package/chip/types.d.ts +45 -0
- package/chip/types.js +5 -0
- package/common/variables.js +319 -380
- package/date-input/DateInput.js +66 -55
- package/date-input/DateInput.stories.tsx +138 -0
- package/date-input/DateInput.test.js +479 -0
- package/date-input/types.d.ts +16 -9
- package/dialog/Dialog.d.ts +4 -0
- package/dialog/Dialog.js +52 -74
- package/dialog/Dialog.stories.tsx +211 -0
- package/dialog/Dialog.test.js +70 -0
- package/dialog/types.d.ts +43 -0
- package/dialog/types.js +5 -0
- package/dropdown/Dropdown.d.ts +1 -1
- package/dropdown/Dropdown.js +243 -273
- package/dropdown/Dropdown.stories.tsx +312 -0
- package/dropdown/Dropdown.test.js +591 -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 +30 -19
- package/file-input/FileInput.d.ts +4 -0
- package/file-input/FileInput.js +172 -111
- package/file-input/FileInput.stories.tsx +507 -0
- package/file-input/FileInput.test.js +457 -0
- package/file-input/FileItem.d.ts +14 -0
- package/file-input/FileItem.js +16 -23
- package/file-input/types.d.ts +112 -0
- package/file-input/types.js +5 -0
- 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/flex/types.js +5 -0
- package/footer/Footer.d.ts +1 -1
- package/footer/Footer.js +32 -113
- package/footer/Footer.stories.tsx +137 -0
- package/footer/Footer.test.js +109 -0
- package/footer/Icons.d.ts +2 -0
- package/footer/Icons.js +4 -4
- package/footer/types.d.ts +22 -18
- package/header/Header.d.ts +7 -0
- package/header/Header.js +119 -140
- package/header/Header.stories.tsx +172 -0
- package/header/Header.test.js +79 -0
- package/header/Icons.d.ts +2 -0
- package/header/Icons.js +4 -29
- package/header/types.d.ts +47 -0
- package/header/types.js +5 -0
- package/heading/Heading.d.ts +4 -0
- package/heading/Heading.js +7 -24
- package/heading/Heading.stories.tsx +54 -0
- package/heading/Heading.test.js +186 -0
- package/heading/types.d.ts +33 -0
- package/heading/types.js +5 -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 +20 -0
- package/layout/ApplicationLayout.js +71 -135
- package/layout/ApplicationLayout.stories.tsx +162 -0
- 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 +42 -0
- package/layout/types.js +5 -0
- package/link/Link.d.ts +4 -0
- package/link/Link.js +60 -107
- package/link/Link.stories.tsx +193 -0
- package/link/Link.test.js +83 -0
- package/link/types.d.ts +54 -0
- package/link/types.js +5 -0
- package/main.d.ts +12 -12
- package/main.js +64 -58
- package/number-input/NumberInput.d.ts +4 -0
- package/number-input/NumberInput.js +16 -68
- package/number-input/NumberInput.stories.tsx +115 -0
- package/number-input/NumberInput.test.js +506 -0
- package/number-input/NumberInputContext.d.ts +4 -0
- package/number-input/NumberInputContext.js +5 -2
- package/number-input/numberInputContextTypes.d.ts +19 -0
- package/number-input/numberInputContextTypes.js +5 -0
- package/number-input/types.d.ts +124 -0
- package/number-input/types.js +5 -0
- package/package.json +16 -12
- package/paginator/Paginator.js +19 -46
- package/paginator/Paginator.stories.tsx +63 -0
- 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.d.ts +4 -0
- package/password-input/PasswordInput.js +22 -55
- package/password-input/{PasswordInput.stories.jsx → PasswordInput.stories.tsx} +4 -4
- package/password-input/PasswordInput.test.js +180 -0
- package/password-input/types.d.ts +110 -0
- package/password-input/types.js +5 -0
- package/progress-bar/ProgressBar.d.ts +2 -2
- package/progress-bar/ProgressBar.js +60 -54
- package/progress-bar/ProgressBar.stories.jsx +60 -0
- 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 +118 -0
- package/quick-nav/QuickNav.stories.tsx +264 -0
- package/quick-nav/types.d.ts +21 -0
- package/quick-nav/types.js +5 -0
- package/radio-group/Radio.d.ts +4 -0
- package/radio-group/Radio.js +141 -0
- package/radio-group/RadioGroup.d.ts +4 -0
- package/radio-group/RadioGroup.js +281 -0
- package/radio-group/RadioGroup.stories.tsx +100 -0
- package/radio-group/RadioGroup.test.js +695 -0
- package/radio-group/types.d.ts +114 -0
- package/radio-group/types.js +5 -0
- package/resultsetTable/ResultsetTable.d.ts +4 -0
- package/resultsetTable/ResultsetTable.js +9 -29
- package/resultsetTable/ResultsetTable.stories.tsx +275 -0
- package/resultsetTable/ResultsetTable.test.js +348 -0
- package/resultsetTable/types.d.ts +67 -0
- package/resultsetTable/types.js +5 -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.d.ts +4 -0
- package/select/Select.js +158 -380
- package/select/Select.stories.tsx +627 -0
- package/select/Select.test.js +2175 -0
- package/select/types.d.ts +210 -0
- package/select/types.js +5 -0
- package/sidenav/Sidenav.d.ts +10 -0
- package/sidenav/Sidenav.js +186 -63
- package/sidenav/Sidenav.stories.tsx +180 -0
- package/sidenav/Sidenav.test.js +44 -0
- package/sidenav/types.d.ts +73 -0
- package/sidenav/types.js +5 -0
- package/slider/Slider.d.ts +1 -1
- package/slider/Slider.js +143 -110
- package/slider/Slider.stories.tsx +183 -0
- package/slider/Slider.test.js +250 -0
- package/slider/types.d.ts +8 -9
- package/spinner/Spinner.d.ts +4 -0
- package/spinner/Spinner.js +9 -26
- package/spinner/Spinner.stories.jsx +103 -0
- package/spinner/Spinner.test.js +64 -0
- package/spinner/types.d.ts +32 -0
- package/spinner/types.js +5 -0
- package/switch/Switch.d.ts +2 -2
- package/switch/Switch.js +130 -58
- package/switch/Switch.stories.tsx +138 -0
- package/switch/Switch.test.js +212 -0
- package/switch/types.d.ts +9 -6
- package/table/Table.d.ts +4 -0
- package/table/Table.js +3 -3
- package/table/Table.stories.jsx +277 -0
- package/table/Table.test.js +26 -0
- package/table/types.d.ts +21 -0
- package/table/types.js +5 -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 -108
- package/tabs/Tabs.stories.tsx +186 -0
- package/tabs/Tabs.test.js +351 -0
- package/tabs/types.d.ts +41 -20
- 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 +4 -0
- package/tag/Tag.js +35 -60
- package/tag/Tag.stories.tsx +142 -0
- package/tag/Tag.test.js +60 -0
- package/tag/types.d.ts +69 -0
- package/tag/types.js +5 -0
- 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.d.ts +4 -0
- package/text-input/TextInput.js +166 -328
- package/text-input/TextInput.stories.tsx +481 -0
- package/text-input/TextInput.test.js +1713 -0
- package/text-input/types.d.ts +192 -0
- package/text-input/types.js +5 -0
- package/textarea/Textarea.d.ts +4 -0
- package/textarea/Textarea.js +39 -79
- package/textarea/Textarea.stories.jsx +37 -15
- package/textarea/Textarea.test.js +437 -0
- package/textarea/types.d.ts +137 -0
- package/textarea/types.js +5 -0
- package/toggle-group/ToggleGroup.d.ts +4 -0
- package/toggle-group/ToggleGroup.js +18 -46
- package/toggle-group/ToggleGroup.stories.tsx +173 -0
- package/toggle-group/ToggleGroup.test.js +156 -0
- package/toggle-group/types.d.ts +105 -0
- package/toggle-group/types.js +5 -0
- 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.d.ts +2 -0
- package/useTheme.js +2 -2
- package/useTranslatedLabels.d.ts +2 -0
- package/useTranslatedLabels.js +20 -0
- package/wizard/Wizard.d.ts +4 -0
- package/wizard/Wizard.js +118 -104
- package/wizard/Wizard.stories.tsx +233 -0
- package/wizard/Wizard.test.js +141 -0
- package/wizard/types.d.ts +65 -0
- package/wizard/types.js +5 -0
- package/ThemeContext.js +0 -246
- 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/box/index.d.ts +0 -25
- package/chip/index.d.ts +0 -22
- package/date/Date.js +0 -373
- package/date/index.d.ts +0 -27
- package/dialog/index.d.ts +0 -18
- package/file-input/index.d.ts +0 -81
- package/header/index.d.ts +0 -25
- package/heading/index.d.ts +0 -17
- package/input-text/Icons.js +0 -22
- package/input-text/InputText.js +0 -611
- package/input-text/index.d.ts +0 -36
- package/link/index.d.ts +0 -23
- package/number-input/index.d.ts +0 -113
- package/password-input/index.d.ts +0 -94
- package/radio/Radio.d.ts +0 -4
- package/radio/Radio.js +0 -174
- package/radio/types.d.ts +0 -54
- package/resultsetTable/index.d.ts +0 -19
- package/select/index.d.ts +0 -131
- package/sidenav/index.d.ts +0 -13
- package/spinner/index.d.ts +0 -17
- package/table/index.d.ts +0 -13
- package/tag/index.d.ts +0 -24
- package/text-input/index.d.ts +0 -135
- package/textarea/index.d.ts +0 -117
- package/toggle/Toggle.js +0 -186
- package/toggle/index.d.ts +0 -21
- package/toggle-group/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/wizard/Icons.js +0 -65
- package/wizard/index.d.ts +0 -18
package/switch/Switch.js
CHANGED
|
@@ -19,26 +19,29 @@ 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
|
|
|
28
26
|
var _utils = require("../common/utils.js");
|
|
29
27
|
|
|
30
|
-
var _useTheme = _interopRequireDefault(require("../useTheme
|
|
28
|
+
var _useTheme = _interopRequireDefault(require("../useTheme"));
|
|
29
|
+
|
|
30
|
+
var _useTranslatedLabels = _interopRequireDefault(require("../useTranslatedLabels"));
|
|
31
31
|
|
|
32
|
-
var _BackgroundColorContext = _interopRequireDefault(require("../BackgroundColorContext
|
|
32
|
+
var _BackgroundColorContext = _interopRequireDefault(require("../BackgroundColorContext"));
|
|
33
33
|
|
|
34
|
-
var _templateObject, _templateObject2;
|
|
34
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
|
|
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
40
|
var DxcSwitch = function DxcSwitch(_ref) {
|
|
41
|
-
var
|
|
41
|
+
var _ref2;
|
|
42
|
+
|
|
43
|
+
var defaultChecked = _ref.defaultChecked,
|
|
44
|
+
checked = _ref.checked,
|
|
42
45
|
value = _ref.value,
|
|
43
46
|
_ref$label = _ref.label,
|
|
44
47
|
label = _ref$label === void 0 ? "" : _ref$label,
|
|
@@ -48,22 +51,52 @@ var DxcSwitch = function DxcSwitch(_ref) {
|
|
|
48
51
|
name = _ref$name === void 0 ? "" : _ref$name,
|
|
49
52
|
_ref$disabled = _ref.disabled,
|
|
50
53
|
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
54
|
+
_ref$optional = _ref.optional,
|
|
55
|
+
optional = _ref$optional === void 0 ? false : _ref$optional,
|
|
51
56
|
onChange = _ref.onChange,
|
|
52
|
-
_ref$required = _ref.required,
|
|
53
|
-
required = _ref$required === void 0 ? false : _ref$required,
|
|
54
57
|
margin = _ref.margin,
|
|
55
58
|
_ref$size = _ref.size,
|
|
56
59
|
size = _ref$size === void 0 ? "fitContent" : _ref$size,
|
|
57
60
|
_ref$tabIndex = _ref.tabIndex,
|
|
58
61
|
tabIndex = _ref$tabIndex === void 0 ? 0 : _ref$tabIndex;
|
|
59
62
|
|
|
60
|
-
var _useState = (0, _react.useState)(
|
|
61
|
-
_useState2 = (0, _slicedToArray2["default"])(_useState,
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
var _useState = (0, _react.useState)("switch-".concat((0, _uuid.v4)())),
|
|
64
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 1),
|
|
65
|
+
switchId = _useState2[0];
|
|
66
|
+
|
|
67
|
+
var labelId = "label-".concat(switchId);
|
|
68
|
+
|
|
69
|
+
var _useState3 = (0, _react.useState)(defaultChecked !== null && defaultChecked !== void 0 ? defaultChecked : false),
|
|
70
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
71
|
+
innerChecked = _useState4[0],
|
|
72
|
+
setInnerChecked = _useState4[1];
|
|
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];
|
|
64
77
|
|
|
65
78
|
var colorsTheme = (0, _useTheme["default"])();
|
|
79
|
+
var translatedLabels = (0, _useTranslatedLabels["default"])();
|
|
66
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
|
+
};
|
|
67
100
|
|
|
68
101
|
var handlerSwitchChange = function handlerSwitchChange(event) {
|
|
69
102
|
if (checked === undefined) {
|
|
@@ -71,34 +104,64 @@ var DxcSwitch = function DxcSwitch(_ref) {
|
|
|
71
104
|
|
|
72
105
|
var isChecked = (_event$target$checked = event.target.checked) !== null && _event$target$checked !== void 0 ? _event$target$checked : !innerChecked;
|
|
73
106
|
setInnerChecked(isChecked);
|
|
74
|
-
|
|
75
|
-
|
|
107
|
+
|
|
108
|
+
if (typeof onChange === "function") {
|
|
109
|
+
onChange(isChecked);
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
if (typeof onChange === "function") {
|
|
113
|
+
onChange(!checked);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
76
116
|
};
|
|
77
117
|
|
|
78
118
|
return /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
|
|
79
119
|
theme: colorsTheme["switch"]
|
|
80
120
|
}, /*#__PURE__*/_react["default"].createElement(SwitchContainer, {
|
|
81
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,
|
|
82
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, {
|
|
83
132
|
labelPosition: labelPosition,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
onChange: handlerSwitchChange,
|
|
93
|
-
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,
|
|
94
141
|
disabled: disabled,
|
|
95
|
-
|
|
96
|
-
|
|
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, {
|
|
158
|
+
id: labelId,
|
|
97
159
|
labelPosition: labelPosition,
|
|
98
|
-
onClick: !disabled
|
|
160
|
+
onClick: !disabled ? handlerSwitchChange : undefined,
|
|
99
161
|
disabled: disabled,
|
|
100
|
-
backgroundType: backgroundType
|
|
101
|
-
|
|
162
|
+
backgroundType: backgroundType,
|
|
163
|
+
hasLabel: hasLabel
|
|
164
|
+
}, optional && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, translatedLabels.formFields.optionalLabel), " ", label)));
|
|
102
165
|
};
|
|
103
166
|
|
|
104
167
|
var sizes = {
|
|
@@ -106,17 +169,15 @@ var sizes = {
|
|
|
106
169
|
medium: "240px",
|
|
107
170
|
large: "480px",
|
|
108
171
|
fillParent: "100%",
|
|
109
|
-
fitContent: "
|
|
172
|
+
fitContent: "fit-content"
|
|
110
173
|
};
|
|
111
174
|
|
|
112
175
|
var calculateWidth = function calculateWidth(margin, size) {
|
|
113
176
|
return size === "fillParent" ? "calc(".concat(sizes[size], " - ").concat((0, _utils.getMargin)(margin, "left"), " - ").concat((0, _utils.getMargin)(margin, "right"), ")") : sizes[size];
|
|
114
177
|
};
|
|
115
178
|
|
|
116
|
-
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) {
|
|
117
180
|
return calculateWidth(props.margin, props.size);
|
|
118
|
-
}, function (props) {
|
|
119
|
-
return props.labelPosition === "after" ? "row" : "row-reverse";
|
|
120
181
|
}, function (props) {
|
|
121
182
|
return props.margin && (0, _typeof2["default"])(props.margin) !== "object" ? _variables.spaces[props.margin] : "0px";
|
|
122
183
|
}, function (props) {
|
|
@@ -127,16 +188,38 @@ var SwitchContainer = _styledComponents["default"].div(_templateObject || (_temp
|
|
|
127
188
|
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.bottom ? _variables.spaces[props.margin.bottom] : "";
|
|
128
189
|
}, function (props) {
|
|
129
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;
|
|
130
195
|
}, function (props) {
|
|
131
|
-
return props.
|
|
196
|
+
return props.theme.labelFontFamily;
|
|
132
197
|
}, function (props) {
|
|
133
|
-
return props.theme.
|
|
198
|
+
return props.theme.labelFontSize;
|
|
134
199
|
}, function (props) {
|
|
135
|
-
return
|
|
200
|
+
return props.disabled ? props.theme.disabledLabelFontStyle : props.theme.labelFontStyle;
|
|
136
201
|
}, function (props) {
|
|
137
|
-
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;
|
|
138
219
|
}, function (props) {
|
|
139
220
|
return props.theme.trackHeight;
|
|
221
|
+
}, function (props) {
|
|
222
|
+
return "".concat(props.backgroundType === "dark" ? props.theme.thumbFocusColorOnDark : props.theme.thumbFocusColor, " solid 2px");
|
|
140
223
|
}, function (props) {
|
|
141
224
|
return props.theme.thumbWidth;
|
|
142
225
|
}, function (props) {
|
|
@@ -144,36 +227,25 @@ var SwitchContainer = _styledComponents["default"].div(_templateObject || (_temp
|
|
|
144
227
|
}, function (props) {
|
|
145
228
|
return props.backgroundType === "dark" ? props.theme.uncheckedThumbBackgroundColorOnDark : props.theme.uncheckedThumbBackgroundColor;
|
|
146
229
|
}, function (props) {
|
|
147
|
-
return props.backgroundType === "dark" ? props.theme.
|
|
148
|
-
}, function (props) {
|
|
149
|
-
return props.backgroundType === "dark" ? props.theme.disabledUncheckedTrackBackgroundColorOnDark : props.theme.disabledUncheckedTrackBackgroundColor;
|
|
150
|
-
}, function (props) {
|
|
151
|
-
return props.backgroundType === "dark" ? props.theme.disabledCheckedThumbBackgroundColorOnDark : props.theme.disabledCheckedThumbBackgroundColor;
|
|
152
|
-
}, function (props) {
|
|
153
|
-
return props.backgroundType === "dark" ? props.theme.disabledCheckedTrackBackgroundColorOnDark : props.theme.disabledCheckedTrackBackgroundColor;
|
|
230
|
+
return props.backgroundType === "dark" ? props.theme.uncheckedTrackBackgroundColorOnDark : props.theme.uncheckedTrackBackgroundColor;
|
|
154
231
|
}, function (props) {
|
|
155
|
-
return props.backgroundType === "dark" ? props.theme.
|
|
232
|
+
return props.backgroundType === "dark" ? props.theme.checkedTrackBackgroundColorOnDark : props.theme.checkedTrackBackgroundColor;
|
|
156
233
|
}, function (props) {
|
|
157
234
|
return props.theme.thumbShift;
|
|
158
235
|
}, function (props) {
|
|
159
|
-
return props.backgroundType === "dark" ? props.theme.
|
|
236
|
+
return props.backgroundType === "dark" ? props.theme.checkedThumbBackgroundColorOnDark : props.theme.checkedThumbBackgroundColor;
|
|
160
237
|
});
|
|
161
238
|
|
|
162
|
-
var
|
|
163
|
-
return props.
|
|
164
|
-
}, function (props) {
|
|
165
|
-
return props.theme.labelFontFamily;
|
|
166
|
-
}, function (props) {
|
|
167
|
-
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;
|
|
168
241
|
}, function (props) {
|
|
169
|
-
return props.
|
|
242
|
+
return props.backgroundType === "dark" ? props.theme.disabledUncheckedThumbBackgroundColorOnDark : props.theme.disabledUncheckedThumbBackgroundColor;
|
|
170
243
|
}, function (props) {
|
|
171
|
-
return props.theme.
|
|
244
|
+
return props.backgroundType === "dark" ? props.theme.disabledCheckedTrackBackgroundColorOnDark : props.theme.disabledCheckedTrackBackgroundColor;
|
|
172
245
|
}, function (props) {
|
|
173
|
-
return props.
|
|
246
|
+
return props.theme.thumbShift;
|
|
174
247
|
}, function (props) {
|
|
175
|
-
return props.
|
|
248
|
+
return props.backgroundType === "dark" ? props.theme.disabledCheckedThumbBackgroundColorOnDark : props.theme.disabledCheckedThumbBackgroundColor;
|
|
176
249
|
});
|
|
177
|
-
|
|
178
250
|
var _default = DxcSwitch;
|
|
179
251
|
exports["default"] = _default;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import DxcSwitch from "./Switch";
|
|
3
|
+
import { BackgroundColorProvider } from "../BackgroundColorContext";
|
|
4
|
+
import Title from "../../.storybook/components/Title";
|
|
5
|
+
import ExampleContainer from "../../.storybook/components/ExampleContainer";
|
|
6
|
+
import DarkContainer from "../../.storybook/components/DarkSection";
|
|
7
|
+
|
|
8
|
+
export default {
|
|
9
|
+
title: "Switch",
|
|
10
|
+
component: DxcSwitch,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const Chromatic = () => (
|
|
14
|
+
<>
|
|
15
|
+
<ExampleContainer>
|
|
16
|
+
<Title title="With label after" theme="light" level={4} />
|
|
17
|
+
<DxcSwitch label="Switch" labelPosition="after" />
|
|
18
|
+
</ExampleContainer>
|
|
19
|
+
<ExampleContainer>
|
|
20
|
+
<Title title="Without label" theme="light" level={4} />
|
|
21
|
+
<DxcSwitch />
|
|
22
|
+
</ExampleContainer>
|
|
23
|
+
<ExampleContainer pseudoState="pseudo-focus-visible">
|
|
24
|
+
<Title title="Focused" theme="light" level={4} />
|
|
25
|
+
<DxcSwitch label="Switch" labelPosition="after" />
|
|
26
|
+
</ExampleContainer>
|
|
27
|
+
<ExampleContainer>
|
|
28
|
+
<Title title="Checked" theme="light" level={4} />
|
|
29
|
+
<DxcSwitch label="Switch" defaultChecked />
|
|
30
|
+
</ExampleContainer>
|
|
31
|
+
<ExampleContainer>
|
|
32
|
+
<Title title="Optional" theme="light" level={4} />
|
|
33
|
+
<DxcSwitch label="Switch" optional />
|
|
34
|
+
</ExampleContainer>
|
|
35
|
+
<ExampleContainer>
|
|
36
|
+
<Title title="Disabled" theme="light" level={4} />
|
|
37
|
+
<DxcSwitch label="Switch" disabled />
|
|
38
|
+
</ExampleContainer>
|
|
39
|
+
<ExampleContainer>
|
|
40
|
+
<Title title="Disabled optional" theme="light" level={4} />
|
|
41
|
+
<DxcSwitch label="Switch" disabled optional labelPosition="after" />
|
|
42
|
+
</ExampleContainer>
|
|
43
|
+
<ExampleContainer>
|
|
44
|
+
<Title title="Disabled checked" theme="light" level={4} />
|
|
45
|
+
<DxcSwitch label="Switch" disabled defaultChecked labelPosition="after" />
|
|
46
|
+
</ExampleContainer>
|
|
47
|
+
<BackgroundColorProvider color="#333333">
|
|
48
|
+
<DarkContainer>
|
|
49
|
+
<ExampleContainer>
|
|
50
|
+
<Title title="With label" theme="dark" level={4} />
|
|
51
|
+
<DxcSwitch label="Switch" />
|
|
52
|
+
</ExampleContainer>
|
|
53
|
+
<ExampleContainer pseudoState="pseudo-focus-visible">
|
|
54
|
+
<Title title="Focused" theme="dark" level={4} />
|
|
55
|
+
<DxcSwitch label="Switch" labelPosition="after" />
|
|
56
|
+
</ExampleContainer>
|
|
57
|
+
<ExampleContainer>
|
|
58
|
+
<Title title="Checked" theme="dark" level={4} />
|
|
59
|
+
<DxcSwitch label="Switch" defaultChecked />
|
|
60
|
+
</ExampleContainer>
|
|
61
|
+
<ExampleContainer>
|
|
62
|
+
<Title title="Optional" theme="dark" level={4} />
|
|
63
|
+
<DxcSwitch label="Switch" optional />
|
|
64
|
+
</ExampleContainer>
|
|
65
|
+
<ExampleContainer>
|
|
66
|
+
<Title title="Disabled" theme="dark" level={4} />
|
|
67
|
+
<DxcSwitch label="Switch" disabled />
|
|
68
|
+
</ExampleContainer>
|
|
69
|
+
<ExampleContainer>
|
|
70
|
+
<Title title="Disabled optional" theme="dark" level={4} />
|
|
71
|
+
<DxcSwitch label="Switch" disabled optional labelPosition="after" />
|
|
72
|
+
</ExampleContainer>
|
|
73
|
+
<ExampleContainer>
|
|
74
|
+
<Title title="Disabled checked" theme="dark" level={4} />
|
|
75
|
+
<DxcSwitch label="Switch" disabled defaultChecked labelPosition="after" />
|
|
76
|
+
</ExampleContainer>
|
|
77
|
+
</DarkContainer>
|
|
78
|
+
</BackgroundColorProvider>
|
|
79
|
+
<Title title="Margins" theme="light" level={2} />
|
|
80
|
+
<ExampleContainer>
|
|
81
|
+
<Title title="Xxsmall margin" theme="light" level={4} />
|
|
82
|
+
<DxcSwitch label="Xxsmall" margin="xxsmall" />
|
|
83
|
+
</ExampleContainer>
|
|
84
|
+
<ExampleContainer>
|
|
85
|
+
<Title title="Xsmall margin" theme="light" level={4} />
|
|
86
|
+
<DxcSwitch label="Xsmall" margin="xsmall" />
|
|
87
|
+
</ExampleContainer>
|
|
88
|
+
<ExampleContainer>
|
|
89
|
+
<Title title="Small margin" theme="light" level={4} />
|
|
90
|
+
<DxcSwitch label="Small" margin="small" />
|
|
91
|
+
</ExampleContainer>
|
|
92
|
+
<ExampleContainer>
|
|
93
|
+
<Title title="Medium margin" theme="light" level={4} />
|
|
94
|
+
<DxcSwitch label="Medium" margin="medium" />
|
|
95
|
+
</ExampleContainer>
|
|
96
|
+
<ExampleContainer>
|
|
97
|
+
<Title title="Large margin" theme="light" level={4} />
|
|
98
|
+
<DxcSwitch label="Large" margin="large" />
|
|
99
|
+
</ExampleContainer>
|
|
100
|
+
<ExampleContainer>
|
|
101
|
+
<Title title="Xlarge margin" theme="light" level={4} />
|
|
102
|
+
<DxcSwitch label="Xlarge" margin="xlarge" />
|
|
103
|
+
</ExampleContainer>
|
|
104
|
+
<ExampleContainer>
|
|
105
|
+
<Title title="Xxlarge margin" theme="light" level={4} />
|
|
106
|
+
<DxcSwitch label="Xxlarge" margin="xxlarge" />
|
|
107
|
+
</ExampleContainer>
|
|
108
|
+
<Title title="Sizes" theme="light" level={2} />
|
|
109
|
+
<ExampleContainer>
|
|
110
|
+
<Title title="Small size" theme="light" level={4} />
|
|
111
|
+
<DxcSwitch label="Small" size="small" />
|
|
112
|
+
</ExampleContainer>
|
|
113
|
+
<ExampleContainer>
|
|
114
|
+
<Title title="Medium size (with large label)" theme="light" level={4} />
|
|
115
|
+
<DxcSwitch label="Very very very large label or even huge" size="medium" />
|
|
116
|
+
</ExampleContainer>
|
|
117
|
+
<ExampleContainer>
|
|
118
|
+
<Title title="Medium size (with long label)" theme="light" level={4} />
|
|
119
|
+
<DxcSwitch
|
|
120
|
+
label="Large texttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
|
|
121
|
+
labelPosition="after"
|
|
122
|
+
size="medium"
|
|
123
|
+
/>
|
|
124
|
+
</ExampleContainer>
|
|
125
|
+
<ExampleContainer>
|
|
126
|
+
<Title title="Large size" theme="light" level={4} />
|
|
127
|
+
<DxcSwitch label="Large" size="large" />
|
|
128
|
+
</ExampleContainer>
|
|
129
|
+
<ExampleContainer>
|
|
130
|
+
<Title title="FillParent size" theme="light" level={4} />
|
|
131
|
+
<DxcSwitch label="FillParent" size="fillParent" />
|
|
132
|
+
</ExampleContainer>
|
|
133
|
+
<ExampleContainer>
|
|
134
|
+
<Title title="FitContent size" theme="light" level={4} />
|
|
135
|
+
<DxcSwitch label="FitContent" size="fitContent" />
|
|
136
|
+
</ExampleContainer>
|
|
137
|
+
</>
|
|
138
|
+
);
|
|
@@ -0,0 +1,212 @@
|
|
|
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 _render10 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
189
|
+
label: "Default label",
|
|
190
|
+
defaultChecked: true,
|
|
191
|
+
value: "test-defaultChecked"
|
|
192
|
+
})),
|
|
193
|
+
getByRole = _render10.getByRole;
|
|
194
|
+
|
|
195
|
+
var inputEl = getByRole("switch");
|
|
196
|
+
expect(inputEl.checked).toBe(true);
|
|
197
|
+
expect(inputEl.value).toBe("test-defaultChecked");
|
|
198
|
+
expect(inputEl.getAttribute("aria-checked")).toBe("true");
|
|
199
|
+
});
|
|
200
|
+
test("Renders with correct aria attributes", function () {
|
|
201
|
+
var _render11 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
202
|
+
label: "Default label"
|
|
203
|
+
})),
|
|
204
|
+
getByRole = _render11.getByRole,
|
|
205
|
+
getByText = _render11.getByText;
|
|
206
|
+
|
|
207
|
+
var inputEl = getByRole("switch");
|
|
208
|
+
var label = getByText("Default label");
|
|
209
|
+
expect(inputEl.getAttribute("aria-labelledby")).toBe(label.id);
|
|
210
|
+
expect(inputEl.getAttribute("aria-checked")).toBe("false");
|
|
211
|
+
});
|
|
212
|
+
});
|