forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataListDemo.tsx
More file actions
160 lines (153 loc) · 5.33 KB
/
DataListDemo.tsx
File metadata and controls
160 lines (153 loc) · 5.33 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import { Component } from 'react';
import {
DataList,
DataListProps,
DataListItem,
DataListItemRow,
DataListItemCells,
DataListCell,
DataListAction,
DataListWrapModifier,
Dropdown,
DropdownItem,
DropdownList,
MenuToggle
} from '@patternfly/react-core';
import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon';
interface DataListState {
selectedDataListItemId: string;
isOpen: boolean;
}
class DataListDemo extends Component<DataListProps, DataListState> {
static displayName = 'DataListDemo';
constructor(props: DataListProps) {
super(props);
this.state = {
selectedDataListItemId: '',
isOpen: false
};
}
onSelectDataListItem = (_event: React.MouseEvent | React.KeyboardEvent, id: string) => {
this.setState({ selectedDataListItemId: id });
};
onToggle = () => {
this.setState((prevState) => ({
isOpen: !prevState.isOpen
}));
};
onSelect = () => {
this.setState({
isOpen: false
});
};
render() {
return (
<>
<DataList
aria-label="Simple data list example"
selectedDataListItemId={this.state.selectedDataListItemId}
onSelectDataListItem={this.onSelectDataListItem}
>
<DataListItem aria-labelledby="simple-item1" id="row1">
<DataListItemRow>
<DataListItemCells
dataListCells={[
<DataListCell key="primary content">
<span id="simple-item1">Primary content</span>
</DataListCell>,
<DataListCell key="secondary content">
<span id="simple-item2">Secondary content</span>
</DataListCell>
]}
/>
<DataListAction
aria-labelledby="selectable-action-item1 selectable-action-action1"
id="selectable-action-action1"
aria-label="Actions"
>
<Dropdown
id="dropdown"
isOpen={this.state.isOpen}
onSelect={this.onSelect}
onOpenChange={(isOpen) => this.setState({ isOpen })}
toggle={(toggleRef) => (
<MenuToggle
variant="plain"
ref={toggleRef}
isExpanded={this.state.isOpen}
onClick={this.onToggle}
icon={<EllipsisVIcon />}
/>
)}
>
<DropdownList>
<DropdownItem key="link">Link</DropdownItem>
<DropdownItem key="action">Action</DropdownItem>
<DropdownItem key="disabled link" isDisabled>
Disabled Link
</DropdownItem>
</DropdownList>
</Dropdown>
</DataListAction>
</DataListItemRow>
</DataListItem>
<DataListItem aria-labelledby="simple-item2" id="row2">
<DataListItemRow>
<DataListItemCells
dataListCells={[
<DataListCell isFilled={false} key="secondary content fill">
<span id="simple-item3">Secondary content (pf-m-no-fill)</span>
</DataListCell>,
<DataListCell isFilled={false} alignRight key="secondary content align">
<span id="simple-item4">Secondary content (pf-m-align-right pf-m-no-fill)</span>
</DataListCell>
]}
/>
</DataListItemRow>
</DataListItem>
<DataListItem aria-labelledby="simple-item3">
<DataListItemRow>
<DataListItemCells
dataListCells={[
<DataListCell key="primary content" wrapModifier={DataListWrapModifier.breakWord}>
<span id="simple-item1">Primary content</span>
</DataListCell>,
<DataListCell
id="truncate-content"
key="secondary content"
wrapModifier={DataListWrapModifier.truncate}
>
Really really really really really really really really really really really really really really
really really really really really really really really really really really really really really
long description that should be truncated before it ends
</DataListCell>
]}
/>
</DataListItemRow>
</DataListItem>
</DataList>
<br />
<DataList
data-testid="data-list-glass-plain-both"
aria-label="Data list for glass theme integration test"
isPlain
isNoPlainOnGlass
>
<DataListItem aria-labelledby="glass-plain-item1">
<DataListItemRow>
<DataListItemCells
dataListCells={[
<DataListCell key="primary">
<span id="glass-plain-item1">Glass theme: isPlain and isNoPlainOnGlass</span>
</DataListCell>
]}
/>
</DataListItemRow>
</DataListItem>
</DataList>
</>
);
}
}
DataListDemo.displayName = 'DataListDemo';
export { DataListDemo };