@dxc-technology/halstack-react 0.0.0-b41d935 → 0.0.0-b4aec06
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 +1 -10
- package/BackgroundColorContext.js +5 -22
- package/HalstackContext.d.ts +1243 -6
- package/HalstackContext.js +126 -111
- package/README.md +47 -0
- package/accordion/Accordion.d.ts +1 -1
- package/accordion/Accordion.js +42 -118
- package/accordion/Accordion.stories.tsx +85 -139
- package/accordion/Accordion.test.js +19 -34
- package/accordion/types.d.ts +6 -18
- package/accordion-group/AccordionGroup.d.ts +2 -2
- package/accordion-group/AccordionGroup.js +29 -77
- package/accordion-group/AccordionGroup.stories.tsx +78 -77
- package/accordion-group/AccordionGroup.test.js +44 -72
- package/accordion-group/AccordionGroupAccordion.d.ts +4 -0
- package/accordion-group/AccordionGroupAccordion.js +31 -0
- package/accordion-group/AccordionGroupContext.d.ts +3 -0
- package/accordion-group/AccordionGroupContext.js +8 -0
- package/accordion-group/types.d.ts +7 -19
- package/action-icon/ActionIcon.d.ts +4 -0
- package/action-icon/ActionIcon.js +48 -0
- package/action-icon/ActionIcon.stories.tsx +41 -0
- package/action-icon/ActionIcon.test.js +64 -0
- package/action-icon/types.d.ts +26 -0
- package/alert/Alert.js +31 -124
- package/alert/Alert.stories.tsx +28 -0
- package/alert/Alert.test.js +29 -46
- package/alert/types.d.ts +5 -5
- package/badge/Badge.d.ts +1 -1
- package/badge/Badge.js +141 -43
- package/badge/Badge.stories.tsx +210 -0
- package/badge/Badge.test.js +30 -0
- package/badge/types.d.ts +52 -3
- package/bleed/Bleed.js +13 -21
- package/bleed/Bleed.stories.tsx +1 -0
- package/bleed/types.d.ts +2 -2
- package/box/Box.d.ts +1 -1
- package/box/Box.js +18 -59
- package/box/Box.stories.tsx +38 -51
- package/box/Box.test.js +2 -7
- package/box/types.d.ts +3 -15
- package/bulleted-list/BulletedList.js +19 -53
- package/bulleted-list/BulletedList.stories.tsx +8 -93
- package/bulleted-list/types.d.ts +32 -5
- package/button/Button.d.ts +1 -1
- package/button/Button.js +71 -106
- package/button/Button.stories.tsx +144 -101
- package/button/Button.test.js +20 -17
- package/button/types.d.ts +9 -5
- package/card/Card.d.ts +1 -1
- package/card/Card.js +48 -89
- package/card/Card.stories.tsx +12 -42
- package/card/Card.test.js +11 -22
- package/card/types.d.ts +6 -12
- package/checkbox/Checkbox.d.ts +2 -2
- package/checkbox/Checkbox.js +90 -124
- package/checkbox/Checkbox.stories.tsx +68 -54
- package/checkbox/Checkbox.test.js +108 -64
- package/checkbox/types.d.ts +11 -3
- package/chip/Chip.js +39 -79
- package/chip/Chip.stories.tsx +121 -26
- package/chip/Chip.test.js +16 -31
- package/chip/types.d.ts +4 -4
- package/common/coreTokens.d.ts +237 -0
- package/common/coreTokens.js +184 -0
- package/common/utils.d.ts +1 -0
- package/common/utils.js +6 -12
- package/common/variables.d.ts +1395 -0
- package/common/variables.js +914 -1156
- package/container/Container.d.ts +4 -0
- package/container/Container.js +194 -0
- package/container/Container.stories.tsx +214 -0
- package/container/types.d.ts +74 -0
- package/contextual-menu/ContextualMenu.d.ts +7 -0
- package/contextual-menu/ContextualMenu.js +71 -0
- package/contextual-menu/ContextualMenu.stories.tsx +182 -0
- package/contextual-menu/ContextualMenu.test.js +71 -0
- package/contextual-menu/MenuItemAction.d.ts +4 -0
- package/contextual-menu/MenuItemAction.js +46 -0
- package/contextual-menu/types.d.ts +22 -0
- package/date-input/Calendar.d.ts +4 -0
- package/date-input/Calendar.js +214 -0
- package/date-input/DateInput.js +150 -299
- package/date-input/DateInput.stories.tsx +203 -56
- package/date-input/DateInput.test.js +700 -371
- package/date-input/DatePicker.d.ts +4 -0
- package/date-input/DatePicker.js +115 -0
- package/date-input/Icons.d.ts +6 -0
- package/date-input/Icons.js +58 -0
- package/date-input/YearPicker.d.ts +4 -0
- package/date-input/YearPicker.js +100 -0
- package/date-input/types.d.ts +72 -15
- package/dialog/Dialog.d.ts +1 -1
- package/dialog/Dialog.js +61 -119
- package/dialog/Dialog.stories.tsx +310 -212
- package/dialog/Dialog.test.js +269 -32
- package/dialog/types.d.ts +18 -26
- package/divider/Divider.d.ts +4 -0
- package/divider/Divider.js +36 -0
- package/divider/Divider.stories.tsx +223 -0
- package/divider/Divider.test.js +38 -0
- package/divider/types.d.ts +21 -0
- package/divider/types.js +5 -0
- package/dropdown/Dropdown.js +84 -153
- package/dropdown/Dropdown.stories.tsx +209 -94
- package/dropdown/Dropdown.test.js +409 -400
- package/dropdown/DropdownMenu.js +20 -37
- package/dropdown/DropdownMenuItem.js +15 -37
- package/dropdown/types.d.ts +20 -24
- package/file-input/FileInput.d.ts +2 -2
- package/file-input/FileInput.js +193 -262
- package/file-input/FileInput.stories.tsx +86 -3
- package/file-input/FileInput.test.js +356 -395
- package/file-input/FileItem.js +15 -41
- package/file-input/types.d.ts +13 -9
- package/flex/Flex.js +27 -39
- package/flex/Flex.stories.tsx +35 -26
- package/flex/types.d.ts +74 -9
- package/footer/Footer.d.ts +1 -1
- package/footer/Footer.js +70 -117
- package/footer/Footer.stories.tsx +55 -21
- package/footer/Footer.test.js +33 -57
- package/footer/Icons.d.ts +3 -2
- package/footer/Icons.js +66 -7
- package/footer/types.d.ts +25 -27
- package/grid/Grid.d.ts +7 -0
- package/grid/Grid.js +76 -0
- package/grid/Grid.stories.tsx +219 -0
- package/grid/types.d.ts +115 -0
- package/grid/types.js +5 -0
- package/header/Header.d.ts +4 -3
- package/header/Header.js +48 -133
- package/header/Header.stories.tsx +115 -36
- package/header/Header.test.js +13 -26
- package/header/Icons.d.ts +2 -2
- package/header/Icons.js +2 -7
- package/header/types.d.ts +7 -22
- package/heading/Heading.js +10 -32
- package/heading/Heading.test.js +71 -88
- package/heading/types.d.ts +7 -7
- package/icon/Icon.d.ts +4 -0
- package/icon/Icon.js +33 -0
- package/icon/Icon.stories.tsx +28 -0
- package/icon/types.d.ts +4 -0
- package/icon/types.js +5 -0
- package/image/Image.d.ts +4 -0
- package/image/Image.js +70 -0
- package/image/Image.stories.tsx +129 -0
- package/image/types.d.ts +72 -0
- package/image/types.js +5 -0
- package/inset/Inset.js +13 -21
- package/inset/Inset.stories.tsx +2 -1
- package/inset/types.d.ts +2 -2
- package/layout/ApplicationLayout.d.ts +5 -5
- package/layout/ApplicationLayout.js +30 -67
- package/layout/ApplicationLayout.stories.tsx +1 -1
- package/layout/Icons.d.ts +8 -5
- package/layout/Icons.js +51 -59
- package/layout/types.d.ts +5 -6
- package/link/Link.js +25 -46
- package/link/Link.stories.tsx +60 -0
- package/link/Link.test.js +24 -44
- package/link/types.d.ts +14 -14
- package/main.d.ts +10 -5
- package/main.js +47 -59
- package/nav-tabs/NavTabs.d.ts +7 -0
- package/{tabs-nav → nav-tabs}/NavTabs.js +25 -57
- package/{tabs-nav → nav-tabs}/NavTabs.stories.tsx +115 -9
- package/{tabs-nav → nav-tabs}/NavTabs.test.js +39 -45
- package/nav-tabs/NavTabsContext.d.ts +3 -0
- package/nav-tabs/NavTabsContext.js +8 -0
- package/nav-tabs/Tab.js +118 -0
- package/{tabs-nav → nav-tabs}/types.d.ts +14 -15
- package/nav-tabs/types.js +5 -0
- package/number-input/NumberInput.js +46 -36
- package/number-input/NumberInput.stories.tsx +42 -26
- package/number-input/NumberInput.test.js +860 -414
- package/number-input/NumberInputContext.d.ts +3 -4
- package/number-input/NumberInputContext.js +3 -14
- package/number-input/types.d.ts +17 -5
- package/package.json +37 -40
- package/paginator/Icons.d.ts +5 -0
- package/paginator/Icons.js +21 -47
- package/paginator/Paginator.js +22 -58
- package/paginator/Paginator.stories.tsx +24 -0
- package/paginator/Paginator.test.js +252 -225
- package/paginator/types.d.ts +3 -3
- package/paragraph/Paragraph.d.ts +3 -4
- package/paragraph/Paragraph.js +6 -22
- package/paragraph/Paragraph.stories.tsx +0 -17
- package/password-input/Icons.d.ts +6 -0
- package/password-input/Icons.js +35 -0
- package/password-input/PasswordInput.js +57 -126
- package/password-input/PasswordInput.stories.tsx +1 -33
- package/password-input/PasswordInput.test.js +158 -141
- package/password-input/types.d.ts +8 -7
- package/progress-bar/ProgressBar.d.ts +2 -2
- package/progress-bar/ProgressBar.js +23 -55
- package/progress-bar/{ProgressBar.stories.jsx → ProgressBar.stories.tsx} +36 -3
- package/progress-bar/ProgressBar.test.js +36 -53
- package/progress-bar/types.d.ts +4 -3
- package/quick-nav/QuickNav.js +4 -27
- package/quick-nav/QuickNav.stories.tsx +15 -1
- package/quick-nav/types.d.ts +10 -10
- package/radio-group/Radio.d.ts +1 -1
- package/radio-group/Radio.js +31 -63
- package/radio-group/RadioGroup.js +45 -93
- package/radio-group/RadioGroup.stories.tsx +131 -18
- package/radio-group/RadioGroup.test.js +505 -471
- package/radio-group/types.d.ts +8 -8
- package/resultset-table/Icons.d.ts +7 -0
- package/resultset-table/Icons.js +47 -0
- package/resultset-table/ResultsetTable.d.ts +7 -0
- package/resultset-table/ResultsetTable.js +170 -0
- package/{resultsetTable → resultset-table}/ResultsetTable.stories.tsx +156 -30
- package/resultset-table/ResultsetTable.test.js +381 -0
- package/{resultsetTable → resultset-table}/types.d.ts +44 -11
- package/resultset-table/types.js +5 -0
- package/select/Icons.d.ts +7 -7
- package/select/Icons.js +1 -5
- package/select/Listbox.d.ts +1 -1
- package/select/Listbox.js +17 -72
- package/select/Option.js +27 -50
- package/select/Select.js +120 -175
- package/select/Select.stories.tsx +497 -153
- package/select/Select.test.js +1974 -1837
- package/select/types.d.ts +16 -17
- package/sidenav/Icons.d.ts +7 -0
- package/{text-input → sidenav}/Icons.js +10 -23
- package/sidenav/Sidenav.d.ts +2 -2
- package/sidenav/Sidenav.js +83 -154
- package/sidenav/Sidenav.stories.tsx +165 -63
- package/sidenav/Sidenav.test.js +3 -10
- package/{layout → sidenav}/SidenavContext.d.ts +1 -1
- package/{layout → sidenav}/SidenavContext.js +3 -9
- package/sidenav/types.d.ts +31 -28
- package/slider/Slider.d.ts +2 -2
- package/slider/Slider.js +77 -134
- package/slider/Slider.test.js +108 -104
- package/slider/types.d.ts +7 -3
- package/spinner/Spinner.js +31 -75
- package/spinner/{Spinner.stories.jsx → Spinner.stories.tsx} +53 -27
- package/spinner/Spinner.test.js +26 -35
- package/spinner/types.d.ts +3 -3
- package/status-light/StatusLight.d.ts +4 -0
- package/status-light/StatusLight.js +51 -0
- package/status-light/StatusLight.stories.tsx +74 -0
- package/status-light/StatusLight.test.js +25 -0
- package/status-light/types.d.ts +17 -0
- package/status-light/types.js +5 -0
- package/switch/Switch.d.ts +3 -3
- package/switch/Switch.js +56 -103
- package/switch/Switch.stories.tsx +33 -34
- package/switch/Switch.test.js +52 -97
- package/switch/types.d.ts +8 -3
- package/table/DropdownTheme.js +62 -0
- package/table/Table.d.ts +6 -2
- package/table/Table.js +78 -35
- package/table/Table.stories.tsx +651 -0
- package/table/Table.test.js +95 -8
- package/table/types.d.ts +34 -6
- package/tabs/Tab.js +26 -45
- package/tabs/Tabs.js +62 -145
- package/tabs/Tabs.stories.tsx +46 -6
- package/tabs/Tabs.test.js +66 -123
- package/tabs/types.d.ts +19 -19
- package/tag/Tag.js +28 -60
- package/tag/Tag.stories.tsx +14 -1
- package/tag/Tag.test.js +20 -31
- package/tag/types.d.ts +7 -7
- package/text-input/Suggestion.js +35 -25
- package/text-input/Suggestions.d.ts +1 -1
- package/text-input/Suggestions.js +19 -67
- package/text-input/TextInput.js +223 -333
- package/text-input/TextInput.stories.tsx +139 -155
- package/text-input/TextInput.test.js +1389 -1404
- package/text-input/types.d.ts +25 -17
- package/textarea/Textarea.js +70 -113
- package/textarea/Textarea.stories.tsx +174 -0
- package/textarea/Textarea.test.js +152 -183
- package/textarea/types.d.ts +9 -5
- package/toggle-group/ToggleGroup.d.ts +2 -2
- package/toggle-group/ToggleGroup.js +92 -106
- package/toggle-group/ToggleGroup.stories.tsx +49 -4
- package/toggle-group/ToggleGroup.test.js +69 -88
- package/toggle-group/types.d.ts +26 -17
- package/typography/Typography.d.ts +2 -2
- package/typography/Typography.js +15 -123
- package/typography/Typography.stories.tsx +1 -1
- package/typography/types.d.ts +1 -1
- package/useTheme.d.ts +1147 -1
- package/useTheme.js +2 -9
- package/useTranslatedLabels.d.ts +84 -1
- package/useTranslatedLabels.js +1 -7
- package/utils/BaseTypography.d.ts +21 -0
- package/utils/BaseTypography.js +94 -0
- package/utils/FocusLock.d.ts +13 -0
- package/utils/FocusLock.js +124 -0
- package/wizard/Wizard.js +16 -51
- package/wizard/Wizard.stories.tsx +20 -0
- package/wizard/Wizard.test.js +54 -81
- package/wizard/types.d.ts +9 -10
- package/card/ice-cream.jpg +0 -0
- package/common/OpenSans.css +0 -81
- package/common/RequiredComponent.js +0 -32
- package/common/fonts/OpenSans-Bold.ttf +0 -0
- package/common/fonts/OpenSans-BoldItalic.ttf +0 -0
- package/common/fonts/OpenSans-ExtraBold.ttf +0 -0
- package/common/fonts/OpenSans-ExtraBoldItalic.ttf +0 -0
- package/common/fonts/OpenSans-Italic.ttf +0 -0
- package/common/fonts/OpenSans-Light.ttf +0 -0
- package/common/fonts/OpenSans-LightItalic.ttf +0 -0
- package/common/fonts/OpenSans-Regular.ttf +0 -0
- package/common/fonts/OpenSans-SemiBold.ttf +0 -0
- package/common/fonts/OpenSans-SemiBoldItalic.ttf +0 -0
- package/number-input/numberInputContextTypes.d.ts +0 -19
- package/resultsetTable/ResultsetTable.d.ts +0 -4
- package/resultsetTable/ResultsetTable.js +0 -252
- package/resultsetTable/ResultsetTable.test.js +0 -348
- package/slider/Slider.stories.tsx +0 -183
- package/table/Table.stories.jsx +0 -277
- package/tabs-nav/NavTabs.d.ts +0 -8
- package/tabs-nav/Tab.js +0 -130
- package/text-input/Icons.d.ts +0 -8
- package/textarea/Textarea.stories.jsx +0 -157
- /package/{resultsetTable → action-icon}/types.js +0 -0
- /package/{tabs-nav → container}/types.js +0 -0
- /package/{number-input/numberInputContextTypes.js → contextual-menu/types.js} +0 -0
- /package/{tabs-nav → nav-tabs}/Tab.d.ts +0 -0
|
@@ -1,49 +1,110 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
4
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
5
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
5
6
|
var _react = _interopRequireDefault(require("react"));
|
|
6
|
-
|
|
7
7
|
var _react2 = require("@testing-library/react");
|
|
8
|
-
|
|
9
8
|
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
10
|
-
|
|
11
|
-
var _Checkbox = _interopRequireDefault(require("./Checkbox"));
|
|
12
|
-
|
|
9
|
+
var _Checkbox = _interopRequireDefault(require("./Checkbox.tsx"));
|
|
13
10
|
describe("Checkbox component tests", function () {
|
|
14
11
|
test("Checkbox renders with correct aria-labelledby and aria-required", function () {
|
|
15
12
|
var _render = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Checkbox["default"], {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
label: "Checkbox"
|
|
14
|
+
})),
|
|
15
|
+
getByText = _render.getByText,
|
|
16
|
+
getByRole = _render.getByRole;
|
|
21
17
|
var labelId = getByText("Checkbox").getAttribute("id");
|
|
22
18
|
expect(getByRole("checkbox").getAttribute("aria-labelledby")).toBe(labelId);
|
|
23
19
|
expect(getByRole("checkbox").getAttribute("aria-required")).toBe("true");
|
|
20
|
+
expect(getByRole("checkbox").getAttribute("aria-readonly")).toBe("false");
|
|
21
|
+
expect(getByRole("checkbox").getAttribute("aria-disabled")).toBe("false");
|
|
24
22
|
});
|
|
25
23
|
test("Optional checkbox renders with correct aria-required", function () {
|
|
26
24
|
var _render2 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Checkbox["default"], {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
label: "Checkbox",
|
|
26
|
+
optional: true
|
|
27
|
+
})),
|
|
28
|
+
getByRole = _render2.getByRole;
|
|
32
29
|
expect(getByRole("checkbox").getAttribute("aria-required")).toBe("false");
|
|
33
30
|
});
|
|
34
|
-
test("Calls correct function
|
|
31
|
+
test("Calls correct function onChange", function () {
|
|
35
32
|
var onChange = jest.fn();
|
|
36
|
-
|
|
37
33
|
var _render3 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Checkbox["default"], {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
label: "Checkbox",
|
|
35
|
+
onChange: onChange
|
|
36
|
+
})),
|
|
37
|
+
getByText = _render3.getByText;
|
|
43
38
|
_react2.fireEvent.click(getByText("Checkbox"));
|
|
44
|
-
|
|
45
39
|
expect(onChange).toHaveBeenCalled();
|
|
46
40
|
});
|
|
41
|
+
test("Read-only checkbox does not trigger onChange function", function () {
|
|
42
|
+
var onChange = jest.fn();
|
|
43
|
+
var _render4 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Checkbox["default"], {
|
|
44
|
+
label: "Checkbox",
|
|
45
|
+
onChange: onChange,
|
|
46
|
+
readOnly: true
|
|
47
|
+
})),
|
|
48
|
+
getByRole = _render4.getByRole;
|
|
49
|
+
var checkbox = getByRole("checkbox");
|
|
50
|
+
expect(checkbox.getAttribute("aria-readonly")).toBe("true");
|
|
51
|
+
_react2.fireEvent.click(checkbox);
|
|
52
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
53
|
+
});
|
|
54
|
+
test("Read-only checkbox sends its value on submit", /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
55
|
+
var handlerOnSubmit, _render5, getByText, submit;
|
|
56
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
57
|
+
while (1) switch (_context.prev = _context.next) {
|
|
58
|
+
case 0:
|
|
59
|
+
handlerOnSubmit = jest.fn(function (e) {
|
|
60
|
+
e.preventDefault();
|
|
61
|
+
var formData = new FormData(e.target);
|
|
62
|
+
var formProps = Object.fromEntries(formData);
|
|
63
|
+
expect(formProps).toStrictEqual({
|
|
64
|
+
data: "checked"
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
_render5 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement("form", {
|
|
68
|
+
onSubmit: handlerOnSubmit
|
|
69
|
+
}, /*#__PURE__*/_react["default"].createElement(_Checkbox["default"], {
|
|
70
|
+
label: "Checkbox",
|
|
71
|
+
name: "data",
|
|
72
|
+
value: "checked",
|
|
73
|
+
readOnly: true,
|
|
74
|
+
defaultChecked: true
|
|
75
|
+
}), /*#__PURE__*/_react["default"].createElement("button", {
|
|
76
|
+
type: "submit"
|
|
77
|
+
}, "Submit"))), getByText = _render5.getByText;
|
|
78
|
+
submit = getByText("Submit");
|
|
79
|
+
_context.next = 5;
|
|
80
|
+
return _userEvent["default"].click(submit);
|
|
81
|
+
case 5:
|
|
82
|
+
expect(handlerOnSubmit).toHaveBeenCalled();
|
|
83
|
+
case 6:
|
|
84
|
+
case "end":
|
|
85
|
+
return _context.stop();
|
|
86
|
+
}
|
|
87
|
+
}, _callee);
|
|
88
|
+
})));
|
|
89
|
+
test("Read-only checkbox doesn't change its value with Space key", function () {
|
|
90
|
+
var onChange = jest.fn();
|
|
91
|
+
var _render6 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Checkbox["default"], {
|
|
92
|
+
label: "Checkbox",
|
|
93
|
+
onChange: onChange,
|
|
94
|
+
readOnly: true
|
|
95
|
+
})),
|
|
96
|
+
getByRole = _render6.getByRole;
|
|
97
|
+
var checkbox = getByRole("checkbox");
|
|
98
|
+
_userEvent["default"].tab();
|
|
99
|
+
expect(document.activeElement === checkbox).toBeTruthy();
|
|
100
|
+
_react2.fireEvent.keyDown(checkbox, {
|
|
101
|
+
key: " ",
|
|
102
|
+
code: "Space",
|
|
103
|
+
keyCode: 32,
|
|
104
|
+
charCode: 32
|
|
105
|
+
});
|
|
106
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
107
|
+
});
|
|
47
108
|
test("Uncontrolled checkbox", function () {
|
|
48
109
|
var onChange = jest.fn();
|
|
49
110
|
var component = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Checkbox["default"], {
|
|
@@ -56,9 +117,7 @@ describe("Checkbox component tests", function () {
|
|
|
56
117
|
var submitInput = component.container.querySelector("input[name=\"test\"]");
|
|
57
118
|
expect(input.getAttribute("aria-checked")).toBe("false");
|
|
58
119
|
expect(submitInput.checked).toBe(false);
|
|
59
|
-
|
|
60
120
|
_react2.fireEvent.click(visibleCheckbox);
|
|
61
|
-
|
|
62
121
|
expect(onChange).toHaveBeenCalled();
|
|
63
122
|
expect(onChange).toHaveBeenCalledWith(true);
|
|
64
123
|
expect(input.getAttribute("aria-checked")).toBe("true");
|
|
@@ -75,24 +134,21 @@ describe("Checkbox component tests", function () {
|
|
|
75
134
|
var input = component.getByRole("checkbox");
|
|
76
135
|
var visibleCheckbox = component.getByText("Checkbox");
|
|
77
136
|
var submitInput = component.container.querySelector("input[name=\"test\"]");
|
|
78
|
-
|
|
79
137
|
_react2.fireEvent.click(visibleCheckbox);
|
|
80
|
-
|
|
81
138
|
expect(onChange).toHaveBeenCalled();
|
|
82
139
|
expect(onChange).toHaveBeenCalledWith(true);
|
|
83
140
|
expect(input.getAttribute("aria-checked")).toBe("false");
|
|
84
141
|
expect(submitInput.checked).toBe(false);
|
|
85
142
|
});
|
|
86
143
|
test("Renders with correct initial value and initial state when it is uncontrolled", function () {
|
|
87
|
-
var
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
144
|
+
var _render7 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Checkbox["default"], {
|
|
145
|
+
label: "Default label",
|
|
146
|
+
defaultChecked: true,
|
|
147
|
+
value: "test-defaultChecked",
|
|
148
|
+
name: "test"
|
|
149
|
+
})),
|
|
150
|
+
getByRole = _render7.getByRole,
|
|
151
|
+
container = _render7.container;
|
|
96
152
|
var checkbox = getByRole("checkbox");
|
|
97
153
|
var submitInput = container.querySelector("input[name=\"test\"]");
|
|
98
154
|
expect(submitInput.value).toBe("test-defaultChecked");
|
|
@@ -101,55 +157,43 @@ describe("Checkbox component tests", function () {
|
|
|
101
157
|
});
|
|
102
158
|
test("Test disable keyboard and mouse interactions", function () {
|
|
103
159
|
var onChange = jest.fn();
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
container = _render5.container;
|
|
114
|
-
|
|
160
|
+
var _render8 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Checkbox["default"], {
|
|
161
|
+
label: "Checkbox",
|
|
162
|
+
onChange: onChange,
|
|
163
|
+
disabled: true,
|
|
164
|
+
name: "test"
|
|
165
|
+
})),
|
|
166
|
+
getByRole = _render8.getByRole,
|
|
167
|
+
getByText = _render8.getByText,
|
|
168
|
+
container = _render8.container;
|
|
115
169
|
var input = getByRole("checkbox");
|
|
116
170
|
var visibleCheckbox = getByText("Checkbox");
|
|
117
171
|
var submitInput = container.querySelector("input[name=\"test\"]");
|
|
118
|
-
|
|
119
172
|
_react2.fireEvent.click(visibleCheckbox);
|
|
120
|
-
|
|
121
173
|
expect(onChange).toHaveBeenCalledTimes(0);
|
|
122
174
|
expect(input.getAttribute("aria-checked")).toBe("false");
|
|
123
175
|
expect(input.getAttribute("aria-disabled")).toBe("true");
|
|
124
176
|
expect(submitInput.checked).toBe(false);
|
|
125
|
-
|
|
126
177
|
_userEvent["default"].tab();
|
|
127
|
-
|
|
128
178
|
expect(document.activeElement === input).toBeFalsy();
|
|
129
179
|
});
|
|
130
180
|
test("Test keyboard interactions", function () {
|
|
131
181
|
var onChange = jest.fn();
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
getByRole = _render6.getByRole;
|
|
139
|
-
|
|
182
|
+
var _render9 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Checkbox["default"], {
|
|
183
|
+
label: "Checkbox",
|
|
184
|
+
name: "test",
|
|
185
|
+
onChange: onChange
|
|
186
|
+
})),
|
|
187
|
+
getByRole = _render9.getByRole;
|
|
140
188
|
var checkbox = getByRole("checkbox");
|
|
141
|
-
|
|
142
189
|
_userEvent["default"].tab();
|
|
143
|
-
|
|
144
190
|
expect(document.activeElement === checkbox).toBeTruthy();
|
|
145
|
-
|
|
146
191
|
_react2.fireEvent.keyDown(checkbox, {
|
|
147
192
|
key: " ",
|
|
148
193
|
code: "Space",
|
|
149
194
|
keyCode: 32,
|
|
150
195
|
charCode: 32
|
|
151
196
|
});
|
|
152
|
-
|
|
153
197
|
expect(onChange).toHaveBeenCalledWith(true);
|
|
154
198
|
});
|
|
155
199
|
});
|
package/checkbox/types.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type Space = "xxsmall" | "xsmall" | "small" | "medium" | "large" | "xlarge" | "xxlarge";
|
|
2
|
+
type Margin = {
|
|
3
3
|
top?: Space;
|
|
4
4
|
bottom?: Space;
|
|
5
5
|
left?: Space;
|
|
6
6
|
right?: Space;
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
type Props = {
|
|
9
9
|
/**
|
|
10
10
|
* Initial state of the checkbox, only when it is uncontrolled.
|
|
11
11
|
*/
|
|
@@ -40,6 +40,10 @@ declare type Props = {
|
|
|
40
40
|
* If true, the component will display '(Optional)' next to the label.
|
|
41
41
|
*/
|
|
42
42
|
optional?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* If true, the component will not be mutable, meaning the user can not edit the control.
|
|
45
|
+
*/
|
|
46
|
+
readOnly?: boolean;
|
|
43
47
|
/**
|
|
44
48
|
* This function will be called when the user clicks the checkbox.
|
|
45
49
|
* The new value will be passed as a parameter.
|
|
@@ -61,4 +65,8 @@ declare type Props = {
|
|
|
61
65
|
*/
|
|
62
66
|
tabIndex?: number;
|
|
63
67
|
};
|
|
68
|
+
/**
|
|
69
|
+
* Reference to the component.
|
|
70
|
+
*/
|
|
71
|
+
export type RefType = HTMLDivElement;
|
|
64
72
|
export default Props;
|
package/chip/Chip.js
CHANGED
|
@@ -1,94 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
var _typeof3 = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports["default"] = void 0;
|
|
11
|
-
|
|
12
9
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
13
|
-
|
|
14
10
|
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
15
|
-
|
|
16
11
|
var _react = _interopRequireDefault(require("react"));
|
|
17
|
-
|
|
18
12
|
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
var _utils = require("../common/utils.js");
|
|
23
|
-
|
|
13
|
+
var _variables = require("../common/variables");
|
|
14
|
+
var _utils = require("../common/utils");
|
|
24
15
|
var _useTheme = _interopRequireDefault(require("../useTheme"));
|
|
25
|
-
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
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); }
|
|
29
|
-
|
|
30
|
-
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; }
|
|
31
|
-
|
|
16
|
+
var _templateObject, _templateObject2, _templateObject3;
|
|
17
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
18
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
32
19
|
var DxcChip = function DxcChip(_ref) {
|
|
33
20
|
var label = _ref.label,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
21
|
+
suffixIcon = _ref.suffixIcon,
|
|
22
|
+
prefixIcon = _ref.prefixIcon,
|
|
23
|
+
onClickSuffix = _ref.onClickSuffix,
|
|
24
|
+
onClickPrefix = _ref.onClickPrefix,
|
|
25
|
+
disabled = _ref.disabled,
|
|
26
|
+
margin = _ref.margin,
|
|
27
|
+
_ref$tabIndex = _ref.tabIndex,
|
|
28
|
+
tabIndex = _ref$tabIndex === void 0 ? 0 : _ref$tabIndex;
|
|
42
29
|
var colorsTheme = (0, _useTheme["default"])();
|
|
43
30
|
return /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
|
|
44
31
|
theme: colorsTheme.chip
|
|
45
|
-
}, /*#__PURE__*/_react["default"].createElement(
|
|
32
|
+
}, /*#__PURE__*/_react["default"].createElement(Chip, {
|
|
46
33
|
disabled: disabled,
|
|
47
34
|
margin: margin
|
|
48
35
|
}, prefixIcon && /*#__PURE__*/_react["default"].createElement(IconContainer, {
|
|
36
|
+
role: typeof onClickPrefix === "function" ? "button" : undefined,
|
|
49
37
|
disabled: disabled,
|
|
50
|
-
|
|
51
|
-
label: label,
|
|
52
|
-
mode: "prefix",
|
|
38
|
+
interactuable: typeof onClickPrefix === "function" && !disabled,
|
|
53
39
|
tabIndex: typeof onClickPrefix === "function" && !disabled ? tabIndex : -1,
|
|
54
40
|
onClick: function onClick() {
|
|
55
41
|
return onClickPrefix && !disabled && onClickPrefix();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
}, typeof prefixIcon === "string" ? /*#__PURE__*/_react["default"].createElement(PrefixIconContainer, {
|
|
42
|
+
}
|
|
43
|
+
}, typeof prefixIcon === "string" ? /*#__PURE__*/_react["default"].createElement("img", {
|
|
59
44
|
src: prefixIcon
|
|
60
|
-
}) : prefixIcon), label && /*#__PURE__*/_react["default"].createElement(
|
|
45
|
+
}) : prefixIcon), label && /*#__PURE__*/_react["default"].createElement(LabelContainer, {
|
|
61
46
|
disabled: disabled
|
|
62
47
|
}, label), suffixIcon && /*#__PURE__*/_react["default"].createElement(IconContainer, {
|
|
48
|
+
role: typeof onClickSuffix === "function" ? "button" : undefined,
|
|
63
49
|
disabled: disabled,
|
|
64
|
-
|
|
65
|
-
mode: "suffix",
|
|
66
|
-
label: label,
|
|
50
|
+
interactuable: typeof onClickSuffix === "function" && !disabled,
|
|
67
51
|
tabIndex: typeof onClickSuffix === "function" && !disabled ? tabIndex : -1,
|
|
68
52
|
onClick: function onClick() {
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
}, typeof suffixIcon === "string" ? /*#__PURE__*/_react["default"].createElement(SuffixIconContainer, {
|
|
53
|
+
return !disabled && (onClickSuffix === null || onClickSuffix === void 0 ? void 0 : onClickSuffix());
|
|
54
|
+
}
|
|
55
|
+
}, typeof suffixIcon === "string" ? /*#__PURE__*/_react["default"].createElement("img", {
|
|
73
56
|
src: suffixIcon
|
|
74
57
|
}) : suffixIcon)));
|
|
75
58
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (disabled) {
|
|
79
|
-
return "cursor:not-allowed;";
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (interactuable) {
|
|
83
|
-
return "cursor:pointer;";
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return "cursor:default; outline:none;";
|
|
59
|
+
var calculateWidth = function calculateWidth(margin) {
|
|
60
|
+
return "calc(100% - ".concat((0, _utils.getMargin)(margin, "left"), " - ").concat((0, _utils.getMargin)(margin, "right"), ")");
|
|
87
61
|
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return
|
|
62
|
+
var Chip = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n box-sizing: border-box;\n display: inline-flex;\n align-items: center;\n gap: ", ";\n min-height: 40px;\n max-width: ", ";\n background-color: ", ";\n border-radius: ", ";\n border-width: ", ";\n border-style: ", ";\n border-color: ", ";\n\n padding-top: ", ";\n padding-bottom: ", ";\n padding-left: ", ";\n padding-right: ", ";\n margin: ", ";\n margin-top: ", ";\n margin-right: ", ";\n margin-bottom: ", ";\n margin-left: ", ";\n cursor: ", ";\n"])), function (props) {
|
|
63
|
+
return props.theme.iconSpacing;
|
|
64
|
+
}, function (props) {
|
|
65
|
+
return calculateWidth(props.margin);
|
|
92
66
|
}, function (props) {
|
|
93
67
|
return props.disabled && props.theme.disabledBackgroundColor || props.theme.backgroundColor;
|
|
94
68
|
}, function (props) {
|
|
@@ -117,12 +91,11 @@ var StyledDxcChip = _styledComponents["default"].div(_templateObject || (_templa
|
|
|
117
91
|
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.bottom ? _variables.spaces[props.margin.bottom] : "";
|
|
118
92
|
}, function (props) {
|
|
119
93
|
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.left ? _variables.spaces[props.margin.left] : "";
|
|
120
|
-
}, function (
|
|
121
|
-
var disabled =
|
|
94
|
+
}, function (_ref2) {
|
|
95
|
+
var disabled = _ref2.disabled;
|
|
122
96
|
return disabled && "not-allowed";
|
|
123
97
|
});
|
|
124
|
-
|
|
125
|
-
var ChipTextContainer = _styledComponents["default"].span(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["\n font-size: ", ";\n font-family: ", ";\n font-weight: ", ";\n font-style: ", ";\n color: ", ";\n cursor: ", ";\n text-overflow: ellipsis;\n white-space: nowrap;\n overflow: hidden;\n"])), function (props) {
|
|
98
|
+
var LabelContainer = _styledComponents["default"].span(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["\n font-size: ", ";\n font-family: ", ";\n font-weight: ", ";\n font-style: ", ";\n color: ", ";\n text-overflow: ellipsis;\n white-space: nowrap;\n overflow: hidden;\n"])), function (props) {
|
|
126
99
|
return props.theme.fontSize;
|
|
127
100
|
}, function (props) {
|
|
128
101
|
return props.theme.fontFamily;
|
|
@@ -132,30 +105,17 @@ var ChipTextContainer = _styledComponents["default"].span(_templateObject2 || (_
|
|
|
132
105
|
return props.theme.fontStyle;
|
|
133
106
|
}, function (props) {
|
|
134
107
|
return props.disabled ? props.theme.disabledFontColor : props.theme.fontColor;
|
|
135
|
-
}, function (_ref4) {
|
|
136
|
-
var disabled = _ref4.disabled;
|
|
137
|
-
return disabled && "not-allowed" || "default";
|
|
138
108
|
});
|
|
139
|
-
|
|
140
|
-
var SuffixIconContainer = _styledComponents["default"].img(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2["default"])([""])));
|
|
141
|
-
|
|
142
|
-
var PrefixIconContainer = _styledComponents["default"].img(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])([""])));
|
|
143
|
-
|
|
144
|
-
var IconContainer = _styledComponents["default"].div(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2["default"])(["\n color: ", ";\n ", "\n ", "\n width: ", ";\n height: ", ";\n overflow: hidden;\n\n img,\n svg {\n height: 100%;\n width: 100%;\n }\n &:focus {\n outline-color: ", ";\n outline-width: 2px;\n ", "\n }\n"])), function (props) {
|
|
109
|
+
var IconContainer = _styledComponents["default"].div(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n border-radius: 0.25rem;\n color: ", ";\n ", "\n\n ", "\n\n img,\n svg {\n width: ", ";\n height: ", ";\n }\n"])), function (props) {
|
|
145
110
|
return props.disabled ? props.theme.disabledIconColor : props.theme.iconColor;
|
|
111
|
+
}, function (_ref3) {
|
|
112
|
+
var interactuable = _ref3.interactuable;
|
|
113
|
+
return interactuable && "cursor: pointer;";
|
|
146
114
|
}, function (props) {
|
|
147
|
-
return props.
|
|
148
|
-
}, function (props) {
|
|
149
|
-
return getCursor(props.interactuable, props.disabled);
|
|
115
|
+
return props.interactuable && "\n &:hover {\n color: ".concat(props.theme.hoverIconColor, ";\n }\n &:focus,\n &:focus-visible {\n outline: ").concat(props.theme.focusBorderThickness, " ").concat(props.theme.focusBorderStyle, " ").concat(props.theme.focusColor, ";\n }\n &:active {\n color: ").concat(props.theme.activeIconColor, ";\n }\n ");
|
|
150
116
|
}, function (props) {
|
|
151
117
|
return props.theme.iconSize;
|
|
152
118
|
}, function (props) {
|
|
153
119
|
return props.theme.iconSize;
|
|
154
|
-
}, function (props) {
|
|
155
|
-
return props.theme.focusColor;
|
|
156
|
-
}, function (props) {
|
|
157
|
-
return props.disabled && "outline: none;";
|
|
158
120
|
});
|
|
159
|
-
|
|
160
|
-
var _default = DxcChip;
|
|
161
|
-
exports["default"] = _default;
|
|
121
|
+
var _default = exports["default"] = DxcChip;
|