Debian Codegraph @

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

raw
1 import { Fragment, useState } from 'react';
2 import {
3 Card,
4 CardTitle,
5 CardHeader,
6 CardBody,
7 CardFooter,
8 Title,
9 Gallery,
10 GalleryItem,
11 Flex,
12 FlexItem,
13 Select,
14 SelectList,
15 SelectOption,
16 MenuToggle,
17 MenuToggleElement,
18 Icon
19 } from '@patternfly/react-core';
20 import RhUiErrorFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-error-fill-icon';
21 import { Chart, ChartStack, ChartBar, ChartTooltip } from '@patternfly/react-charts/victory';
22 import chart_color_yellow_100 from '@patternfly/react-tokens/dist/esm/chart_color_yellow_100';
23 import chart_color_yellow_300 from '@patternfly/react-tokens/dist/esm/chart_color_yellow_300';
24 import chart_color_orange_300 from '@patternfly/react-tokens/dist/esm/chart_color_orange_300';
25 import chart_color_red_orange_400 from '@patternfly/react-tokens/dist/esm/chart_color_red_orange_400';
26 import flex from '@patternfly/react-styles/css/utilities/Flex/flex';
27
28 export const CardUtilizationDemo3: React.FunctionComponent = () => {
29 const [isOpen, setIsOpen] = useState(false);
30
31 const selectItems = (
32 <SelectList>
33 <SelectOption key="option1" value="Last hour">
34 Last hour
35 </SelectOption>
36 <SelectOption key="option2" value="Last 6 hours">
37 Last 6 hours
38 </SelectOption>
39 <SelectOption key="option3" value="Last 24 hours">
40 Last 24 hours
41 </SelectOption>
42 <SelectOption key="option4" value="Last 7 days">
43 Last 7 days
44 </SelectOption>
45 </SelectList>
46 );
47
48 const toggle = (toggleRef: React.Ref<MenuToggleElement>) => (
49 <MenuToggle ref={toggleRef} onClick={() => setIsOpen(!isOpen)} isExpanded={isOpen} variant="plainText">
50 Filter
51 </MenuToggle>
52 );
53
54 const headerActions = (
55 <Select onSelect={() => setIsOpen(!isOpen)} onOpenChange={setIsOpen} isOpen={isOpen} toggle={toggle}>
56 {selectItems}
57 </Select>
58 );
59
60 return (
61 <Fragment>
62 <b>Note:</b> Custom CSS is used in this demo to align the card title and select toggle text to{' '}
63 <code>baseline</code> alignment.
64 <br />
65 <br />
66 <Gallery hasGutter minWidths={{ default: '360px' }}>
67 <GalleryItem>
68 <Card id="utilization-card-3-card" component="div">
69 <CardHeader className={flex.alignItemsFlexStart} actions={{ actions: headerActions, hasNoOffset: true }}>
70 <CardTitle>
71 <Title headingLevel="h4" size="lg" style={{ paddingTop: '3px' }}>
72 Recommendations
73 </Title>
74 </CardTitle>
75 </CardHeader>
76 <CardBody>
77 <Flex direction={{ default: 'column' }}>
78 <FlexItem>
79 <span>System</span>
80 </FlexItem>
81 <Flex>
82 <Icon status="danger">
83 <RhUiErrorFillIcon />
84 </Icon>
85 <a href="#">25 incidents detected</a>
86 </Flex>
87 <FlexItem>
88 <Chart
89 ariaDesc="Mock incidents chart"
90 ariaTitle="Mock stack chart"
91 domainPadding={{ x: [30, 25] }}
92 legendData={[
93 { name: 'Low', symbol: { fill: chart_color_yellow_100.value } },
94 { name: 'Important', symbol: { fill: chart_color_yellow_300.value } },
95 { name: 'Moderate', symbol: { fill: chart_color_orange_300.value } },
96 { name: 'Critical', symbol: { fill: chart_color_red_orange_400.value } }
97 ]}
98 legendPosition="bottom-left"
99 height={50}
100 padding={{
101 bottom: 40,
102 left: 0,
103 right: 0,
104 top: 0
105 }}
106 width={350}
107 showAxis={false}
108 >
109 <ChartStack
110 horizontal
111 colorScale={[
112 chart_color_yellow_100.value,
113 chart_color_yellow_300.value,
114 chart_color_orange_300.value,
115 chart_color_red_orange_400.value
116 ]}
117 >
118 <ChartBar
119 data={[
120 {
121 name: 'Low',
122 x: 'Cluster A',
123 y: 6,
124 label: 'Low: 6'
125 }
126 ]}
127 labelComponent={<ChartTooltip constrainToVisibleArea />}
128 />
129 <ChartBar
130 data={[
131 {
132 name: 'Important',
133 x: 'Cluster A',
134 y: 2,
135 label: 'Important: 2'
136 }
137 ]}
138 labelComponent={<ChartTooltip constrainToVisibleArea />}
139 />
140 <ChartBar
141 data={[
142 {
143 name: 'Moderate',
144 x: 'Cluster A',
145 y: 4,
146 label: 'Moderate: 4'
147 }
148 ]}
149 labelComponent={<ChartTooltip constrainToVisibleArea />}
150 />
151 <ChartBar
152 data={[
153 {
154 name: 'Critical',
155 x: 'Cluster A',
156 y: 2,
157 label: 'Critical: 2'
158 }
159 ]}
160 labelComponent={<ChartTooltip constrainToVisibleArea />}
161 />
162 </ChartStack>
163 </Chart>
164 </FlexItem>
165 </Flex>
166 </CardBody>
167 <CardFooter>
168 <a href="#">See details</a>
169 </CardFooter>
170 </Card>
171 </GalleryItem>
172 </Gallery>
173 </Fragment>
174 );
175 };