Skip to content

Commit 66a4bae

Browse files
committed
wip menu component
1 parent 0b1da6a commit 66a4bae

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/components/Menu.stories.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { MenuItem } from "react-aria-components";
2+
import { Menu } from "./Menu";
3+
import { Info } from './svgs/Info';
4+
5+
export const Default = () =>
6+
<>
7+
<Menu buttonLabel="Test menu" buttonIcon={Info}>
8+
<button>Example button</button>
9+
<button>Another button</button>
10+
</Menu>
11+
<Menu buttonLabel="Test menu" buttonIcon={"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAAPoAAAD6AG1e1JrAAACh0lEQVR4nO2TT0gUURyAp1MUdPBUEBS7KpQakkJE2Rt2y3lvHXUlmBl3MCiK9ZDtzjxRO0SE/TPqkCBBIiHieyt7MAgjNSzNgnizIkFSkB62pejgTNQl8LIxawepNaeaXQj2g+/wTu97v/kNxxUoUCAL7SO1FTpFCVtM4bRO4UNMURwT2K9TdBsTdE0nqAtTeFYnwilMkKTFkIAJqtFGYJVGRG+E+rd3DDRu4/4GncAOTFHaPeEXTNFHncDF1YfBGUzQI52iluwBFHW7G5BdnaI36wTAC/kIwBTOZw0IP6jf2h6DJ3QKI5ig85jCHo2gPkzRvR+7MKFROIsJmsMULmGCPukUfv3TAI3AKS6pid5kRKx2y7muOvD8Yr0w2S02jl5FLfEbgTOxm4G2oVuws3MQtmKKzmUW2F7kEaGSS0XrVlLRunRejIjhX8adjAR630cD8VybigZiH7T6qt/+frIqH5ZV+ZhbKopSzDlFVVVvs9qcdtkXjgNCodAetwNkVTb+nwBJknYoIeWbmwGKqow5DrCRJGmLqqpFax3uO7473t/gmRiqrZimR/ez+8Kh+THB93pcQAvj/qa3kz558an/5NIT/+nkjF9LPvPpqVn+ku3yy5oei/E9FgN3TIO/axr8sMX4+GfGa9xGWAxctww+nQtNxr9yEjCQqwDLAAsbBpgMXPmpesVkvGUaYNk0+KWMDCRW5acsAzw2GT9qj9hkYDAzcsb32p/AZKDbNECXmQDtJgNhKwGOrHtxaaW4s7isKVxaHmw9cLBBq6huaLPP/6pnb3D9S9fiKQte9pYH027rKQ++45zgLWvsyFHAnKMAjuM27donFrltSQna7DSgQAEun3wHXrEVP1Vyp4cAAAAASUVORK5CYII="}>
12+
<MenuItem>Cool menu item</MenuItem>
13+
</Menu>
14+
</>

src/components/Menu.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import styled from "styled-components";
3+
import { Button, ButtonProps, Dialog, DialogTrigger, Popover, PopoverProps } from 'react-aria-components';
4+
5+
const StyledButton = styled(Button)`
6+
`;
7+
8+
const StyledPopover = styled(Popover)`
9+
`;
10+
11+
export interface MenuProps {
12+
buttonLabel: string;
13+
buttonIcon: string | React.ReactNode;
14+
buttonProps?: ButtonProps;
15+
popoverProps?: PopoverProps;
16+
}
17+
18+
export const Menu = ({ buttonLabel, buttonIcon, ...props }: React.PropsWithChildren<MenuProps>) => {
19+
return (
20+
<DialogTrigger>
21+
<StyledButton aria-label={buttonLabel} {...props.buttonProps}>
22+
{typeof buttonIcon === 'string' ?
23+
<img aria-hidden='true' src={buttonIcon} alt='' /> : buttonIcon}
24+
</StyledButton>
25+
<StyledPopover {...props.popoverProps}>
26+
<Dialog>
27+
{props.children}
28+
</Dialog>
29+
</StyledPopover>
30+
</DialogTrigger>
31+
);
32+
};

0 commit comments

Comments
 (0)