@bootsmonday/corncob-design-language-react 0.1.0 → 0.2.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/CHANGELOG.md +11 -0
- package/dist-types/common/choice-name.d.ts +8 -0
- package/dist-types/common/field.d.ts +22 -0
- package/dist-types/common/form-item.d.ts +11 -0
- package/dist-types/components/badges/badge.d.ts +12 -0
- package/dist-types/components/button-bars/button-bar.d.ts +12 -0
- package/dist-types/components/buttons/button.d.ts +16 -0
- package/dist-types/components/checkboxes/checkbox-group.d.ts +13 -0
- package/dist-types/components/checkboxes/checkbox.d.ts +20 -0
- package/dist-types/components/expandables/expandable.d.ts +43 -0
- package/dist-types/components/footers/footer.d.ts +62 -0
- package/dist-types/components/headers/header.d.ts +72 -0
- package/dist-types/components/links/link.d.ts +22 -0
- package/dist-types/components/messages/message.d.ts +42 -0
- package/dist-types/components/modals/modal.d.ts +30 -0
- package/dist-types/components/panel-menus/panel-menu.d.ts +33 -0
- package/dist-types/components/panels/panel.d.ts +11 -0
- package/dist-types/components/popovers/popover.d.ts +35 -0
- package/dist-types/components/radio-buttons/radio-button-group.d.ts +13 -0
- package/dist-types/components/radio-buttons/radio-button.d.ts +18 -0
- package/dist-types/components/selects/select.d.ts +14 -0
- package/dist-types/components/sliders/slider.d.ts +7 -0
- package/dist-types/components/text-inputs/text-input.d.ts +6 -0
- package/dist-types/components/toasts/toast.d.ts +7 -0
- package/dist-types/components/toggles/toggle.d.ts +13 -0
- package/dist-types/components/tooltips/tooltip.d.ts +8 -0
- package/dist-types/custom-elements.d.ts +3 -0
- package/dist-types/index.d.ts +24 -0
- package/dist-types/utils/assign-ref.d.ts +7 -0
- package/dist-types/utils/class-names.d.ts +14 -0
- package/package.json +29 -8
- package/src/common/choice-name.js +7 -0
- package/src/common/field.jsx +17 -0
- package/src/common/form-item.jsx +5 -0
- package/src/components/badges/badge.jsx +5 -0
- package/src/components/button-bars/button-bar.jsx +5 -1
- package/src/components/buttons/button.jsx +5 -1
- package/src/components/checkboxes/checkbox-group.jsx +5 -0
- package/src/components/checkboxes/checkbox.jsx +5 -0
- package/src/components/expandables/expandable.jsx +20 -0
- package/src/components/footers/footer.jsx +30 -0
- package/src/components/headers/header.jsx +35 -0
- package/src/components/links/link.jsx +10 -0
- package/src/components/messages/message.jsx +20 -0
- package/src/components/modals/modal.jsx +15 -0
- package/src/components/panel-menus/panel-menu.jsx +15 -0
- package/src/components/panels/panel.jsx +5 -0
- package/src/components/popovers/popover.jsx +15 -0
- package/src/components/radio-buttons/radio-button-group.jsx +5 -0
- package/src/components/radio-buttons/radio-button.jsx +5 -0
- package/src/components/selects/select.jsx +10 -0
- package/src/components/sliders/slider.jsx +5 -0
- package/src/components/text-inputs/text-input.jsx +5 -0
- package/src/components/toasts/toast.jsx +5 -0
- package/src/components/toggles/toggle.jsx +10 -0
- package/src/components/tooltips/tooltip.jsx +5 -0
- package/src/custom-elements.d.ts +9 -0
- package/src/utils/assign-ref.js +6 -0
- package/src/utils/class-names.js +12 -0
- package/.changelog/README.md +0 -33
- package/jest.config.cjs +0 -17
- package/jest.setup.cjs +0 -19
- package/src/common/choice-name.test.js +0 -46
- package/src/common/field.test.js +0 -33
- package/src/common/form-item.test.js +0 -45
- package/src/components/badges/badge.stickersheet.jsx +0 -39
- package/src/components/badges/badge.test.js +0 -69
- package/src/components/button-bars/button-bar.stickersheet.jsx +0 -86
- package/src/components/button-bars/button-bar.test.js +0 -58
- package/src/components/buttons/button.stickersheet.jsx +0 -204
- package/src/components/buttons/button.test.js +0 -84
- package/src/components/checkboxes/checkbox.stickersheet.jsx +0 -53
- package/src/components/checkboxes/checkbox.test.js +0 -154
- package/src/components/expandables/expandable.stickersheet.jsx +0 -100
- package/src/components/expandables/expandable.test.js +0 -125
- package/src/components/footers/footer.stickersheet.jsx +0 -77
- package/src/components/footers/footer.test.js +0 -64
- package/src/components/headers/header.stickersheet.jsx +0 -63
- package/src/components/headers/header.test.js +0 -63
- package/src/components/links/link.stickersheet.jsx +0 -75
- package/src/components/links/link.test.js +0 -70
- package/src/components/messages/message.stickersheet.jsx +0 -96
- package/src/components/messages/message.test.js +0 -92
- package/src/components/modals/modal.stickersheet.jsx +0 -44
- package/src/components/modals/modal.test.js +0 -32
- package/src/components/panel-menus/panel-menu.stickersheet.jsx +0 -34
- package/src/components/panel-menus/panel-menu.test.js +0 -98
- package/src/components/panels/panel.stickersheet.jsx +0 -13
- package/src/components/panels/panel.test.js +0 -54
- package/src/components/popovers/popover.stickersheet.jsx +0 -236
- package/src/components/popovers/popover.test.js +0 -98
- package/src/components/radio-buttons/radio-button.stickersheet.jsx +0 -40
- package/src/components/radio-buttons/radio-button.test.js +0 -119
- package/src/components/selects/select.stickersheet.jsx +0 -34
- package/src/components/selects/select.test.js +0 -119
- package/src/components/sliders/slider.stickersheet.jsx +0 -29
- package/src/components/sliders/slider.test.js +0 -81
- package/src/components/text-inputs/text-input.stickersheet.jsx +0 -41
- package/src/components/text-inputs/text-input.test.js +0 -83
- package/src/components/toasts/toast.stickersheet.jsx +0 -54
- package/src/components/toasts/toast.test.js +0 -50
- package/src/components/toggles/toggle.stickersheet.jsx +0 -81
- package/src/components/toggles/toggle.test.js +0 -165
- package/src/components/tooltips/tooltip.stickersheet.jsx +0 -34
- package/src/components/tooltips/tooltip.test.js +0 -60
- package/src/stickersheets/badges.html +0 -31
- package/src/stickersheets/button-bars.html +0 -29
- package/src/stickersheets/buttons-standard.html +0 -33
- package/src/stickersheets/checkboxes.html +0 -32
- package/src/stickersheets/expandables.html +0 -29
- package/src/stickersheets/footers.html +0 -29
- package/src/stickersheets/headers.html +0 -29
- package/src/stickersheets/index.html +0 -56
- package/src/stickersheets/links.html +0 -29
- package/src/stickersheets/messages.html +0 -29
- package/src/stickersheets/modals.html +0 -29
- package/src/stickersheets/panel-menus.html +0 -29
- package/src/stickersheets/panels.html +0 -29
- package/src/stickersheets/popovers.html +0 -29
- package/src/stickersheets/radio-buttons.html +0 -32
- package/src/stickersheets/select.html +0 -31
- package/src/stickersheets/sliders.html +0 -31
- package/src/stickersheets/src/stickersheet-controls.html +0 -13
- package/src/stickersheets/src/stickersheet-header.html +0 -17
- package/src/stickersheets/src/stickersheet-react-header.html +0 -17
- package/src/stickersheets/src/stickersheet.css +0 -17
- package/src/stickersheets/src/stickersheet.js +0 -80
- package/src/stickersheets/text-inputs.html +0 -31
- package/src/stickersheets/toasts.html +0 -29
- package/src/stickersheets/toggles.html +0 -32
- package/src/stickersheets/tooltips.html +0 -29
- package/src/utils/assign-ref.test.js +0 -35
- package/src/utils/class-names.test.js +0 -21
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import ReactDOM from 'react-dom/client';
|
|
3
|
-
import { CornButton } from '../../index.js';
|
|
4
|
-
|
|
5
|
-
const root = ReactDOM.createRoot(document.getElementById('test-stickersheet'));
|
|
6
|
-
root.render(
|
|
7
|
-
<div className="button-demo">
|
|
8
|
-
<h2>Buttons</h2>
|
|
9
|
-
<div className="corn-form--row">
|
|
10
|
-
<CornButton size="md">MD Button</CornButton>
|
|
11
|
-
<CornButton variant="secondary" size="md">
|
|
12
|
-
MD Secondary
|
|
13
|
-
</CornButton>
|
|
14
|
-
<CornButton variant="danger" size="md">
|
|
15
|
-
MD Danger
|
|
16
|
-
</CornButton>
|
|
17
|
-
<CornButton variant="primary" size="md" disabled>
|
|
18
|
-
MD Disabled
|
|
19
|
-
</CornButton>
|
|
20
|
-
</div>
|
|
21
|
-
<h3>Extra Small (xs)</h3>
|
|
22
|
-
<div className="corn-form--row">
|
|
23
|
-
<CornButton size="xs">XS Button</CornButton>
|
|
24
|
-
<CornButton variant="secondary" size="xs">
|
|
25
|
-
XS Secondary
|
|
26
|
-
</CornButton>
|
|
27
|
-
<CornButton variant="danger" size="xs">
|
|
28
|
-
XS Danger
|
|
29
|
-
</CornButton>
|
|
30
|
-
<CornButton variant="primary" size="xs" disabled>
|
|
31
|
-
XS Disabled
|
|
32
|
-
</CornButton>
|
|
33
|
-
</div>
|
|
34
|
-
<h3>Small (sm)</h3>
|
|
35
|
-
<div className="corn-form--row">
|
|
36
|
-
<CornButton size="sm">SM Button</CornButton>
|
|
37
|
-
<CornButton variant="secondary" size="sm">
|
|
38
|
-
SM Secondary
|
|
39
|
-
</CornButton>
|
|
40
|
-
<CornButton variant="danger" size="sm">
|
|
41
|
-
SM Danger
|
|
42
|
-
</CornButton>
|
|
43
|
-
<CornButton variant="primary" size="sm" disabled>
|
|
44
|
-
SM Disabled
|
|
45
|
-
</CornButton>
|
|
46
|
-
</div>
|
|
47
|
-
<h3>Large (lg)</h3>
|
|
48
|
-
<div className="corn-form--row">
|
|
49
|
-
<CornButton size="lg">LG Button</CornButton>
|
|
50
|
-
<CornButton variant="secondary" size="lg">
|
|
51
|
-
LG Secondary
|
|
52
|
-
</CornButton>
|
|
53
|
-
<CornButton variant="danger" size="lg">
|
|
54
|
-
LG Danger
|
|
55
|
-
</CornButton>
|
|
56
|
-
<CornButton variant="primary" size="lg" disabled>
|
|
57
|
-
LG Disabled
|
|
58
|
-
</CornButton>
|
|
59
|
-
</div>
|
|
60
|
-
<h3>Extra Large (xl)</h3>
|
|
61
|
-
<div className="corn-form--row">
|
|
62
|
-
<CornButton size="xl">XL Button</CornButton>
|
|
63
|
-
<CornButton variant="secondary" size="xl">
|
|
64
|
-
XL Secondary
|
|
65
|
-
</CornButton>
|
|
66
|
-
<CornButton variant="danger" size="xl">
|
|
67
|
-
XL Danger
|
|
68
|
-
</CornButton>
|
|
69
|
-
<CornButton variant="primary" size="xl" disabled>
|
|
70
|
-
XL Disabled
|
|
71
|
-
</CornButton>
|
|
72
|
-
</div>
|
|
73
|
-
<h3>Icon Only (md)</h3>
|
|
74
|
-
<div className="corn-form--row">
|
|
75
|
-
<CornButton size="md" icon>
|
|
76
|
-
<svg xmlns="http://www.w3.org/2000/svg" className="corn-icon">
|
|
77
|
-
<use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#x"></use>
|
|
78
|
-
</svg>
|
|
79
|
-
</CornButton>
|
|
80
|
-
<CornButton variant="secondary" size="md" icon>
|
|
81
|
-
<svg xmlns="http://www.w3.org/2000/svg" className="corn-icon">
|
|
82
|
-
<use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#x"></use>
|
|
83
|
-
</svg>
|
|
84
|
-
</CornButton>
|
|
85
|
-
<CornButton variant="danger" size="md" icon>
|
|
86
|
-
<svg xmlns="http://www.w3.org/2000/svg" className="corn-icon">
|
|
87
|
-
<use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#x"></use>
|
|
88
|
-
</svg>
|
|
89
|
-
</CornButton>
|
|
90
|
-
<CornButton variant="primary" size="md" icon>
|
|
91
|
-
<svg xmlns="http://www.w3.org/2000/svg" className="corn-icon">
|
|
92
|
-
<use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#x"></use>
|
|
93
|
-
</svg>
|
|
94
|
-
</CornButton>
|
|
95
|
-
<CornButton variant="primary" size="md" icon disabled>
|
|
96
|
-
<svg xmlns="http://www.w3.org/2000/svg" className="corn-icon">
|
|
97
|
-
<use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#x"></use>
|
|
98
|
-
</svg>
|
|
99
|
-
</CornButton>
|
|
100
|
-
</div>
|
|
101
|
-
<h3>Icon Only (xs)</h3>
|
|
102
|
-
<div className="corn-form--row">
|
|
103
|
-
<CornButton size="xs" icon>
|
|
104
|
-
<svg xmlns="http://www.w3.org/2000/svg" className="corn-icon">
|
|
105
|
-
<use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#x"></use>
|
|
106
|
-
</svg>
|
|
107
|
-
</CornButton>
|
|
108
|
-
<CornButton variant="secondary" size="xs" icon>
|
|
109
|
-
<svg xmlns="http://www.w3.org/2000/svg" className="corn-icon">
|
|
110
|
-
<use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#x"></use>
|
|
111
|
-
</svg>
|
|
112
|
-
</CornButton>
|
|
113
|
-
<CornButton variant="danger" size="xs" icon>
|
|
114
|
-
<svg xmlns="http://www.w3.org/2000/svg" className="corn-icon">
|
|
115
|
-
<use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#x"></use>
|
|
116
|
-
</svg>
|
|
117
|
-
</CornButton>
|
|
118
|
-
<CornButton variant="primary" size="xs" icon disabled>
|
|
119
|
-
<svg xmlns="http://www.w3.org/2000/svg" className="corn-icon">
|
|
120
|
-
<use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#x"></use>
|
|
121
|
-
</svg>
|
|
122
|
-
</CornButton>
|
|
123
|
-
</div>
|
|
124
|
-
<h3>Icon Only (sm)</h3>
|
|
125
|
-
<div className="corn-form--row">
|
|
126
|
-
<CornButton size="sm" icon>
|
|
127
|
-
<svg xmlns="http://www.w3.org/2000/svg" className="corn-icon">
|
|
128
|
-
<use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#x"></use>
|
|
129
|
-
</svg>
|
|
130
|
-
</CornButton>
|
|
131
|
-
<CornButton variant="secondary" size="sm" icon>
|
|
132
|
-
<svg xmlns="http://www.w3.org/2000/svg" className="corn-icon">
|
|
133
|
-
<use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#x"></use>
|
|
134
|
-
</svg>
|
|
135
|
-
</CornButton>
|
|
136
|
-
<CornButton variant="danger" size="sm" icon>
|
|
137
|
-
<svg xmlns="http://www.w3.org/2000/svg" className="corn-icon">
|
|
138
|
-
<use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#x"></use>
|
|
139
|
-
</svg>
|
|
140
|
-
</CornButton>
|
|
141
|
-
<CornButton variant="primary" size="sm" icon disabled>
|
|
142
|
-
<svg xmlns="http://www.w3.org/2000/svg" className="corn-icon">
|
|
143
|
-
<use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#x"></use>
|
|
144
|
-
</svg>
|
|
145
|
-
</CornButton>
|
|
146
|
-
</div>
|
|
147
|
-
<h3>Icon Only (lg)</h3>
|
|
148
|
-
<div className="corn-form--row">
|
|
149
|
-
<CornButton size="lg" icon>
|
|
150
|
-
<svg xmlns="http://www.w3.org/2000/svg" className="corn-icon">
|
|
151
|
-
<use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#x"></use>
|
|
152
|
-
</svg>
|
|
153
|
-
</CornButton>
|
|
154
|
-
<CornButton variant="secondary" size="lg" icon>
|
|
155
|
-
<svg xmlns="http://www.w3.org/2000/svg" className="corn-icon">
|
|
156
|
-
<use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#x"></use>
|
|
157
|
-
</svg>
|
|
158
|
-
</CornButton>
|
|
159
|
-
<CornButton variant="danger" size="lg" icon>
|
|
160
|
-
<svg xmlns="http://www.w3.org/2000/svg" className="corn-icon">
|
|
161
|
-
<use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#x"></use>
|
|
162
|
-
</svg>
|
|
163
|
-
</CornButton>
|
|
164
|
-
<CornButton variant="primary" size="lg" icon disabled>
|
|
165
|
-
<svg xmlns="http://www.w3.org/2000/svg" className="corn-icon">
|
|
166
|
-
<use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#x"></use>
|
|
167
|
-
</svg>
|
|
168
|
-
</CornButton>
|
|
169
|
-
</div>
|
|
170
|
-
<h3>Icon Only (xl)</h3>
|
|
171
|
-
<div className="corn-form--row">
|
|
172
|
-
<CornButton size="xl" icon>
|
|
173
|
-
<svg xmlns="http://www.w3.org/2000/svg" className="corn-icon">
|
|
174
|
-
<use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#x"></use>
|
|
175
|
-
</svg>
|
|
176
|
-
</CornButton>
|
|
177
|
-
<CornButton variant="secondary" size="xl" icon>
|
|
178
|
-
<svg xmlns="http://www.w3.org/2000/svg" className="corn-icon">
|
|
179
|
-
<use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#x"></use>
|
|
180
|
-
</svg>
|
|
181
|
-
</CornButton>
|
|
182
|
-
<CornButton variant="danger" size="xl" icon>
|
|
183
|
-
<svg xmlns="http://www.w3.org/2000/svg" className="corn-icon">
|
|
184
|
-
<use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#x"></use>
|
|
185
|
-
</svg>
|
|
186
|
-
</CornButton>
|
|
187
|
-
<CornButton variant="primary" size="xl" icon disabled>
|
|
188
|
-
<svg xmlns="http://www.w3.org/2000/svg" className="corn-icon">
|
|
189
|
-
<use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#x"></use>
|
|
190
|
-
</svg>
|
|
191
|
-
</CornButton>
|
|
192
|
-
</div>
|
|
193
|
-
<h3>Button Group</h3>
|
|
194
|
-
<div className="corn-form--row corn-button-group">
|
|
195
|
-
<CornButton size="md">MD Button</CornButton>
|
|
196
|
-
<CornButton variant="secondary" size="md">
|
|
197
|
-
MD Secondary
|
|
198
|
-
</CornButton>
|
|
199
|
-
<CornButton variant="danger" size="md">
|
|
200
|
-
MD Danger
|
|
201
|
-
</CornButton>
|
|
202
|
-
</div>
|
|
203
|
-
</div>
|
|
204
|
-
);
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { createRef } from 'react';
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import { CornButton } from './button.jsx';
|
|
4
|
-
|
|
5
|
-
describe('CornButton', () => {
|
|
6
|
-
test('renders a button with corn-button and type="button" by default', () => {
|
|
7
|
-
render(<CornButton>Save</CornButton>);
|
|
8
|
-
|
|
9
|
-
const button = screen.getByRole('button', { name: 'Save' });
|
|
10
|
-
expect(button).toHaveClass('corn-button');
|
|
11
|
-
expect(button).toHaveAttribute('type', 'button');
|
|
12
|
-
expect(button.className).toBe('corn-button');
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test('maps variant, size, and icon props to classes', () => {
|
|
16
|
-
render(
|
|
17
|
-
<CornButton variant="secondary" size="lg" icon aria-label="Close">
|
|
18
|
-
x
|
|
19
|
-
</CornButton>
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
expect(screen.getByRole('button', { name: 'Close' })).toHaveClass('corn-button', 'corn-button--secondary', 'corn-button--lg', 'corn-button--icon');
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('forwards disabled and extra className', () => {
|
|
26
|
-
render(
|
|
27
|
-
<CornButton disabled className="toolbar-action">
|
|
28
|
-
Delete
|
|
29
|
-
</CornButton>
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
const button = screen.getByRole('button', { name: 'Delete' });
|
|
33
|
-
expect(button).toBeDisabled();
|
|
34
|
-
expect(button).toHaveClass('corn-button', 'toolbar-action');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('renders an anchor without a type attribute when as="a"', () => {
|
|
38
|
-
render(
|
|
39
|
-
<CornButton as="a" href="#section">
|
|
40
|
-
Link styled as button
|
|
41
|
-
</CornButton>
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
const link = screen.getByRole('link', { name: 'Link styled as button' });
|
|
45
|
-
expect(link).toHaveClass('corn-button');
|
|
46
|
-
expect(link).toHaveAttribute('href', '#section');
|
|
47
|
-
expect(link).not.toHaveAttribute('type');
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('allows type="submit" on a button', () => {
|
|
51
|
-
render(<CornButton type="submit">Submit</CornButton>);
|
|
52
|
-
|
|
53
|
-
const button = screen.getByRole('button', { name: 'Submit' });
|
|
54
|
-
expect(button).toHaveAttribute('type', 'submit');
|
|
55
|
-
expect(button).not.toBeDisabled();
|
|
56
|
-
expect(button).not.toHaveAttribute('aria-busy');
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test('keeps a submit button enabled outside a pending form', () => {
|
|
60
|
-
render(
|
|
61
|
-
<form>
|
|
62
|
-
<CornButton type="submit">Save</CornButton>
|
|
63
|
-
</form>
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
const button = screen.getByRole('button', { name: 'Save' });
|
|
67
|
-
expect(button).not.toBeDisabled();
|
|
68
|
-
expect(button).not.toHaveAttribute('aria-busy');
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('forwards a ref to the host element', () => {
|
|
72
|
-
const ref = createRef();
|
|
73
|
-
render(<CornButton ref={ref}>Save</CornButton>);
|
|
74
|
-
|
|
75
|
-
expect(ref.current).toBe(screen.getByRole('button', { name: 'Save' }));
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test('supports a callback ref', () => {
|
|
79
|
-
const ref = jest.fn();
|
|
80
|
-
render(<CornButton ref={ref}>Save</CornButton>);
|
|
81
|
-
|
|
82
|
-
expect(ref).toHaveBeenCalledWith(screen.getByRole('button', { name: 'Save' }));
|
|
83
|
-
});
|
|
84
|
-
});
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import ReactDOM from 'react-dom/client';
|
|
3
|
-
import { CornCheckbox, CornCheckboxGroup } from '../../index.js';
|
|
4
|
-
|
|
5
|
-
const root = ReactDOM.createRoot(document.getElementById('test-stickersheet'));
|
|
6
|
-
root.render(
|
|
7
|
-
<div className="checkbox-demo">
|
|
8
|
-
<h2>Checkboxes</h2>
|
|
9
|
-
<section id="checkboxes">
|
|
10
|
-
<h3>Checkboxes</h3>
|
|
11
|
-
<CornCheckboxGroup legend="Group Label" name="example">
|
|
12
|
-
<CornCheckbox indeterminate>Indeterminate checkbox</CornCheckbox>
|
|
13
|
-
<hr />
|
|
14
|
-
<CornCheckbox size="xs">Checkbox One xs</CornCheckbox>
|
|
15
|
-
<CornCheckbox size="sm">Checkbox Two sm</CornCheckbox>
|
|
16
|
-
<CornCheckbox size="md">Checkbox Default md </CornCheckbox>
|
|
17
|
-
<CornCheckbox size="lg">Checkbox 4 lg</CornCheckbox>
|
|
18
|
-
<CornCheckbox size="xl" defaultChecked>
|
|
19
|
-
Checkbox 5 xl
|
|
20
|
-
</CornCheckbox>
|
|
21
|
-
<CornCheckbox>Checkbox Six...</CornCheckbox>
|
|
22
|
-
</CornCheckboxGroup>
|
|
23
|
-
</section>
|
|
24
|
-
|
|
25
|
-
<hr />
|
|
26
|
-
|
|
27
|
-
<section id="checkboxes-inline">
|
|
28
|
-
<h3>Inline Checkboxes</h3>
|
|
29
|
-
<CornCheckboxGroup legend="Group Label" name="example-inline" inline>
|
|
30
|
-
<CornCheckbox>Checkbox One...</CornCheckbox>
|
|
31
|
-
<CornCheckbox>Checkbox Two...</CornCheckbox>
|
|
32
|
-
<CornCheckbox>Checkbox Three...</CornCheckbox>
|
|
33
|
-
<CornCheckbox>Checkbox Four...</CornCheckbox>
|
|
34
|
-
<CornCheckbox defaultChecked>Checkbox Five...</CornCheckbox>
|
|
35
|
-
<CornCheckbox>Checkbox Six...</CornCheckbox>
|
|
36
|
-
<CornCheckbox>Checkbox Seven...</CornCheckbox>
|
|
37
|
-
</CornCheckboxGroup>
|
|
38
|
-
</section>
|
|
39
|
-
|
|
40
|
-
<hr />
|
|
41
|
-
|
|
42
|
-
<section id="task-checkboxes">
|
|
43
|
-
<h3>Task Checkboxes</h3>
|
|
44
|
-
<CornCheckboxGroup legend="Group Label" name="example-task">
|
|
45
|
-
<CornCheckbox task defaultChecked>
|
|
46
|
-
Task Complete
|
|
47
|
-
</CornCheckbox>
|
|
48
|
-
<CornCheckbox task>Task Complete</CornCheckbox>
|
|
49
|
-
<CornCheckbox task>Task Complete</CornCheckbox>
|
|
50
|
-
</CornCheckboxGroup>
|
|
51
|
-
</section>
|
|
52
|
-
</div>
|
|
53
|
-
);
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { createRef } from 'react';
|
|
2
|
-
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
|
-
import { CornCheckbox } from './checkbox.jsx';
|
|
4
|
-
import { CornCheckboxGroup } from './checkbox-group.jsx';
|
|
5
|
-
|
|
6
|
-
describe('CornCheckboxGroup', () => {
|
|
7
|
-
test('renders a fieldset group with legend and checkbox items', () => {
|
|
8
|
-
const { container } = render(
|
|
9
|
-
<CornCheckboxGroup legend="Options" name="example">
|
|
10
|
-
<CornCheckbox>Checkbox One</CornCheckbox>
|
|
11
|
-
<CornCheckbox>Checkbox Two</CornCheckbox>
|
|
12
|
-
</CornCheckboxGroup>
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
const group = screen.getByRole('group', { name: 'Options' });
|
|
16
|
-
expect(group.tagName).toBe('FIELDSET');
|
|
17
|
-
expect(group).toHaveClass('corn-form--item', 'corn-checkbox-group');
|
|
18
|
-
expect(container.querySelectorAll('.corn-checkbox')).toHaveLength(2);
|
|
19
|
-
expect(group.querySelector('legend')).toHaveTextContent('Options');
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('adds the inline modifier class', () => {
|
|
23
|
-
render(
|
|
24
|
-
<CornCheckboxGroup legend="Group Label" name="example-inline" inline>
|
|
25
|
-
<CornCheckbox>Inline One</CornCheckbox>
|
|
26
|
-
</CornCheckboxGroup>
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
expect(screen.getByRole('group', { name: 'Group Label' })).toHaveClass('corn-checkbox-group--inline');
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
describe('CornCheckbox', () => {
|
|
34
|
-
test('renders a checkbox input with matching id and htmlFor', () => {
|
|
35
|
-
const { container } = render(
|
|
36
|
-
<CornCheckbox id="ex1" name="example">
|
|
37
|
-
Checkbox One
|
|
38
|
-
</CornCheckbox>
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
const input = screen.getByRole('checkbox', { name: 'Checkbox One' });
|
|
42
|
-
const label = container.querySelector('label');
|
|
43
|
-
|
|
44
|
-
expect(input).toHaveAttribute('type', 'checkbox');
|
|
45
|
-
expect(input).toHaveAttribute('id', 'ex1');
|
|
46
|
-
expect(label).toHaveAttribute('for', 'ex1');
|
|
47
|
-
expect(container.querySelector('.corn-checkbox')).toContainElement(input);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('adds size and task classes on the item wrapper', () => {
|
|
51
|
-
const { container } = render(
|
|
52
|
-
<CornCheckbox size="lg" task>
|
|
53
|
-
Task Complete
|
|
54
|
-
</CornCheckbox>
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
expect(container.querySelector('.corn-checkbox')).toHaveClass('corn-checkbox', 'corn-checkbox--lg', 'corn-checkbox--task');
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test('inherits name from the group and allows an override', () => {
|
|
61
|
-
render(
|
|
62
|
-
<CornCheckboxGroup legend="Options" name="example">
|
|
63
|
-
<CornCheckbox>One</CornCheckbox>
|
|
64
|
-
<CornCheckbox name="other">Two</CornCheckbox>
|
|
65
|
-
</CornCheckboxGroup>
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
expect(screen.getByRole('checkbox', { name: 'One' })).toHaveAttribute('name', 'example');
|
|
69
|
-
expect(screen.getByRole('checkbox', { name: 'Two' })).toHaveAttribute('name', 'other');
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('does not copy the group name onto a wrapping element', () => {
|
|
73
|
-
const { container } = render(
|
|
74
|
-
<CornCheckboxGroup legend="Options" name="example">
|
|
75
|
-
<div>
|
|
76
|
-
<CornCheckbox>Nested</CornCheckbox>
|
|
77
|
-
</div>
|
|
78
|
-
</CornCheckboxGroup>
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
expect(container.querySelector('div.corn-checkbox').parentElement).not.toHaveAttribute('name');
|
|
82
|
-
expect(screen.getByRole('checkbox', { name: 'Nested' })).not.toHaveAttribute('name');
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test('forwards disabled and checked', () => {
|
|
86
|
-
render(
|
|
87
|
-
<>
|
|
88
|
-
<CornCheckbox disabled>Disabled</CornCheckbox>
|
|
89
|
-
<CornCheckbox checked onChange={() => {}}>
|
|
90
|
-
Checked
|
|
91
|
-
</CornCheckbox>
|
|
92
|
-
</>
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
expect(screen.getByRole('checkbox', { name: 'Disabled' })).toBeDisabled();
|
|
96
|
-
expect(screen.getByRole('checkbox', { name: 'Checked' })).toBeChecked();
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test('prefers uncontrolled state by default', () => {
|
|
100
|
-
const onChange = jest.fn();
|
|
101
|
-
|
|
102
|
-
render(<CornCheckbox defaultChecked>Default on</CornCheckbox>);
|
|
103
|
-
|
|
104
|
-
const uncontrolled = screen.getByRole('checkbox', { name: 'Default on' });
|
|
105
|
-
expect(uncontrolled).toBeChecked();
|
|
106
|
-
|
|
107
|
-
fireEvent.click(uncontrolled);
|
|
108
|
-
expect(uncontrolled).not.toBeChecked();
|
|
109
|
-
expect(onChange).not.toHaveBeenCalled();
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test('supports controlled state when checked is passed', () => {
|
|
113
|
-
const onChange = jest.fn();
|
|
114
|
-
|
|
115
|
-
render(
|
|
116
|
-
<CornCheckbox checked onChange={onChange}>
|
|
117
|
-
Controlled
|
|
118
|
-
</CornCheckbox>
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
const controlled = screen.getByRole('checkbox', { name: 'Controlled' });
|
|
122
|
-
expect(controlled).toBeChecked();
|
|
123
|
-
|
|
124
|
-
fireEvent.click(controlled);
|
|
125
|
-
expect(onChange).toHaveBeenCalledTimes(1);
|
|
126
|
-
expect(controlled).toBeChecked();
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
test('sets the indeterminate DOM property', () => {
|
|
130
|
-
render(<CornCheckbox indeterminate>Indeterminate checkbox</CornCheckbox>);
|
|
131
|
-
|
|
132
|
-
expect(screen.getByRole('checkbox', { name: 'Indeterminate checkbox' }).indeterminate).toBe(true);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test('forwards a ref to the native input', () => {
|
|
136
|
-
const ref = createRef();
|
|
137
|
-
render(<CornCheckbox ref={ref}>One</CornCheckbox>);
|
|
138
|
-
|
|
139
|
-
expect(ref.current).toBe(screen.getByRole('checkbox', { name: 'One' }));
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test('supports a callback ref and keeps indeterminate in sync', () => {
|
|
143
|
-
const ref = jest.fn();
|
|
144
|
-
render(
|
|
145
|
-
<CornCheckbox ref={ref} indeterminate>
|
|
146
|
-
Indeterminate checkbox
|
|
147
|
-
</CornCheckbox>
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
const input = screen.getByRole('checkbox', { name: 'Indeterminate checkbox' });
|
|
151
|
-
expect(ref).toHaveBeenCalledWith(input);
|
|
152
|
-
expect(input.indeterminate).toBe(true);
|
|
153
|
-
});
|
|
154
|
-
});
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import ReactDOM from 'react-dom/client';
|
|
3
|
-
import { CornExpandable, CornAccordion, CornExpandableSummary, CornExpandableContent } from '../../index.js';
|
|
4
|
-
function SummaryIcon({ icon }) {
|
|
5
|
-
return (
|
|
6
|
-
<svg xmlns="http://www.w3.org/2000/svg" className="corn-icon" aria-hidden="true">
|
|
7
|
-
<use href={`/node_modules/bootstrap-icons/bootstrap-icons.svg#${icon}`}></use>
|
|
8
|
-
</svg>
|
|
9
|
-
);
|
|
10
|
-
}
|
|
11
|
-
const root = ReactDOM.createRoot(document.getElementById('test-stickersheet'));
|
|
12
|
-
root.render(
|
|
13
|
-
<div className="expandables-demo">
|
|
14
|
-
<h2>Corn Expandables</h2>
|
|
15
|
-
|
|
16
|
-
<h3>Default</h3>
|
|
17
|
-
<CornExpandable>
|
|
18
|
-
<CornExpandableSummary>
|
|
19
|
-
Summary <SummaryIcon icon="chevron-right" />
|
|
20
|
-
</CornExpandableSummary>
|
|
21
|
-
<CornExpandableContent>
|
|
22
|
-
<div>
|
|
23
|
-
<h3>heading</h3>
|
|
24
|
-
<div>content</div>
|
|
25
|
-
</div>
|
|
26
|
-
</CornExpandableContent>
|
|
27
|
-
</CornExpandable>
|
|
28
|
-
|
|
29
|
-
<h4>Start Open</h4>
|
|
30
|
-
<CornExpandable open>
|
|
31
|
-
<CornExpandableSummary>
|
|
32
|
-
Summary
|
|
33
|
-
<SummaryIcon icon="chevron-right" />
|
|
34
|
-
</CornExpandableSummary>
|
|
35
|
-
<CornExpandableContent>
|
|
36
|
-
<div>
|
|
37
|
-
<h3>heading</h3>
|
|
38
|
-
<div>content</div>
|
|
39
|
-
</div>
|
|
40
|
-
</CornExpandableContent>
|
|
41
|
-
</CornExpandable>
|
|
42
|
-
|
|
43
|
-
<hr />
|
|
44
|
-
<CornExpandable>
|
|
45
|
-
<CornExpandableSummary>
|
|
46
|
-
Summary 2<SummaryIcon icon="chevron-right" />
|
|
47
|
-
</CornExpandableSummary>
|
|
48
|
-
<CornExpandableContent>details 2</CornExpandableContent>
|
|
49
|
-
</CornExpandable>
|
|
50
|
-
|
|
51
|
-
<hr />
|
|
52
|
-
<CornExpandable>
|
|
53
|
-
<CornExpandableSummary>
|
|
54
|
-
Summary 3<SummaryIcon icon="chevron-right" />
|
|
55
|
-
</CornExpandableSummary>
|
|
56
|
-
<CornExpandableContent>details</CornExpandableContent>
|
|
57
|
-
</CornExpandable>
|
|
58
|
-
|
|
59
|
-
<h3>Accordion Single Open</h3>
|
|
60
|
-
<CornAccordion>
|
|
61
|
-
<CornExpandable name="corn-single">
|
|
62
|
-
<CornExpandableSummary>
|
|
63
|
-
Summary <SummaryIcon icon="chevron-right" />
|
|
64
|
-
</CornExpandableSummary>
|
|
65
|
-
<CornExpandableContent>details</CornExpandableContent>
|
|
66
|
-
</CornExpandable>
|
|
67
|
-
<CornExpandable name="corn-single">
|
|
68
|
-
<CornExpandableSummary>
|
|
69
|
-
Summary 2 <SummaryIcon icon="chevron-right" />
|
|
70
|
-
</CornExpandableSummary>
|
|
71
|
-
<CornExpandableContent>details 2</CornExpandableContent>
|
|
72
|
-
</CornExpandable>
|
|
73
|
-
<CornExpandable name="corn-single">
|
|
74
|
-
<CornExpandableSummary>
|
|
75
|
-
Summary 3 <SummaryIcon icon="chevron-right" />
|
|
76
|
-
</CornExpandableSummary>
|
|
77
|
-
<CornExpandableContent>details</CornExpandableContent>
|
|
78
|
-
</CornExpandable>
|
|
79
|
-
</CornAccordion>
|
|
80
|
-
|
|
81
|
-
<hr />
|
|
82
|
-
|
|
83
|
-
<h3>Nested expandable</h3>
|
|
84
|
-
<CornExpandable className="corn-tree-view">
|
|
85
|
-
<CornExpandableSummary>
|
|
86
|
-
<SummaryIcon icon="chevron-right" />
|
|
87
|
-
Summary
|
|
88
|
-
</CornExpandableSummary>
|
|
89
|
-
<CornExpandableContent>
|
|
90
|
-
<CornExpandable className="corn-tree-view">
|
|
91
|
-
<CornExpandableSummary>
|
|
92
|
-
<SummaryIcon icon="chevron-right" />
|
|
93
|
-
Summary 2
|
|
94
|
-
</CornExpandableSummary>
|
|
95
|
-
<CornExpandableContent>More details</CornExpandableContent>
|
|
96
|
-
</CornExpandable>
|
|
97
|
-
</CornExpandableContent>
|
|
98
|
-
</CornExpandable>
|
|
99
|
-
</div>
|
|
100
|
-
);
|