diff --git a/packages/grafana-ui/src/components/ContextMenu/ContextMenu.story.tsx b/packages/grafana-ui/src/components/ContextMenu/ContextMenu.story.tsx index 4489725ae93..b3c36d35a5d 100644 --- a/packages/grafana-ui/src/components/ContextMenu/ContextMenu.story.tsx +++ b/packages/grafana-ui/src/components/ContextMenu/ContextMenu.story.tsx @@ -1,14 +1,14 @@ -import { ComponentMeta } from '@storybook/react'; +import { action } from '@storybook/addon-actions'; +import { ComponentStory, ComponentMeta } from '@storybook/react'; import React from 'react'; import { withCenteredStory } from '../../utils/storybook/withCenteredStory'; import { IconButton } from '../IconButton/IconButton'; -import { MenuGroup } from '../Menu/MenuGroup'; -import { MenuItem } from '../Menu/MenuItem'; -import { ContextMenu } from './ContextMenu'; +import { ContextMenu, ContextMenuProps } from './ContextMenu'; import mdx from './ContextMenu.mdx'; -import { WithContextMenu } from './WithContextMenu'; +import { renderMenuItems } from './ContextMenuStoryHelper'; +import { WithContextMenu, WithContextMenuProps } from './WithContextMenu'; const meta: ComponentMeta = { title: 'General/ContextMenu', @@ -18,39 +18,29 @@ const meta: ComponentMeta = { docs: { page: mdx, }, + controls: { + exclude: ['renderMenuItems', 'renderHeader', 'onClose', 'children'], + }, + }, + args: { + x: 200, + y: 300, + focusOnOpen: true, + renderMenuItems: renderMenuItems, }, }; -const menuItems = [ - { - label: 'Test', - items: [ - { label: 'First', ariaLabel: 'First' }, - { label: 'Second', ariaLabel: 'Second' }, - { label: 'Third', ariaLabel: 'Third' }, - { label: 'Fourth', ariaLabel: 'Fourth' }, - { label: 'Fifth', ariaLabel: 'Fifth' }, - ], - }, -]; - -const renderMenuItems = () => { - return menuItems.map((group, index) => ( - - {group.items.map((item) => ( - - ))} - - )); +const renderHeader = (): React.ReactNode => { + return
Menu
; }; -export const Basic = () => { - return {}} renderMenuItems={renderMenuItems} />; +export const Basic: ComponentStory = (args: ContextMenuProps) => { + return action('onClose')('closed menu')} renderHeader={renderHeader} />; }; -export const WithState = () => { +export const WithState: ComponentStory = (args: WithContextMenuProps) => { return ( - + {({ openMenu }) => } ); diff --git a/packages/grafana-ui/src/components/ContextMenu/ContextMenuStoryHelper.tsx b/packages/grafana-ui/src/components/ContextMenu/ContextMenuStoryHelper.tsx new file mode 100644 index 00000000000..66b905a0239 --- /dev/null +++ b/packages/grafana-ui/src/components/ContextMenu/ContextMenuStoryHelper.tsx @@ -0,0 +1,27 @@ +import React from 'react'; + +import { MenuGroup } from '../Menu/MenuGroup'; +import { MenuItem } from '../Menu/MenuItem'; + +const menuItems = [ + { + label: 'Test', + items: [ + { label: 'First', ariaLabel: 'First' }, + { label: 'Second', ariaLabel: 'Second' }, + { label: 'Third', ariaLabel: 'Third' }, + { label: 'Fourth', ariaLabel: 'Fourth' }, + { label: 'Fifth', ariaLabel: 'Fifth' }, + ], + }, +]; + +export const renderMenuItems = () => { + return menuItems.map((group, index) => ( + + {group.items.map((item) => ( + + ))} + + )); +}; diff --git a/packages/grafana-ui/src/components/ContextMenu/WithContextMenu.tsx b/packages/grafana-ui/src/components/ContextMenu/WithContextMenu.tsx index c502306b351..4809c7b42c7 100644 --- a/packages/grafana-ui/src/components/ContextMenu/WithContextMenu.tsx +++ b/packages/grafana-ui/src/components/ContextMenu/WithContextMenu.tsx @@ -2,7 +2,7 @@ import React, { useState } from 'react'; import { ContextMenu } from '../ContextMenu/ContextMenu'; -interface WithContextMenuProps { +export interface WithContextMenuProps { /** Menu item trigger that accepts openMenu prop */ children: (props: { openMenu: React.MouseEventHandler }) => JSX.Element; /** A function that returns an array of menu items */