diff --git a/src/components/menu/Menu.stories.mdx b/src/components/menu/Menu.stories.mdx index f8407d08..56a69ce9 100644 --- a/src/components/menu/Menu.stories.mdx +++ b/src/components/menu/Menu.stories.mdx @@ -1,7 +1,7 @@ import { Meta, Story, Canvas, ArgsTable } from '@storybook/addon-docs' import { action } from '@storybook/addon-actions' import { Theme } from '../../../.storybook/components' -import { Menu } from './Menu' +import { Menu, MenuDirection } from './Menu' import { MenuItem } from './MenuItem' @@ -32,6 +32,7 @@ export const Template = ({ menuLabel, className, ...args }) => { args={{ menuLabel: 'Menu', menuButtonContent: 'Menu', + direction: MenuDirection.down, }} > {Template.bind({})} diff --git a/src/components/menu/Menu.tsx b/src/components/menu/Menu.tsx index acb2a639..a27b9e89 100644 --- a/src/components/menu/Menu.tsx +++ b/src/components/menu/Menu.tsx @@ -5,6 +5,11 @@ import { ReactNode } from 'react' import { useTheme } from '../../framework' import { ClassNameProps } from '../types' +export enum MenuDirection { + up = 'up', + down = 'down', +} + export type MenuProps = ClassNameProps & { /** * Defines the accessibility label for the menu. @@ -19,6 +24,7 @@ export type MenuProps = ClassNameProps & { **/ menuButtonId?: string children?: ReactNode + direction: MenuDirection } export function Menu({ @@ -27,13 +33,25 @@ export function Menu({ menuButtonContent, children, menuButtonId, + direction, }: MenuProps) { const { menu } = useTheme() + const items = ( + + {children} + + ) return ( {({ open }) => ( - <> +
+ {direction === MenuDirection.up && items} - - {children} - - + {direction === MenuDirection.down && items} +
)}
) diff --git a/src/components/menu/theme.ts b/src/components/menu/theme.ts index b5468a30..d9d36c5c 100644 --- a/src/components/menu/theme.ts +++ b/src/components/menu/theme.ts @@ -10,6 +10,10 @@ export default { active: 'bg-primary-100', }, menuList: { - base: 'py-2 mb-1 w-32 shadow focus:outline-none bg-white', + base: 'py-2 mb-2 w-32 shadow focus:outline-none bg-white absolute', + direction: { + up: '-mt-2 -translate-y-full', + down: '', + }, }, }