@patternfly/react-core 4.199.0 → 4.199.1
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 +8 -0
- package/package.json +5 -5
- 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/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/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 4.199.1 (2022-03-16)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @patternfly/react-core
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# 4.199.0 (2022-03-15)
|
|
7
15
|
|
|
8
16
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "4.199.
|
|
3
|
+
"version": "4.199.1",
|
|
4
4
|
"description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
|
|
5
5
|
"main": "dist/js/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"generate": "node scripts/copyStyles.js"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@patternfly/react-icons": "^4.50.
|
|
38
|
-
"@patternfly/react-styles": "^4.49.
|
|
39
|
-
"@patternfly/react-tokens": "^4.51.
|
|
37
|
+
"@patternfly/react-icons": "^4.50.1",
|
|
38
|
+
"@patternfly/react-styles": "^4.49.1",
|
|
39
|
+
"@patternfly/react-tokens": "^4.51.1",
|
|
40
40
|
"focus-trap": "6.2.2",
|
|
41
41
|
"react-dropzone": "9.0.0",
|
|
42
42
|
"tippy.js": "5.1.2",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"react": "^16.8.0 || ^17.0.0",
|
|
61
61
|
"react-dom": "^16.8.0 || ^17.0.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "1cd7ab585c501674c2a1d741f460f73be08ad861"
|
|
64
64
|
}
|
|
@@ -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
|
+
);
|
|
@@ -8,145 +8,17 @@ ouia: true
|
|
|
8
8
|
|
|
9
9
|
## Examples
|
|
10
10
|
|
|
11
|
-
### Simple inline
|
|
11
|
+
### Simple inline
|
|
12
12
|
|
|
13
|
-
```
|
|
14
|
-
import React from 'react';
|
|
15
|
-
import { Chip, ChipGroup } from '@patternfly/react-core';
|
|
16
|
-
|
|
17
|
-
class SimpleInlineChipGroup extends React.Component {
|
|
18
|
-
constructor(props) {
|
|
19
|
-
super(props);
|
|
20
|
-
this.state = {
|
|
21
|
-
chips: ['Chip one', 'Really long chip that goes on and on', 'Chip three', 'Chip four', 'Chip five']
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
this.deleteItem = id => {
|
|
25
|
-
const copyOfChips = this.state.chips;
|
|
26
|
-
const index = copyOfChips.indexOf(id);
|
|
27
|
-
if (index !== -1) {
|
|
28
|
-
copyOfChips.splice(index, 1);
|
|
29
|
-
this.setState({ chips: copyOfChips });
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
render() {
|
|
35
|
-
const { chips } = this.state;
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<ChipGroup>
|
|
39
|
-
{chips.map(currentChip => (
|
|
40
|
-
<Chip key={currentChip} onClick={() => this.deleteItem(currentChip)}>
|
|
41
|
-
{currentChip}
|
|
42
|
-
</Chip>
|
|
43
|
-
))}
|
|
44
|
-
</ChipGroup>
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
13
|
+
```ts file='./ChipGroupInline.tsx'
|
|
48
14
|
```
|
|
49
15
|
|
|
50
|
-
###
|
|
51
|
-
|
|
52
|
-
```js
|
|
53
|
-
import React from 'react';
|
|
54
|
-
import { Chip, ChipGroup } from '@patternfly/react-core';
|
|
55
|
-
|
|
56
|
-
class SimpleCategoryChipGroup extends React.Component {
|
|
57
|
-
constructor(props) {
|
|
58
|
-
super(props);
|
|
59
|
-
this.state = {
|
|
60
|
-
chips: ['Chip one', 'Chip two', 'Chip three', 'Chip four', 'Chip five']
|
|
61
|
-
};
|
|
62
|
-
this.deleteItem = id => {
|
|
63
|
-
const copyOfChips = this.state.chips;
|
|
64
|
-
const index = copyOfChips.indexOf(id);
|
|
65
|
-
if (index !== -1) {
|
|
66
|
-
copyOfChips.splice(index, 1);
|
|
67
|
-
this.setState({ chips: copyOfChips });
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
render() {
|
|
73
|
-
const { chips } = this.state;
|
|
16
|
+
### With categories
|
|
74
17
|
|
|
75
|
-
|
|
76
|
-
<ChipGroup categoryName="Category one">
|
|
77
|
-
{chips.map(currentChip => (
|
|
78
|
-
<Chip key={currentChip} onClick={() => this.deleteItem(currentChip)}>
|
|
79
|
-
{currentChip}
|
|
80
|
-
</Chip>
|
|
81
|
-
))}
|
|
82
|
-
</ChipGroup>
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
18
|
+
```ts file='./ChipGroupWithCategories.tsx'
|
|
86
19
|
```
|
|
87
20
|
|
|
88
|
-
###
|
|
89
|
-
|
|
90
|
-
```js
|
|
91
|
-
import React from 'react';
|
|
92
|
-
import { Chip, ChipGroup } from '@patternfly/react-core';
|
|
93
|
-
|
|
94
|
-
class CategoryChipGroupRemovable extends React.Component {
|
|
95
|
-
constructor(props) {
|
|
96
|
-
super(props);
|
|
97
|
-
this.state = {
|
|
98
|
-
chips: ['Chip one', 'Chip two', 'Chip three'],
|
|
99
|
-
chips2: ['Chip one', 'Chip two', 'Chip three', 'Chip 4']
|
|
100
|
-
};
|
|
101
|
-
this.deleteItem = id => {
|
|
102
|
-
const copyOfChips = this.state.chips;
|
|
103
|
-
const index = copyOfChips.indexOf(id);
|
|
104
|
-
if (index !== -1) {
|
|
105
|
-
copyOfChips.splice(index, 1);
|
|
106
|
-
this.setState({ chips: copyOfChips });
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
this.deleteItem2 = id => {
|
|
111
|
-
const copyOfChips = this.state.chips2;
|
|
112
|
-
const index = copyOfChips.indexOf(id);
|
|
113
|
-
if (index !== -1) {
|
|
114
|
-
copyOfChips.splice(index, 1);
|
|
115
|
-
this.setState({ chips2: copyOfChips });
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
this.deleteCategory = () => {
|
|
120
|
-
this.setState({ chips: [] });
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
this.deleteCategory2 = () => {
|
|
124
|
-
this.setState({ chips2: [] });
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
render() {
|
|
129
|
-
const { chips, chips2 } = this.state;
|
|
21
|
+
### With removable categories
|
|
130
22
|
|
|
131
|
-
|
|
132
|
-
<React.Fragment>
|
|
133
|
-
<ChipGroup categoryName="Category one" isClosable onClick={this.deleteCategory}>
|
|
134
|
-
{chips.map(currentChip => (
|
|
135
|
-
<Chip key={currentChip} onClick={() => this.deleteItem(currentChip)}>
|
|
136
|
-
{currentChip}
|
|
137
|
-
</Chip>
|
|
138
|
-
))}
|
|
139
|
-
</ChipGroup>
|
|
140
|
-
<br /> <br />
|
|
141
|
-
<ChipGroup categoryName="Category two has a very long name" isClosable onClick={this.deleteCategory2}>
|
|
142
|
-
{chips2.map(currentChip => (
|
|
143
|
-
<Chip key={currentChip} onClick={() => this.deleteItem2(currentChip)}>
|
|
144
|
-
{currentChip}
|
|
145
|
-
</Chip>
|
|
146
|
-
))}
|
|
147
|
-
</ChipGroup>
|
|
148
|
-
</React.Fragment>
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
23
|
+
```ts file='./ChipGroupRemovableCategories.tsx'
|
|
152
24
|
```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Chip, ChipGroup } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const ChipGroupInline: React.FunctionComponent = () => {
|
|
5
|
+
const [chips, setChips] = React.useState([
|
|
6
|
+
'Chip one',
|
|
7
|
+
'Really long chip that goes on and on',
|
|
8
|
+
'Chip three',
|
|
9
|
+
'Chip four',
|
|
10
|
+
'Chip five'
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
const deleteItem = (id: string) => {
|
|
14
|
+
const copyOfChips = [...chips];
|
|
15
|
+
const filteredCopy = copyOfChips.filter(chip => chip !== id);
|
|
16
|
+
setChips(filteredCopy);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<ChipGroup>
|
|
21
|
+
{chips.map(currentChip => (
|
|
22
|
+
<Chip key={currentChip} onClick={() => deleteItem(currentChip)}>
|
|
23
|
+
{currentChip}
|
|
24
|
+
</Chip>
|
|
25
|
+
))}
|
|
26
|
+
</ChipGroup>
|
|
27
|
+
);
|
|
28
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Chip, ChipGroup } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const ChipGroupRemovableCategories: React.FunctionComponent = () => {
|
|
5
|
+
const [chipGroup1, setChipGroup1] = React.useState(['Chip one', 'Chip two', 'Chip three']);
|
|
6
|
+
const [chipGroup2, setChipGroup2] = React.useState(['Chip one', 'Chip two', 'Chip three', 'Chip four']);
|
|
7
|
+
|
|
8
|
+
const deleteItem = (id: string, group: string[]) => {
|
|
9
|
+
const copyOfChips = [...group];
|
|
10
|
+
const filteredCopy = copyOfChips.filter(chip => chip !== id);
|
|
11
|
+
|
|
12
|
+
if (group === chipGroup1) {
|
|
13
|
+
setChipGroup1(filteredCopy);
|
|
14
|
+
} else {
|
|
15
|
+
setChipGroup2(filteredCopy);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const deleteCategory = (group: string[]) => {
|
|
20
|
+
if (group === chipGroup1) {
|
|
21
|
+
setChipGroup1([]);
|
|
22
|
+
} else {
|
|
23
|
+
setChipGroup2([]);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<React.Fragment>
|
|
29
|
+
<ChipGroup categoryName="Category one" isClosable onClick={() => deleteCategory(chipGroup1)}>
|
|
30
|
+
{chipGroup1.map(currentChip => (
|
|
31
|
+
<Chip key={currentChip} onClick={() => deleteItem(currentChip, chipGroup1)}>
|
|
32
|
+
{currentChip}
|
|
33
|
+
</Chip>
|
|
34
|
+
))}
|
|
35
|
+
</ChipGroup>
|
|
36
|
+
<br /> <br />
|
|
37
|
+
<ChipGroup categoryName="Category two has a very long name" isClosable onClick={() => deleteCategory(chipGroup2)}>
|
|
38
|
+
{chipGroup2.map(currentChip => (
|
|
39
|
+
<Chip key={currentChip} onClick={() => deleteItem(currentChip, chipGroup2)}>
|
|
40
|
+
{currentChip}
|
|
41
|
+
</Chip>
|
|
42
|
+
))}
|
|
43
|
+
</ChipGroup>
|
|
44
|
+
</React.Fragment>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Chip, ChipGroup } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const ChipGroupWithCategories: React.FunctionComponent = () => {
|
|
5
|
+
const [chips, setChips] = React.useState([
|
|
6
|
+
'Chip one',
|
|
7
|
+
'Really long chip that goes on and on',
|
|
8
|
+
'Chip three',
|
|
9
|
+
'Chip four',
|
|
10
|
+
'Chip five'
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
const deleteItem = (id: string) => {
|
|
14
|
+
const copyOfChips = [...chips];
|
|
15
|
+
const filteredCopy = copyOfChips.filter(chip => chip !== id);
|
|
16
|
+
setChips(filteredCopy);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<ChipGroup categoryName="Category one">
|
|
21
|
+
{chips.map(currentChip => (
|
|
22
|
+
<Chip key={currentChip} onClick={() => deleteItem(currentChip)}>
|
|
23
|
+
{currentChip}
|
|
24
|
+
</Chip>
|
|
25
|
+
))}
|
|
26
|
+
</ChipGroup>
|
|
27
|
+
);
|
|
28
|
+
};
|