@dxc-technology/halstack-react 0.0.0-d3ac293 → 0.0.0-d3df47e
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 +4 -21
- package/HalstackContext.d.ts +24 -139
- package/HalstackContext.js +11 -36
- package/README.md +47 -0
- package/accordion/Accordion.d.ts +1 -1
- package/accordion/Accordion.js +26 -83
- package/accordion/Accordion.stories.tsx +2 -114
- package/accordion/Accordion.test.js +18 -33
- package/accordion/types.d.ts +5 -17
- package/accordion-group/AccordionGroup.d.ts +4 -3
- package/accordion-group/AccordionGroup.js +27 -75
- package/accordion-group/AccordionGroup.stories.tsx +78 -77
- package/accordion-group/AccordionGroup.test.js +43 -71
- package/accordion-group/AccordionGroupAccordion.d.ts +4 -0
- package/accordion-group/AccordionGroupAccordion.js +31 -0
- package/accordion-group/types.d.ts +6 -18
- package/action-icon/ActionIcon.d.ts +4 -0
- package/action-icon/ActionIcon.js +47 -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 +17 -56
- package/alert/Alert.test.js +28 -45
- package/alert/types.d.ts +5 -5
- package/badge/Badge.d.ts +1 -1
- package/badge/Badge.js +142 -42
- 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 +16 -55
- package/box/Box.stories.tsx +25 -53
- package/box/Box.test.js +1 -6
- 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 +66 -100
- package/button/Button.stories.tsx +9 -90
- package/button/Button.test.js +19 -16
- package/button/types.d.ts +8 -4
- package/card/Card.d.ts +1 -1
- package/card/Card.js +47 -88
- package/card/Card.stories.tsx +12 -42
- package/card/Card.test.js +10 -21
- package/card/types.d.ts +6 -12
- package/checkbox/Checkbox.js +85 -120
- package/checkbox/Checkbox.stories.tsx +16 -54
- package/checkbox/Checkbox.test.js +107 -63
- package/checkbox/types.d.ts +8 -4
- package/chip/Chip.js +34 -68
- package/chip/Chip.stories.tsx +25 -17
- package/chip/Chip.test.js +15 -28
- package/chip/types.d.ts +4 -4
- package/common/OpenSans.css +68 -80
- package/common/coreTokens.d.ts +237 -0
- package/common/coreTokens.js +184 -0
- package/common/utils.js +2 -8
- package/common/variables.d.ts +24 -282
- package/common/variables.js +860 -1125
- 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/date-input/Calendar.js +15 -59
- package/date-input/DateInput.js +50 -96
- package/date-input/DateInput.stories.tsx +11 -30
- package/date-input/DateInput.test.js +674 -701
- package/date-input/DatePicker.js +11 -42
- package/date-input/Icons.d.ts +6 -6
- package/date-input/Icons.js +6 -23
- package/date-input/YearPicker.js +8 -34
- package/date-input/types.d.ts +27 -21
- package/dialog/Dialog.d.ts +1 -1
- package/dialog/Dialog.js +15 -60
- package/dialog/Dialog.stories.tsx +215 -169
- package/dialog/Dialog.test.js +125 -187
- package/dialog/types.d.ts +18 -26
- package/dropdown/Dropdown.js +39 -93
- package/dropdown/Dropdown.test.js +391 -378
- package/dropdown/DropdownMenu.js +13 -20
- package/dropdown/DropdownMenuItem.js +5 -19
- package/dropdown/types.d.ts +17 -19
- package/file-input/FileInput.js +180 -249
- package/file-input/FileInput.stories.tsx +1 -1
- package/file-input/FileInput.test.js +356 -354
- package/file-input/FileItem.js +14 -41
- package/file-input/types.d.ts +10 -10
- 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 +69 -116
- package/footer/Footer.stories.tsx +38 -95
- package/footer/Footer.test.js +21 -33
- 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 +33 -116
- package/header/Header.stories.tsx +7 -71
- package/header/Header.test.js +12 -25
- package/header/Icons.d.ts +2 -2
- package/header/Icons.js +2 -7
- package/header/types.d.ts +5 -20
- package/heading/Heading.js +9 -31
- package/heading/Heading.test.js +70 -87
- package/heading/types.d.ts +7 -7
- package/image/Image.d.ts +4 -0
- package/image/Image.js +70 -0
- package/image/Image.stories.tsx +127 -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 +28 -65
- package/layout/ApplicationLayout.stories.tsx +1 -1
- package/layout/Icons.d.ts +8 -5
- package/layout/Icons.js +51 -59
- package/layout/SidenavContext.d.ts +1 -1
- package/layout/SidenavContext.js +3 -9
- package/layout/types.d.ts +5 -6
- package/link/Link.js +23 -44
- package/link/Link.test.js +23 -41
- package/link/types.d.ts +14 -14
- package/main.d.ts +7 -4
- package/main.js +32 -58
- package/nav-tabs/NavTabs.d.ts +2 -2
- package/nav-tabs/NavTabs.js +22 -54
- package/nav-tabs/NavTabs.stories.tsx +21 -5
- package/nav-tabs/NavTabs.test.js +38 -44
- package/nav-tabs/Tab.js +40 -72
- package/nav-tabs/types.d.ts +14 -15
- package/number-input/NumberInput.d.ts +7 -0
- package/number-input/NumberInput.js +26 -35
- package/number-input/NumberInput.stories.tsx +42 -26
- package/number-input/NumberInput.test.js +700 -412
- package/number-input/types.d.ts +11 -5
- package/package.json +30 -28
- package/paginator/Icons.d.ts +5 -5
- package/paginator/Icons.js +5 -19
- package/paginator/Paginator.js +17 -47
- package/paginator/Paginator.test.js +229 -199
- package/paginator/types.d.ts +3 -3
- package/paragraph/Paragraph.d.ts +2 -3
- package/paragraph/Paragraph.js +3 -19
- 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 +157 -140
- package/password-input/types.d.ts +8 -7
- package/progress-bar/ProgressBar.d.ts +2 -2
- package/progress-bar/ProgressBar.js +21 -53
- package/progress-bar/{ProgressBar.stories.jsx → ProgressBar.stories.tsx} +1 -1
- package/progress-bar/ProgressBar.test.js +35 -52
- package/progress-bar/types.d.ts +4 -3
- package/quick-nav/QuickNav.js +4 -27
- package/quick-nav/QuickNav.stories.tsx +1 -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 +10 -10
- package/radio-group/RadioGroup.test.js +504 -470
- package/radio-group/types.d.ts +8 -8
- package/resultset-table/Icons.d.ts +7 -0
- package/{resultsetTable → resultset-table}/Icons.js +1 -5
- package/{resultsetTable → resultset-table}/ResultsetTable.d.ts +1 -1
- package/{resultsetTable → resultset-table}/ResultsetTable.js +33 -63
- package/{resultsetTable → resultset-table}/ResultsetTable.stories.tsx +19 -0
- package/{resultsetTable → resultset-table}/ResultsetTable.test.js +72 -92
- package/{resultsetTable → resultset-table}/types.d.ts +13 -7
- package/resultset-table/types.js +5 -0
- package/select/Icons.d.ts +7 -7
- package/select/Icons.js +1 -5
- package/select/Listbox.js +13 -39
- package/select/Option.js +17 -27
- package/select/Select.js +92 -166
- package/select/Select.stories.tsx +3 -3
- package/select/Select.test.js +1946 -1804
- package/select/types.d.ts +14 -15
- package/sidenav/Icons.d.ts +7 -0
- package/sidenav/Icons.js +47 -0
- package/sidenav/Sidenav.d.ts +2 -2
- package/sidenav/Sidenav.js +80 -150
- package/sidenav/Sidenav.stories.tsx +60 -60
- package/sidenav/Sidenav.test.js +3 -10
- package/sidenav/types.d.ts +31 -28
- package/slider/Slider.js +68 -126
- package/slider/Slider.test.js +107 -103
- package/slider/types.d.ts +4 -4
- package/spinner/Spinner.js +28 -72
- package/spinner/{Spinner.stories.jsx → Spinner.stories.tsx} +28 -28
- package/spinner/Spinner.test.js +25 -34
- 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.js +49 -97
- package/switch/Switch.stories.tsx +0 -34
- package/switch/Switch.test.js +51 -96
- package/switch/types.d.ts +4 -4
- package/table/Table.d.ts +1 -1
- package/table/Table.js +23 -30
- package/table/{Table.stories.jsx → Table.stories.tsx} +98 -0
- package/table/Table.test.js +1 -6
- package/table/types.d.ts +12 -6
- package/tabs/Tab.js +19 -36
- package/tabs/Tabs.js +61 -144
- package/tabs/Tabs.stories.tsx +1 -1
- package/tabs/Tabs.test.js +65 -121
- package/tabs/types.d.ts +19 -19
- package/tag/Tag.js +26 -58
- package/tag/Tag.test.js +19 -30
- package/tag/types.d.ts +7 -7
- package/text-input/Icons.d.ts +5 -5
- package/text-input/Icons.js +1 -5
- package/text-input/Suggestion.js +11 -28
- package/text-input/Suggestions.d.ts +1 -1
- package/text-input/Suggestions.js +15 -65
- package/text-input/TextInput.js +217 -318
- package/text-input/TextInput.stories.tsx +48 -152
- package/text-input/TextInput.test.js +1210 -1194
- package/text-input/types.d.ts +25 -17
- package/textarea/Textarea.js +68 -111
- package/textarea/{Textarea.stories.jsx → Textarea.stories.tsx} +58 -100
- package/textarea/Textarea.test.js +151 -182
- package/textarea/types.d.ts +9 -5
- package/toggle-group/ToggleGroup.d.ts +2 -2
- package/toggle-group/ToggleGroup.js +91 -105
- package/toggle-group/ToggleGroup.stories.tsx +7 -4
- package/toggle-group/ToggleGroup.test.js +68 -87
- package/toggle-group/types.d.ts +26 -17
- package/typography/Typography.js +4 -13
- package/typography/types.d.ts +1 -1
- package/useTheme.d.ts +21 -136
- package/useTheme.js +1 -8
- package/useTranslatedLabels.js +1 -7
- package/utils/BaseTypography.d.ts +2 -2
- package/utils/BaseTypography.js +16 -30
- package/utils/FocusLock.js +28 -43
- package/wizard/Wizard.js +15 -50
- package/wizard/Wizard.test.js +53 -80
- package/wizard/types.d.ts +8 -9
- package/card/ice-cream.jpg +0 -0
- package/number-input/NumberInputContext.d.ts +0 -4
- package/number-input/NumberInputContext.js +0 -19
- package/number-input/numberInputContextTypes.d.ts +0 -19
- package/resultsetTable/Icons.d.ts +0 -7
- package/slider/Slider.stories.tsx +0 -240
- /package/{resultsetTable → action-icon}/types.js +0 -0
- /package/{number-input/numberInputContextTypes.js → container/types.js} +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
9
|
var _Checkbox = _interopRequireDefault(require("./Checkbox.tsx"));
|
|
12
|
-
|
|
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.
|
|
@@ -64,5 +68,5 @@ declare type Props = {
|
|
|
64
68
|
/**
|
|
65
69
|
* Reference to the component.
|
|
66
70
|
*/
|
|
67
|
-
export
|
|
71
|
+
export type RefType = HTMLDivElement;
|
|
68
72
|
export default Props;
|
package/chip/Chip.js
CHANGED
|
@@ -1,86 +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
13
|
var _variables = require("../common/variables");
|
|
21
|
-
|
|
22
14
|
var _utils = require("../common/utils");
|
|
23
|
-
|
|
24
15
|
var _useTheme = _interopRequireDefault(require("../useTheme"));
|
|
25
|
-
|
|
26
16
|
var _templateObject, _templateObject2, _templateObject3;
|
|
27
|
-
|
|
28
|
-
function
|
|
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
|
-
|
|
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
|
-
interactuable: typeof onClickPrefix === "function" && !disabled
|
|
42
|
+
}
|
|
58
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
|
-
interactuable: typeof onClickSuffix === "function" && !disabled
|
|
53
|
+
return !disabled && (onClickSuffix === null || onClickSuffix === void 0 ? void 0 : onClickSuffix());
|
|
54
|
+
}
|
|
72
55
|
}, typeof suffixIcon === "string" ? /*#__PURE__*/_react["default"].createElement("img", {
|
|
73
56
|
src: suffixIcon
|
|
74
57
|
}) : suffixIcon)));
|
|
75
58
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (disabled) return "cursor: not-allowed;";else if (interactuable) return "cursor: pointer;";else 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"), ")");
|
|
79
61
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
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);
|
|
84
66
|
}, function (props) {
|
|
85
67
|
return props.disabled && props.theme.disabledBackgroundColor || props.theme.backgroundColor;
|
|
86
68
|
}, function (props) {
|
|
@@ -109,12 +91,11 @@ var StyledDxcChip = _styledComponents["default"].div(_templateObject || (_templa
|
|
|
109
91
|
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.bottom ? _variables.spaces[props.margin.bottom] : "";
|
|
110
92
|
}, function (props) {
|
|
111
93
|
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.left ? _variables.spaces[props.margin.left] : "";
|
|
112
|
-
}, function (
|
|
113
|
-
var disabled =
|
|
94
|
+
}, function (_ref2) {
|
|
95
|
+
var disabled = _ref2.disabled;
|
|
114
96
|
return disabled && "not-allowed";
|
|
115
97
|
});
|
|
116
|
-
|
|
117
|
-
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) {
|
|
118
99
|
return props.theme.fontSize;
|
|
119
100
|
}, function (props) {
|
|
120
101
|
return props.theme.fontFamily;
|
|
@@ -124,32 +105,17 @@ var ChipTextContainer = _styledComponents["default"].span(_templateObject2 || (_
|
|
|
124
105
|
return props.theme.fontStyle;
|
|
125
106
|
}, function (props) {
|
|
126
107
|
return props.disabled ? props.theme.disabledFontColor : props.theme.fontColor;
|
|
127
|
-
}, function (_ref4) {
|
|
128
|
-
var disabled = _ref4.disabled;
|
|
129
|
-
return disabled && "not-allowed" || "default";
|
|
130
108
|
});
|
|
131
|
-
|
|
132
|
-
var IconContainer = _styledComponents["default"].div(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n ", "\n color: ", ";\n ", "\n\n &:hover {\n color: ", ";\n }\n &:focus {\n outline-color: ", ";\n outline-width: ", ";\n ", "\n }\n &:active {\n color: ", ";\n }\n img,\n svg {\n width: ", ";\n height: ", ";\n }\n"])), function (props) {
|
|
133
|
-
return props.prefixIcon ? "margin-right: ".concat((props.label || props.suffixIcon) && props.theme.iconSpacing || props.prefixIcon && "0", ";") : "margin-left: ".concat((props.label || props.prefixIcon) && props.theme.iconSpacing || props.prefixIcon && "0", ";");
|
|
134
|
-
}, 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) {
|
|
135
110
|
return props.disabled ? props.theme.disabledIconColor : props.theme.iconColor;
|
|
111
|
+
}, function (_ref3) {
|
|
112
|
+
var interactuable = _ref3.interactuable;
|
|
113
|
+
return interactuable && "cursor: pointer;";
|
|
136
114
|
}, function (props) {
|
|
137
|
-
return
|
|
138
|
-
}, function (props) {
|
|
139
|
-
return !props.disabled && props.theme.hoverIconColor;
|
|
140
|
-
}, function (props) {
|
|
141
|
-
return !props.disabled && props.theme.focusColor;
|
|
142
|
-
}, function (props) {
|
|
143
|
-
return !props.disabled && props.theme.focusBorderThickness;
|
|
144
|
-
}, function (props) {
|
|
145
|
-
return props.disabled && "outline: none;";
|
|
146
|
-
}, function (props) {
|
|
147
|
-
return !props.disabled && props.theme.activeIconColor;
|
|
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 ");
|
|
148
116
|
}, function (props) {
|
|
149
117
|
return props.theme.iconSize;
|
|
150
118
|
}, function (props) {
|
|
151
119
|
return props.theme.iconSize;
|
|
152
120
|
});
|
|
153
|
-
|
|
154
|
-
var _default = DxcChip;
|
|
155
|
-
exports["default"] = _default;
|
|
121
|
+
var _default = exports["default"] = DxcChip;
|
package/chip/Chip.stories.tsx
CHANGED
|
@@ -81,29 +81,37 @@ export const Chromatic = () => (
|
|
|
81
81
|
</ExampleContainer>
|
|
82
82
|
<ExampleContainer>
|
|
83
83
|
<Title title="Chip with ellipsis" theme="light" level={4} />
|
|
84
|
-
<
|
|
84
|
+
<div style={{ width: "200px" }}>
|
|
85
|
+
<DxcChip label="With ellipsis asdfasdf asdf asdfasdf asdf asdfasdf asdfasdf asdf asdf adfasrfasf afsdg afgasfg asdf asdf asdf asdf asdf asdf asdf afdg asfg asdfg asdf asdf asdf asdfasdf asd fas df asd asdf asdf asdfasd fg ssssssssssss ssss" />
|
|
86
|
+
</div>
|
|
85
87
|
</ExampleContainer>
|
|
86
88
|
<ExampleContainer>
|
|
87
89
|
<Title title="Chip with ellipsis and suffix" theme="light" level={4} />
|
|
88
|
-
<
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
<div style={{ width: "200px" }}>
|
|
91
|
+
<DxcChip
|
|
92
|
+
suffixIcon={iconSVG}
|
|
93
|
+
label="With ellipsis asdfasdf asdf asdfasdf asdf asdfasdf asdfasdf asdf asdf adfasrfasf afsdg afgasfg asdf asdf asdf asdf asdf asdf asdf afdg asfg asdfg asdf asdf asdf asdfasdf asd fas df asd asdf asdf asdfasd fgsss"
|
|
94
|
+
/>
|
|
95
|
+
</div>
|
|
92
96
|
</ExampleContainer>
|
|
93
97
|
<ExampleContainer>
|
|
94
98
|
<Title title="Chip with ellipsis and prefix" theme="light" level={4} />
|
|
95
|
-
<
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
<div style={{ width: "200px" }}>
|
|
100
|
+
<DxcChip
|
|
101
|
+
prefixIcon={iconSVG}
|
|
102
|
+
label="With ellipsis asdfasdf asdf asdfasdf asdf asdfasdf asdfasdf asdf asdf adfasrfasf afsdg afgasfg asdf asdf asdf asdf asdf asdf asdf afdg asfg asdfg asdf asdf asdf asdfasdf asd fas df asd asdf asdf asdfasd fgsss"
|
|
103
|
+
/>
|
|
104
|
+
</div>
|
|
99
105
|
</ExampleContainer>
|
|
100
106
|
<ExampleContainer>
|
|
101
107
|
<Title title="Chip with ellipsis, suffix and prefix" theme="light" level={4} />
|
|
102
|
-
<
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
108
|
+
<div style={{ width: "200px" }}>
|
|
109
|
+
<DxcChip
|
|
110
|
+
prefixIcon={iconSVG}
|
|
111
|
+
suffixIcon={iconSVG}
|
|
112
|
+
label="With ellipsis asdfasdf asdf asdfasdf asdf asdfasdf asdfasdf asdf asdf adfasrfasf afsdg afgasfg asdf asdf asdf asdf asdf asdf asdf afdg asfg asdfg asdf asdf asdf asdfasdf asd fas df asd asdf asdf asdfasdf"
|
|
113
|
+
/>
|
|
114
|
+
</div>
|
|
107
115
|
</ExampleContainer>
|
|
108
116
|
<Title title="Margins" theme="light" level={2} />
|
|
109
117
|
<ExampleContainer>
|
|
@@ -191,16 +199,16 @@ const ChipPrefixFocused = () => (
|
|
|
191
199
|
const ChipSuffixFocused = () => (
|
|
192
200
|
<ExampleContainer>
|
|
193
201
|
<Title title="Chip with suffix" theme="light" level={4} />
|
|
194
|
-
<DxcChip label="Chip with suffix" suffixIcon=
|
|
202
|
+
<DxcChip label="Chip with suffix" suffixIcon="https://cdn.iconscout.com/icon/free/png-256/free-delete-2902143-2411575.png" onClickSuffix={() => {}} />
|
|
195
203
|
</ExampleContainer>
|
|
196
204
|
);
|
|
197
205
|
|
|
198
206
|
export const PrefixFocused = ChipPrefixFocused.bind({});
|
|
199
|
-
PrefixFocused.play = async (
|
|
207
|
+
PrefixFocused.play = async () => {
|
|
200
208
|
await userEvent.tab();
|
|
201
209
|
};
|
|
202
210
|
|
|
203
211
|
export const SuffixFocused = ChipSuffixFocused.bind({});
|
|
204
|
-
SuffixFocused.play = async (
|
|
212
|
+
SuffixFocused.play = async () => {
|
|
205
213
|
await userEvent.tab();
|
|
206
214
|
};
|
package/chip/Chip.test.js
CHANGED
|
@@ -1,54 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
var _react = _interopRequireDefault(require("react"));
|
|
6
|
-
|
|
7
5
|
var _react2 = require("@testing-library/react");
|
|
8
|
-
|
|
9
6
|
var _Chip = _interopRequireDefault(require("./Chip.tsx"));
|
|
10
|
-
|
|
11
7
|
describe("Chip component tests", function () {
|
|
12
8
|
test("Chip renders with correct text", function () {
|
|
13
9
|
var _render = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Chip["default"], {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
label: "Chip"
|
|
11
|
+
})),
|
|
12
|
+
getByText = _render.getByText;
|
|
18
13
|
expect(getByText("Chip")).toBeTruthy();
|
|
19
14
|
});
|
|
20
15
|
test("Calls correct function when clicking on prefix icon", function () {
|
|
21
16
|
var onClick = jest.fn();
|
|
22
|
-
|
|
23
17
|
var _render2 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Chip["default"], {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
label: "Chip",
|
|
19
|
+
prefixIcon: "https://developer.apple.com/design/human-interface-guidelines/foundations/app-icons/images/icon-and-image-large-icon-settings_2x.png",
|
|
20
|
+
onClickPrefix: onClick
|
|
21
|
+
})),
|
|
22
|
+
getByText = _render2.getByText,
|
|
23
|
+
getByRole = _render2.getByRole;
|
|
31
24
|
expect(getByText("Chip")).toBeTruthy();
|
|
32
|
-
|
|
33
25
|
_react2.fireEvent.click(getByRole("img"));
|
|
34
|
-
|
|
35
26
|
expect(onClick).toHaveBeenCalled();
|
|
36
27
|
});
|
|
37
28
|
test("Calls correct function when clicking on suffix icon", function () {
|
|
38
29
|
var onClick = jest.fn();
|
|
39
|
-
|
|
40
30
|
var _render3 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Chip["default"], {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
31
|
+
label: "Chip",
|
|
32
|
+
suffixIcon: "https://developer.apple.com/design/human-interface-guidelines/foundations/app-icons/images/icon-and-image-large-icon-settings_2x.png",
|
|
33
|
+
onClickSuffix: onClick
|
|
34
|
+
})),
|
|
35
|
+
getByText = _render3.getByText,
|
|
36
|
+
getByRole = _render3.getByRole;
|
|
48
37
|
expect(getByText("Chip")).toBeTruthy();
|
|
49
|
-
|
|
50
38
|
_react2.fireEvent.click(getByRole("img"));
|
|
51
|
-
|
|
52
39
|
expect(onClick).toHaveBeenCalled();
|
|
53
40
|
});
|
|
54
41
|
});
|
package/chip/types.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type Space = "xxsmall" | "xsmall" | "small" | "medium" | "large" | "xlarge" | "xxlarge";
|
|
3
|
+
type Margin = {
|
|
4
4
|
top?: Space;
|
|
5
5
|
bottom?: Space;
|
|
6
6
|
left?: Space;
|
|
7
7
|
right?: Space;
|
|
8
8
|
};
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
type SVG = React.ReactNode & React.SVGProps<SVGSVGElement>;
|
|
10
|
+
type Props = {
|
|
11
11
|
/**
|
|
12
12
|
* Text to be placed on the chip.
|
|
13
13
|
*/
|