@dxc-technology/halstack-react 10.1.0 → 11.0.0
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 +2 -2
- package/BackgroundColorContext.js +5 -17
- package/HalstackContext.d.ts +18 -6
- package/HalstackContext.js +9 -34
- package/accordion/Accordion.js +21 -58
- package/accordion/Accordion.stories.tsx +1 -15
- package/accordion/Accordion.test.js +18 -33
- package/accordion/types.d.ts +5 -5
- package/accordion-group/AccordionGroup.js +15 -42
- package/accordion-group/AccordionGroup.stories.tsx +1 -1
- package/accordion-group/AccordionGroup.test.js +42 -60
- package/accordion-group/AccordionGroupAccordion.js +9 -21
- package/accordion-group/types.d.ts +6 -6
- package/alert/Alert.js +14 -46
- package/alert/Alert.test.js +28 -45
- package/alert/types.d.ts +5 -5
- package/badge/Badge.js +4 -17
- package/badge/types.d.ts +1 -1
- package/bleed/Bleed.js +13 -21
- package/bleed/types.d.ts +2 -2
- package/box/Box.js +10 -29
- package/box/Box.test.js +1 -6
- package/box/types.d.ts +3 -3
- package/bulleted-list/BulletedList.js +7 -33
- package/bulleted-list/BulletedList.stories.tsx +1 -91
- package/bulleted-list/types.d.ts +5 -5
- package/button/Button.js +23 -46
- package/button/Button.stories.tsx +5 -86
- package/button/Button.test.js +11 -21
- package/button/types.d.ts +4 -4
- package/card/Card.js +21 -44
- package/card/Card.test.js +10 -21
- package/card/types.d.ts +5 -5
- package/checkbox/Checkbox.js +81 -111
- 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 +12 -31
- package/chip/Chip.test.js +15 -28
- package/chip/types.d.ts +4 -4
- package/common/coreTokens.js +1 -2
- package/common/utils.js +2 -8
- package/common/variables.d.ts +15 -6
- package/common/variables.js +17 -15
- package/date-input/Calendar.js +13 -57
- 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.js +11 -35
- package/dialog/Dialog.test.js +125 -187
- package/dialog/types.d.ts +18 -13
- package/dropdown/Dropdown.js +39 -93
- package/dropdown/Dropdown.test.js +391 -378
- package/dropdown/DropdownMenu.js +8 -19
- package/dropdown/DropdownMenuItem.js +5 -17
- package/dropdown/types.d.ts +17 -19
- package/file-input/FileInput.js +131 -220
- package/file-input/FileInput.stories.tsx +1 -1
- package/file-input/FileInput.test.js +293 -342
- package/file-input/FileItem.js +12 -39
- package/file-input/types.d.ts +9 -9
- package/flex/Flex.js +25 -39
- package/flex/types.d.ts +6 -6
- package/footer/Footer.js +9 -39
- package/footer/Footer.test.js +18 -32
- package/footer/Icons.d.ts +2 -2
- package/footer/Icons.js +2 -7
- package/footer/types.d.ts +13 -13
- package/grid/Grid.js +1 -16
- package/grid/types.d.ts +10 -10
- package/header/Header.d.ts +1 -1
- package/header/Header.js +19 -64
- 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 -7
- 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 +2 -2
- package/image/Image.js +17 -32
- package/image/types.d.ts +2 -2
- package/inset/Inset.js +13 -21
- package/inset/types.d.ts +2 -2
- package/layout/ApplicationLayout.d.ts +1 -1
- package/layout/ApplicationLayout.js +14 -54
- package/layout/Icons.d.ts +5 -5
- package/layout/Icons.js +1 -5
- package/layout/SidenavContext.d.ts +1 -1
- package/layout/SidenavContext.js +3 -9
- package/layout/types.d.ts +3 -3
- package/link/Link.js +21 -42
- package/link/Link.test.js +23 -41
- package/link/types.d.ts +14 -14
- package/main.d.ts +1 -1
- package/main.js +3 -52
- package/nav-tabs/NavTabs.js +11 -43
- package/nav-tabs/NavTabs.stories.tsx +1 -1
- package/nav-tabs/NavTabs.test.js +36 -43
- package/nav-tabs/Tab.js +16 -45
- package/nav-tabs/types.d.ts +9 -9
- package/number-input/NumberInput.d.ts +1 -1
- package/number-input/NumberInput.js +24 -35
- package/number-input/NumberInput.stories.tsx +42 -26
- package/number-input/NumberInput.test.js +682 -577
- package/number-input/types.d.ts +11 -5
- package/package.json +27 -25
- package/paginator/Icons.d.ts +5 -5
- package/paginator/Icons.js +5 -19
- package/paginator/Paginator.js +14 -39
- package/paginator/Paginator.test.js +224 -207
- package/paginator/types.d.ts +3 -3
- package/paragraph/Paragraph.js +3 -14
- package/paragraph/Paragraph.stories.tsx +0 -17
- package/password-input/Icons.d.ts +3 -3
- package/password-input/Icons.js +1 -5
- package/password-input/PasswordInput.js +26 -48
- package/password-input/PasswordInput.stories.tsx +1 -33
- package/password-input/PasswordInput.test.js +153 -129
- package/password-input/types.d.ts +8 -7
- package/progress-bar/ProgressBar.js +16 -42
- 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 +3 -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 +22 -54
- package/radio-group/RadioGroup.js +37 -83
- 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.js +22 -58
- package/{resultsetTable → resultset-table}/ResultsetTable.test.js +72 -92
- package/{resultsetTable → resultset-table}/types.d.ts +7 -7
- package/select/Icons.d.ts +7 -7
- package/select/Icons.js +1 -5
- package/select/Listbox.js +13 -39
- package/select/Option.js +9 -26
- package/select/Select.js +54 -138
- package/select/Select.test.js +1902 -1796
- package/select/types.d.ts +14 -15
- package/sidenav/Icons.d.ts +4 -4
- package/sidenav/Icons.js +1 -5
- package/sidenav/Sidenav.js +24 -63
- package/sidenav/Sidenav.test.js +3 -10
- package/sidenav/types.d.ts +18 -18
- package/slider/Slider.js +38 -86
- package/slider/Slider.test.js +107 -103
- package/slider/types.d.ts +4 -4
- package/spinner/Spinner.js +10 -40
- package/spinner/Spinner.test.js +25 -34
- package/spinner/types.d.ts +3 -3
- package/switch/Switch.js +26 -69
- package/switch/Switch.stories.tsx +0 -34
- package/switch/Switch.test.js +51 -96
- package/switch/types.d.ts +4 -4
- package/table/Table.js +4 -23
- package/table/Table.test.js +1 -6
- package/table/types.d.ts +8 -8
- package/tabs/Tab.js +10 -29
- package/tabs/Tabs.js +48 -124
- package/tabs/Tabs.test.js +62 -118
- package/tabs/types.d.ts +19 -19
- package/tag/Tag.js +21 -51
- 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 +9 -26
- package/text-input/Suggestions.d.ts +1 -1
- package/text-input/Suggestions.js +12 -57
- package/text-input/TextInput.js +128 -193
- 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 +60 -96
- package/textarea/{Textarea.stories.jsx → Textarea.stories.tsx} +58 -99
- package/textarea/Textarea.test.js +150 -179
- package/textarea/types.d.ts +9 -5
- package/toggle-group/ToggleGroup.js +20 -57
- package/toggle-group/ToggleGroup.stories.tsx +1 -1
- package/toggle-group/ToggleGroup.test.js +48 -81
- package/toggle-group/types.d.ts +10 -10
- package/typography/Typography.js +4 -13
- package/typography/types.d.ts +1 -1
- package/useTheme.d.ts +12 -3
- 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 +12 -36
- package/wizard/Wizard.js +14 -49
- package/wizard/Wizard.test.js +53 -80
- package/wizard/types.d.ts +6 -6
- package/resultsetTable/Icons.d.ts +0 -7
- package/slider/Slider.stories.tsx +0 -240
- /package/{resultsetTable → resultset-table}/ResultsetTable.d.ts +0 -0
- /package/{resultsetTable → resultset-table}/ResultsetTable.stories.tsx +0 -0
- /package/{resultsetTable → resultset-table}/types.js +0 -0
- /package/spinner/{Spinner.stories.jsx → Spinner.stories.tsx} +0 -0
- /package/table/{Table.stories.jsx → Table.stories.tsx} +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,44 +1,31 @@
|
|
|
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
|
|
@@ -69,11 +56,9 @@ var DxcChip = function DxcChip(_ref) {
|
|
|
69
56
|
src: suffixIcon
|
|
70
57
|
}) : suffixIcon)));
|
|
71
58
|
};
|
|
72
|
-
|
|
73
59
|
var calculateWidth = function calculateWidth(margin) {
|
|
74
60
|
return "calc(100% - ".concat((0, _utils.getMargin)(margin, "left"), " - ").concat((0, _utils.getMargin)(margin, "right"), ")");
|
|
75
61
|
};
|
|
76
|
-
|
|
77
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) {
|
|
78
63
|
return props.theme.iconSpacing;
|
|
79
64
|
}, function (props) {
|
|
@@ -110,7 +95,6 @@ var Chip = _styledComponents["default"].div(_templateObject || (_templateObject
|
|
|
110
95
|
var disabled = _ref2.disabled;
|
|
111
96
|
return disabled && "not-allowed";
|
|
112
97
|
});
|
|
113
|
-
|
|
114
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) {
|
|
115
99
|
return props.theme.fontSize;
|
|
116
100
|
}, function (props) {
|
|
@@ -122,19 +106,16 @@ var LabelContainer = _styledComponents["default"].span(_templateObject2 || (_tem
|
|
|
122
106
|
}, function (props) {
|
|
123
107
|
return props.disabled ? props.theme.disabledFontColor : props.theme.fontColor;
|
|
124
108
|
});
|
|
125
|
-
|
|
126
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) {
|
|
127
110
|
return props.disabled ? props.theme.disabledIconColor : props.theme.iconColor;
|
|
128
111
|
}, function (_ref3) {
|
|
129
112
|
var interactuable = _ref3.interactuable;
|
|
130
113
|
return interactuable && "cursor: pointer;";
|
|
131
114
|
}, function (props) {
|
|
132
|
-
return props.interactuable && "\n &:hover {\n color: ".concat(props.theme.hoverIconColor, ";\n }\n &:focus,\n &:focus-visible {\n outline: ").concat(props.theme.focusBorderThickness, "
|
|
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 ");
|
|
133
116
|
}, function (props) {
|
|
134
117
|
return props.theme.iconSize;
|
|
135
118
|
}, function (props) {
|
|
136
119
|
return props.theme.iconSize;
|
|
137
120
|
});
|
|
138
|
-
|
|
139
|
-
var _default = DxcChip;
|
|
140
|
-
exports["default"] = _default;
|
|
121
|
+
var _default = exports["default"] = DxcChip;
|
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
|
*/
|
package/common/coreTokens.js
CHANGED
package/common/utils.js
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.getMargin = void 0;
|
|
9
|
-
|
|
10
8
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
|
-
|
|
12
9
|
var _variables = require("./variables");
|
|
13
|
-
|
|
14
|
-
var getMargin = function getMargin(marginProp, side) {
|
|
10
|
+
var getMargin = exports.getMargin = function getMargin(marginProp, side) {
|
|
15
11
|
if (marginProp && (0, _typeof2["default"])(marginProp) === "object") {
|
|
16
12
|
return marginProp[side] && _variables.spaces[marginProp[side]] || "0px";
|
|
17
13
|
} else if (marginProp && typeof marginProp === "string") {
|
|
18
14
|
return _variables.spaces[marginProp];
|
|
19
15
|
} else return "0px";
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
exports.getMargin = getMargin;
|
|
16
|
+
};
|
package/common/variables.d.ts
CHANGED
|
@@ -197,16 +197,21 @@ export declare const componentTokens: {
|
|
|
197
197
|
hoverBackgroundColorCheckedOnDark: string;
|
|
198
198
|
disabledBackgroundColorChecked: string;
|
|
199
199
|
disabledBackgroundColorCheckedOnDark: string;
|
|
200
|
+
readOnlyBackgroundColorChecked: string;
|
|
201
|
+
hoverReadOnlyBackgroundColorChecked: string;
|
|
200
202
|
borderColor: string;
|
|
201
203
|
borderColorOnDark: string;
|
|
202
204
|
hoverBorderColor: string;
|
|
203
205
|
hoverBorderColorOnDark: string;
|
|
204
206
|
disabledBorderColor: string;
|
|
205
207
|
disabledBorderColorOnDark: string;
|
|
208
|
+
readOnlyBorderColor: string;
|
|
209
|
+
hoverReadOnlyBorderColor: string;
|
|
206
210
|
checkColor: string;
|
|
207
211
|
checkColorOnDark: string;
|
|
208
212
|
disabledCheckColor: string;
|
|
209
213
|
disabledCheckColorOnDark: string;
|
|
214
|
+
readOnlyCheckColor: string;
|
|
210
215
|
fontFamily: string;
|
|
211
216
|
fontSize: string;
|
|
212
217
|
fontWeight: string;
|
|
@@ -616,9 +621,9 @@ export declare const componentTokens: {
|
|
|
616
621
|
errorRadioInputColor: string;
|
|
617
622
|
hoverErrorRadioInputColor: string;
|
|
618
623
|
activeErrorRadioInputColor: string;
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
624
|
+
readOnlyRadioInputColor: string;
|
|
625
|
+
hoverReadOnlyRadioInputColor: string;
|
|
626
|
+
activeReadOnlyRadioInputColor: string;
|
|
622
627
|
disabledRadioInputColor: string;
|
|
623
628
|
disabledLabelFontColor: string;
|
|
624
629
|
disabledHelperTextFontColor: string;
|
|
@@ -1000,6 +1005,8 @@ export declare const componentTokens: {
|
|
|
1000
1005
|
disabledBorderColorOnDark: string;
|
|
1001
1006
|
disabledContainerFillColor: string;
|
|
1002
1007
|
disabledContainerFillColorOnDark: string;
|
|
1008
|
+
readOnlyBorderColor: string;
|
|
1009
|
+
hoverReadOnlyBorderColor: string;
|
|
1003
1010
|
errorBorderColor: string;
|
|
1004
1011
|
errorBorderColorOnDark: string;
|
|
1005
1012
|
hoverErrorBorderColor: string;
|
|
@@ -1049,6 +1056,8 @@ export declare const componentTokens: {
|
|
|
1049
1056
|
disabledBorderColorOnDark: string;
|
|
1050
1057
|
disabledContainerFillColor: string;
|
|
1051
1058
|
disabledContainerFillColorOnDark: string;
|
|
1059
|
+
readOnlyBorderColor: string;
|
|
1060
|
+
hoverReadOnlyBorderColor: string;
|
|
1052
1061
|
errorBorderColor: string;
|
|
1053
1062
|
errorBorderColorOnDark: string;
|
|
1054
1063
|
hoverErrorBorderColor: string;
|
|
@@ -1240,8 +1249,8 @@ export declare const componentTokens: {
|
|
|
1240
1249
|
focusColor: string;
|
|
1241
1250
|
};
|
|
1242
1251
|
};
|
|
1243
|
-
export
|
|
1244
|
-
export
|
|
1252
|
+
export type AdvancedTheme = typeof componentTokens;
|
|
1253
|
+
export type OpinionatedTheme = {
|
|
1245
1254
|
accordion: {
|
|
1246
1255
|
accentColor: string;
|
|
1247
1256
|
titleFontColor: string;
|
|
@@ -1487,4 +1496,4 @@ export declare const defaultTranslatedComponentLabels: {
|
|
|
1487
1496
|
nextMonthTitle: string;
|
|
1488
1497
|
};
|
|
1489
1498
|
};
|
|
1490
|
-
export
|
|
1499
|
+
export type TranslatedLabels = typeof defaultTranslatedComponentLabels;
|