| 1 |
import { Fragment, useState } from 'react'; |
| 2 |
import { |
| 3 |
Button, |
| 4 |
ButtonVariant, |
| 5 |
Content, |
| 6 |
DataList, |
| 7 |
DataListAction, |
| 8 |
DataListCell, |
| 9 |
DataListItem, |
| 10 |
DataListItemCells, |
| 11 |
DataListItemRow, |
| 12 |
Toolbar, |
| 13 |
ToolbarItem, |
| 14 |
ToolbarContent, |
| 15 |
ToolbarToggleGroup, |
| 16 |
ToolbarGroup, |
| 17 |
Divider, |
| 18 |
Drawer, |
| 19 |
DrawerActions, |
| 20 |
DrawerCloseButton, |
| 21 |
DrawerContent, |
| 22 |
DrawerContentBody, |
| 23 |
DrawerHead, |
| 24 |
DrawerPanelBody, |
| 25 |
DrawerPanelContent, |
| 26 |
Flex, |
| 27 |
FlexItem, |
| 28 |
InputGroup, |
| 29 |
InputGroupItem, |
| 30 |
PageSection, |
| 31 |
Progress, |
| 32 |
Stack, |
| 33 |
StackItem, |
| 34 |
TextInput, |
| 35 |
Title, |
| 36 |
Select, |
| 37 |
SelectOption, |
| 38 |
SelectOptionProps, |
| 39 |
MenuToggle |
| 40 |
} from '@patternfly/react-core'; |
| 41 |
import { DashboardWrapper } from '@patternfly/react-core/dist/js/demos/DashboardWrapper'; |
| 42 |
import RhUiCodeIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-code-icon'; |
| 43 |
import RhUiBranchFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-branch-fill-icon'; |
| 44 |
import CubeIcon from '@patternfly/react-icons/dist/esm/icons/cube-icon'; |
| 45 |
import RhUiCheckCircleFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-check-circle-fill-icon'; |
| 46 |
import RhUiWarningFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-warning-fill-icon'; |
| 47 |
import FilterIcon from '@patternfly/react-icons/dist/esm/icons/filter-icon'; |
| 48 |
import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon'; |
| 49 |
import TimesCircleIcon from '@patternfly/react-icons/dist/esm/icons/times-circle-icon'; |
| 50 |
|
| 51 |
interface SelectOptionType extends Omit<SelectOptionProps, 'children'> { |
| 52 |
label: string; |
| 53 |
} |
| 54 |
|
| 55 |
const statusOptions: SelectOptionType[] = [ |
| 56 |
{ value: 'New', label: 'New' }, |
| 57 |
{ value: 'Pending', label: 'Pending' }, |
| 58 |
{ value: 'Running', label: 'Running' }, |
| 59 |
{ value: 'Cancelled', label: 'Cancelled' } |
| 60 |
]; |
| 61 |
|
| 62 |
const riskOptions: SelectOptionType[] = [ |
| 63 |
{ value: 'Low', label: 'Low' }, |
| 64 |
{ value: 'Medium', label: 'Medium' }, |
| 65 |
{ value: 'High', label: 'High' } |
| 66 |
]; |
| 67 |
|
| 68 |
export const PrimaryDetailFullPage: React.FunctionComponent = () => { |
| 69 |
const [isDrawerExpanded, setIsDrawerExpanded] = useState(false); |
| 70 |
const [drawerPanelBodyContent, setDrawerPanelBodyContent] = useState(''); |
| 71 |
const [inputValue, setInputValue] = useState(''); |
| 72 |
const [statusIsOpen, setStatusIsOpen] = useState(false); |
| 73 |
const [statusSelected, setStatusSelected] = useState<string | number | undefined>('Status'); |
| 74 |
const [riskIsOpen, setRiskIsOpen] = useState(false); |
| 75 |
const [riskSelected, setRiskSelected] = useState<string | number | undefined>('Risk'); |
| 76 |
const [selectedDataListItemId, setSelectedDataListItemId] = useState(''); |
| 77 |
|
| 78 |
const onStatusSelect = (_event: React.MouseEvent<Element> | undefined, value: string | number | undefined) => { |
| 79 |
setStatusSelected(value); |
| 80 |
setStatusIsOpen(false); |
| 81 |
}; |
| 82 |
|
| 83 |
const onRiskSelect = (_event: React.MouseEvent<Element> | undefined, value: string | number | undefined) => { |
| 84 |
setRiskSelected(value); |
| 85 |
setRiskIsOpen(false); |
| 86 |
}; |
| 87 |
|
| 88 |
const onSelectDataListItem = ( |
| 89 |
_event: React.MouseEvent<Element, MouseEvent> | React.KeyboardEvent<Element>, |
| 90 |
id: string |
| 91 |
) => { |
| 92 |
setSelectedDataListItemId(id); |
| 93 |
setIsDrawerExpanded(true); |
| 94 |
setDrawerPanelBodyContent(id.charAt(id.length - 1)); |
| 95 |
}; |
| 96 |
|
| 97 |
const onCloseDrawerClick = (_event: React.MouseEvent<HTMLDivElement>) => { |
| 98 |
setIsDrawerExpanded(false); |
| 99 |
setSelectedDataListItemId(''); |
| 100 |
}; |
| 101 |
|
| 102 |
const toggleGroupItems = ( |
| 103 |
<Flex alignItems={{ default: 'alignItemsCenter' }}> |
| 104 |
<ToolbarItem> |
| 105 |
<InputGroup> |
| 106 |
<InputGroupItem isFill> |
| 107 |
<TextInput |
| 108 |
name="full-page-data-toolbar-input1" |
| 109 |
id="full-page-data-toolbar-input1" |
| 110 |
type="search" |
| 111 |
aria-label="search input example" |
| 112 |
onChange={(_event: React.FormEvent<HTMLInputElement>, value: string) => setInputValue(value)} |
| 113 |
value={inputValue} |
| 114 |
/> |
| 115 |
</InputGroupItem> |
| 116 |
<InputGroupItem> |
| 117 |
<Button variant={ButtonVariant.control} aria-label="search button for search input" icon={<SearchIcon />} /> |
| 118 |
</InputGroupItem> |
| 119 |
</InputGroup> |
| 120 |
</ToolbarItem> |
| 121 |
<ToolbarGroup variant="filter-group"> |
| 122 |
<ToolbarItem> |
| 123 |
<Select |
| 124 |
aria-label="Status select" |
| 125 |
selected={statusSelected} |
| 126 |
isOpen={statusIsOpen} |
| 127 |
toggle={(toggleRef) => ( |
| 128 |
<MenuToggle |
| 129 |
ref={toggleRef} |
| 130 |
onClick={() => setStatusIsOpen((prevIsOpen) => !prevIsOpen)} |
| 131 |
isExpanded={statusIsOpen} |
| 132 |
> |
| 133 |
{statusSelected} |
| 134 |
</MenuToggle> |
| 135 |
)} |
| 136 |
onOpenChange={(isOpen: boolean) => setStatusIsOpen(isOpen)} |
| 137 |
onSelect={onStatusSelect} |
| 138 |
> |
| 139 |
{statusOptions.map(({ label, value }) => ( |
| 140 |
<SelectOption key={label} value={value}> |
| 141 |
{label} |
| 142 |
</SelectOption> |
| 143 |
))} |
| 144 |
</Select> |
| 145 |
</ToolbarItem> |
| 146 |
<ToolbarItem> |
| 147 |
<Select |
| 148 |
aria-label="Risk select" |
| 149 |
selected={riskSelected} |
| 150 |
isOpen={riskIsOpen} |
| 151 |
toggle={(toggleRef) => ( |
| 152 |
<MenuToggle |
| 153 |
ref={toggleRef} |
| 154 |
onClick={() => setRiskIsOpen((prevIsOpen) => !prevIsOpen)} |
| 155 |
isExpanded={riskIsOpen} |
| 156 |
> |
| 157 |
{riskSelected} |
| 158 |
</MenuToggle> |
| 159 |
)} |
| 160 |
onOpenChange={(isOpen: boolean) => setRiskIsOpen(isOpen)} |
| 161 |
onSelect={onRiskSelect} |
| 162 |
> |
| 163 |
{riskOptions.map(({ label, value }) => ( |
| 164 |
<SelectOption key={label} value={value}> |
| 165 |
{label} |
| 166 |
</SelectOption> |
| 167 |
))} |
| 168 |
</Select> |
| 169 |
</ToolbarItem> |
| 170 |
</ToolbarGroup> |
| 171 |
</Flex> |
| 172 |
); |
| 173 |
|
| 174 |
const ToolbarItems = ( |
| 175 |
<ToolbarToggleGroup toggleIcon={<FilterIcon />} breakpoint="xl"> |
| 176 |
{toggleGroupItems} |
| 177 |
</ToolbarToggleGroup> |
| 178 |
); |
| 179 |
|
| 180 |
const panelContent = ( |
| 181 |
<DrawerPanelContent> |
| 182 |
<DrawerHead> |
| 183 |
<Title headingLevel="h2" size="xl"> |
| 184 |
node-{drawerPanelBodyContent} |
| 185 |
</Title> |
| 186 |
<DrawerActions> |
| 187 |
<DrawerCloseButton onClick={onCloseDrawerClick} /> |
| 188 |
</DrawerActions> |
| 189 |
</DrawerHead> |
| 190 |
<DrawerPanelBody> |
| 191 |
<Flex spaceItems={{ default: 'spaceItemsLg' }} direction={{ default: 'column' }}> |
| 192 |
<FlexItem> |
| 193 |
<p> |
| 194 |
The content of the drawer really is up to you. It could have form fields, definition lists, text lists, |
| 195 |
labels, charts, progress bars, etc. Spacing recommendation is 24px margins. You can put tabs in here, and |
| 196 |
can also make the drawer scrollable. |
| 197 |
</p> |
| 198 |
</FlexItem> |
| 199 |
<FlexItem> |
| 200 |
<Progress value={parseInt(drawerPanelBodyContent) * 10} title="Title" /> |
| 201 |
</FlexItem> |
| 202 |
<FlexItem> |
| 203 |
<Progress value={parseInt(drawerPanelBodyContent) * 5} title="Title" /> |
| 204 |
</FlexItem> |
| 205 |
</Flex> |
| 206 |
</DrawerPanelBody> |
| 207 |
</DrawerPanelContent> |
| 208 |
); |
| 209 |
|
| 210 |
const drawerContent = ( |
| 211 |
<Fragment> |
| 212 |
<Toolbar id="full-page-data-toolbar"> |
| 213 |
<ToolbarContent>{ToolbarItems}</ToolbarContent> |
| 214 |
</Toolbar> |
| 215 |
<DataList |
| 216 |
aria-label="data list" |
| 217 |
selectedDataListItemId={selectedDataListItemId} |
| 218 |
onSelectDataListItem={onSelectDataListItem} |
| 219 |
> |
| 220 |
<DataListItem id="full-page-item1"> |
| 221 |
<DataListItemRow> |
| 222 |
<DataListItemCells |
| 223 |
dataListCells={[ |
| 224 |
<DataListCell key="primary-content"> |
| 225 |
<Flex spaceItems={{ default: 'spaceItemsMd' }} direction={{ default: 'column' }}> |
| 226 |
<FlexItem> |
| 227 |
<p>patternfly</p> |
| 228 |
<small> |
| 229 |
Working repo for PatternFly 5 <a>https://pf5.patternfly.org/</a> |
| 230 |
</small> |
| 231 |
</FlexItem> |
| 232 |
<Flex spaceItems={{ default: 'spaceItemsMd' }}> |
| 233 |
<FlexItem> |
| 234 |
<RhUiBranchFillIcon /> 10 |
| 235 |
</FlexItem> |
| 236 |
<FlexItem> |
| 237 |
<RhUiCodeIcon /> 4 |
| 238 |
</FlexItem> |
| 239 |
<FlexItem> |
| 240 |
<CubeIcon /> 5 |
| 241 |
</FlexItem> |
| 242 |
<FlexItem>Updated 2 days ago</FlexItem> |
| 243 |
</Flex> |
| 244 |
</Flex> |
| 245 |
</DataListCell>, |
| 246 |
<DataListAction |
| 247 |
key="actions" |
| 248 |
aria-labelledby="full-page-item1 full-page-action1" |
| 249 |
id="full-page-action1" |
| 250 |
aria-label="Actions" |
| 251 |
> |
| 252 |
<Stack> |
| 253 |
<StackItem> |
| 254 |
<Button variant={ButtonVariant.secondary}>Secondary</Button> |
| 255 |
</StackItem> |
| 256 |
<StackItem> |
| 257 |
<Button variant={ButtonVariant.link}>Link Button</Button> |
| 258 |
</StackItem> |
| 259 |
</Stack> |
| 260 |
</DataListAction> |
| 261 |
]} |
| 262 |
/> |
| 263 |
</DataListItemRow> |
| 264 |
</DataListItem> |
| 265 |
<DataListItem id="full-page-item2"> |
| 266 |
<DataListItemRow> |
| 267 |
<DataListItemCells |
| 268 |
dataListCells={[ |
| 269 |
<DataListCell key="primary-content"> |
| 270 |
<Flex spaceItems={{ default: 'spaceItemsMd' }} direction={{ default: 'column' }}> |
| 271 |
<FlexItem> |
| 272 |
<p>patternfly-elements</p> |
| 273 |
<small>PatternFly elements</small> |
| 274 |
</FlexItem> |
| 275 |
<Flex spaceItems={{ default: 'spaceItemsMd' }}> |
| 276 |
<FlexItem> |
| 277 |
<RhUiBranchFillIcon /> 10 |
| 278 |
</FlexItem> |
| 279 |
<FlexItem> |
| 280 |
<RhUiCodeIcon /> 4 |
| 281 |
</FlexItem> |
| 282 |
<FlexItem> |
| 283 |
<CubeIcon /> 5 |
| 284 |
</FlexItem> |
| 285 |
<FlexItem> |
| 286 |
<RhUiCheckCircleFillIcon /> 7 |
| 287 |
</FlexItem> |
| 288 |
<FlexItem> |
| 289 |
<RhUiWarningFillIcon /> 5 |
| 290 |
</FlexItem> |
| 291 |
<FlexItem> |
| 292 |
<TimesCircleIcon /> 5 |
| 293 |
</FlexItem> |
| 294 |
<FlexItem>Updated 2 days ago</FlexItem> |
| 295 |
</Flex> |
| 296 |
</Flex> |
| 297 |
</DataListCell>, |
| 298 |
<DataListAction |
| 299 |
key="actions" |
| 300 |
aria-labelledby="full-page-item2 full-page-action2" |
| 301 |
id="full-page-action2" |
| 302 |
aria-label="Actions" |
| 303 |
> |
| 304 |
<Stack> |
| 305 |
<StackItem> |
| 306 |
<Button variant={ButtonVariant.secondary}>Secondary</Button> |
| 307 |
</StackItem> |
| 308 |
<StackItem> |
| 309 |
<Button variant={ButtonVariant.link}>Link Button</Button> |
| 310 |
</StackItem> |
| 311 |
</Stack> |
| 312 |
</DataListAction> |
| 313 |
]} |
| 314 |
/> |
| 315 |
</DataListItemRow> |
| 316 |
</DataListItem> |
| 317 |
<DataListItem id="full-page-item3"> |
| 318 |
<DataListItemRow> |
| 319 |
<DataListItemCells |
| 320 |
dataListCells={[ |
| 321 |
<DataListCell key="primary-content"> |
| 322 |
<Flex spaceItems={{ default: 'spaceItemsMd' }} direction={{ default: 'column' }}> |
| 323 |
<FlexItem> |
| 324 |
<p>patternfly</p> |
| 325 |
<small> |
| 326 |
Working repo for PatternFly 5 <a>https://pf5.patternfly.org/</a> |
| 327 |
</small> |
| 328 |
</FlexItem> |
| 329 |
<Flex spaceItems={{ default: 'spaceItemsMd' }}> |
| 330 |
<FlexItem> |
| 331 |
<RhUiBranchFillIcon /> 10 |
| 332 |
</FlexItem> |
| 333 |
<FlexItem> |
| 334 |
<RhUiCodeIcon /> 4 |
| 335 |
</FlexItem> |
| 336 |
<FlexItem> |
| 337 |
<CubeIcon /> 5 |
| 338 |
</FlexItem> |
| 339 |
<FlexItem>Updated 2 days ago</FlexItem> |
| 340 |
</Flex> |
| 341 |
</Flex> |
| 342 |
</DataListCell>, |
| 343 |
<DataListAction |
| 344 |
key="actions" |
| 345 |
aria-labelledby="full-page-item3 full-page-action3" |
| 346 |
id="full-page-action3" |
| 347 |
aria-label="Actions" |
| 348 |
> |
| 349 |
<Stack> |
| 350 |
<StackItem> |
| 351 |
<Button variant={ButtonVariant.secondary}>Secondary</Button> |
| 352 |
</StackItem> |
| 353 |
<StackItem> |
| 354 |
<Button variant={ButtonVariant.link}>Link Button</Button> |
| 355 |
</StackItem> |
| 356 |
</Stack> |
| 357 |
</DataListAction> |
| 358 |
]} |
| 359 |
/> |
| 360 |
</DataListItemRow> |
| 361 |
</DataListItem> |
| 362 |
<DataListItem id="full-page-item4"> |
| 363 |
<DataListItemRow> |
| 364 |
<DataListItemCells |
| 365 |
dataListCells={[ |
| 366 |
<DataListCell key="primary-content"> |
| 367 |
<Flex spaceItems={{ default: 'spaceItemsMd' }} direction={{ default: 'column' }}> |
| 368 |
<FlexItem> |
| 369 |
<p>patternfly-elements</p> |
| 370 |
<small>PatternFly elements</small> |
| 371 |
</FlexItem> |
| 372 |
<Flex spaceItems={{ default: 'spaceItemsMd' }}> |
| 373 |
<FlexItem> |
| 374 |
<RhUiBranchFillIcon /> 10 |
| 375 |
</FlexItem> |
| 376 |
<FlexItem> |
| 377 |
<RhUiCodeIcon /> 4 |
| 378 |
</FlexItem> |
| 379 |
<FlexItem> |
| 380 |
<CubeIcon /> 5 |
| 381 |
</FlexItem> |
| 382 |
<FlexItem> |
| 383 |
<RhUiCheckCircleFillIcon /> 7 |
| 384 |
</FlexItem> |
| 385 |
<FlexItem> |
| 386 |
<RhUiWarningFillIcon /> 5 |
| 387 |
</FlexItem> |
| 388 |
<FlexItem> |
| 389 |
<TimesCircleIcon /> 5 |
| 390 |
</FlexItem> |
| 391 |
<FlexItem>Updated 2 days ago</FlexItem> |
| 392 |
</Flex> |
| 393 |
</Flex> |
| 394 |
</DataListCell>, |
| 395 |
<DataListAction |
| 396 |
key="actions" |
| 397 |
aria-labelledby="full-page-item4 full-page-action4" |
| 398 |
id="full-page-action4" |
| 399 |
aria-label="Actions" |
| 400 |
> |
| 401 |
<Stack> |
| 402 |
<StackItem> |
| 403 |
<Button variant={ButtonVariant.secondary}>Secondary</Button> |
| 404 |
</StackItem> |
| 405 |
<StackItem> |
| 406 |
<Button variant={ButtonVariant.link}>Link Button</Button> |
| 407 |
</StackItem> |
| 408 |
</Stack> |
| 409 |
</DataListAction> |
| 410 |
]} |
| 411 |
/> |
| 412 |
</DataListItemRow> |
| 413 |
</DataListItem> |
| 414 |
</DataList> |
| 415 |
</Fragment> |
| 416 |
); |
| 417 |
|
| 418 |
return ( |
| 419 |
<DashboardWrapper mainContainerId="main-content-page-layout-default-nav"> |
| 420 |
<PageSection aria-labelledby="main-title"> |
| 421 |
<Content> |
| 422 |
<h1 id="main-title">Main title</h1> |
| 423 |
<p> |
| 424 |
Body text should be Red Hat Text at 1rem(16px). It should have leading of 1.5rem(24px) because <br /> |
| 425 |
of it's relative line height of 1.5. |
| 426 |
</p> |
| 427 |
</Content> |
| 428 |
</PageSection> |
| 429 |
<Divider component="div" /> |
| 430 |
<PageSection padding={{ default: 'noPadding' }} aria-label="Card with drawer content"> |
| 431 |
<Drawer isExpanded={isDrawerExpanded}> |
| 432 |
<DrawerContent panelContent={panelContent}> |
| 433 |
<DrawerContentBody>{drawerContent}</DrawerContentBody> |
| 434 |
</DrawerContent> |
| 435 |
</Drawer> |
| 436 |
</PageSection> |
| 437 |
</DashboardWrapper> |
| 438 |
); |
| 439 |
}; |