Debian Codegraph @

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

raw
1 import { useState } from 'react';
2 import {
3 Card,
4 CardBody,
5 CardHeader,
6 DescriptionList,
7 DescriptionListDescription,
8 DescriptionListGroup,
9 DescriptionListTerm,
10 Flex,
11 FlexItem,
12 Icon,
13 Tab,
14 TabContent,
15 Tabs,
16 TabTitleText,
17 Title
18 } from '@patternfly/react-core';
19 import RhUiCheckCircleFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-check-circle-fill-icon';
20 import RhUiErrorFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-error-fill-icon';
21
22 const descriptionListData = [
23 {
24 status: 'Running',
25 resourceName: 'Resource name that is long and can wrap',
26 detail: '121 Systems',
27 icon: (
28 <Icon status="success">
29 <RhUiCheckCircleFillIcon />
30 </Icon>
31 )
32 },
33 {
34 status: 'Failed',
35 resourceName: 'Resource name that is long and can wrap',
36 detail: '123 Systems',
37 icon: (
38 <Icon status="danger">
39 <RhUiErrorFillIcon />
40 </Icon>
41 )
42 },
43 {
44 status: 'Running',
45 resourceName: 'Resource name that is long and can wrap',
46 detail: '122 Systems',
47 icon: (
48 <Icon status="success">
49 <RhUiCheckCircleFillIcon />
50 </Icon>
51 )
52 },
53 {
54 status: 'Failed',
55 resourceName: 'Resource name that is long and can wrap',
56 detail: '124 Systems',
57 icon: (
58 <Icon status="danger">
59 <RhUiErrorFillIcon />
60 </Icon>
61 )
62 }
63 ];
64
65 export const CardStatusTabbed: React.FunctionComponent = () => {
66 const [activeTabKey, setActiveTabKey] = useState(0);
67 const handleTabClick = (_e: React.MouseEvent<HTMLElement, MouseEvent>, tabIndex: string | number) => {
68 setActiveTabKey(Number(tabIndex));
69 };
70
71 const tabContent = (tabIndex: number) => (
72 <DescriptionList isHorizontal columnModifier={{ lg: '2Col' }} aria-label={`Object ${tabIndex + 1} status`}>
73 {descriptionListData.map(({ status, resourceName, detail, icon }, index) => (
74 <DescriptionListGroup key={index}>
75 <DescriptionListTerm>
76 <Flex>
77 <FlexItem>{icon}</FlexItem>
78 <FlexItem>
79 <Title headingLevel="h4" size="md">
80 {status}
81 </Title>
82 </FlexItem>
83 </Flex>
84 </DescriptionListTerm>
85 <DescriptionListDescription>
86 <a href="#">{resourceName}</a>
87 <div>{detail}</div>
88 </DescriptionListDescription>
89 </DescriptionListGroup>
90 ))}
91 </DescriptionList>
92 );
93
94 return (
95 <>
96 <Card>
97 <CardHeader>
98 <Title headingLevel="h4" size="lg">
99 Status
100 </Title>
101 </CardHeader>
102 <CardBody>
103 <Tabs isFilled id="status-tabs" activeKey={activeTabKey} onSelect={handleTabClick}>
104 {[1, 2, 3].map((tab, tabIndex) => (
105 <Tab
106 key={tabIndex}
107 eventKey={tabIndex}
108 title={<TabTitleText>{`Object ${tabIndex + 1}`}</TabTitleText>}
109 tabContentId={`tabContent${tabIndex}`}
110 />
111 ))}
112 </Tabs>
113 </CardBody>
114 <CardBody>
115 {[1, 2, 3].map((tab, tabIndex) => (
116 <TabContent
117 key={tabIndex}
118 eventKey={tabIndex}
119 id={`tabContent${tabIndex}`}
120 activeKey={activeTabKey}
121 hidden={tabIndex !== activeTabKey}
122 >
123 {tabContent(tabIndex)}
124 </TabContent>
125 ))}
126 </CardBody>
127 </Card>
128 </>
129 );
130 };