| 1 |
import { Fragment, useState } from 'react'; |
| 2 |
import { |
| 3 |
Card, |
| 4 |
CardTitle, |
| 5 |
CardBody, |
| 6 |
CardHeader, |
| 7 |
Title, |
| 8 |
Gallery, |
| 9 |
GalleryItem, |
| 10 |
Flex, |
| 11 |
FlexItem, |
| 12 |
Select, |
| 13 |
SelectList, |
| 14 |
SelectOption, |
| 15 |
MenuToggle, |
| 16 |
MenuToggleElement |
| 17 |
} from '@patternfly/react-core'; |
| 18 |
import { ChartArea, ChartGroup, ChartVoronoiContainer } from '@patternfly/react-charts/victory'; |
| 19 |
|
| 20 |
export const CardTrendDemo1: React.FunctionComponent = () => { |
| 21 |
const [isOpen, setIsOpen] = useState(false); |
| 22 |
|
| 23 |
const selectItems = ( |
| 24 |
<SelectList> |
| 25 |
<SelectOption key="option1" value="Last hour"> |
| 26 |
Last hour |
| 27 |
</SelectOption> |
| 28 |
<SelectOption key="option2" value="Last 6 hours"> |
| 29 |
Last 6 hours |
| 30 |
</SelectOption> |
| 31 |
<SelectOption key="option3" value="Last 24 hours"> |
| 32 |
Last 24 hours |
| 33 |
</SelectOption> |
| 34 |
<SelectOption key="option4" value="Last 7 days"> |
| 35 |
Last 7 days |
| 36 |
</SelectOption> |
| 37 |
</SelectList> |
| 38 |
); |
| 39 |
|
| 40 |
const toggle = (toggleRef: React.Ref<MenuToggleElement>) => ( |
| 41 |
<MenuToggle ref={toggleRef} onClick={() => setIsOpen(!isOpen)} isExpanded={isOpen} variant="plainText"> |
| 42 |
Filter |
| 43 |
</MenuToggle> |
| 44 |
); |
| 45 |
|
| 46 |
const headerActions = ( |
| 47 |
<Select onSelect={() => setIsOpen(!isOpen)} onOpenChange={setIsOpen} isOpen={isOpen} toggle={toggle}> |
| 48 |
{selectItems} |
| 49 |
</Select> |
| 50 |
); |
| 51 |
|
| 52 |
return ( |
| 53 |
<Fragment> |
| 54 |
<b>Note:</b> Custom CSS is used in this demo to align the card title and select toggle text to{' '} |
| 55 |
<code>baseline</code> alignment. |
| 56 |
<br /> |
| 57 |
<br /> |
| 58 |
<Gallery hasGutter minWidths={{ default: '360px' }}> |
| 59 |
<GalleryItem> |
| 60 |
<Card id="trend-card-1-card" component="div"> |
| 61 |
<CardHeader actions={{ actions: headerActions, hasNoOffset: true }}> |
| 62 |
<Flex direction={{ default: 'column' }} spaceItems={{ default: 'spaceItemsNone' }}> |
| 63 |
<FlexItem> |
| 64 |
<CardTitle> |
| 65 |
<Title headingLevel="h4" size="lg"> |
| 66 |
1,050,765 IOPS |
| 67 |
</Title> |
| 68 |
</CardTitle> |
| 69 |
</FlexItem> |
| 70 |
<FlexItem> |
| 71 |
<span>Workload</span> |
| 72 |
</FlexItem> |
| 73 |
</Flex> |
| 74 |
</CardHeader> |
| 75 |
<CardBody> |
| 76 |
<ChartGroup |
| 77 |
ariaDesc="Mock average cluster utilization" |
| 78 |
ariaTitle="Mock cluster sparkline chart" |
| 79 |
containerComponent={ |
| 80 |
<ChartVoronoiContainer labels={({ datum }) => `${datum.name}: ${datum.y}`} constrainToVisibleArea /> |
| 81 |
} |
| 82 |
height={100} |
| 83 |
maxDomain={{ y: 9 }} |
| 84 |
padding={0} |
| 85 |
width={400} |
| 86 |
> |
| 87 |
<ChartArea |
| 88 |
data={[ |
| 89 |
{ name: 'Cluster', x: '2015', y: 7 }, |
| 90 |
{ name: 'Cluster', x: '2016', y: 6 }, |
| 91 |
{ name: 'Cluster', x: '2017', y: 8 }, |
| 92 |
{ name: 'Cluster', x: '2018', y: 3 }, |
| 93 |
{ name: 'Cluster', x: '2019', y: 4 }, |
| 94 |
{ name: 'Cluster', x: '2020', y: 1 }, |
| 95 |
{ name: 'Cluster', x: '2021', y: 0 } |
| 96 |
]} |
| 97 |
/> |
| 98 |
</ChartGroup> |
| 99 |
</CardBody> |
| 100 |
</Card> |
| 101 |
</GalleryItem> |
| 102 |
</Gallery> |
| 103 |
</Fragment> |
| 104 |
); |
| 105 |
}; |