Skip to content

Commit

Permalink
add properties for popover position
Browse files Browse the repository at this point in the history
  • Loading branch information
kaulfield23 committed Sep 12, 2023
1 parent a54ebc2 commit ea8d581
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/features/events/components/SelectionBarEllipsis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,16 @@ const SelectionBarEllipsis = () => {
});
}

return <ZUIEllipsisMenu items={ellipsisMenuItems} />;
return (
<ZUIEllipsisMenu
anchorOrigin={{ horizontal: 'right', vertical: 'top' }}
items={ellipsisMenuItems}
transformOrigin={{
horizontal: 'right',
vertical: 'bottom',
}}
/>
);
};

export default SelectionBarEllipsis;
13 changes: 13 additions & 0 deletions src/zui/ZUIEllipsisMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
} from '@mui/material';
import { FunctionComponent, ReactElement, useState } from 'react';

type horizontalType = 'left' | 'center' | 'right';
type verticalType = 'top' | 'center' | 'bottom';

interface MenuItem {
disabled?: boolean;
divider?: boolean;
Expand All @@ -23,10 +26,14 @@ interface MenuItem {

export interface ZUIEllipsisMenuProps {
items: MenuItem[];
anchorOrigin?: { horizontal: horizontalType; vertical: verticalType };
transformOrigin?: { horizontal: horizontalType; vertical: verticalType };
}

const ZUIEllipsisMenu: FunctionComponent<ZUIEllipsisMenuProps> = ({
items,
anchorOrigin,
transformOrigin,
}) => {
const [menuActivator, setMenuActivator] = useState<null | HTMLElement>(null);
const [subMenuActivator, setSubMenuActivator] = useState<null | HTMLElement>(
Expand All @@ -49,6 +56,9 @@ const ZUIEllipsisMenu: FunctionComponent<ZUIEllipsisMenuProps> = ({
</Button>
<Menu
anchorEl={menuActivator}
anchorOrigin={
anchorOrigin ?? { horizontal: 'left', vertical: 'bottom' }
}
keepMounted
onClose={() => setMenuActivator(null)}
open={Boolean(menuActivator)}
Expand All @@ -62,6 +72,9 @@ const ZUIEllipsisMenu: FunctionComponent<ZUIEllipsisMenuProps> = ({
marginTop: theme.spacing(1),
},
}}
transformOrigin={
transformOrigin ?? { horizontal: 'left', vertical: 'top' }
}
>
{items.map((item, idx) => (
<MenuItem
Expand Down
5 changes: 5 additions & 0 deletions src/zui/ZUIOrganizeSidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ const ZUIOrganizeSidebar = (): JSX.Element => {
}}
>
<ZUIEllipsisMenu
anchorOrigin={{ horizontal: 'right', vertical: 'top' }}
items={[
{
label: (
Expand All @@ -354,6 +355,10 @@ const ZUIOrganizeSidebar = (): JSX.Element => {
startIcon: <Logout />,
},
]}
transformOrigin={{
horizontal: 'right',
vertical: 'bottom',
}}
/>
</Box>
</>
Expand Down

0 comments on commit ea8d581

Please sign in to comment.