@dxc-technology/halstack-react 0.0.0-a7970fd → 0.0.0-a7fec42
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 +4 -2
- package/HalstackContext.js +110 -58
- package/accordion/Accordion.js +122 -103
- package/accordion/Accordion.stories.tsx +2 -3
- package/accordion/Accordion.test.js +9 -10
- package/accordion/types.d.ts +5 -4
- package/accordion-group/AccordionGroup.js +2 -21
- package/accordion-group/AccordionGroup.stories.tsx +27 -1
- package/accordion-group/AccordionGroup.test.js +20 -45
- package/accordion-group/types.d.ts +10 -3
- package/alert/Alert.js +5 -2
- 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 +23 -33
- 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/{list → bulleted-list}/types.js +0 -0
- package/button/Button.js +43 -61
- package/button/Button.stories.tsx +9 -0
- package/button/types.d.ts +7 -7
- package/card/Card.js +34 -36
- package/card/types.d.ts +1 -0
- package/checkbox/Checkbox.js +90 -95
- package/checkbox/Checkbox.test.js +93 -16
- package/checkbox/types.d.ts +2 -2
- package/chip/types.d.ts +1 -1
- package/common/variables.js +232 -96
- package/date-input/DateInput.js +8 -5
- package/dialog/Dialog.js +52 -28
- package/dialog/Dialog.stories.tsx +57 -2
- package/dialog/Dialog.test.js +34 -4
- package/dialog/types.d.ts +3 -2
- package/dropdown/Dropdown.d.ts +1 -1
- package/dropdown/Dropdown.js +244 -247
- package/dropdown/Dropdown.stories.tsx +126 -63
- package/dropdown/Dropdown.test.js +509 -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 +69 -0
- package/flex/Flex.stories.tsx +103 -0
- package/flex/types.d.ts +32 -0
- package/{quick-nav-container → flex}/types.js +0 -0
- package/footer/Footer.js +7 -5
- package/footer/Footer.stories.tsx +8 -1
- package/footer/Icons.js +1 -1
- package/footer/types.d.ts +2 -1
- package/header/Header.js +80 -75
- package/header/Header.stories.tsx +4 -4
- package/header/Icons.js +2 -2
- package/header/types.d.ts +3 -2
- package/inset/Inset.js +1 -34
- package/inset/Inset.stories.tsx +36 -36
- package/inset/types.d.ts +1 -1
- package/layout/ApplicationLayout.d.ts +16 -6
- package/layout/ApplicationLayout.js +70 -117
- 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 +57 -70
- 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 +8 -11
- package/main.js +40 -58
- package/number-input/NumberInput.test.js +1 -1
- package/number-input/types.d.ts +1 -1
- package/package.json +10 -9
- 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 +11 -6
- package/password-input/PasswordInput.test.js +14 -14
- package/password-input/types.d.ts +1 -1
- 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 +75 -22
- package/quick-nav/QuickNav.stories.tsx +131 -26
- package/quick-nav/types.d.ts +1 -1
- package/radio-group/Radio.d.ts +1 -1
- package/radio-group/Radio.js +43 -28
- package/radio-group/RadioGroup.js +30 -27
- package/radio-group/RadioGroup.stories.tsx +1 -0
- package/radio-group/RadioGroup.test.js +123 -96
- package/radio-group/types.d.ts +2 -2
- package/resultsetTable/ResultsetTable.test.js +42 -0
- package/select/Listbox.d.ts +1 -1
- package/select/Listbox.js +58 -8
- package/select/Select.js +80 -90
- package/select/Select.stories.tsx +145 -100
- package/select/Select.test.js +425 -249
- package/select/types.d.ts +2 -5
- 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.js +116 -92
- package/slider/Slider.stories.tsx +7 -1
- package/slider/Slider.test.js +121 -21
- package/slider/types.d.ts +2 -2
- package/spinner/Spinner.js +1 -1
- package/switch/Switch.d.ts +1 -1
- package/switch/Switch.js +135 -66
- package/switch/Switch.stories.tsx +8 -30
- package/switch/Switch.test.js +144 -17
- package/switch/types.d.ts +3 -4
- package/table/Table.js +1 -1
- package/tabs/Tab.d.ts +4 -0
- package/tabs/Tab.js +135 -0
- package/tabs/Tabs.js +360 -104
- package/tabs/Tabs.stories.tsx +74 -0
- package/tabs/Tabs.test.js +217 -6
- package/tabs/types.d.ts +15 -5
- 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/{radio → tabs-nav}/types.js +0 -0
- package/tag/Tag.js +1 -1
- package/tag/types.d.ts +1 -1
- 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 +206 -329
- package/text-input/TextInput.stories.tsx +189 -182
- package/text-input/TextInput.test.js +166 -164
- package/text-input/types.d.ts +35 -4
- package/textarea/Textarea.js +10 -19
- package/textarea/types.d.ts +1 -1
- package/toggle-group/types.d.ts +1 -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/{row → typography}/types.js +0 -0
- package/useTranslatedLabels.d.ts +2 -0
- package/useTranslatedLabels.js +20 -0
- package/wizard/Wizard.js +36 -41
- package/wizard/Wizard.stories.tsx +20 -1
- package/wizard/types.d.ts +5 -4
- 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/quick-nav-container/HeadingLink.d.ts +0 -8
- package/quick-nav-container/HeadingLink.js +0 -58
- package/quick-nav-container/QuickNavContainer.d.ts +0 -4
- package/quick-nav-container/QuickNavContainer.js +0 -69
- package/quick-nav-container/Section.d.ts +0 -9
- package/quick-nav-container/Section.js +0 -37
- package/quick-nav-container/types.d.ts +0 -34
- package/radio/Radio.d.ts +0 -4
- package/radio/Radio.js +0 -173
- 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/stack/types.js +0 -5
- package/text/Text.d.ts +0 -7
- package/text/Text.js +0 -30
- package/text/Text.stories.tsx +0 -19
package/switch/Switch.js
CHANGED
|
@@ -19,8 +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
22
|
var _uuid = require("uuid");
|
|
25
23
|
|
|
26
24
|
var _variables = require("../common/variables.js");
|
|
@@ -29,9 +27,11 @@ 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
|
|
|
@@ -70,48 +70,69 @@ var DxcSwitch = function DxcSwitch(_ref) {
|
|
|
70
70
|
setInnerChecked = _useState4[1];
|
|
71
71
|
|
|
72
72
|
var colorsTheme = (0, _useTheme["default"])();
|
|
73
|
+
var translatedLabels = (0, _useTranslatedLabels["default"])();
|
|
73
74
|
var backgroundType = (0, _react.useContext)(_BackgroundColorContext["default"]);
|
|
75
|
+
var refTrack = (0, _react.useRef)(null);
|
|
74
76
|
|
|
75
|
-
var
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
+
}
|
|
83
89
|
};
|
|
84
90
|
|
|
85
|
-
var
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}, labelPosition === "before" ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, label, " ", optional && /*#__PURE__*/_react["default"].createElement("span", null, "(Optional)")) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, optional && /*#__PURE__*/_react["default"].createElement("span", null, "(Optional)"), " ", label));
|
|
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);
|
|
96
|
+
};
|
|
92
97
|
|
|
93
98
|
return /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
|
|
94
99
|
theme: colorsTheme["switch"]
|
|
95
100
|
}, /*#__PURE__*/_react["default"].createElement(SwitchContainer, {
|
|
96
101
|
margin: margin,
|
|
102
|
+
size: size,
|
|
103
|
+
onKeyDown: handleOnKeyDown,
|
|
97
104
|
disabled: disabled,
|
|
105
|
+
onClick: !disabled ? handlerSwitchChange : undefined
|
|
106
|
+
}, labelPosition === "before" && label && /*#__PURE__*/_react["default"].createElement(LabelContainer, {
|
|
107
|
+
id: labelId,
|
|
98
108
|
labelPosition: labelPosition,
|
|
99
|
-
|
|
100
|
-
backgroundType: backgroundType
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
role: "switch",
|
|
107
|
-
"aria-checked": checked !== null && checked !== void 0 ? checked : innerChecked,
|
|
108
|
-
tabIndex: tabIndex
|
|
109
|
-
},
|
|
110
|
-
onChange: handlerSwitchChange,
|
|
109
|
+
disabled: disabled,
|
|
110
|
+
backgroundType: backgroundType,
|
|
111
|
+
label: label
|
|
112
|
+
}, label, " ", optional && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, translatedLabels.formFields.optionalLabel)), /*#__PURE__*/_react["default"].createElement(ValueInput, {
|
|
113
|
+
type: "checkbox",
|
|
114
|
+
name: name,
|
|
115
|
+
"aria-hidden": true,
|
|
111
116
|
value: value,
|
|
112
117
|
disabled: disabled,
|
|
113
|
-
|
|
114
|
-
|
|
118
|
+
checked: checked !== null && checked !== void 0 ? checked : innerChecked,
|
|
119
|
+
readOnly: true
|
|
120
|
+
}), /*#__PURE__*/_react["default"].createElement(SwitchBase, null, /*#__PURE__*/_react["default"].createElement(SwitchTrack, {
|
|
121
|
+
role: "switch",
|
|
122
|
+
backgroundType: backgroundType,
|
|
123
|
+
"aria-checked": checked !== null && checked !== void 0 ? checked : innerChecked,
|
|
124
|
+
"aria-disabled": disabled,
|
|
125
|
+
disabled: disabled,
|
|
126
|
+
"aria-labelledby": labelId,
|
|
127
|
+
tabIndex: !disabled ? tabIndex : -1,
|
|
128
|
+
ref: refTrack
|
|
129
|
+
})), labelPosition === "after" && label && /*#__PURE__*/_react["default"].createElement(LabelContainer, {
|
|
130
|
+
id: labelId,
|
|
131
|
+
labelPosition: labelPosition,
|
|
132
|
+
disabled: disabled,
|
|
133
|
+
backgroundType: backgroundType,
|
|
134
|
+
label: label
|
|
135
|
+
}, optional && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, translatedLabels.formFields.optionalLabel), " ", label)));
|
|
115
136
|
};
|
|
116
137
|
|
|
117
138
|
var sizes = {
|
|
@@ -119,15 +140,67 @@ var sizes = {
|
|
|
119
140
|
medium: "240px",
|
|
120
141
|
large: "480px",
|
|
121
142
|
fillParent: "100%",
|
|
122
|
-
fitContent: "
|
|
143
|
+
fitContent: "fit-content"
|
|
123
144
|
};
|
|
124
145
|
|
|
125
146
|
var calculateWidth = function calculateWidth(margin, size) {
|
|
126
147
|
return size === "fillParent" ? "calc(".concat(sizes[size], " - ").concat((0, _utils.getMargin)(margin, "left"), " - ").concat((0, _utils.getMargin)(margin, "right"), ")") : sizes[size];
|
|
127
148
|
};
|
|
128
149
|
|
|
129
|
-
var
|
|
150
|
+
var getDisabledColor = function getDisabledColor(props, element, subelement) {
|
|
151
|
+
switch (element) {
|
|
152
|
+
case "track":
|
|
153
|
+
switch (subelement) {
|
|
154
|
+
case "check":
|
|
155
|
+
return props.backgroundType && props.backgroundType === "dark" ? props.theme.disabledCheckedTrackBackgroundColorOnDark : props.theme.disabledCheckedTrackBackgroundColor;
|
|
156
|
+
|
|
157
|
+
case "uncheck":
|
|
158
|
+
return props.backgroundType && props.backgroundType === "dark" ? props.theme.disabledUncheckedTrackBackgroundColorOnDark : props.theme.disabledUncheckedTrackBackgroundColor;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
case "thumb":
|
|
162
|
+
switch (subelement) {
|
|
163
|
+
case "check":
|
|
164
|
+
return props.backgroundType && props.backgroundType === "dark" ? props.theme.disabledCheckedThumbBackgroundColorOnDark : props.theme.disabledCheckedThumbBackgroundColor;
|
|
165
|
+
|
|
166
|
+
case "uncheck":
|
|
167
|
+
return props.backgroundType && props.backgroundType === "dark" ? props.theme.disabledUncheckedThumbBackgroundColorOnDark : props.theme.disabledUncheckedThumbBackgroundColor;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
case "label":
|
|
171
|
+
return props.backgroundType && props.backgroundType === "dark" ? props.theme.disabledLabelFontColorOnDark : props.theme.disabledLabelFontColor;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
var getNotDisabledColor = function getNotDisabledColor(props, element, subelement) {
|
|
176
|
+
switch (element) {
|
|
177
|
+
case "track":
|
|
178
|
+
switch (subelement) {
|
|
179
|
+
case "check":
|
|
180
|
+
return props.backgroundType && props.backgroundType === "dark" ? props.theme.checkedTrackBackgroundColorOnDark : props.theme.checkedTrackBackgroundColor;
|
|
181
|
+
|
|
182
|
+
case "uncheck":
|
|
183
|
+
return props.backgroundType && props.backgroundType === "dark" ? props.theme.uncheckedTrackBackgroundColorOnDark : props.theme.uncheckedTrackBackgroundColor;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
case "thumb":
|
|
187
|
+
switch (subelement) {
|
|
188
|
+
case "check":
|
|
189
|
+
return props.backgroundType && props.backgroundType === "dark" ? props.theme.checkedThumbBackgroundColorOnDark : props.theme.checkedThumbBackgroundColor;
|
|
190
|
+
|
|
191
|
+
case "uncheck":
|
|
192
|
+
return props.backgroundType && props.backgroundType === "dark" ? props.theme.uncheckedThumbBackgroundColorOnDark : props.theme.uncheckedThumbBackgroundColor;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
case "label":
|
|
196
|
+
return props.backgroundType && props.backgroundType === "dark" ? props.theme.labelFontColorOnDark : props.theme.labelFontColor;
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
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) {
|
|
130
201
|
return calculateWidth(props.margin, props.size);
|
|
202
|
+
}, function (props) {
|
|
203
|
+
return props.disabled === true ? "not-allowed" : "pointer";
|
|
131
204
|
}, function (props) {
|
|
132
205
|
return props.margin && (0, _typeof2["default"])(props.margin) !== "object" ? _variables.spaces[props.margin] : "0px";
|
|
133
206
|
}, function (props) {
|
|
@@ -138,54 +211,50 @@ var SwitchContainer = _styledComponents["default"].div(_templateObject || (_temp
|
|
|
138
211
|
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.bottom ? _variables.spaces[props.margin.bottom] : "";
|
|
139
212
|
}, function (props) {
|
|
140
213
|
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.left ? _variables.spaces[props.margin.left] : "";
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
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) {
|
|
217
|
+
return props.disabled ? getDisabledColor(props, "label") : getNotDisabledColor(props, "label");
|
|
141
218
|
}, function (props) {
|
|
142
|
-
return props.
|
|
143
|
-
}, function (props) {
|
|
144
|
-
return props.theme.trackWidth;
|
|
145
|
-
}, function (props) {
|
|
146
|
-
return "".concat(props.backgroundType === "dark" ? props.theme.thumbFocusColorOnDark : props.theme.thumbFocusColor, " solid 2px");
|
|
147
|
-
}, function (props) {
|
|
148
|
-
return props.backgroundType === "dark" ? props.theme.uncheckedTrackBackgroundColorOnDark : props.theme.uncheckedTrackBackgroundColor;
|
|
149
|
-
}, function (props) {
|
|
150
|
-
return props.theme.trackHeight;
|
|
151
|
-
}, function (props) {
|
|
152
|
-
return props.theme.thumbWidth;
|
|
153
|
-
}, function (props) {
|
|
154
|
-
return props.theme.thumbHeight;
|
|
219
|
+
return props.theme.labelFontFamily;
|
|
155
220
|
}, function (props) {
|
|
156
|
-
return props.
|
|
221
|
+
return props.theme.labelFontSize;
|
|
157
222
|
}, function (props) {
|
|
158
|
-
return props.
|
|
223
|
+
return props.disabled ? props.theme.disabledLabelFontStyle : props.theme.labelFontStyle;
|
|
159
224
|
}, function (props) {
|
|
160
|
-
return props.
|
|
225
|
+
return props.theme.labelFontWeight;
|
|
161
226
|
}, function (props) {
|
|
162
|
-
return props.
|
|
227
|
+
return !props.label ? "margin: 0px;" : props.labelPosition === "after" ? "margin-left: ".concat(props.theme.spaceBetweenLabelSwitch, ";") : "margin-right: ".concat(props.theme.spaceBetweenLabelSwitch, ";");
|
|
163
228
|
}, function (props) {
|
|
164
|
-
return props.
|
|
229
|
+
return props.labelPosition === "before" && "order: -1";
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
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"])));
|
|
233
|
+
|
|
234
|
+
var ValueInput = _styledComponents["default"].input(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["\n display: none;\n"])));
|
|
235
|
+
|
|
236
|
+
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) {
|
|
237
|
+
return props.theme.trackWidth;
|
|
165
238
|
}, function (props) {
|
|
166
|
-
return props.
|
|
239
|
+
return props.theme.trackHeight;
|
|
167
240
|
}, function (props) {
|
|
168
|
-
return props.
|
|
241
|
+
return props.disabled ? "not-allowed" : "pointer";
|
|
169
242
|
}, function (props) {
|
|
170
|
-
return props.backgroundType === "dark" ? props.theme.
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
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"])), function (props) {
|
|
174
|
-
return props.disabled ? props.backgroundType === "dark" ? props.theme.disabledLabelFontColorOnDark : props.theme.disabledLabelFontColor : props.backgroundType === "dark" ? props.theme.labelFontColorOnDark : props.theme.labelFontColor;
|
|
243
|
+
return "".concat(props.backgroundType === "dark" ? props.theme.thumbFocusColorOnDark : props.theme.thumbFocusColor, " solid 2px");
|
|
175
244
|
}, function (props) {
|
|
176
|
-
return props.theme.
|
|
245
|
+
return props.theme.thumbWidth;
|
|
177
246
|
}, function (props) {
|
|
178
|
-
return props.theme.
|
|
247
|
+
return props.theme.thumbHeight;
|
|
179
248
|
}, function (props) {
|
|
180
|
-
return props.disabled ? props
|
|
249
|
+
return props.disabled ? getDisabledColor(props, "thumb", "uncheck") : getNotDisabledColor(props, "thumb", "uncheck");
|
|
181
250
|
}, function (props) {
|
|
182
|
-
return props.
|
|
251
|
+
return props.disabled ? getDisabledColor(props, "track", "uncheck") : getNotDisabledColor(props, "track", "uncheck");
|
|
183
252
|
}, function (props) {
|
|
184
|
-
return props.disabled
|
|
253
|
+
return props.disabled ? getDisabledColor(props, "track", "check") : getNotDisabledColor(props, "track", "check");
|
|
185
254
|
}, function (props) {
|
|
186
|
-
return props.
|
|
255
|
+
return props.theme.thumbShift;
|
|
187
256
|
}, function (props) {
|
|
188
|
-
return props.
|
|
257
|
+
return props.disabled ? getDisabledColor(props, "thumb", "check") : getNotDisabledColor(props, "thumb", "check");
|
|
189
258
|
});
|
|
190
259
|
|
|
191
260
|
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,6 +20,10 @@ 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 />
|
|
@@ -47,6 +50,10 @@ 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 />
|
|
@@ -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
|
-
};
|
package/switch/Switch.test.js
CHANGED
|
@@ -37,7 +37,7 @@ describe("Switch component tests", function () {
|
|
|
37
37
|
|
|
38
38
|
expect(onChange).toHaveBeenCalled();
|
|
39
39
|
});
|
|
40
|
-
test("
|
|
40
|
+
test("Calls correct function on key down", function () {
|
|
41
41
|
var onChange = jest.fn();
|
|
42
42
|
|
|
43
43
|
var _render3 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
@@ -47,6 +47,30 @@ describe("Switch component tests", function () {
|
|
|
47
47
|
})),
|
|
48
48
|
getByText = _render3.getByText;
|
|
49
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
|
+
|
|
50
74
|
_react2.fireEvent.click(getByText("SwitchComponent"));
|
|
51
75
|
|
|
52
76
|
_react2.fireEvent.click(getByText("SwitchComponent"));
|
|
@@ -54,14 +78,60 @@ describe("Switch component tests", function () {
|
|
|
54
78
|
expect(onChange.mock.calls[0][0]).toBe(true);
|
|
55
79
|
expect(onChange.mock.calls[1][0]).toBe(true);
|
|
56
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
|
+
});
|
|
57
127
|
test("Everytime the user clicks the component the onchange function is called with the correct value UNCONTROLLED COMPONENT", function () {
|
|
58
128
|
var onChange = jest.fn();
|
|
59
129
|
|
|
60
|
-
var
|
|
130
|
+
var _render7 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
61
131
|
label: "SwitchComponent",
|
|
62
132
|
onChange: onChange
|
|
63
133
|
})),
|
|
64
|
-
getByText =
|
|
134
|
+
getByText = _render7.getByText;
|
|
65
135
|
|
|
66
136
|
_react2.fireEvent.click(getByText("SwitchComponent"));
|
|
67
137
|
|
|
@@ -70,29 +140,86 @@ describe("Switch component tests", function () {
|
|
|
70
140
|
expect(onChange.mock.calls[0][0]).toBe(true);
|
|
71
141
|
expect(onChange.mock.calls[1][0]).toBe(false);
|
|
72
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
|
+
});
|
|
73
187
|
test("Renders with correct initial value and initial state when it is uncontrolled", function () {
|
|
74
|
-
var
|
|
188
|
+
var component = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
75
189
|
label: "Default label",
|
|
76
190
|
defaultChecked: true,
|
|
77
|
-
value: "test-defaultChecked"
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
var inputEl =
|
|
82
|
-
expect(inputEl.checked).toBe(true);
|
|
191
|
+
value: "test-defaultChecked",
|
|
192
|
+
name: "test"
|
|
193
|
+
}));
|
|
194
|
+
var switchEl = component.getByRole("switch");
|
|
195
|
+
var inputEl = component.container.querySelector("input[name=\"test\"]");
|
|
83
196
|
expect(inputEl.value).toBe("test-defaultChecked");
|
|
84
|
-
expect(
|
|
197
|
+
expect(switchEl.getAttribute("aria-checked")).toBe("true");
|
|
85
198
|
});
|
|
86
199
|
test("Renders with correct aria attributes", function () {
|
|
87
|
-
var
|
|
200
|
+
var _render10 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
88
201
|
label: "Default label"
|
|
89
202
|
})),
|
|
90
|
-
|
|
91
|
-
|
|
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;
|
|
92
218
|
|
|
93
|
-
var
|
|
219
|
+
var switchEl = getByRole("switch");
|
|
94
220
|
var label = getByText("Default label");
|
|
95
|
-
expect(
|
|
96
|
-
expect(
|
|
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");
|
|
97
224
|
});
|
|
98
225
|
});
|
package/switch/types.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
declare type Space = "xxsmall" | "xsmall" | "small" | "medium" | "large" | "xlarge" | "xxlarge";
|
|
2
|
-
declare type Margin = {
|
|
1
|
+
export declare type Space = "xxsmall" | "xsmall" | "small" | "medium" | "large" | "xlarge" | "xxlarge";
|
|
2
|
+
export declare type Margin = {
|
|
3
3
|
top?: Space;
|
|
4
4
|
bottom?: Space;
|
|
5
5
|
left?: Space;
|
|
6
6
|
right?: Space;
|
|
7
7
|
};
|
|
8
|
-
declare type
|
|
8
|
+
export declare type SwitchPropsType = {
|
|
9
9
|
/**
|
|
10
10
|
* Initial state of the switch, only when it is uncontrolled.
|
|
11
11
|
*/
|
|
@@ -59,4 +59,3 @@ declare type Props = {
|
|
|
59
59
|
*/
|
|
60
60
|
tabIndex?: number;
|
|
61
61
|
};
|
|
62
|
-
export default Props;
|
package/table/Table.js
CHANGED
|
@@ -66,7 +66,7 @@ var DxcTableContainer = _styledComponents["default"].div(_templateObject || (_te
|
|
|
66
66
|
return props.theme.scrollBarTrackColor;
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
-
var DxcTableContent = _styledComponents["default"].table(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["\n border-collapse: collapse;\n width: 100%;\n\n & tr {\n border-bottom: ", ";\n }\n & td {\n background-color: ", ";\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n color: ", ";\n text-transform: ", ";\n text-align: ", ";\n line-height: ", ";\n padding: ", ";\n }\n & th {\n background-color: ", ";\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n color: ", ";\n text-transform: ", ";\n text-align: ", ";\n line-height: ", ";\n padding: ", ";\n }\n & th:first-child {\n border-top-left-radius: ", ";\n }\n & th:last-child {\n border-top-right-radius: ", ";\n }\n"])), function (props) {
|
|
69
|
+
var DxcTableContent = _styledComponents["default"].table(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["\n border-collapse: collapse;\n width: 100%;\n\n & tr {\n border-bottom: ", ";\n }\n & td {\n background-color: ", ";\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n color: ", ";\n text-transform: ", ";\n text-align: ", ";\n line-height: ", ";\n padding: ", ";\n }\n & th {\n background-color: ", ";\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n color: ", ";\n text-transform: ", ";\n text-align: ", ";\n line-height: ", ";\n padding: ", ";\n }\n & th:first-child {\n border-top-left-radius: ", ";\n }\n & th:last-child {\n border-top-right-radius: ", ";\n }\n & td:last-child {\n padding-right: 40px;\n }\n"])), function (props) {
|
|
70
70
|
return "".concat(props.theme.rowSeparatorThickness, " ").concat(props.theme.rowSeparatorStyle, " ").concat(props.theme.rowSeparatorColor);
|
|
71
71
|
}, function (props) {
|
|
72
72
|
return props.theme.dataBackgroundColor;
|
package/tabs/Tab.d.ts
ADDED