-
Notifications
You must be signed in to change notification settings - Fork 392
Expand file tree
/
Copy pathToggleGroupDemo.tsx
More file actions
115 lines (110 loc) · 3.32 KB
/
Copy pathToggleGroupDemo.tsx
File metadata and controls
115 lines (110 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { Component } from 'react';
import { ToggleGroup, ToggleGroupItem, ToggleGroupProps } from '@patternfly/react-core';
import UndoIcon from '@patternfly/react-icons/dist/esm/icons/undo-icon';
import RhUiCopyFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-copy-fill-icon';
import ShareSquareIcon from '@patternfly/react-icons/dist/esm/icons/share-square-icon';
interface ToggleGroupState {
isSelected: {
first: boolean;
second: boolean;
third: boolean;
fourth: boolean;
fifth: boolean;
sixth: boolean;
seventh: boolean;
};
}
export class ToggleGroupDemo extends Component<ToggleGroupProps, ToggleGroupState> {
static displayName = 'ToggleGroupDemo';
constructor(props: ToggleGroupProps) {
super(props);
this.state = {
isSelected: {
first: false,
second: false,
third: false,
fourth: false,
fifth: false,
sixth: false,
seventh: false
}
};
}
handleItemClick = (event: React.MouseEvent<any> | React.KeyboardEvent | MouseEvent, isSelected: boolean) => {
const id = event.currentTarget.id as 'first' | 'second' | 'third' | 'fourth' | 'fifth' | 'sixth' | 'seventh';
this.setState((prevState) => {
prevState.isSelected[id] = isSelected;
return {
isSelected: prevState.isSelected
};
});
};
render() {
const { isSelected } = this.state;
return (
<>
<ToggleGroup>
<ToggleGroupItem
text="Option 1"
key={0}
buttonId="first"
isSelected={isSelected.first}
onChange={this.handleItemClick}
/>
<ToggleGroupItem
text="Option 2"
key={1}
buttonId="second"
isSelected={isSelected.second}
onChange={this.handleItemClick}
/>
<ToggleGroupItem text="Option 3" key={2} buttonId="disabled" isDisabled />
</ToggleGroup>
<ToggleGroup>
<ToggleGroupItem
icon={<RhUiCopyFillIcon />}
key={3}
buttonId="third"
isSelected={isSelected.third}
onChange={this.handleItemClick}
aria-label="copy icon button"
/>
<ToggleGroupItem
icon={<UndoIcon />}
key={4}
buttonId="fourth"
isSelected={isSelected.fourth}
onChange={this.handleItemClick}
aria-label="undo icon button"
/>
<ToggleGroupItem
icon={<ShareSquareIcon />}
text="Share"
key={5}
buttonId="fifth"
isSelected={isSelected.fifth}
onChange={this.handleItemClick}
aria-label="share square icon button"
/>
</ToggleGroup>
<ToggleGroup isCompact>
<ToggleGroupItem
text="Option 1"
key={6}
buttonId="sixth"
isSelected={isSelected.sixth}
onChange={this.handleItemClick}
/>
<ToggleGroupItem
text="Option 2"
key={7}
buttonId="seventh"
isSelected={isSelected.seventh}
onChange={this.handleItemClick}
/>
<ToggleGroupItem icon={<RhUiCopyFillIcon />} text="Option 3" key={8} isDisabled />
</ToggleGroup>
</>
);
}
}