|
| 1 | +import React from 'react'; |
| 2 | +import { |
| 3 | + Button, |
| 4 | + Content, |
| 5 | + DataList, |
| 6 | + DataListItem, |
| 7 | + DataListCell, |
| 8 | + DataListItemRow, |
| 9 | + DataListItemCells, |
| 10 | + DataListAction, |
| 11 | + Dropdown, |
| 12 | + DropdownList, |
| 13 | + DropdownItem, |
| 14 | + MenuToggle, |
| 15 | + MenuToggleElement, |
| 16 | + PageSection, |
| 17 | + PageSectionVariants, |
| 18 | + Title |
| 19 | +} from '@patternfly/react-core'; |
| 20 | +import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon'; |
| 21 | +import { DashboardWrapper } from '@patternfly/react-core/dist/js/demos/DashboardWrapper'; |
| 22 | + |
| 23 | +export const DataListActionable: React.FunctionComponent = () => { |
| 24 | + const [isOpen, setIsOpen] = React.useState(false); |
| 25 | + const [isDeleted, setIsDeleted] = React.useState(false); |
| 26 | + |
| 27 | + const onToggle = () => { |
| 28 | + setIsOpen(!isOpen); |
| 29 | + }; |
| 30 | + |
| 31 | + const onSelect = () => { |
| 32 | + setIsOpen(!isOpen); |
| 33 | + }; |
| 34 | + |
| 35 | + return ( |
| 36 | + <DashboardWrapper mainContainerId="main-content-datalist-view-actions" breadcrumb={null}> |
| 37 | + <PageSection variant={PageSectionVariants.secondary}> |
| 38 | + <Content> |
| 39 | + <Title headingLevel="h1">Projects</Title> |
| 40 | + <Content component="p">This is a demo that showcases PatternFly Data List</Content> |
| 41 | + </Content> |
| 42 | + </PageSection> |
| 43 | + <DataList aria-label="single action data list example "> |
| 44 | + {!isDeleted && ( |
| 45 | + <DataListItem aria-labelledby="single-action-item1"> |
| 46 | + <DataListItemRow> |
| 47 | + <DataListItemCells |
| 48 | + dataListCells={[ |
| 49 | + <DataListCell key="primary content"> |
| 50 | + <span id="single-action-item1">Single actionable Primary content</span> |
| 51 | + </DataListCell>, |
| 52 | + <DataListCell key="secondary content">Single actionable Secondary content</DataListCell> |
| 53 | + ]} |
| 54 | + /> |
| 55 | + <DataListAction |
| 56 | + aria-labelledby="single-action-item1 single-action-action1" |
| 57 | + id="single-action-action1" |
| 58 | + aria-label="Actions" |
| 59 | + > |
| 60 | + <Button |
| 61 | + onClick={() => { |
| 62 | + if (confirm('Are you sure?')) { |
| 63 | + setIsDeleted(true); |
| 64 | + } |
| 65 | + }} |
| 66 | + variant="primary" |
| 67 | + key="delete-action" |
| 68 | + > |
| 69 | + Delete |
| 70 | + </Button> |
| 71 | + </DataListAction> |
| 72 | + </DataListItemRow> |
| 73 | + </DataListItem> |
| 74 | + )} |
| 75 | + <DataListItem aria-labelledby="multi-actions-item1"> |
| 76 | + <DataListItemRow> |
| 77 | + <DataListItemCells |
| 78 | + dataListCells={[ |
| 79 | + <DataListCell key="primary content"> |
| 80 | + <span id="multi-actions-item1">Multi actions Primary content</span> |
| 81 | + </DataListCell>, |
| 82 | + <DataListCell key="secondary content">Multi actions Secondary content</DataListCell> |
| 83 | + ]} |
| 84 | + /> |
| 85 | + <DataListAction |
| 86 | + aria-labelledby="multi-actions-item1 multi-actions-action1" |
| 87 | + id="multi-actions-action1" |
| 88 | + aria-label="Actions" |
| 89 | + > |
| 90 | + <Dropdown |
| 91 | + popperProps={{ position: 'right' }} |
| 92 | + onSelect={onSelect} |
| 93 | + toggle={(toggleRef: React.Ref<MenuToggleElement>) => ( |
| 94 | + <MenuToggle |
| 95 | + ref={toggleRef} |
| 96 | + isExpanded={isOpen} |
| 97 | + onClick={onToggle} |
| 98 | + variant="plain" |
| 99 | + aria-label="Data list with actions example kebab toggle" |
| 100 | + > |
| 101 | + <EllipsisVIcon aria-hidden="true" /> |
| 102 | + </MenuToggle> |
| 103 | + )} |
| 104 | + isOpen={isOpen} |
| 105 | + onOpenChange={(isOpen: boolean) => setIsOpen(isOpen)} |
| 106 | + > |
| 107 | + <DropdownList> |
| 108 | + <DropdownItem key="action">Action</DropdownItem> |
| 109 | + {/* Prevent default onClick functionality for example |
| 110 | + purposes */} |
| 111 | + <DropdownItem key="link" to="#" onClick={(event: any) => event.preventDefault()}> |
| 112 | + Link |
| 113 | + </DropdownItem> |
| 114 | + <DropdownItem key="disabled action" isDisabled> |
| 115 | + Disabled Action |
| 116 | + </DropdownItem> |
| 117 | + <DropdownItem key="disabled link" isDisabled to="#" onClick={(event: any) => event.preventDefault()}> |
| 118 | + Disabled Link |
| 119 | + </DropdownItem> |
| 120 | + </DropdownList> |
| 121 | + </Dropdown> |
| 122 | + </DataListAction> |
| 123 | + </DataListItemRow> |
| 124 | + </DataListItem> |
| 125 | + </DataList> |
| 126 | + </DashboardWrapper> |
| 127 | + ); |
| 128 | +}; |
0 commit comments