@automattic/vip-design-system 2.10.0 → 2.10.2
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/babel.config.js +23 -19
- package/build/declaration.d.js +0 -1
- package/build/system/Accordion/Accordion.js +28 -33
- package/build/system/Accordion/Accordion.stories.js +34 -35
- package/build/system/Accordion/Accordion.test.js +35 -34
- package/build/system/Accordion/index.js +5 -8
- package/build/system/Avatar/Avatar.js +13 -17
- package/build/system/Avatar/Avatar.stories.js +10 -12
- package/build/system/Avatar/Avatar.test.js +15 -14
- package/build/system/Avatar/index.js +4 -6
- package/build/system/Badge/Badge.js +9 -14
- package/build/system/Badge/Badge.stories.js +23 -23
- package/build/system/Badge/Badge.test.js +15 -14
- package/build/system/Badge/index.js +4 -6
- package/build/system/Box/Box.js +9 -13
- package/build/system/Box/Box.stories.js +5 -8
- package/build/system/Breadcrumbs/Breadcrumbs.js +34 -38
- package/build/system/Breadcrumbs/Breadcrumbs.stories.js +18 -21
- package/build/system/Breadcrumbs/Breadcrumbs.test.js +28 -30
- package/build/system/Breadcrumbs/styles.js +5 -9
- package/build/system/Button/Button.js +11 -17
- package/build/system/Button/Button.stories.js +34 -33
- package/build/system/Button/Button.test.js +17 -16
- package/build/system/Button/ButtonSubmit.js +12 -16
- package/build/system/Button/ButtonSubmit.stories.js +12 -16
- package/build/system/Button/ButtonSubmit.test.js +15 -14
- package/build/system/Button/index.js +5 -8
- package/build/system/Card/Card.js +12 -14
- package/build/system/Card/Card.stories.js +21 -24
- package/build/system/Card/Card.test.js +19 -18
- package/build/system/Card/index.js +4 -6
- package/build/system/Code/Code.js +19 -23
- package/build/system/Code/Code.stories.js +16 -18
- package/build/system/Code/Code.test.js +20 -19
- package/build/system/Code/index.js +4 -6
- package/build/system/Drawer/Drawer.js +25 -30
- package/build/system/Drawer/Drawer.stories.js +38 -39
- package/build/system/Drawer/Drawer.test.js +19 -18
- package/build/system/Drawer/styles.js +9 -11
- package/build/system/Dropdown/Dropdown.js +23 -26
- package/build/system/Dropdown/Dropdown.test.js +16 -18
- package/build/system/Dropdown/DropdownContent.js +14 -20
- package/build/system/Dropdown/DropdownItem.js +19 -25
- package/build/system/Dropdown/DropdownLabel.js +10 -16
- package/build/system/Dropdown/DropdownSeparator.js +10 -16
- package/build/system/Dropdown/index.js +20 -23
- package/build/system/FilterDropdown/FilterDropdown.js +23 -29
- package/build/system/FilterDropdown/FilterDropdown.stories.js +9 -11
- package/build/system/FilterDropdown/FilterDropdown.test.js +7 -10
- package/build/system/Flex/Flex.js +7 -10
- package/build/system/Flex/Flex.stories.js +6 -10
- package/build/system/Flex/index.js +4 -6
- package/build/system/Footer/Footer.d.ts +33 -0
- package/build/system/Footer/Footer.js +82 -0
- package/build/system/Footer/Footer.stories.d.ts +41 -0
- package/build/system/Footer/Footer.stories.js +53 -0
- package/build/system/Footer/Footer.test.d.ts +1 -0
- package/build/system/Footer/Footer.test.js +36 -0
- package/build/system/Form/Checkbox/Checkbox.js +14 -18
- package/build/system/Form/Checkbox/Checkbox.stories.js +47 -48
- package/build/system/Form/Checkbox/Checkbox.test.js +23 -21
- package/build/system/Form/Checkbox/styles.js +7 -10
- package/build/system/Form/Input.js +19 -18
- package/build/system/Form/Input.stories.js +16 -18
- package/build/system/Form/Input.styles.js +5 -9
- package/build/system/Form/Label.js +14 -16
- package/build/system/Form/Label.stories.js +15 -15
- package/build/system/Form/Radio/Radio.js +13 -18
- package/build/system/Form/Radio/Radio.stories.js +43 -43
- package/build/system/Form/Radio/Radio.test.js +19 -18
- package/build/system/Form/Radio/RadioOption.js +22 -23
- package/build/system/Form/Radio/styles.js +7 -10
- package/build/system/Form/RadioGroupChip.js +26 -29
- package/build/system/Form/RadioGroupChip.stories.js +12 -15
- package/build/system/Form/RadioGroupChip.test.js +12 -11
- package/build/system/Form/RequiredLabel.js +3 -7
- package/build/system/Form/Toggle.js +11 -16
- package/build/system/Form/Toggle.stories.js +25 -27
- package/build/system/Form/Toggle.test.js +12 -11
- package/build/system/Form/Validation.js +10 -12
- package/build/system/Form/index.d.ts +2 -1
- package/build/system/Form/index.js +2 -0
- package/build/system/Grid/Grid.js +7 -10
- package/build/system/Grid/Grid.stories.js +6 -10
- package/build/system/Grid/index.js +4 -6
- package/build/system/Heading/Heading.js +9 -14
- package/build/system/Heading/Heading.stories.js +13 -16
- package/build/system/Hr/Hr.js +3 -7
- package/build/system/Hr/Hr.stories.js +10 -11
- package/build/system/Hr/Hr.test.js +14 -14
- package/build/system/Link/Link.js +11 -14
- package/build/system/Link/Link.stories.js +11 -14
- package/build/system/Link/index.js +4 -6
- package/build/system/LinkExternal/LinkExternal.d.ts +23 -3
- package/build/system/LinkExternal/LinkExternal.js +17 -23
- package/build/system/LinkExternal/LinkExternal.stories.d.ts +1 -8
- package/build/system/LinkExternal/LinkExternal.stories.js +4 -9
- package/build/system/LinkExternal/LinkExternal.test.js +14 -15
- package/build/system/MobileMenu/MobileMenu.js +24 -29
- package/build/system/MobileMenu/MobileMenu.stories.js +66 -67
- package/build/system/MobileMenu/MobileMenu.test.js +21 -22
- package/build/system/Nav/Nav.js +26 -32
- package/build/system/Nav/Nav.stories.js +97 -99
- package/build/system/Nav/Nav.test.js +32 -28
- package/build/system/Nav/NavItem.js +40 -45
- package/build/system/Nav/NavItemGroup.js +34 -39
- package/build/system/Nav/NavItemGroup.test.js +26 -23
- package/build/system/Nav/styles/variants/breadcrumbs.js +4 -7
- package/build/system/Nav/styles/variants/menu.js +8 -12
- package/build/system/Nav/styles/variants/menugroup.js +7 -11
- package/build/system/Nav/styles/variants/primary.js +4 -8
- package/build/system/Nav/styles/variants/tabs.js +3 -7
- package/build/system/Nav/styles/variants/toolbar.js +5 -8
- package/build/system/Nav/styles.js +26 -29
- package/build/system/NewDialog/DialogClose.js +14 -18
- package/build/system/NewDialog/DialogClose.test.js +11 -14
- package/build/system/NewDialog/DialogDescription.js +9 -15
- package/build/system/NewDialog/DialogOverlay.js +11 -13
- package/build/system/NewDialog/DialogTitle.js +7 -15
- package/build/system/NewDialog/NewDialog.js +24 -29
- package/build/system/NewDialog/index.js +7 -11
- package/build/system/NewDialog/styles.js +1 -5
- package/build/system/NewForm/Fieldset.js +13 -17
- package/build/system/NewForm/Form.js +8 -13
- package/build/system/NewForm/FormAutocomplete.js +2 -2
- package/build/system/NewForm/Legend.js +11 -15
- package/build/system/Notice/Notice.js +22 -25
- package/build/system/Notice/Notice.stories.js +41 -43
- package/build/system/Notice/index.js +5 -5
- package/build/system/Page/Page.js +4 -8
- package/build/system/Page/Page.test.js +14 -14
- package/build/system/Progress/Progress.js +21 -24
- package/build/system/Progress/Progress.stories.js +9 -15
- package/build/system/Progress/Progress.test.js +14 -13
- package/build/system/Progress/index.js +4 -6
- package/build/system/ScreenReaderText/ScreenReaderText.js +9 -9
- package/build/system/Spinner/Spinner.js +9 -14
- package/build/system/Spinner/Spinner.stories.js +6 -10
- package/build/system/Spinner/Spinner.test.js +14 -13
- package/build/system/Spinner/index.js +1 -6
- package/build/system/Table/Table.js +20 -22
- package/build/system/Table/Table.stories.js +29 -30
- package/build/system/Table/TableCell.js +9 -11
- package/build/system/Table/TableRow.js +10 -11
- package/build/system/Table/index.js +6 -10
- package/build/system/Text/Text.js +9 -14
- package/build/system/Text/Text.stories.js +24 -25
- package/build/system/Text/index.js +4 -6
- package/build/system/Toolbar/Logo.js +11 -15
- package/build/system/Toolbar/Toolbar.js +12 -17
- package/build/system/Toolbar/Toolbar.stories.js +47 -50
- package/build/system/Toolbar/Toolbar.test.js +26 -24
- package/build/system/Toolbar/ToolbarUtilNav.js +9 -16
- package/build/system/Toolbar/index.js +10 -15
- package/build/system/Tooltip/Tooltip.js +9 -14
- package/build/system/Tooltip/Tooltip.stories.js +29 -31
- package/build/system/Tooltip/index.js +5 -5
- package/build/system/Wizard/Wizard.js +11 -18
- package/build/system/Wizard/Wizard.stories.js +37 -38
- package/build/system/Wizard/WizardStep.js +26 -32
- package/build/system/Wizard/index.js +6 -7
- package/build/system/assets/a8cLogo.d.ts +2 -0
- package/build/system/assets/a8cLogo.js +39 -0
- package/build/system/index.d.ts +2 -1
- package/build/system/index.js +2 -0
- package/build/system/theme/breakpoints.js +1 -5
- package/build/system/utils/stories/CustomLink.js +7 -13
- package/package.json +1 -1
- package/src/system/Footer/Footer.stories.tsx +46 -0
- package/src/system/Footer/Footer.test.tsx +40 -0
- package/src/system/Footer/Footer.tsx +120 -0
- package/src/system/Form/index.js +2 -0
- package/src/system/LinkExternal/LinkExternal.tsx +27 -8
- package/src/system/NewForm/FormAutocomplete.js +2 -2
- package/src/system/assets/a8cLogo.tsx +30 -0
- package/src/system/index.js +2 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
var _excluded = ["children"];
|
|
2
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
3
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
4
|
+
/** @jsxImportSource theme-ui */
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { Box } from '../Box/Box';
|
|
10
|
+
import { LinkExternal } from '../LinkExternal/LinkExternal';
|
|
11
|
+
import { navItemStyles } from '../Nav/styles';
|
|
12
|
+
import { a8cLogo } from '../assets/a8cLogo';
|
|
13
|
+
import { jsx as _jsx } from "theme-ui/jsx-runtime";
|
|
14
|
+
import { jsxs as _jsxs } from "theme-ui/jsx-runtime";
|
|
15
|
+
export var Footer = function Footer(_ref) {
|
|
16
|
+
var _ref$hasTrailingSepar = _ref.hasTrailingSeparator,
|
|
17
|
+
hasTrailingSeparator = _ref$hasTrailingSepar === void 0 ? false : _ref$hasTrailingSepar,
|
|
18
|
+
_ref$hasUnderlinedLin = _ref.hasUnderlinedLinks,
|
|
19
|
+
hasUnderlinedLinks = _ref$hasUnderlinedLin === void 0 ? false : _ref$hasUnderlinedLin,
|
|
20
|
+
links = _ref.links,
|
|
21
|
+
customLogo = _ref.customLogo,
|
|
22
|
+
_ref$maxWidth = _ref.maxWidth,
|
|
23
|
+
maxWidth = _ref$maxWidth === void 0 ? '100%' : _ref$maxWidth;
|
|
24
|
+
var FooterLinks = function FooterLinks(_ref2) {
|
|
25
|
+
var children = _ref2.children,
|
|
26
|
+
props = _objectWithoutPropertiesLoose(_ref2, _excluded);
|
|
27
|
+
return _jsx("li", _extends({}, props, {
|
|
28
|
+
children: children
|
|
29
|
+
}));
|
|
30
|
+
};
|
|
31
|
+
var trailingSeparator = {
|
|
32
|
+
'&:last-of-type::after': {
|
|
33
|
+
display: 'inline-block',
|
|
34
|
+
margin: '0 0.45em 0 1em ',
|
|
35
|
+
transform: 'rotate(15deg)',
|
|
36
|
+
borderRightColor: 'text',
|
|
37
|
+
borderRightStyle: 'solid',
|
|
38
|
+
borderRightWidth: '0.1em',
|
|
39
|
+
height: '0.8em',
|
|
40
|
+
content: '""'
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
return _jsxs("footer", {
|
|
44
|
+
sx: {
|
|
45
|
+
display: 'flex',
|
|
46
|
+
flexDirection: ['column', 'column', 'row'],
|
|
47
|
+
justifyContent: 'space-between',
|
|
48
|
+
gap: 4,
|
|
49
|
+
fontSize: 1,
|
|
50
|
+
mt: 2,
|
|
51
|
+
maxWidth: maxWidth,
|
|
52
|
+
textAlign: 'left'
|
|
53
|
+
},
|
|
54
|
+
children: [(links == null ? void 0 : links.length) && _jsx("ul", {
|
|
55
|
+
sx: {
|
|
56
|
+
display: 'flex',
|
|
57
|
+
alignSelf: 'center',
|
|
58
|
+
gap: 2,
|
|
59
|
+
listStyle: 'none',
|
|
60
|
+
paddingInlineStart: 0
|
|
61
|
+
},
|
|
62
|
+
children: links.map(function (linkProps, index) {
|
|
63
|
+
return _jsx(FooterLinks, {
|
|
64
|
+
sx: hasTrailingSeparator ? _extends({}, navItemStyles('horizontal', 'breadcrumbs'), trailingSeparator) : _extends({}, navItemStyles('horizontal', 'breadcrumbs')),
|
|
65
|
+
children: _jsx(LinkExternal, _extends({}, linkProps, {
|
|
66
|
+
sx: {
|
|
67
|
+
ml: 1,
|
|
68
|
+
textDecoration: hasUnderlinedLinks ? undefined : 'none'
|
|
69
|
+
}
|
|
70
|
+
}))
|
|
71
|
+
}, "footer-link_" + index);
|
|
72
|
+
})
|
|
73
|
+
}), _jsx(Box, {
|
|
74
|
+
sx: {
|
|
75
|
+
backgroundColor: ['layer.1', 'layer.1', 'transparent'],
|
|
76
|
+
py: 2,
|
|
77
|
+
textAlign: ['center', 'center', 'right']
|
|
78
|
+
},
|
|
79
|
+
children: customLogo ? customLogo : a8cLogo
|
|
80
|
+
})]
|
|
81
|
+
});
|
|
82
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/**
|
|
3
|
+
* Internal dependencies
|
|
4
|
+
*/
|
|
5
|
+
import { StoryObj } from '@storybook/react';
|
|
6
|
+
import { Footer } from '../Footer/Footer';
|
|
7
|
+
declare const _default: {
|
|
8
|
+
title: string;
|
|
9
|
+
component: ({ hasTrailingSeparator, hasUnderlinedLinks, links, customLogo, maxWidth, }: {
|
|
10
|
+
hasTrailingSeparator?: boolean | undefined;
|
|
11
|
+
hasUnderlinedLinks?: boolean | undefined;
|
|
12
|
+
links: import("../LinkExternal/LinkExternal").LinkExternalProps[];
|
|
13
|
+
customLogo?: import("react").ReactNode;
|
|
14
|
+
maxWidth?: string | number | undefined;
|
|
15
|
+
}) => import("react").JSX.Element;
|
|
16
|
+
argTypes: {
|
|
17
|
+
hasTrailingSeparator: {
|
|
18
|
+
control: {
|
|
19
|
+
type: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
links: {
|
|
23
|
+
control: {
|
|
24
|
+
type: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
customLogo: {
|
|
28
|
+
control: {
|
|
29
|
+
type: null;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
maxWidth: {
|
|
33
|
+
control: {
|
|
34
|
+
type: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export default _default;
|
|
40
|
+
type Story = StoryObj<typeof Footer>;
|
|
41
|
+
export declare const Default: Story;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Footer } from '../Footer/Footer';
|
|
6
|
+
import { jsx as _jsx } from "theme-ui/jsx-runtime";
|
|
7
|
+
export default {
|
|
8
|
+
title: 'Navigation/Footer',
|
|
9
|
+
component: Footer,
|
|
10
|
+
argTypes: {
|
|
11
|
+
hasTrailingSeparator: {
|
|
12
|
+
control: {
|
|
13
|
+
type: 'boolean'
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
links: {
|
|
17
|
+
control: {
|
|
18
|
+
type: 'array'
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
customLogo: {
|
|
22
|
+
control: {
|
|
23
|
+
type: null
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
maxWidth: {
|
|
27
|
+
control: {
|
|
28
|
+
type: 'text'
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
export var Default = {
|
|
34
|
+
render: function render() {
|
|
35
|
+
return _jsx(Footer, {
|
|
36
|
+
links: [{
|
|
37
|
+
children: 'About',
|
|
38
|
+
href: 'https://wpvip.com/',
|
|
39
|
+
screenReaderText: 'WordPress VIP. Learn more about us',
|
|
40
|
+
showExternalIcon: false
|
|
41
|
+
}, {
|
|
42
|
+
children: 'Docs',
|
|
43
|
+
href: 'https://docs.wpvip.com/',
|
|
44
|
+
screenReaderText: 'our public documentation on our platform and tools'
|
|
45
|
+
}, {
|
|
46
|
+
children: 'Status',
|
|
47
|
+
href: 'https://wpvipstatus.com',
|
|
48
|
+
screenReaderText: ". See real-time availability and performance monitoring for WordPress VIP's services",
|
|
49
|
+
newTab: true
|
|
50
|
+
}]
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Internal dependencies
|
|
6
|
+
*/
|
|
7
|
+
import { Footer } from './Footer';
|
|
8
|
+
import { jsx as _jsx } from "theme-ui/jsx-runtime";
|
|
9
|
+
var links = [{
|
|
10
|
+
children: 'Link1',
|
|
11
|
+
href: 'https://wpvip.com/'
|
|
12
|
+
}, {
|
|
13
|
+
children: 'Link2',
|
|
14
|
+
href: 'https://docs.wpvip.com/'
|
|
15
|
+
}];
|
|
16
|
+
describe('<Footer />', function () {
|
|
17
|
+
it('should accept LinkExternal props for Footer links', function () {
|
|
18
|
+
var moreLinks = [{
|
|
19
|
+
children: 'Link3',
|
|
20
|
+
href: 'https://wpvipstatus.com',
|
|
21
|
+
newTab: true
|
|
22
|
+
}];
|
|
23
|
+
var combinedLinks = [].concat(links, moreLinks);
|
|
24
|
+
render(_jsx(Footer, {
|
|
25
|
+
links: combinedLinks
|
|
26
|
+
}));
|
|
27
|
+
var link1 = screen.getByRole('link', {
|
|
28
|
+
name: /link1/i
|
|
29
|
+
});
|
|
30
|
+
var link3 = screen.getByRole('link', {
|
|
31
|
+
name: /link3/i
|
|
32
|
+
});
|
|
33
|
+
expect(link1).toHaveAttribute('target', '_self');
|
|
34
|
+
expect(link3).toHaveAttribute('target', '_blank');
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -1,34 +1,29 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports.Checkbox = void 0;
|
|
5
|
-
var CheckboxPrimitive = _interopRequireWildcard(require("@radix-ui/react-checkbox"));
|
|
6
|
-
var _styles = require("./styles");
|
|
7
|
-
var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
8
1
|
var _excluded = ["variant"],
|
|
9
2
|
_excluded2 = ["variant"],
|
|
10
3
|
_excluded3 = ["disabled", "onCheckedChange", "variant"];
|
|
11
|
-
/** @jsxImportSource theme-ui */
|
|
12
|
-
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); }
|
|
13
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof 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; }
|
|
14
4
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
15
5
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
6
|
+
/** @jsxImportSource theme-ui */
|
|
7
|
+
|
|
8
|
+
import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
|
|
9
|
+
import { checkboxIndicatorStyle, checkboxStyle } from './styles';
|
|
10
|
+
import { jsx as _jsx } from "theme-ui/jsx-runtime";
|
|
16
11
|
var StyledCheckbox = function StyledCheckbox(_ref) {
|
|
17
12
|
var _ref$variant = _ref.variant,
|
|
18
13
|
variant = _ref$variant === void 0 ? 'primary' : _ref$variant,
|
|
19
14
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
20
|
-
return (
|
|
21
|
-
sx:
|
|
15
|
+
return _jsx(CheckboxPrimitive.Root, _extends({
|
|
16
|
+
sx: checkboxStyle(variant)
|
|
22
17
|
}, rest));
|
|
23
18
|
};
|
|
24
19
|
var StyledIndicator = function StyledIndicator(_ref2) {
|
|
25
20
|
var variant = _ref2.variant,
|
|
26
21
|
rest = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
27
|
-
return (
|
|
28
|
-
sx:
|
|
22
|
+
return _jsx(CheckboxPrimitive.Indicator, _extends({
|
|
23
|
+
sx: checkboxIndicatorStyle(variant)
|
|
29
24
|
}, rest));
|
|
30
25
|
};
|
|
31
|
-
var Checkbox =
|
|
26
|
+
var Checkbox = function Checkbox(_ref3) {
|
|
32
27
|
var _ref3$disabled = _ref3.disabled,
|
|
33
28
|
disabled = _ref3$disabled === void 0 ? false : _ref3$disabled,
|
|
34
29
|
onCheckedChange = _ref3.onCheckedChange,
|
|
@@ -38,13 +33,14 @@ var Checkbox = exports.Checkbox = function Checkbox(_ref3) {
|
|
|
38
33
|
if (disabled === true || disabled === undefined) {
|
|
39
34
|
variant = 'disabled';
|
|
40
35
|
}
|
|
41
|
-
return (
|
|
36
|
+
return _jsx(StyledCheckbox, _extends({
|
|
42
37
|
onCheckedChange: disabled ? undefined : onCheckedChange,
|
|
43
38
|
"aria-disabled": disabled,
|
|
44
39
|
variant: variant
|
|
45
40
|
}, props, {
|
|
46
|
-
children: (
|
|
41
|
+
children: _jsx(StyledIndicator, {
|
|
47
42
|
variant: variant
|
|
48
43
|
})
|
|
49
44
|
}));
|
|
50
|
-
};
|
|
45
|
+
};
|
|
46
|
+
export { Checkbox };
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports["default"] = exports.Indeterminate = exports.Default = void 0;
|
|
5
|
-
var _react = require("react");
|
|
6
|
-
var _Checkbox = require("./Checkbox");
|
|
7
|
-
var _ = require("../..");
|
|
8
|
-
var _Flex = require("../../Flex");
|
|
9
|
-
var _Label = require("../Label");
|
|
10
|
-
var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
11
1
|
/**
|
|
12
2
|
* External dependencies
|
|
13
3
|
*/
|
|
4
|
+
|
|
5
|
+
import { createRef, useEffect, useState } from 'react';
|
|
6
|
+
|
|
14
7
|
/**
|
|
15
8
|
* Internal dependencies
|
|
16
9
|
*/
|
|
17
|
-
|
|
10
|
+
import { Checkbox } from './Checkbox';
|
|
11
|
+
import { Form, Text } from '../..';
|
|
12
|
+
import { Flex } from '../../Flex';
|
|
13
|
+
import { Label } from '../Label';
|
|
14
|
+
import { jsxs as _jsxs } from "theme-ui/jsx-runtime";
|
|
15
|
+
import { jsx as _jsx } from "theme-ui/jsx-runtime";
|
|
16
|
+
export default {
|
|
18
17
|
title: 'Form/Checkbox',
|
|
19
|
-
component:
|
|
18
|
+
component: Checkbox,
|
|
20
19
|
parameters: {
|
|
21
20
|
docs: {
|
|
22
21
|
description: {
|
|
@@ -25,45 +24,45 @@ var _default = exports["default"] = {
|
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
26
|
};
|
|
28
|
-
var Default =
|
|
29
|
-
var _useState =
|
|
27
|
+
export var Default = function Default() {
|
|
28
|
+
var _useState = useState(true),
|
|
30
29
|
checked = _useState[0],
|
|
31
30
|
setChecked = _useState[1];
|
|
32
|
-
var _useState2 =
|
|
31
|
+
var _useState2 = useState(false),
|
|
33
32
|
checked2 = _useState2[0],
|
|
34
33
|
setChecked2 = _useState2[1];
|
|
35
|
-
return (
|
|
34
|
+
return _jsxs(Form.Root, {
|
|
36
35
|
children: [['primary', 'brand'].map(function (variant) {
|
|
37
|
-
return (
|
|
38
|
-
children: [(
|
|
36
|
+
return _jsxs(Form.Fieldset, {
|
|
37
|
+
children: [_jsxs(Form.Legend, {
|
|
39
38
|
children: ["Tell me your ", variant, " prefereces"]
|
|
40
|
-
}), (
|
|
39
|
+
}), _jsxs(Flex, {
|
|
41
40
|
sx: {
|
|
42
41
|
alignItems: 'center'
|
|
43
42
|
},
|
|
44
|
-
children: [(
|
|
43
|
+
children: [_jsx(Checkbox, {
|
|
45
44
|
variant: variant,
|
|
46
45
|
id: "check1-" + variant,
|
|
47
46
|
checked: checked,
|
|
48
47
|
"aria-labelledby": "label-check1-" + variant,
|
|
49
48
|
onCheckedChange: setChecked
|
|
50
|
-
}), (
|
|
49
|
+
}), _jsx(Label, {
|
|
51
50
|
clickable: true,
|
|
52
51
|
htmlFor: "check1-" + variant,
|
|
53
52
|
id: "label-check1-" + variant,
|
|
54
53
|
children: "This option"
|
|
55
54
|
})]
|
|
56
|
-
}), (
|
|
55
|
+
}), _jsxs(Flex, {
|
|
57
56
|
sx: {
|
|
58
57
|
alignItems: 'center'
|
|
59
58
|
},
|
|
60
|
-
children: [(
|
|
59
|
+
children: [_jsx(Checkbox, {
|
|
61
60
|
variant: variant,
|
|
62
61
|
id: "check2-" + variant,
|
|
63
62
|
checked: checked2,
|
|
64
63
|
"aria-labelledby": "label-check2-" + variant,
|
|
65
64
|
onCheckedChange: setChecked2
|
|
66
|
-
}), (
|
|
65
|
+
}), _jsx(Label, {
|
|
67
66
|
clickable: true,
|
|
68
67
|
htmlFor: "check2-" + variant,
|
|
69
68
|
id: "label-check2-" + variant,
|
|
@@ -71,37 +70,37 @@ var Default = exports.Default = function Default() {
|
|
|
71
70
|
})]
|
|
72
71
|
})]
|
|
73
72
|
}, variant);
|
|
74
|
-
}), (
|
|
75
|
-
children: [(
|
|
73
|
+
}), _jsxs(Form.Fieldset, {
|
|
74
|
+
children: [_jsx(Form.Legend, {
|
|
76
75
|
children: "Tell me your Disabled prefereces"
|
|
77
|
-
}), (
|
|
76
|
+
}), _jsxs(Flex, {
|
|
78
77
|
sx: {
|
|
79
78
|
alignItems: 'center'
|
|
80
79
|
},
|
|
81
|
-
children: [(
|
|
80
|
+
children: [_jsx(Checkbox, {
|
|
82
81
|
disabled: true,
|
|
83
82
|
variant: "disabled",
|
|
84
83
|
id: "check1-disabled",
|
|
85
84
|
checked: checked,
|
|
86
85
|
"aria-labelledby": "label-check1-disabled",
|
|
87
86
|
onCheckedChange: setChecked
|
|
88
|
-
}), (
|
|
87
|
+
}), _jsx(Label, {
|
|
89
88
|
clickable: true,
|
|
90
89
|
htmlFor: "check1-disabled",
|
|
91
90
|
id: "label-check1-disabled",
|
|
92
91
|
children: "This option"
|
|
93
92
|
})]
|
|
94
|
-
}), (
|
|
93
|
+
}), _jsxs(Flex, {
|
|
95
94
|
sx: {
|
|
96
95
|
alignItems: 'center'
|
|
97
96
|
},
|
|
98
|
-
children: [(
|
|
97
|
+
children: [_jsx(Checkbox, {
|
|
99
98
|
disabled: true,
|
|
100
99
|
id: "check2-disabled",
|
|
101
100
|
checked: checked2,
|
|
102
101
|
"aria-labelledby": "label-check2-disabled",
|
|
103
102
|
onCheckedChange: setChecked2
|
|
104
|
-
}), (
|
|
103
|
+
}), _jsx(Label, {
|
|
105
104
|
clickable: true,
|
|
106
105
|
htmlFor: "check2-disabled",
|
|
107
106
|
id: "label-check2-disabled",
|
|
@@ -111,55 +110,55 @@ var Default = exports.Default = function Default() {
|
|
|
111
110
|
})]
|
|
112
111
|
});
|
|
113
112
|
};
|
|
114
|
-
var Indeterminate =
|
|
113
|
+
export var Indeterminate = function Indeterminate() {
|
|
115
114
|
// Creat a ref to the manipula an input
|
|
116
|
-
var checkRef = /*#__PURE__*/
|
|
117
|
-
|
|
115
|
+
var checkRef = /*#__PURE__*/createRef();
|
|
116
|
+
useEffect(function () {
|
|
118
117
|
if (checkRef.current) {
|
|
119
118
|
checkRef.current.indeterminate = true;
|
|
120
119
|
}
|
|
121
120
|
}, [checkRef]);
|
|
122
|
-
return (
|
|
121
|
+
return _jsxs(Form.Root, {
|
|
123
122
|
children: [['primary', 'brand'].map(function (variant) {
|
|
124
|
-
return (
|
|
125
|
-
children: [(
|
|
123
|
+
return _jsxs(Form.Fieldset, {
|
|
124
|
+
children: [_jsxs(Form.Legend, {
|
|
126
125
|
children: ["Indeterminate state ", variant]
|
|
127
|
-
}), (
|
|
126
|
+
}), _jsxs(Flex, {
|
|
128
127
|
sx: {
|
|
129
128
|
alignItems: 'center'
|
|
130
129
|
},
|
|
131
|
-
children: [(
|
|
130
|
+
children: [_jsx(Checkbox, {
|
|
132
131
|
variant: variant,
|
|
133
132
|
id: "check1-" + variant,
|
|
134
133
|
"aria-labelledby": "label-check1-" + variant,
|
|
135
134
|
checked: 'indeterminate'
|
|
136
|
-
}), (
|
|
135
|
+
}), _jsx(Label, {
|
|
137
136
|
htmlFor: "check1-" + variant,
|
|
138
137
|
id: "label-check1-" + variant,
|
|
139
138
|
children: "This option"
|
|
140
139
|
})]
|
|
141
140
|
})]
|
|
142
141
|
}, variant);
|
|
143
|
-
}), (
|
|
144
|
-
children: [(
|
|
142
|
+
}), _jsxs(Form.Fieldset, {
|
|
143
|
+
children: [_jsx(Form.Legend, {
|
|
145
144
|
children: "Indeterminate state disabled"
|
|
146
|
-
}), (
|
|
145
|
+
}), _jsxs(Flex, {
|
|
147
146
|
sx: {
|
|
148
147
|
alignItems: 'center'
|
|
149
148
|
},
|
|
150
|
-
children: [(
|
|
149
|
+
children: [_jsx(Checkbox, {
|
|
151
150
|
variant: "disabled",
|
|
152
151
|
id: "check1-disabled",
|
|
153
152
|
"aria-labelledby": "label-check1-disabled",
|
|
154
153
|
checked: 'indeterminate'
|
|
155
|
-
}), (
|
|
154
|
+
}), _jsx(Label, {
|
|
156
155
|
htmlFor: "check1-disabled",
|
|
157
156
|
id: "label-check1-disabled",
|
|
158
157
|
children: "This option"
|
|
159
158
|
})]
|
|
160
159
|
})]
|
|
161
|
-
}), (
|
|
162
|
-
children: ["Reference:", ' ', (
|
|
160
|
+
}), _jsxs(Text, {
|
|
161
|
+
children: ["Reference:", ' ', _jsx("a", {
|
|
163
162
|
href: "https://css-tricks.com/indeterminate-checkboxes/",
|
|
164
163
|
children: "Indeterminate Checkboxes"
|
|
165
164
|
})]
|
|
@@ -1,48 +1,50 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _react = require("@testing-library/react");
|
|
4
|
-
var _jestAxe = require("jest-axe");
|
|
5
|
-
var _themeUi = require("theme-ui");
|
|
6
|
-
var _Checkbox = require("./Checkbox");
|
|
7
|
-
var _ = require("..");
|
|
8
|
-
var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
9
1
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(typeof e + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
10
2
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
11
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
3
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
4
|
+
/**
|
|
12
5
|
* External dependencies
|
|
13
|
-
*/
|
|
6
|
+
*/
|
|
7
|
+
import { render, screen } from '@testing-library/react';
|
|
8
|
+
import { axe } from 'jest-axe';
|
|
9
|
+
import { Flex } from 'theme-ui';
|
|
10
|
+
|
|
11
|
+
/**
|
|
14
12
|
* Internal dependencies
|
|
15
13
|
*/
|
|
14
|
+
import { Checkbox } from './Checkbox';
|
|
15
|
+
import { Label } from '..';
|
|
16
|
+
import { jsx as _jsx } from "theme-ui/jsx-runtime";
|
|
17
|
+
import { jsxs as _jsxs } from "theme-ui/jsx-runtime";
|
|
16
18
|
describe('<Checkbox />', function () {
|
|
17
19
|
it('renders', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
18
20
|
var _render, container, checkbox;
|
|
19
21
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
20
22
|
while (1) switch (_context.prev = _context.next) {
|
|
21
23
|
case 0:
|
|
22
|
-
_render =
|
|
24
|
+
_render = render(_jsxs(Flex, {
|
|
23
25
|
sx: {
|
|
24
26
|
alignItems: 'center'
|
|
25
27
|
},
|
|
26
|
-
children: [(
|
|
28
|
+
children: [_jsx(Checkbox, {
|
|
27
29
|
id: "check1",
|
|
28
30
|
checked: true,
|
|
29
31
|
"aria-labelledby": "label-check1",
|
|
30
32
|
onCheckedChange: function onCheckedChange() {}
|
|
31
|
-
}), (
|
|
33
|
+
}), _jsx(Label, {
|
|
32
34
|
clickable: true,
|
|
33
35
|
htmlFor: "check1",
|
|
34
36
|
id: "label-check1",
|
|
35
37
|
children: "This option"
|
|
36
38
|
})]
|
|
37
39
|
})), container = _render.container;
|
|
38
|
-
expect(
|
|
39
|
-
checkbox =
|
|
40
|
+
expect(screen.getByLabelText('This option')).toBeInTheDocument();
|
|
41
|
+
checkbox = screen.getByRole('checkbox');
|
|
40
42
|
expect(checkbox).toBeChecked();
|
|
41
43
|
|
|
42
44
|
// Check for accessibility issues
|
|
43
45
|
_context.t0 = expect;
|
|
44
46
|
_context.next = 7;
|
|
45
|
-
return
|
|
47
|
+
return axe(container);
|
|
46
48
|
case 7:
|
|
47
49
|
_context.t1 = _context.sent;
|
|
48
50
|
(0, _context.t0)(_context.t1).toHaveNoViolations();
|
|
@@ -57,29 +59,29 @@ describe('<Checkbox />', function () {
|
|
|
57
59
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
58
60
|
while (1) switch (_context2.prev = _context2.next) {
|
|
59
61
|
case 0:
|
|
60
|
-
_render2 =
|
|
62
|
+
_render2 = render(_jsxs(Flex, {
|
|
61
63
|
sx: {
|
|
62
64
|
alignItems: 'center'
|
|
63
65
|
},
|
|
64
|
-
children: [(
|
|
66
|
+
children: [_jsx(Checkbox, {
|
|
65
67
|
id: "check1",
|
|
66
68
|
disabled: true,
|
|
67
69
|
"aria-labelledby": "label-check1",
|
|
68
70
|
onCheckedChange: function onCheckedChange() {}
|
|
69
|
-
}), (
|
|
71
|
+
}), _jsx(Label, {
|
|
70
72
|
clickable: true,
|
|
71
73
|
htmlFor: "check1",
|
|
72
74
|
id: "label-check1",
|
|
73
75
|
children: "This option"
|
|
74
76
|
})]
|
|
75
77
|
})), container = _render2.container;
|
|
76
|
-
button =
|
|
78
|
+
button = screen.getByLabelText('This option');
|
|
77
79
|
expect(button).toHaveAttribute('aria-disabled', 'true');
|
|
78
80
|
|
|
79
81
|
// Check for accessibility issues
|
|
80
82
|
_context2.t0 = expect;
|
|
81
83
|
_context2.next = 6;
|
|
82
|
-
return
|
|
84
|
+
return axe(container);
|
|
83
85
|
case 6:
|
|
84
86
|
_context2.t1 = _context2.sent;
|
|
85
87
|
(0, _context2.t0)(_context2.t1).toHaveNoViolations();
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports.checkboxStyle = exports.checkboxIndicatorStyle = void 0;
|
|
5
|
-
var _Input = require("../Input.styles");
|
|
6
1
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
import { baseControlBorderStyle, baseControlFocusStyle, inputBaseBackground, inputBaseText } from '../Input.styles';
|
|
3
|
+
|
|
7
4
|
// The output willl be 16px because of the 1px border.
|
|
8
5
|
var CHECKBOX_SIZE = 14;
|
|
9
|
-
var checkboxStyle =
|
|
6
|
+
export var checkboxStyle = function checkboxStyle(variant) {
|
|
10
7
|
var variantColor = variant === 'disabled' ? 'input.background.disabled' : variant;
|
|
11
8
|
return _extends({
|
|
12
9
|
all: 'unset',
|
|
13
10
|
position: 'relative',
|
|
14
|
-
backgroundColor:
|
|
15
|
-
},
|
|
11
|
+
backgroundColor: inputBaseBackground
|
|
12
|
+
}, baseControlBorderStyle, baseControlFocusStyle, {
|
|
16
13
|
width: CHECKBOX_SIZE,
|
|
17
14
|
height: CHECKBOX_SIZE,
|
|
18
15
|
borderRadius: 0,
|
|
@@ -30,7 +27,7 @@ var checkboxStyle = exports.checkboxStyle = function checkboxStyle(variant) {
|
|
|
30
27
|
},
|
|
31
28
|
'& ~ label': {
|
|
32
29
|
fontWeight: 'regular',
|
|
33
|
-
color:
|
|
30
|
+
color: inputBaseText,
|
|
34
31
|
m: 0,
|
|
35
32
|
ml: 2
|
|
36
33
|
},
|
|
@@ -42,7 +39,7 @@ var checkboxStyle = exports.checkboxStyle = function checkboxStyle(variant) {
|
|
|
42
39
|
}
|
|
43
40
|
});
|
|
44
41
|
};
|
|
45
|
-
var checkboxIndicatorStyle =
|
|
42
|
+
export var checkboxIndicatorStyle = function checkboxIndicatorStyle(variant) {
|
|
46
43
|
var backgroundColor = variant === 'disabled' ? 'icon.inverse-disabled' : 'icon.inverse';
|
|
47
44
|
return {
|
|
48
45
|
width: 14,
|