Debian Codegraph @

node/@patternfly/react-core/src/demos/examples/Card/CardHorizontalGrid.tsx

raw
1 import { useState } from 'react';
2 import {
3 Card,
4 CardHeader,
5 CardTitle,
6 CardBody,
7 CardExpandableContent,
8 Level,
9 LabelGroup,
10 Label,
11 LabelColor,
12 Grid,
13 Flex,
14 List,
15 ListItem,
16 Button,
17 Dropdown,
18 DropdownList,
19 DropdownItem,
20 MenuToggle,
21 MenuToggleElement
22 } from '@patternfly/react-core';
23 import RhUiInformationFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-information-fill-icon';
24 import RhMicronsCaretRightIcon from '@patternfly/react-icons/dist/esm/icons/rh-microns-caret-right-icon';
25 import RhMicronsExternalLinkIcon from '@patternfly/react-icons/dist/esm/icons/rh-microns-external-link-icon';
26 import RhUiEllipsisVerticalFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-ellipsis-vertical-fill-icon';
27
28 export const CardHorizontalGrid: React.FunctionComponent = () => {
29 const [isCardExpanded, setIsCardExpanded] = useState(false);
30 const [isDropdownOpen, setIsDropdownOpen] = useState(false);
31
32 const onCardExpand = () => {
33 setIsCardExpanded(!isCardExpanded);
34 };
35
36 const onActionToggle = () => {
37 setIsDropdownOpen(!isDropdownOpen);
38 };
39
40 const onActionSelect = () => {
41 setIsDropdownOpen(false);
42 };
43
44 const dropdownItems = (
45 <>
46 <DropdownItem key="action1">Action 1</DropdownItem>
47 <DropdownItem key="action2">Action 2</DropdownItem>
48 <DropdownItem key="disabled action3" isDisabled>
49 Disabled Action 3
50 </DropdownItem>
51 <DropdownItem key="action4">Action 4</DropdownItem>
52 </>
53 );
54 const headerActions = (
55 <Dropdown
56 onSelect={onActionSelect}
57 isOpen={isDropdownOpen}
58 popperProps={{ position: 'right' }}
59 onOpenChange={(isOpen: boolean) => setIsDropdownOpen(isOpen)}
60 toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
61 <MenuToggle
62 ref={toggleRef}
63 isExpanded={isDropdownOpen}
64 onClick={onActionToggle}
65 variant="plain"
66 aria-label="Horizontal card grid demo kebab toggle"
67 icon={<RhUiEllipsisVerticalFillIcon />}
68 />
69 )}
70 >
71 <DropdownList>{dropdownItems}</DropdownList>
72 </Dropdown>
73 );
74
75 return (
76 <Card id="horizontal card" isExpanded={isCardExpanded}>
77 <CardHeader
78 actions={{ actions: headerActions }}
79 onExpand={onCardExpand}
80 toggleButtonProps={{
81 id: 'toggle-button',
82 'aria-label': 'Actions',
83 'aria-labelledby': 'titleId toggle-button',
84 'aria-expanded': isCardExpanded
85 }}
86 >
87 {isCardExpanded && <CardTitle id="titleId">Getting Started</CardTitle>}
88 {!isCardExpanded && (
89 <Level hasGutter>
90 <CardTitle id="titleId">Getting Started</CardTitle>
91 <LabelGroup isCompact>
92 <Label isCompact icon={<RhUiInformationFillIcon />} color={LabelColor.blue}>
93 Set up your cluster
94 </Label>
95 <Label isCompact icon={<RhUiInformationFillIcon />} color={LabelColor.purple}>
96 Guided tours
97 </Label>
98 <Label isCompact icon={<RhUiInformationFillIcon />} color={LabelColor.green}>
99 Quick starts
100 </Label>
101 <Label isCompact icon={<RhUiInformationFillIcon />} color={LabelColor.orange}>
102 Learning resources
103 </Label>
104 </LabelGroup>
105 </Level>
106 )}
107 </CardHeader>
108 <CardExpandableContent>
109 <CardBody>
110 <Grid md={6} lg={3} hasGutter>
111 <Flex
112 spaceItems={{ default: 'spaceItemsLg' }}
113 alignItems={{ default: 'alignItemsFlexStart' }}
114 direction={{ default: 'column' }}
115 >
116 <Flex
117 spaceItems={{ default: 'spaceItemsSm' }}
118 alignItems={{ default: 'alignItemsFlexStart' }}
119 direction={{ default: 'column' }}
120 grow={{ default: 'grow' }}
121 >
122 <Label icon={<RhUiInformationFillIcon />} color={LabelColor.blue}>
123 Set up your cluster
124 </Label>
125 <p>Continue setting up your cluster to access all you cain in the Console</p>
126 <List isPlain>
127 <ListItem>
128 <a href="#">Add identity provider</a>
129 </ListItem>
130 <ListItem>
131 <a href="#">Configure alert receivers</a>
132 </ListItem>
133 <ListItem>
134 <a href="#">Configure default ingress certificate</a>
135 </ListItem>
136 </List>
137 </Flex>
138 <Button
139 href="#"
140 component="a"
141 variant="link"
142 isInline
143 icon={<RhMicronsCaretRightIcon />}
144 iconPosition="right"
145 >
146 View all set up cluster steps
147 </Button>
148 </Flex>
149 <Flex
150 spaceItems={{ default: 'spaceItemsLg' }}
151 alignItems={{ default: 'alignItemsFlexStart' }}
152 direction={{ default: 'column' }}
153 >
154 <Flex
155 spaceItems={{ default: 'spaceItemsSm' }}
156 alignItems={{ default: 'alignItemsFlexStart' }}
157 direction={{ default: 'column' }}
158 grow={{ default: 'grow' }}
159 >
160 <Label icon={<RhUiInformationFillIcon />} color={LabelColor.purple}>
161 Guided tours
162 </Label>
163 <p>Tour some of the key features around the console</p>
164 <List isPlain>
165 <ListItem>
166 <a href="#">Tour the console</a>
167 </ListItem>
168 <ListItem>
169 <a href="#">Getting started with Serverless</a>
170 </ListItem>
171 </List>
172 </Flex>
173 <Button
174 href="#"
175 component="a"
176 variant="link"
177 isInline
178 icon={<RhMicronsCaretRightIcon />}
179 iconPosition="right"
180 >
181 View all guided tours
182 </Button>
183 </Flex>
184 <Flex
185 spaceItems={{ default: 'spaceItemsLg' }}
186 alignItems={{ default: 'alignItemsFlexStart' }}
187 direction={{ default: 'column' }}
188 >
189 <Flex
190 spaceItems={{ default: 'spaceItemsSm' }}
191 alignItems={{ default: 'alignItemsFlexStart' }}
192 direction={{ default: 'column' }}
193 grow={{ default: 'grow' }}
194 >
195 <Label icon={<RhUiInformationFillIcon />} color={LabelColor.green}>
196 Quick starts
197 </Label>
198 <p>Get started with features using our step-by-step documentation</p>
199 <List isPlain>
200 <ListItem>
201 <a href="#">Getting started with Serverless</a>
202 </ListItem>
203 <ListItem>
204 <a href="#">Explore virtualization</a>
205 </ListItem>
206 <ListItem>
207 <a href="#">Build pipelines</a>
208 </ListItem>
209 </List>
210 </Flex>
211 <Button
212 href="#"
213 component="a"
214 variant="link"
215 isInline
216 icon={<RhMicronsCaretRightIcon />}
217 iconPosition="right"
218 >
219 View all quick starts
220 </Button>
221 </Flex>
222 <Flex
223 spaceItems={{ default: 'spaceItemsLg' }}
224 alignItems={{ default: 'alignItemsFlexStart' }}
225 direction={{ default: 'column' }}
226 >
227 <Flex
228 spaceItems={{ default: 'spaceItemsSm' }}
229 alignItems={{ default: 'alignItemsFlexStart' }}
230 direction={{ default: 'column' }}
231 grow={{ default: 'grow' }}
232 >
233 <Label icon={<RhUiInformationFillIcon />} color={LabelColor.orange}>
234 Learning resources
235 </Label>
236 <p>Learn about new features within the Console and get started with demo apps</p>
237 <List isPlain>
238 <ListItem>
239 <a href="#">See what's possible with the Explore page</a>
240 </ListItem>
241 <ListItem>
242 <a href="#">
243 OpenShift 4.5: Top Tasks
244 <RhMicronsExternalLinkIcon />
245 </a>
246 </ListItem>
247 <ListItem>
248 <a href="#">Try a demo app</a>
249 </ListItem>
250 </List>
251 </Flex>
252 <Button
253 href="#"
254 component="a"
255 variant="link"
256 isInline
257 icon={<RhMicronsCaretRightIcon />}
258 iconPosition="right"
259 >
260 View all learning resources
261 </Button>
262 </Flex>
263 </Grid>
264 </CardBody>
265 </CardExpandableContent>
266 </Card>
267 );
268 };