-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
93 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React from 'react'; | ||
import { Button, ButtonVariant, Dropdown, DropdownList, MenuToggle, OverflowMenu, OverflowMenuContent, OverflowMenuControl, OverflowMenuDropdownItem, OverflowMenuGroup, OverflowMenuItem, OverflowMenuProps, Toolbar, ToolbarContent, ToolbarItem, ToolbarItemVariant } from '@patternfly/react-core'; | ||
import { EllipsisVIcon } from '@patternfly/react-icons'; | ||
|
||
export interface ResponsiveActionsProps extends Omit<OverflowMenuProps, 'ref' | 'breakpoint'> { | ||
/** Indicates breakpoint at which to switch between horizontal menu and vertical dropdown */ | ||
breakpoint?: OverflowMenuProps['breakpoint']; | ||
/** Custom OUIA ID */ | ||
ouiaId?: string; | ||
/** React component to display actions */ | ||
actions?: React.ReactNode; | ||
} | ||
|
||
export const ResponsiveActions: React.FC<ResponsiveActionsProps> = ({ ouiaId = 'ResponsiveActions', breakpoint = 'lg', ...props }: ResponsiveActionsProps) => { | ||
const [ isOpen, setIsOpen ] = React.useState(false); | ||
|
||
const onToggle = () => { | ||
setIsOpen(!isOpen); | ||
}; | ||
|
||
const onSelect = () => { | ||
setIsOpen(!isOpen); | ||
}; | ||
|
||
const dropdownItems = [ | ||
<OverflowMenuDropdownItem itemId={0} key="secondary" isShared> | ||
Secondary | ||
</OverflowMenuDropdownItem>, | ||
<OverflowMenuDropdownItem itemId={1} key="tertiary" isShared> | ||
Tertiary | ||
</OverflowMenuDropdownItem>, | ||
<OverflowMenuDropdownItem itemId={2} key="action"> | ||
Action 4 | ||
</OverflowMenuDropdownItem> | ||
]; | ||
return ( | ||
<OverflowMenu breakpoint={breakpoint} data-ouia-component-id={`${ouiaId}-menu`} {...props}> | ||
<OverflowMenuContent isPersistent data-ouia-component-id={`${ouiaId}-menu-content`}> | ||
|
||
<OverflowMenuGroup groupType="button" data-ouia-component-id={`${ouiaId}-menu-group`} isPersistent> | ||
<OverflowMenuItem isPersistent> | ||
<Button variant={ButtonVariant.primary}>Primary</Button> | ||
</OverflowMenuItem> | ||
<OverflowMenuItem> | ||
<Button variant={ButtonVariant.secondary}>Secondary</Button> | ||
</OverflowMenuItem> | ||
<OverflowMenuItem> | ||
<Button variant={ButtonVariant.tertiary}>Tertiary</Button> | ||
</OverflowMenuItem> | ||
</OverflowMenuGroup> | ||
|
||
</OverflowMenuContent> | ||
|
||
<OverflowMenuControl hasAdditionalOptions data-ouia-component-id={`${ouiaId}-menu-control`}> | ||
<Dropdown | ||
ouiaId={`${ouiaId}-menu-dropdown`} | ||
onSelect={onSelect} | ||
toggle={(toggleRef) => ( | ||
<MenuToggle | ||
data-ouia-component-id={`${ouiaId}-menu-dropdown-toggle`} | ||
ref={toggleRef} | ||
aria-label="Persistent example overflow menu" | ||
variant="plain" | ||
onClick={onToggle} | ||
isExpanded={isOpen} | ||
> | ||
<EllipsisVIcon /> | ||
</MenuToggle> | ||
)} | ||
isOpen={isOpen} | ||
onOpenChange={(isOpen) => setIsOpen(isOpen)} | ||
> | ||
<DropdownList data-ouia-component-id={`${ouiaId}-menu-dropdown-list`}>{dropdownItems}</DropdownList> | ||
</Dropdown> | ||
</OverflowMenuControl> | ||
|
||
</OverflowMenu> | ||
);} | ||
|
||
export default ResponsiveActions; | ||
|