@dxc-technology/halstack-react 10.1.0 → 12.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 +1 -10
- package/BackgroundColorContext.js +4 -21
- package/HalstackContext.d.ts +45 -143
- package/HalstackContext.js +10 -35
- package/accordion/Accordion.accessibility.test.js +71 -0
- package/accordion/Accordion.js +33 -84
- package/accordion/Accordion.stories.tsx +8 -64
- package/accordion/Accordion.test.js +18 -33
- package/accordion/types.d.ts +6 -6
- package/accordion-group/AccordionGroup.accessibility.test.js +88 -0
- package/accordion-group/AccordionGroup.d.ts +2 -3
- package/accordion-group/AccordionGroup.js +17 -44
- package/accordion-group/AccordionGroup.stories.tsx +24 -24
- package/accordion-group/AccordionGroup.test.js +42 -60
- package/accordion-group/AccordionGroupAccordion.js +11 -23
- package/accordion-group/AccordionGroupContext.d.ts +3 -0
- package/accordion-group/AccordionGroupContext.js +8 -0
- package/accordion-group/types.d.ts +7 -7
- package/action-icon/ActionIcon.accessibility.test.js +63 -0
- 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.accessibility.test.js +95 -0
- package/alert/Alert.js +34 -120
- package/alert/Alert.test.js +28 -45
- package/alert/types.d.ts +5 -5
- package/badge/Badge.accessibility.test.js +129 -0
- 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/types.d.ts +2 -2
- package/box/Box.accessibility.test.js +33 -0
- package/box/Box.js +11 -33
- package/box/Box.test.js +1 -6
- package/box/types.d.ts +3 -3
- package/breadcrumbs/Breadcrumbs.accessibility.test.d.ts +1 -0
- package/breadcrumbs/Breadcrumbs.accessibility.test.js +96 -0
- package/breadcrumbs/Breadcrumbs.d.ts +4 -0
- package/breadcrumbs/Breadcrumbs.js +79 -0
- package/breadcrumbs/Breadcrumbs.stories.tsx +194 -0
- package/breadcrumbs/Breadcrumbs.test.d.ts +1 -0
- package/breadcrumbs/Breadcrumbs.test.js +169 -0
- package/breadcrumbs/Item.d.ts +4 -0
- package/breadcrumbs/Item.js +52 -0
- package/breadcrumbs/dropdownTheme.d.ts +53 -0
- package/breadcrumbs/dropdownTheme.js +62 -0
- package/breadcrumbs/types.d.ts +16 -0
- package/breadcrumbs/types.js +5 -0
- package/bulleted-list/BulletedList.accessibility.test.js +119 -0
- package/bulleted-list/BulletedList.js +22 -55
- package/bulleted-list/BulletedList.stories.tsx +2 -93
- package/bulleted-list/types.d.ts +5 -5
- package/button/Button.accessibility.test.js +127 -0
- package/button/Button.js +36 -59
- package/button/Button.stories.tsx +35 -135
- package/button/Button.test.js +13 -21
- package/button/types.d.ts +5 -5
- package/card/Card.accessibility.test.js +36 -0
- package/card/Card.js +23 -45
- package/card/Card.test.js +10 -21
- package/card/types.d.ts +5 -5
- package/checkbox/Checkbox.accessibility.test.js +87 -0
- package/checkbox/Checkbox.js +88 -123
- package/checkbox/Checkbox.stories.tsx +16 -54
- package/checkbox/Checkbox.test.js +107 -63
- package/checkbox/types.d.ts +8 -4
- package/chip/Chip.accessibility.test.js +67 -0
- package/chip/Chip.js +22 -36
- package/chip/Chip.stories.tsx +10 -25
- package/chip/Chip.test.js +17 -30
- package/chip/types.d.ts +4 -4
- package/common/coreTokens.d.ts +105 -14
- package/common/coreTokens.js +40 -23
- package/common/utils.js +2 -8
- package/common/variables.d.ts +46 -144
- package/common/variables.js +120 -225
- 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/container/types.js +5 -0
- package/contextual-menu/ContextualMenu.accessibility.test.js +97 -0
- package/contextual-menu/ContextualMenu.d.ts +5 -0
- package/contextual-menu/ContextualMenu.js +88 -0
- package/contextual-menu/ContextualMenu.stories.tsx +232 -0
- package/contextual-menu/ContextualMenu.test.js +205 -0
- package/contextual-menu/GroupItem.d.ts +4 -0
- package/contextual-menu/GroupItem.js +67 -0
- package/contextual-menu/ItemAction.d.ts +4 -0
- package/contextual-menu/ItemAction.js +51 -0
- package/contextual-menu/MenuItem.d.ts +4 -0
- package/contextual-menu/MenuItem.js +29 -0
- package/contextual-menu/SingleItem.d.ts +4 -0
- package/contextual-menu/SingleItem.js +38 -0
- package/contextual-menu/types.d.ts +58 -0
- package/contextual-menu/types.js +5 -0
- package/date-input/Calendar.js +13 -57
- package/date-input/DateInput.accessibility.test.js +228 -0
- package/date-input/DateInput.js +53 -100
- package/date-input/DateInput.stories.tsx +19 -31
- package/date-input/DateInput.test.js +674 -701
- package/date-input/DatePicker.js +23 -48
- package/date-input/YearPicker.js +8 -34
- package/date-input/types.d.ts +28 -22
- package/dialog/Dialog.accessibility.test.js +69 -0
- package/dialog/Dialog.js +21 -59
- package/dialog/Dialog.stories.tsx +176 -0
- package/dialog/Dialog.test.js +126 -188
- package/dialog/types.d.ts +18 -13
- package/divider/Divider.accessibility.test.js +33 -0
- 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.accessibility.test.js +180 -0
- package/dropdown/Dropdown.js +63 -130
- package/dropdown/Dropdown.stories.tsx +15 -26
- package/dropdown/Dropdown.test.js +402 -389
- package/dropdown/DropdownMenu.js +12 -23
- package/dropdown/DropdownMenuItem.js +13 -21
- package/dropdown/types.d.ts +20 -24
- package/file-input/FileInput.accessibility.test.js +160 -0
- package/file-input/FileInput.js +180 -284
- package/file-input/FileInput.stories.tsx +1 -1
- package/file-input/FileInput.test.js +279 -354
- package/file-input/FileItem.js +29 -66
- package/file-input/types.d.ts +9 -9
- package/flex/Flex.js +25 -39
- package/flex/types.d.ts +6 -6
- package/footer/Footer.accessibility.test.js +125 -0
- package/footer/Footer.d.ts +1 -1
- package/footer/Footer.js +43 -68
- package/footer/Footer.stories.tsx +58 -2
- package/footer/Footer.test.js +18 -32
- package/footer/Icons.d.ts +3 -2
- package/footer/Icons.js +53 -22
- package/footer/types.d.ts +17 -17
- package/grid/Grid.js +1 -16
- package/grid/types.d.ts +10 -10
- package/header/Header.accessibility.test.js +93 -0
- package/header/Header.d.ts +1 -1
- package/header/Header.js +38 -104
- package/header/Header.stories.tsx +16 -0
- package/header/Header.test.js +12 -25
- package/header/Icons.d.ts +2 -2
- package/header/Icons.js +3 -13
- package/header/types.d.ts +7 -8
- package/heading/Heading.accessibility.test.js +33 -0
- package/heading/Heading.js +9 -31
- package/heading/Heading.test.js +70 -87
- package/heading/types.d.ts +7 -7
- package/icon/Icon.accessibility.test.js +30 -0
- 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.accessibility.test.js +56 -0
- package/image/Image.d.ts +2 -2
- package/image/Image.js +17 -32
- package/image/Image.stories.tsx +3 -1
- 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 +2 -2
- package/layout/ApplicationLayout.js +23 -60
- package/layout/Icons.d.ts +4 -5
- package/layout/Icons.js +2 -16
- package/layout/types.d.ts +3 -3
- package/link/Link.accessibility.test.js +108 -0
- package/link/Link.js +28 -47
- package/link/Link.stories.tsx +4 -4
- package/link/Link.test.js +23 -41
- package/link/types.d.ts +14 -14
- package/main.d.ts +8 -4
- package/main.js +39 -60
- package/nav-tabs/NavTabs.accessibility.test.js +44 -0
- package/nav-tabs/NavTabs.d.ts +1 -2
- package/nav-tabs/NavTabs.js +19 -48
- package/nav-tabs/NavTabs.stories.tsx +30 -25
- package/nav-tabs/NavTabs.test.js +45 -50
- package/nav-tabs/NavTabsContext.d.ts +3 -0
- package/nav-tabs/NavTabsContext.js +8 -0
- package/nav-tabs/Tab.js +38 -67
- package/nav-tabs/types.d.ts +10 -10
- package/number-input/NumberInput.accessibility.test.js +228 -0
- package/number-input/NumberInput.d.ts +0 -7
- package/number-input/NumberInput.js +47 -39
- package/number-input/NumberInput.stories.tsx +42 -26
- package/number-input/NumberInput.test.js +839 -575
- package/number-input/NumberInputContext.d.ts +3 -0
- package/number-input/NumberInputContext.js +8 -0
- package/number-input/types.d.ts +17 -5
- package/package.json +41 -37
- package/paginator/Paginator.accessibility.test.js +79 -0
- package/paginator/Paginator.js +27 -52
- package/paginator/Paginator.test.js +224 -207
- package/paginator/types.d.ts +3 -3
- package/paragraph/Paragraph.accessibility.test.js +28 -0
- package/paragraph/Paragraph.js +3 -19
- package/paragraph/Paragraph.stories.tsx +0 -17
- package/password-input/PasswordInput.accessibility.test.js +153 -0
- package/password-input/PasswordInput.js +32 -54
- package/password-input/PasswordInput.stories.tsx +1 -34
- package/password-input/PasswordInput.test.js +153 -129
- package/password-input/types.d.ts +8 -7
- package/progress-bar/ProgressBar.accessibility.test.js +35 -0
- package/progress-bar/ProgressBar.js +26 -56
- 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.accessibility.test.js +57 -0
- 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.accessibility.test.js +97 -0
- package/radio-group/RadioGroup.js +38 -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/resultset-table/ResultsetTable.accessibility.test.js +285 -0
- package/resultset-table/ResultsetTable.d.ts +7 -0
- package/{resultsetTable → resultset-table}/ResultsetTable.js +45 -69
- package/{resultsetTable → resultset-table}/ResultsetTable.stories.tsx +118 -5
- package/{resultsetTable → resultset-table}/ResultsetTable.test.js +148 -92
- package/{resultsetTable → resultset-table}/types.d.ts +44 -11
- package/resultset-table/types.js +5 -0
- package/select/Listbox.js +40 -54
- package/select/Option.js +28 -36
- package/select/Select.accessibility.test.js +228 -0
- package/select/Select.js +107 -171
- package/select/Select.stories.tsx +59 -111
- package/select/Select.test.js +1895 -1858
- package/select/types.d.ts +15 -16
- package/sidenav/Sidenav.accessibility.test.js +59 -0
- package/sidenav/Sidenav.js +44 -81
- package/sidenav/Sidenav.stories.tsx +4 -9
- 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 +20 -20
- package/slider/Slider.accessibility.test.js +104 -0
- package/slider/Slider.js +70 -126
- package/slider/Slider.test.js +107 -103
- package/slider/types.d.ts +4 -4
- package/spinner/Spinner.accessibility.test.js +96 -0
- package/spinner/Spinner.js +21 -55
- package/spinner/Spinner.test.js +25 -34
- package/spinner/types.d.ts +3 -3
- package/status-light/StatusLight.accessibility.test.js +157 -0
- 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.accessibility.test.js +98 -0
- package/switch/Switch.js +49 -97
- package/switch/Switch.stories.tsx +12 -34
- package/switch/Switch.test.js +51 -96
- package/switch/types.d.ts +4 -4
- package/table/DropdownTheme.js +62 -0
- package/table/Table.accessibility.test.js +93 -0
- package/table/Table.d.ts +6 -2
- package/table/Table.js +76 -33
- package/table/{Table.stories.jsx → Table.stories.tsx} +309 -2
- package/table/Table.test.js +93 -6
- package/table/types.d.ts +34 -6
- package/tabs/Tab.js +22 -37
- package/tabs/Tabs.accessibility.test.js +56 -0
- package/tabs/Tabs.js +59 -147
- package/tabs/Tabs.stories.tsx +8 -4
- package/tabs/Tabs.test.js +57 -131
- package/tabs/types.d.ts +21 -21
- package/tag/Tag.accessibility.test.js +69 -0
- package/tag/Tag.js +27 -57
- package/tag/Tag.stories.tsx +4 -7
- package/tag/Tag.test.js +17 -36
- package/tag/types.d.ts +9 -9
- package/text-input/Suggestion.js +9 -26
- package/text-input/Suggestions.d.ts +1 -1
- package/text-input/Suggestions.js +30 -70
- package/text-input/TextInput.accessibility.test.js +321 -0
- package/text-input/TextInput.js +203 -289
- package/text-input/TextInput.stories.tsx +65 -160
- package/text-input/TextInput.test.js +1227 -1194
- package/text-input/types.d.ts +25 -17
- package/textarea/Textarea.accessibility.test.js +155 -0
- package/textarea/Textarea.js +68 -109
- package/textarea/{Textarea.stories.jsx → Textarea.stories.tsx} +58 -100
- package/textarea/Textarea.test.js +150 -179
- package/textarea/types.d.ts +9 -5
- package/toggle-group/ToggleGroup.accessibility.test.js +107 -0
- package/toggle-group/ToggleGroup.js +25 -64
- package/toggle-group/ToggleGroup.stories.tsx +4 -4
- package/toggle-group/ToggleGroup.test.js +48 -81
- package/toggle-group/types.d.ts +12 -12
- package/typography/Typography.accessibility.test.js +339 -0
- package/typography/Typography.js +4 -13
- package/typography/types.d.ts +1 -1
- package/useTheme.d.ts +43 -141
- 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 +25 -39
- package/wizard/Wizard.accessibility.test.js +55 -0
- package/wizard/Wizard.js +27 -73
- package/wizard/Wizard.stories.tsx +19 -0
- package/wizard/Wizard.test.js +53 -80
- package/wizard/types.d.ts +8 -8
- package/common/OpenSans.css +0 -69
- 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/date-input/Icons.d.ts +0 -6
- package/date-input/Icons.js +0 -75
- package/paginator/Icons.d.ts +0 -5
- package/paginator/Icons.js +0 -54
- package/password-input/Icons.d.ts +0 -6
- package/password-input/Icons.js +0 -39
- package/resultsetTable/Icons.d.ts +0 -7
- package/resultsetTable/ResultsetTable.d.ts +0 -4
- package/select/Icons.d.ts +0 -10
- package/select/Icons.js +0 -93
- package/sidenav/Icons.d.ts +0 -7
- package/sidenav/Icons.js +0 -51
- package/slider/Slider.stories.tsx +0 -240
- package/text-input/Icons.d.ts +0 -8
- package/text-input/Icons.js +0 -60
- /package/{resultsetTable → action-icon}/types.js +0 -0
- /package/spinner/{Spinner.stories.jsx → Spinner.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;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
5
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
6
|
+
var _react = _interopRequireDefault(require("react"));
|
|
7
|
+
var _react2 = require("@testing-library/react");
|
|
8
|
+
var _axeHelper = require("../../test/accessibility/axe-helper.js");
|
|
9
|
+
var _Chip = _interopRequireDefault(require("./Chip.tsx"));
|
|
10
|
+
var iconSVG = /*#__PURE__*/_react["default"].createElement("svg", {
|
|
11
|
+
version: "1.1",
|
|
12
|
+
x: "0px",
|
|
13
|
+
y: "0px",
|
|
14
|
+
width: "438.536px",
|
|
15
|
+
height: "438.536px",
|
|
16
|
+
viewBox: "0 0 438.536 438.536",
|
|
17
|
+
fill: "currentColor"
|
|
18
|
+
}, /*#__PURE__*/_react["default"].createElement("g", null, /*#__PURE__*/_react["default"].createElement("path", {
|
|
19
|
+
d: "M414.41,24.123C398.333,8.042,378.963,0,356.315,0H82.228C59.58,0,40.21,8.042,24.126,24.123\nC8.045,40.207,0.003,59.576,0.003,82.225v274.084c0,22.647,8.042,42.018,24.123,58.102c16.084,16.084,35.454,24.126,58.102,24.126\nh274.084c22.648,0,42.018-8.042,58.095-24.126c16.084-16.084,24.126-35.454,24.126-58.102V82.225\nC438.532,59.576,430.49,40.204,414.41,24.123z M373.155,225.548h-49.963V406.84h-74.802V225.548H210.99V163.02h37.401v-37.402\nc0-26.838,6.283-47.107,18.843-60.813c12.559-13.706,33.304-20.555,62.242-20.555h49.963v62.526h-31.401\nc-10.663,0-17.467,1.853-20.417,5.568c-2.949,3.711-4.428,10.23-4.428,19.558v31.119h56.534L373.155,225.548z"
|
|
20
|
+
})));
|
|
21
|
+
describe("Chip component accessibility tests", function () {
|
|
22
|
+
it("Should not have basic accessibility issues", /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
23
|
+
var _render, container, results;
|
|
24
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
25
|
+
while (1) switch (_context.prev = _context.next) {
|
|
26
|
+
case 0:
|
|
27
|
+
_render = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Chip["default"], {
|
|
28
|
+
margin: "small",
|
|
29
|
+
prefixIcon: iconSVG,
|
|
30
|
+
suffixIcon: iconSVG,
|
|
31
|
+
label: "Chip"
|
|
32
|
+
})), container = _render.container;
|
|
33
|
+
_context.next = 3;
|
|
34
|
+
return (0, _axeHelper.axe)(container);
|
|
35
|
+
case 3:
|
|
36
|
+
results = _context.sent;
|
|
37
|
+
expect(results).toHaveNoViolations();
|
|
38
|
+
case 5:
|
|
39
|
+
case "end":
|
|
40
|
+
return _context.stop();
|
|
41
|
+
}
|
|
42
|
+
}, _callee);
|
|
43
|
+
})));
|
|
44
|
+
it("Should not have basic accessibility issues for disabled mode", /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
45
|
+
var _render2, container, results;
|
|
46
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
47
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
48
|
+
case 0:
|
|
49
|
+
_render2 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Chip["default"], {
|
|
50
|
+
margin: "small",
|
|
51
|
+
prefixIcon: iconSVG,
|
|
52
|
+
suffixIcon: iconSVG,
|
|
53
|
+
label: "Chip",
|
|
54
|
+
disabled: true
|
|
55
|
+
})), container = _render2.container;
|
|
56
|
+
_context2.next = 3;
|
|
57
|
+
return (0, _axeHelper.axe)(container);
|
|
58
|
+
case 3:
|
|
59
|
+
results = _context2.sent;
|
|
60
|
+
expect(results).toHaveNoViolations();
|
|
61
|
+
case 5:
|
|
62
|
+
case "end":
|
|
63
|
+
return _context2.stop();
|
|
64
|
+
}
|
|
65
|
+
}, _callee2);
|
|
66
|
+
})));
|
|
67
|
+
});
|
package/chip/Chip.js
CHANGED
|
@@ -1,44 +1,32 @@
|
|
|
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
|
-
|
|
16
|
+
var _Icon = _interopRequireDefault(require("../icon/Icon"));
|
|
26
17
|
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
|
-
|
|
18
|
+
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); }
|
|
19
|
+
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 && {}.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
20
|
var DxcChip = function DxcChip(_ref) {
|
|
33
21
|
var label = _ref.label,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
22
|
+
suffixIcon = _ref.suffixIcon,
|
|
23
|
+
prefixIcon = _ref.prefixIcon,
|
|
24
|
+
onClickSuffix = _ref.onClickSuffix,
|
|
25
|
+
onClickPrefix = _ref.onClickPrefix,
|
|
26
|
+
disabled = _ref.disabled,
|
|
27
|
+
margin = _ref.margin,
|
|
28
|
+
_ref$tabIndex = _ref.tabIndex,
|
|
29
|
+
tabIndex = _ref$tabIndex === void 0 ? 0 : _ref$tabIndex;
|
|
42
30
|
var colorsTheme = (0, _useTheme["default"])();
|
|
43
31
|
return /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
|
|
44
32
|
theme: colorsTheme.chip
|
|
@@ -47,33 +35,33 @@ var DxcChip = function DxcChip(_ref) {
|
|
|
47
35
|
margin: margin
|
|
48
36
|
}, prefixIcon && /*#__PURE__*/_react["default"].createElement(IconContainer, {
|
|
49
37
|
role: typeof onClickPrefix === "function" ? "button" : undefined,
|
|
38
|
+
"aria-label": typeof onClickPrefix === "function" ? "Prefix Action" : undefined,
|
|
50
39
|
disabled: disabled,
|
|
51
40
|
interactuable: typeof onClickPrefix === "function" && !disabled,
|
|
52
41
|
tabIndex: typeof onClickPrefix === "function" && !disabled ? tabIndex : -1,
|
|
53
42
|
onClick: function onClick() {
|
|
54
43
|
return onClickPrefix && !disabled && onClickPrefix();
|
|
55
44
|
}
|
|
56
|
-
}, typeof prefixIcon === "string" ? /*#__PURE__*/_react["default"].createElement("
|
|
57
|
-
|
|
45
|
+
}, typeof prefixIcon === "string" ? /*#__PURE__*/_react["default"].createElement(_Icon["default"], {
|
|
46
|
+
icon: prefixIcon
|
|
58
47
|
}) : prefixIcon), label && /*#__PURE__*/_react["default"].createElement(LabelContainer, {
|
|
59
48
|
disabled: disabled
|
|
60
49
|
}, label), suffixIcon && /*#__PURE__*/_react["default"].createElement(IconContainer, {
|
|
61
50
|
role: typeof onClickSuffix === "function" ? "button" : undefined,
|
|
51
|
+
"aria-label": typeof onClickSuffix === "function" ? "Suffix Action" : undefined,
|
|
62
52
|
disabled: disabled,
|
|
63
53
|
interactuable: typeof onClickSuffix === "function" && !disabled,
|
|
64
54
|
tabIndex: typeof onClickSuffix === "function" && !disabled ? tabIndex : -1,
|
|
65
55
|
onClick: function onClick() {
|
|
66
56
|
return !disabled && (onClickSuffix === null || onClickSuffix === void 0 ? void 0 : onClickSuffix());
|
|
67
57
|
}
|
|
68
|
-
}, typeof suffixIcon === "string" ? /*#__PURE__*/_react["default"].createElement("
|
|
69
|
-
|
|
58
|
+
}, typeof suffixIcon === "string" ? /*#__PURE__*/_react["default"].createElement(_Icon["default"], {
|
|
59
|
+
icon: suffixIcon
|
|
70
60
|
}) : suffixIcon)));
|
|
71
61
|
};
|
|
72
|
-
|
|
73
62
|
var calculateWidth = function calculateWidth(margin) {
|
|
74
63
|
return "calc(100% - ".concat((0, _utils.getMargin)(margin, "left"), " - ").concat((0, _utils.getMargin)(margin, "right"), ")");
|
|
75
64
|
};
|
|
76
|
-
|
|
77
65
|
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
66
|
return props.theme.iconSpacing;
|
|
79
67
|
}, function (props) {
|
|
@@ -110,7 +98,6 @@ var Chip = _styledComponents["default"].div(_templateObject || (_templateObject
|
|
|
110
98
|
var disabled = _ref2.disabled;
|
|
111
99
|
return disabled && "not-allowed";
|
|
112
100
|
});
|
|
113
|
-
|
|
114
101
|
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
102
|
return props.theme.fontSize;
|
|
116
103
|
}, function (props) {
|
|
@@ -122,19 +109,18 @@ var LabelContainer = _styledComponents["default"].span(_templateObject2 || (_tem
|
|
|
122
109
|
}, function (props) {
|
|
123
110
|
return props.disabled ? props.theme.disabledFontColor : props.theme.fontColor;
|
|
124
111
|
});
|
|
125
|
-
|
|
126
|
-
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) {
|
|
112
|
+
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 font-size: ", ";\n svg {\n width: ", ";\n height: ", ";\n }\n"])), function (props) {
|
|
127
113
|
return props.disabled ? props.theme.disabledIconColor : props.theme.iconColor;
|
|
128
114
|
}, function (_ref3) {
|
|
129
115
|
var interactuable = _ref3.interactuable;
|
|
130
116
|
return interactuable && "cursor: pointer;";
|
|
131
117
|
}, 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, "
|
|
118
|
+
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 ");
|
|
119
|
+
}, function (props) {
|
|
120
|
+
return props.theme.iconSize;
|
|
133
121
|
}, function (props) {
|
|
134
122
|
return props.theme.iconSize;
|
|
135
123
|
}, function (props) {
|
|
136
124
|
return props.theme.iconSize;
|
|
137
125
|
});
|
|
138
|
-
|
|
139
|
-
var _default = DxcChip;
|
|
140
|
-
exports["default"] = _default;
|
|
126
|
+
var _default = exports["default"] = DxcChip;
|
package/chip/Chip.stories.tsx
CHANGED
|
@@ -13,7 +13,6 @@ export default {
|
|
|
13
13
|
const iconSVG = (
|
|
14
14
|
<svg
|
|
15
15
|
version="1.1"
|
|
16
|
-
id="Capa_1"
|
|
17
16
|
x="0px"
|
|
18
17
|
y="0px"
|
|
19
18
|
width="438.536px"
|
|
@@ -64,20 +63,11 @@ export const Chromatic = () => (
|
|
|
64
63
|
</ExampleContainer>
|
|
65
64
|
<ExampleContainer>
|
|
66
65
|
<Title title="Chip with prefix (SVG) and suffix (URL)" theme="light" level={4} />
|
|
67
|
-
<DxcChip
|
|
68
|
-
label="Chip with prefix and suffix"
|
|
69
|
-
prefixIcon={iconSVG}
|
|
70
|
-
suffixIcon="https://upload.wikimedia.org/wikipedia/commons/e/e0/Check_green_icon.svg"
|
|
71
|
-
/>
|
|
66
|
+
<DxcChip label="Chip with prefix and suffix" prefixIcon={iconSVG} suffixIcon="filled_check_circle" />
|
|
72
67
|
</ExampleContainer>
|
|
73
68
|
<ExampleContainer>
|
|
74
69
|
<Title title="Disabled chip" theme="light" level={4} />
|
|
75
|
-
<DxcChip
|
|
76
|
-
label="Disabled"
|
|
77
|
-
disabled
|
|
78
|
-
prefixIcon={iconSVG}
|
|
79
|
-
suffixIcon="https://upload.wikimedia.org/wikipedia/commons/e/e0/Check_green_icon.svg"
|
|
80
|
-
/>
|
|
70
|
+
<DxcChip label="Disabled" disabled prefixIcon={iconSVG} suffixIcon="filled_check_circle" />
|
|
81
71
|
</ExampleContainer>
|
|
82
72
|
<ExampleContainer>
|
|
83
73
|
<Title title="Chip with ellipsis" theme="light" level={4} />
|
|
@@ -146,22 +136,13 @@ export const Chromatic = () => (
|
|
|
146
136
|
<ExampleContainer>
|
|
147
137
|
<Title title="Chip with prefix and suffix" theme="light" level={4} />
|
|
148
138
|
<HalstackProvider theme={opinionatedTheme}>
|
|
149
|
-
<DxcChip
|
|
150
|
-
label="Chip"
|
|
151
|
-
prefixIcon={iconSVG}
|
|
152
|
-
suffixIcon="https://upload.wikimedia.org/wikipedia/commons/e/e0/Check_green_icon.svg"
|
|
153
|
-
/>
|
|
139
|
+
<DxcChip label="Chip" prefixIcon={iconSVG} suffixIcon="filled_check_circle" />
|
|
154
140
|
</HalstackProvider>
|
|
155
141
|
</ExampleContainer>
|
|
156
142
|
<ExampleContainer>
|
|
157
143
|
<Title title="Chip with prefix and suffix" theme="light" level={4} />
|
|
158
144
|
<HalstackProvider theme={opinionatedTheme}>
|
|
159
|
-
<DxcChip
|
|
160
|
-
label="Chip"
|
|
161
|
-
disabled
|
|
162
|
-
prefixIcon={iconSVG}
|
|
163
|
-
suffixIcon="https://upload.wikimedia.org/wikipedia/commons/e/e0/Check_green_icon.svg"
|
|
164
|
-
/>
|
|
145
|
+
<DxcChip label="Chip" disabled prefixIcon={iconSVG} suffixIcon="filled_check_circle" />
|
|
165
146
|
</HalstackProvider>
|
|
166
147
|
</ExampleContainer>
|
|
167
148
|
<ExampleContainer pseudoState="pseudo-hover">
|
|
@@ -193,13 +174,17 @@ export const Chromatic = () => (
|
|
|
193
174
|
const ChipPrefixFocused = () => (
|
|
194
175
|
<ExampleContainer>
|
|
195
176
|
<Title title="Chip with prefix" theme="light" level={4} />
|
|
196
|
-
<DxcChip
|
|
177
|
+
<DxcChip
|
|
178
|
+
label="Chip with prefix"
|
|
179
|
+
prefixIcon={iconSVG}
|
|
180
|
+
onClickPrefix={() => {}}
|
|
181
|
+
/>
|
|
197
182
|
</ExampleContainer>
|
|
198
183
|
);
|
|
199
184
|
const ChipSuffixFocused = () => (
|
|
200
185
|
<ExampleContainer>
|
|
201
186
|
<Title title="Chip with suffix" theme="light" level={4} />
|
|
202
|
-
<DxcChip label="Chip with suffix" suffixIcon="
|
|
187
|
+
<DxcChip label="Chip with suffix" suffixIcon="filled_delete" onClickSuffix={() => {}} />
|
|
203
188
|
</ExampleContainer>
|
|
204
189
|
);
|
|
205
190
|
|
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: "nutrition",
|
|
20
|
+
onClickPrefix: onClick
|
|
21
|
+
})),
|
|
22
|
+
getByText = _render2.getByText,
|
|
23
|
+
getByRole = _render2.getByRole;
|
|
31
24
|
expect(getByText("Chip")).toBeTruthy();
|
|
32
|
-
|
|
33
|
-
_react2.fireEvent.click(getByRole("img"));
|
|
34
|
-
|
|
25
|
+
_react2.fireEvent.click(getByRole("button"));
|
|
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: "nutrition",
|
|
33
|
+
onClickSuffix: onClick
|
|
34
|
+
})),
|
|
35
|
+
getByText = _render3.getByText,
|
|
36
|
+
getByRole = _render3.getByRole;
|
|
48
37
|
expect(getByText("Chip")).toBeTruthy();
|
|
49
|
-
|
|
50
|
-
_react2.fireEvent.click(getByRole("img"));
|
|
51
|
-
|
|
38
|
+
_react2.fireEvent.click(getByRole("button"));
|
|
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
|
*/
|