@patternfly/react-core 4.199.0 → 4.199.3
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 +24 -0
- package/package.json +5 -5
- package/src/components/AboutModal/__tests__/AboutModal.test.tsx +41 -60
- package/src/components/Accordion/__tests__/Accordion.test.tsx +23 -17
- package/src/components/Alert/__tests__/Alert.test.tsx +195 -184
- package/src/components/Alert/__tests__/Generated/AlertActionCloseButton.test.tsx +19 -17
- package/src/components/Alert/__tests__/Generated/__snapshots__/AlertActionCloseButton.test.tsx.snap +26 -4
- package/src/components/Alert/__tests__/__snapshots__/Alert.test.tsx.snap +50 -700
- package/src/components/AlertGroup/__tests__/AlertGroup.test.tsx +68 -73
- package/src/components/AlertGroup/__tests__/__snapshots__/AlertGroup.test.tsx.snap +1 -893
- package/src/components/ApplicationLauncher/__tests__/Generated/ApplicationLauncherSeparator.test.tsx +13 -10
- package/src/components/ApplicationLauncher/__tests__/Generated/__snapshots__/ApplicationLauncherSeparator.test.tsx.snap +12 -1
- package/src/components/Button/__tests__/Button.test.tsx +116 -107
- package/src/components/Button/__tests__/__snapshots__/Button.test.tsx.snap +21 -21
- package/src/components/Card/__tests__/Card.test.tsx +119 -100
- package/src/components/Card/__tests__/CardBody.test.tsx +35 -28
- package/src/components/Card/__tests__/CardFooter.test.tsx +28 -24
- package/src/components/Card/__tests__/CardHeadMain.test.tsx +19 -14
- package/src/components/Card/__tests__/CardHeader.test.tsx +6 -22
- package/src/components/Card/__tests__/CardHeaderMain.test.tsx +19 -14
- package/src/components/Card/__tests__/CardTitle.test.tsx +25 -0
- package/src/components/Card/__tests__/__snapshots__/Card.test.tsx.snap +12 -28
- package/src/components/Card/__tests__/__snapshots__/CardBody.test.tsx.snap +2 -4
- package/src/components/Card/__tests__/__snapshots__/CardFooter.test.tsx.snap +1 -3
- package/src/components/Card/__tests__/__snapshots__/CardHeadMain.test.tsx.snap +1 -11
- package/src/components/Card/__tests__/__snapshots__/CardHeader.test.tsx.snap +1 -11
- package/src/components/Card/__tests__/__snapshots__/CardHeaderMain.test.tsx.snap +1 -11
- package/src/components/Card/__tests__/__snapshots__/CardTitle.test.tsx.snap +3 -0
- package/src/components/Checkbox/__tests__/Checkbox.test.tsx +66 -70
- package/src/components/Checkbox/__tests__/__snapshots__/Checkbox.test.tsx.snap +9 -204
- package/src/components/Checkbox/examples/Checkbox.md +11 -115
- package/src/components/Checkbox/examples/CheckboxControlled.tsx +78 -0
- package/src/components/Checkbox/examples/CheckboxDisabled.tsx +9 -0
- package/src/components/Checkbox/examples/CheckboxStandaloneInput.tsx +6 -0
- package/src/components/Checkbox/examples/CheckboxUncontrolled.tsx +9 -0
- package/src/components/Checkbox/examples/CheckboxWithBody.tsx +6 -0
- package/src/components/Checkbox/examples/CheckboxWithDescription.tsx +10 -0
- package/src/components/Checkbox/examples/CheckboxWithDescriptionBody.tsx +11 -0
- package/src/components/Chip/examples/Chip.md +1 -73
- package/src/components/Chip/examples/ChipDefault.tsx +68 -0
- package/src/components/ChipGroup/examples/ChipGroup.md +6 -134
- package/src/components/ChipGroup/examples/ChipGroupInline.tsx +28 -0
- package/src/components/ChipGroup/examples/ChipGroupRemovableCategories.tsx +46 -0
- package/src/components/ChipGroup/examples/ChipGroupWithCategories.tsx +28 -0
- package/src/layouts/Flex/examples/Flex.md +1 -1
|
@@ -1,86 +1,82 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import {
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { render, screen } from '@testing-library/react';
|
|
4
|
+
import userEvent from '@testing-library/user-event';
|
|
5
|
+
import '@testing-library/jest-dom';
|
|
6
|
+
|
|
4
7
|
import { Checkbox } from '../Checkbox';
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
describe('Checkbox', () => {
|
|
10
|
+
test('controlled', () => {
|
|
11
|
+
render(<Checkbox isChecked id="check" aria-label="check" />);
|
|
12
|
+
expect(screen.getByRole('checkbox').outerHTML).toMatchSnapshot();
|
|
13
|
+
});
|
|
10
14
|
|
|
11
|
-
test('controlled', () => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
});
|
|
15
|
+
test('controlled - 3rd state', () => {
|
|
16
|
+
render(<Checkbox isChecked={null} id="check" aria-label="check" />);
|
|
17
|
+
expect(screen.getByRole('checkbox').outerHTML).toMatchSnapshot();
|
|
18
|
+
});
|
|
15
19
|
|
|
16
|
-
test('
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
20
|
+
test('uncontrolled', () => {
|
|
21
|
+
render(<Checkbox id="check" aria-label="check" />);
|
|
22
|
+
expect(screen.getByRole('checkbox').outerHTML).toMatchSnapshot();
|
|
23
|
+
});
|
|
20
24
|
|
|
21
|
-
test('
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
25
|
+
test('isDisabled', () => {
|
|
26
|
+
render(<Checkbox id="check" isDisabled aria-label="check" />);
|
|
27
|
+
expect(screen.getByRole('checkbox').outerHTML).toMatchSnapshot();
|
|
28
|
+
});
|
|
25
29
|
|
|
26
|
-
test('
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
+
test('label is string', () => {
|
|
31
|
+
render(<Checkbox label="Label" id="check" isChecked aria-label="check" />);
|
|
32
|
+
expect(screen.getByRole('checkbox').outerHTML).toMatchSnapshot();
|
|
33
|
+
});
|
|
30
34
|
|
|
31
|
-
test('label is
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
test('label is function', () => {
|
|
36
|
+
const functionLabel = () => <h1>Header</h1>;
|
|
37
|
+
render(<Checkbox label={functionLabel()} id="check" isChecked aria-label="check" />);
|
|
38
|
+
expect(screen.getByRole('checkbox').outerHTML).toMatchSnapshot();
|
|
39
|
+
});
|
|
35
40
|
|
|
36
|
-
test('label is
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
});
|
|
41
|
+
test('label is node', () => {
|
|
42
|
+
render(<Checkbox label={<h1>Header</h1>} id="check" isChecked aria-label="check" />);
|
|
43
|
+
expect(screen.getByRole('checkbox').outerHTML).toMatchSnapshot();
|
|
44
|
+
});
|
|
41
45
|
|
|
42
|
-
test('
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
46
|
+
test('passing class', () => {
|
|
47
|
+
render(<Checkbox label="label" className="class-123" id="check" isChecked aria-label="check" />);
|
|
48
|
+
expect(screen.getByRole('checkbox').outerHTML).toMatchSnapshot();
|
|
49
|
+
});
|
|
46
50
|
|
|
47
|
-
test('passing
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
51
|
+
test('passing HTML attribute', () => {
|
|
52
|
+
render(<Checkbox label="label" aria-labelledby="labelId" id="check" isChecked aria-label="check" />);
|
|
53
|
+
expect(screen.getByRole('checkbox').outerHTML).toMatchSnapshot();
|
|
54
|
+
});
|
|
51
55
|
|
|
52
|
-
test('passing
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
56
|
+
test('passing description', () => {
|
|
57
|
+
render(<Checkbox id="check" label="checkbox" description="Text description..." />);
|
|
58
|
+
expect(screen.getByText('Text description...')).toBeInTheDocument();
|
|
59
|
+
});
|
|
56
60
|
|
|
57
|
-
test('passing
|
|
58
|
-
|
|
59
|
-
const descriptionEl = view.find('span[className="pf-c-check__description"]');
|
|
60
|
-
expect(descriptionEl.length).toBe(1);
|
|
61
|
-
expect(descriptionEl.text()).toBe('Text description...');
|
|
62
|
-
});
|
|
61
|
+
test('passing body', () => {
|
|
62
|
+
render(<Checkbox id="check" label="checkbox" body="This is where custom content goes." />);
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const bodyEl = view.find('span[className="pf-c-check__body"]');
|
|
67
|
-
expect(bodyEl.length).toBe(1);
|
|
68
|
-
expect(bodyEl.text()).toBe('This is where custom content goes.');
|
|
69
|
-
});
|
|
64
|
+
expect(screen.getByText('This is where custom content goes.')).toBeInTheDocument();
|
|
65
|
+
});
|
|
70
66
|
|
|
71
|
-
test('checkbox
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
67
|
+
test('checkbox onChange handler called when component is clicked', () => {
|
|
68
|
+
const onChangeHandler = jest.fn();
|
|
69
|
+
render(<Checkbox id="check" onChange={onChangeHandler} aria-label="check" isChecked={false} />);
|
|
70
|
+
|
|
71
|
+
userEvent.click(screen.getByLabelText('check'));
|
|
72
|
+
expect(onChangeHandler).toBeCalled();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('should throw console error when no id is given', () => {
|
|
76
|
+
const myMock = jest.fn();
|
|
77
|
+
global.console = { ...global.console, error: myMock };
|
|
80
78
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
render(<Checkbox {...props} />);
|
|
85
|
-
expect(myMock).toBeCalled();
|
|
79
|
+
render(<Checkbox id={undefined} />);
|
|
80
|
+
expect(myMock).toBeCalled();
|
|
81
|
+
});
|
|
86
82
|
});
|
|
@@ -1,214 +1,19 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`controlled - 3rd state 1`] = `
|
|
4
|
-
<div>
|
|
5
|
-
<div
|
|
6
|
-
class="pf-c-check pf-m-standalone"
|
|
7
|
-
>
|
|
8
|
-
<input
|
|
9
|
-
aria-invalid="false"
|
|
10
|
-
aria-label="check"
|
|
11
|
-
class="pf-c-check__input"
|
|
12
|
-
data-ouia-component-id="OUIA-Generated-Checkbox-2"
|
|
13
|
-
data-ouia-component-type="PF4/Checkbox"
|
|
14
|
-
data-ouia-safe="true"
|
|
15
|
-
id="check"
|
|
16
|
-
type="checkbox"
|
|
17
|
-
/>
|
|
18
|
-
</div>
|
|
19
|
-
</div>
|
|
20
|
-
`;
|
|
3
|
+
exports[`Checkbox controlled - 3rd state 1`] = `"<input id=\\"check\\" class=\\"pf-c-check__input\\" type=\\"checkbox\\" aria-invalid=\\"false\\" aria-label=\\"check\\" data-ouia-component-type=\\"PF4/Checkbox\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"OUIA-Generated-Checkbox-2\\">"`;
|
|
21
4
|
|
|
22
|
-
exports[`controlled 1`] = `
|
|
23
|
-
<div>
|
|
24
|
-
<div
|
|
25
|
-
class="pf-c-check pf-m-standalone"
|
|
26
|
-
>
|
|
27
|
-
<input
|
|
28
|
-
aria-invalid="false"
|
|
29
|
-
aria-label="check"
|
|
30
|
-
checked=""
|
|
31
|
-
class="pf-c-check__input"
|
|
32
|
-
data-ouia-component-id="OUIA-Generated-Checkbox-1"
|
|
33
|
-
data-ouia-component-type="PF4/Checkbox"
|
|
34
|
-
data-ouia-safe="true"
|
|
35
|
-
id="check"
|
|
36
|
-
type="checkbox"
|
|
37
|
-
/>
|
|
38
|
-
</div>
|
|
39
|
-
</div>
|
|
40
|
-
`;
|
|
5
|
+
exports[`Checkbox controlled 1`] = `"<input id=\\"check\\" class=\\"pf-c-check__input\\" type=\\"checkbox\\" aria-invalid=\\"false\\" aria-label=\\"check\\" data-ouia-component-type=\\"PF4/Checkbox\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"OUIA-Generated-Checkbox-1\\" checked=\\"\\">"`;
|
|
41
6
|
|
|
42
|
-
exports[`isDisabled 1`] = `
|
|
43
|
-
<div>
|
|
44
|
-
<div
|
|
45
|
-
class="pf-c-check pf-m-standalone"
|
|
46
|
-
>
|
|
47
|
-
<input
|
|
48
|
-
aria-invalid="false"
|
|
49
|
-
aria-label="check"
|
|
50
|
-
class="pf-c-check__input"
|
|
51
|
-
data-ouia-component-id="OUIA-Generated-Checkbox-4"
|
|
52
|
-
data-ouia-component-type="PF4/Checkbox"
|
|
53
|
-
data-ouia-safe="true"
|
|
54
|
-
disabled=""
|
|
55
|
-
id="check"
|
|
56
|
-
type="checkbox"
|
|
57
|
-
/>
|
|
58
|
-
</div>
|
|
59
|
-
</div>
|
|
60
|
-
`;
|
|
7
|
+
exports[`Checkbox isDisabled 1`] = `"<input id=\\"check\\" class=\\"pf-c-check__input\\" type=\\"checkbox\\" aria-invalid=\\"false\\" aria-label=\\"check\\" disabled=\\"\\" data-ouia-component-type=\\"PF4/Checkbox\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"OUIA-Generated-Checkbox-4\\">"`;
|
|
61
8
|
|
|
62
|
-
exports[`label is function 1`] = `
|
|
63
|
-
<div>
|
|
64
|
-
<div
|
|
65
|
-
class="pf-c-check"
|
|
66
|
-
>
|
|
67
|
-
<input
|
|
68
|
-
aria-invalid="false"
|
|
69
|
-
aria-label="check"
|
|
70
|
-
checked=""
|
|
71
|
-
class="pf-c-check__input"
|
|
72
|
-
data-ouia-component-id="OUIA-Generated-Checkbox-6"
|
|
73
|
-
data-ouia-component-type="PF4/Checkbox"
|
|
74
|
-
data-ouia-safe="true"
|
|
75
|
-
id="check"
|
|
76
|
-
type="checkbox"
|
|
77
|
-
/>
|
|
78
|
-
<label
|
|
79
|
-
class="pf-c-check__label"
|
|
80
|
-
for="check"
|
|
81
|
-
>
|
|
82
|
-
<h1>
|
|
83
|
-
Header
|
|
84
|
-
</h1>
|
|
85
|
-
</label>
|
|
86
|
-
</div>
|
|
87
|
-
</div>
|
|
88
|
-
`;
|
|
9
|
+
exports[`Checkbox label is function 1`] = `"<input id=\\"check\\" class=\\"pf-c-check__input\\" type=\\"checkbox\\" aria-invalid=\\"false\\" aria-label=\\"check\\" data-ouia-component-type=\\"PF4/Checkbox\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"OUIA-Generated-Checkbox-6\\" checked=\\"\\">"`;
|
|
89
10
|
|
|
90
|
-
exports[`label is node 1`] = `
|
|
91
|
-
<div>
|
|
92
|
-
<div
|
|
93
|
-
class="pf-c-check"
|
|
94
|
-
>
|
|
95
|
-
<input
|
|
96
|
-
aria-invalid="false"
|
|
97
|
-
aria-label="check"
|
|
98
|
-
checked=""
|
|
99
|
-
class="pf-c-check__input"
|
|
100
|
-
data-ouia-component-id="OUIA-Generated-Checkbox-7"
|
|
101
|
-
data-ouia-component-type="PF4/Checkbox"
|
|
102
|
-
data-ouia-safe="true"
|
|
103
|
-
id="check"
|
|
104
|
-
type="checkbox"
|
|
105
|
-
/>
|
|
106
|
-
<label
|
|
107
|
-
class="pf-c-check__label"
|
|
108
|
-
for="check"
|
|
109
|
-
>
|
|
110
|
-
<h1>
|
|
111
|
-
Header
|
|
112
|
-
</h1>
|
|
113
|
-
</label>
|
|
114
|
-
</div>
|
|
115
|
-
</div>
|
|
116
|
-
`;
|
|
11
|
+
exports[`Checkbox label is node 1`] = `"<input id=\\"check\\" class=\\"pf-c-check__input\\" type=\\"checkbox\\" aria-invalid=\\"false\\" aria-label=\\"check\\" data-ouia-component-type=\\"PF4/Checkbox\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"OUIA-Generated-Checkbox-7\\" checked=\\"\\">"`;
|
|
117
12
|
|
|
118
|
-
exports[`label is string 1`] = `
|
|
119
|
-
<div>
|
|
120
|
-
<div
|
|
121
|
-
class="pf-c-check"
|
|
122
|
-
>
|
|
123
|
-
<input
|
|
124
|
-
aria-invalid="false"
|
|
125
|
-
aria-label="check"
|
|
126
|
-
checked=""
|
|
127
|
-
class="pf-c-check__input"
|
|
128
|
-
data-ouia-component-id="OUIA-Generated-Checkbox-5"
|
|
129
|
-
data-ouia-component-type="PF4/Checkbox"
|
|
130
|
-
data-ouia-safe="true"
|
|
131
|
-
id="check"
|
|
132
|
-
type="checkbox"
|
|
133
|
-
/>
|
|
134
|
-
<label
|
|
135
|
-
class="pf-c-check__label"
|
|
136
|
-
for="check"
|
|
137
|
-
>
|
|
138
|
-
Label
|
|
139
|
-
</label>
|
|
140
|
-
</div>
|
|
141
|
-
</div>
|
|
142
|
-
`;
|
|
13
|
+
exports[`Checkbox label is string 1`] = `"<input id=\\"check\\" class=\\"pf-c-check__input\\" type=\\"checkbox\\" aria-invalid=\\"false\\" aria-label=\\"check\\" data-ouia-component-type=\\"PF4/Checkbox\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"OUIA-Generated-Checkbox-5\\" checked=\\"\\">"`;
|
|
143
14
|
|
|
144
|
-
exports[`passing HTML attribute 1`] = `
|
|
145
|
-
<div>
|
|
146
|
-
<div
|
|
147
|
-
class="pf-c-check"
|
|
148
|
-
>
|
|
149
|
-
<input
|
|
150
|
-
aria-invalid="false"
|
|
151
|
-
aria-label="check"
|
|
152
|
-
aria-labelledby="labelId"
|
|
153
|
-
checked=""
|
|
154
|
-
class="pf-c-check__input"
|
|
155
|
-
data-ouia-component-id="OUIA-Generated-Checkbox-9"
|
|
156
|
-
data-ouia-component-type="PF4/Checkbox"
|
|
157
|
-
data-ouia-safe="true"
|
|
158
|
-
id="check"
|
|
159
|
-
type="checkbox"
|
|
160
|
-
/>
|
|
161
|
-
<label
|
|
162
|
-
class="pf-c-check__label"
|
|
163
|
-
for="check"
|
|
164
|
-
>
|
|
165
|
-
label
|
|
166
|
-
</label>
|
|
167
|
-
</div>
|
|
168
|
-
</div>
|
|
169
|
-
`;
|
|
15
|
+
exports[`Checkbox passing HTML attribute 1`] = `"<input aria-labelledby=\\"labelId\\" id=\\"check\\" class=\\"pf-c-check__input\\" type=\\"checkbox\\" aria-invalid=\\"false\\" aria-label=\\"check\\" data-ouia-component-type=\\"PF4/Checkbox\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"OUIA-Generated-Checkbox-9\\" checked=\\"\\">"`;
|
|
170
16
|
|
|
171
|
-
exports[`passing class 1`] = `
|
|
172
|
-
<div>
|
|
173
|
-
<div
|
|
174
|
-
class="pf-c-check class-123"
|
|
175
|
-
>
|
|
176
|
-
<input
|
|
177
|
-
aria-invalid="false"
|
|
178
|
-
aria-label="check"
|
|
179
|
-
checked=""
|
|
180
|
-
class="pf-c-check__input"
|
|
181
|
-
data-ouia-component-id="OUIA-Generated-Checkbox-8"
|
|
182
|
-
data-ouia-component-type="PF4/Checkbox"
|
|
183
|
-
data-ouia-safe="true"
|
|
184
|
-
id="check"
|
|
185
|
-
type="checkbox"
|
|
186
|
-
/>
|
|
187
|
-
<label
|
|
188
|
-
class="pf-c-check__label"
|
|
189
|
-
for="check"
|
|
190
|
-
>
|
|
191
|
-
label
|
|
192
|
-
</label>
|
|
193
|
-
</div>
|
|
194
|
-
</div>
|
|
195
|
-
`;
|
|
17
|
+
exports[`Checkbox passing class 1`] = `"<input id=\\"check\\" class=\\"pf-c-check__input\\" type=\\"checkbox\\" aria-invalid=\\"false\\" aria-label=\\"check\\" data-ouia-component-type=\\"PF4/Checkbox\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"OUIA-Generated-Checkbox-8\\" checked=\\"\\">"`;
|
|
196
18
|
|
|
197
|
-
exports[`uncontrolled 1`] = `
|
|
198
|
-
<div>
|
|
199
|
-
<div
|
|
200
|
-
class="pf-c-check pf-m-standalone"
|
|
201
|
-
>
|
|
202
|
-
<input
|
|
203
|
-
aria-invalid="false"
|
|
204
|
-
aria-label="check"
|
|
205
|
-
class="pf-c-check__input"
|
|
206
|
-
data-ouia-component-id="OUIA-Generated-Checkbox-3"
|
|
207
|
-
data-ouia-component-type="PF4/Checkbox"
|
|
208
|
-
data-ouia-safe="true"
|
|
209
|
-
id="check"
|
|
210
|
-
type="checkbox"
|
|
211
|
-
/>
|
|
212
|
-
</div>
|
|
213
|
-
</div>
|
|
214
|
-
`;
|
|
19
|
+
exports[`Checkbox uncontrolled 1`] = `"<input id=\\"check\\" class=\\"pf-c-check__input\\" type=\\"checkbox\\" aria-invalid=\\"false\\" aria-label=\\"check\\" data-ouia-component-type=\\"PF4/Checkbox\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"OUIA-Generated-Checkbox-3\\">"`;
|
|
@@ -8,142 +8,38 @@ propComponents: ['Checkbox']
|
|
|
8
8
|
import './checkbox.css';
|
|
9
9
|
|
|
10
10
|
## Examples
|
|
11
|
+
|
|
11
12
|
### Controlled
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import { Checkbox } from '@patternfly/react-core';
|
|
15
|
-
|
|
16
|
-
class ControlledCheckbox extends React.Component {
|
|
17
|
-
constructor(props) {
|
|
18
|
-
super(props);
|
|
19
|
-
this.state = {
|
|
20
|
-
check1: false,
|
|
21
|
-
check2: false,
|
|
22
|
-
check3: false,
|
|
23
|
-
check4: false
|
|
24
|
-
};
|
|
25
|
-
this.handleChange = (checked, event) => {
|
|
26
|
-
const target = event.target;
|
|
27
|
-
const value = target.type === 'checkbox' ? target.checked : target.value;
|
|
28
|
-
const name = target.name;
|
|
29
|
-
this.setState({ [name]: value });
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
componentDidUpdate(_prevProps, prevState) {
|
|
34
|
-
if (prevState.check1 !== this.state.check1 && this.state.check1 !== null) {
|
|
35
|
-
this.setState({
|
|
36
|
-
check2: this.state.check1,
|
|
37
|
-
check3: this.state.check1,
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (prevState.check2 !== this.state.check2 || prevState.check3 !== this.state.check3) {
|
|
42
|
-
this.setState({
|
|
43
|
-
check1: (this.state.check2 && this.state.check3) || (this.state.check2 || this.state.check3 ? null : false)
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
render() {
|
|
49
|
-
return (
|
|
50
|
-
<React.Fragment>
|
|
51
|
-
<Checkbox
|
|
52
|
-
label="Parent CheckBox"
|
|
53
|
-
isChecked={this.state.check1}
|
|
54
|
-
onChange={this.handleChange}
|
|
55
|
-
aria-label="controlled checkbox example"
|
|
56
|
-
id="check-1"
|
|
57
|
-
name="check1"
|
|
58
|
-
/>
|
|
59
|
-
<Checkbox
|
|
60
|
-
className="nested"
|
|
61
|
-
label="Child CheckBox 1"
|
|
62
|
-
isChecked={this.state.check2}
|
|
63
|
-
onChange={this.handleChange}
|
|
64
|
-
aria-label="controlled checkbox example"
|
|
65
|
-
id="check-2"
|
|
66
|
-
name="check2"
|
|
67
|
-
/>
|
|
68
|
-
<Checkbox
|
|
69
|
-
className="nested"
|
|
70
|
-
label="Child CheckBox 2"
|
|
71
|
-
isChecked={this.state.check3}
|
|
72
|
-
onChange={this.handleChange}
|
|
73
|
-
aria-label="controlled checkbox example"
|
|
74
|
-
id="check-3"
|
|
75
|
-
name="check3"
|
|
76
|
-
/>
|
|
77
|
-
<Checkbox
|
|
78
|
-
label="Controlled CheckBox"
|
|
79
|
-
isChecked={this.state.check4}
|
|
80
|
-
onChange={this.handleChange}
|
|
81
|
-
aria-label="controlled checkbox example"
|
|
82
|
-
id="check-4"
|
|
83
|
-
name="check4"
|
|
84
|
-
/>
|
|
85
|
-
</React.Fragment>
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
13
|
+
|
|
14
|
+
```ts file='./CheckboxControlled.tsx'
|
|
89
15
|
```
|
|
90
16
|
|
|
91
17
|
### Uncontrolled
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
import { Checkbox } from '@patternfly/react-core';
|
|
95
|
-
|
|
96
|
-
<React.Fragment>
|
|
97
|
-
<Checkbox label="Uncontrolled CheckBox" aria-label="uncontrolled checkbox example" id="check-5" />
|
|
98
|
-
<Checkbox label="Uncontrolled CheckBox" aria-label="uncontrolled checkbox example" id="check-6" />
|
|
99
|
-
</React.Fragment>
|
|
18
|
+
|
|
19
|
+
```ts file='./CheckboxUncontrolled.tsx'
|
|
100
20
|
```
|
|
101
21
|
|
|
102
22
|
### Disabled
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
import { Checkbox } from '@patternfly/react-core';
|
|
106
|
-
|
|
107
|
-
<React.Fragment>
|
|
108
|
-
<Checkbox
|
|
109
|
-
id="check-7"
|
|
110
|
-
label="Disabled CheckBox"
|
|
111
|
-
aria-label="disabled checked checkbox example"
|
|
112
|
-
defaultChecked
|
|
113
|
-
isDisabled
|
|
114
|
-
/>{' '}
|
|
115
|
-
<Checkbox id="check-8" label="Disabled CheckBox" aria-label="disabled checkbox example" isDisabled />
|
|
116
|
-
</React.Fragment>
|
|
23
|
+
|
|
24
|
+
```ts file='./CheckboxDisabled.tsx'
|
|
117
25
|
```
|
|
118
26
|
|
|
119
27
|
### Checkbox with description
|
|
120
|
-
```js
|
|
121
|
-
import React from 'react';
|
|
122
|
-
import { Checkbox } from '@patternfly/react-core';
|
|
123
28
|
|
|
124
|
-
|
|
29
|
+
```ts file='./CheckboxWithDescription.tsx'
|
|
125
30
|
```
|
|
126
31
|
|
|
127
32
|
### Checkbox with body
|
|
128
|
-
```js
|
|
129
|
-
import React from 'react';
|
|
130
|
-
import { Checkbox } from '@patternfly/react-core';
|
|
131
33
|
|
|
132
|
-
|
|
34
|
+
```ts file='./CheckboxWithBody.tsx'
|
|
133
35
|
```
|
|
134
36
|
|
|
135
37
|
### Checkbox with description and body
|
|
136
|
-
```js
|
|
137
|
-
import React from 'react';
|
|
138
|
-
import { Checkbox } from '@patternfly/react-core';
|
|
139
38
|
|
|
140
|
-
|
|
39
|
+
```ts file='./CheckboxWithDescriptionBody.tsx'
|
|
141
40
|
```
|
|
142
41
|
|
|
143
42
|
### Standalone input
|
|
144
|
-
```js
|
|
145
|
-
import React from 'react';
|
|
146
|
-
import { Checkbox } from '@patternfly/react-core';
|
|
147
43
|
|
|
148
|
-
|
|
44
|
+
```ts file='./CheckboxStandaloneInput.tsx'
|
|
149
45
|
```
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Checkbox } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const CheckboxControlled: React.FunctionComponent = () => {
|
|
5
|
+
const [isChecked1, setIsChecked1] = React.useState<boolean>(false);
|
|
6
|
+
const [isChecked2, setIsChecked2] = React.useState<boolean>(false);
|
|
7
|
+
const [isChecked3, setIsChecked3] = React.useState<boolean>(false);
|
|
8
|
+
const [isChecked4, setIsChecked4] = React.useState<boolean>(false);
|
|
9
|
+
|
|
10
|
+
const handleChange = (checked: boolean, event: React.FormEvent<HTMLInputElement>) => {
|
|
11
|
+
const target = event.currentTarget;
|
|
12
|
+
const name = target.name;
|
|
13
|
+
|
|
14
|
+
switch (name) {
|
|
15
|
+
case 'check1':
|
|
16
|
+
setIsChecked1(checked);
|
|
17
|
+
break;
|
|
18
|
+
case 'check2':
|
|
19
|
+
setIsChecked2(checked);
|
|
20
|
+
break;
|
|
21
|
+
case 'check3':
|
|
22
|
+
setIsChecked3(checked);
|
|
23
|
+
break;
|
|
24
|
+
case 'check4':
|
|
25
|
+
setIsChecked4(checked);
|
|
26
|
+
break;
|
|
27
|
+
default:
|
|
28
|
+
// eslint-disable-next-line no-console
|
|
29
|
+
console.log(name);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
React.useEffect(() => {
|
|
34
|
+
if (isChecked1 !== null) {
|
|
35
|
+
setIsChecked2(isChecked1);
|
|
36
|
+
setIsChecked3(isChecked1);
|
|
37
|
+
}
|
|
38
|
+
}, [isChecked1]);
|
|
39
|
+
|
|
40
|
+
React.useEffect(() => {
|
|
41
|
+
setIsChecked1((isChecked2 && isChecked3) || (isChecked2 || isChecked3 ? null : false));
|
|
42
|
+
}, [isChecked2, isChecked3]);
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<React.Fragment>
|
|
46
|
+
<Checkbox
|
|
47
|
+
label="Parent CheckBox"
|
|
48
|
+
isChecked={isChecked1}
|
|
49
|
+
onChange={handleChange}
|
|
50
|
+
id="controlled-check-1"
|
|
51
|
+
name="check1"
|
|
52
|
+
/>
|
|
53
|
+
<Checkbox
|
|
54
|
+
className="nested"
|
|
55
|
+
label="Child CheckBox 1"
|
|
56
|
+
isChecked={isChecked2}
|
|
57
|
+
onChange={handleChange}
|
|
58
|
+
id="controlled-check-2"
|
|
59
|
+
name="check2"
|
|
60
|
+
/>
|
|
61
|
+
<Checkbox
|
|
62
|
+
className="nested"
|
|
63
|
+
label="Child CheckBox 2"
|
|
64
|
+
isChecked={isChecked3}
|
|
65
|
+
onChange={handleChange}
|
|
66
|
+
id="controlled-check-3"
|
|
67
|
+
name="check3"
|
|
68
|
+
/>
|
|
69
|
+
<Checkbox
|
|
70
|
+
label="Controlled CheckBox"
|
|
71
|
+
isChecked={isChecked4}
|
|
72
|
+
onChange={handleChange}
|
|
73
|
+
id="controlled-check-4"
|
|
74
|
+
name="check4"
|
|
75
|
+
/>
|
|
76
|
+
</React.Fragment>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Checkbox } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const CheckboxDisabled: React.FunctionComponent = () => (
|
|
5
|
+
<React.Fragment>
|
|
6
|
+
<Checkbox id="disabled-check-1" label="Disabled CheckBox 1" defaultChecked isDisabled />
|
|
7
|
+
<Checkbox id="disabled-check-2" label="Disabled CheckBox 2" isDisabled />
|
|
8
|
+
</React.Fragment>
|
|
9
|
+
);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Checkbox } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const CheckboxUncontrolled: React.FunctionComponent = () => (
|
|
5
|
+
<React.Fragment>
|
|
6
|
+
<Checkbox label="Uncontrolled CheckBox 1" id="uncontrolled-check-1" />
|
|
7
|
+
<Checkbox label="Uncontrolled CheckBox 2" id="uncontrolled-check-2" />
|
|
8
|
+
</React.Fragment>
|
|
9
|
+
);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Checkbox } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const CheckboxWithDescription: React.FunctionComponent = () => (
|
|
5
|
+
<Checkbox
|
|
6
|
+
id="description-check-1"
|
|
7
|
+
label="Checkbox with description"
|
|
8
|
+
description="Single-tenant cloud service hosted and managed by Red Hat that offers high-availability enterprise-grade clusters in a virtual private cloud on AWS or GCP."
|
|
9
|
+
/>
|
|
10
|
+
);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Checkbox } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const CheckboxWithDescriptionBody: React.FunctionComponent = () => (
|
|
5
|
+
<Checkbox
|
|
6
|
+
id="description-body-check"
|
|
7
|
+
label="Checkbox with description and body"
|
|
8
|
+
description="Single-tenant cloud service hosted and managed by Red Hat that offers high-availability enterprise-grade clusters in a virtual private cloud on AWS or GCP."
|
|
9
|
+
body="This is where custom content goes."
|
|
10
|
+
/>
|
|
11
|
+
);
|