mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Added controls to ContextMenu story (#54373)
This commit is contained in:
committed by
GitHub
parent
34fe7a1119
commit
042fbcc609
@@ -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 React from 'react';
|
||||||
|
|
||||||
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
|
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
|
||||||
import { IconButton } from '../IconButton/IconButton';
|
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 mdx from './ContextMenu.mdx';
|
||||||
import { WithContextMenu } from './WithContextMenu';
|
import { renderMenuItems } from './ContextMenuStoryHelper';
|
||||||
|
import { WithContextMenu, WithContextMenuProps } from './WithContextMenu';
|
||||||
|
|
||||||
const meta: ComponentMeta<typeof ContextMenu> = {
|
const meta: ComponentMeta<typeof ContextMenu> = {
|
||||||
title: 'General/ContextMenu',
|
title: 'General/ContextMenu',
|
||||||
@@ -18,39 +18,29 @@ const meta: ComponentMeta<typeof ContextMenu> = {
|
|||||||
docs: {
|
docs: {
|
||||||
page: mdx,
|
page: mdx,
|
||||||
},
|
},
|
||||||
|
controls: {
|
||||||
|
exclude: ['renderMenuItems', 'renderHeader', 'onClose', 'children'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
args: {
|
||||||
|
x: 200,
|
||||||
|
y: 300,
|
||||||
|
focusOnOpen: true,
|
||||||
|
renderMenuItems: renderMenuItems,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const menuItems = [
|
const renderHeader = (): React.ReactNode => {
|
||||||
{
|
return <h6>Menu</h6>;
|
||||||
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) => (
|
|
||||||
<MenuGroup key={`${group.label}${index}`} label={group.label}>
|
|
||||||
{group.items.map((item) => (
|
|
||||||
<MenuItem key={item.label} label={item.label} />
|
|
||||||
))}
|
|
||||||
</MenuGroup>
|
|
||||||
));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Basic = () => {
|
export const Basic: ComponentStory<typeof ContextMenu> = (args: ContextMenuProps) => {
|
||||||
return <ContextMenu x={10} y={11} onClose={() => {}} renderMenuItems={renderMenuItems} />;
|
return <ContextMenu {...args} onClose={() => action('onClose')('closed menu')} renderHeader={renderHeader} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const WithState = () => {
|
export const WithState: ComponentStory<typeof WithContextMenu> = (args: WithContextMenuProps) => {
|
||||||
return (
|
return (
|
||||||
<WithContextMenu renderMenuItems={renderMenuItems}>
|
<WithContextMenu {...args}>
|
||||||
{({ openMenu }) => <IconButton name="info-circle" onClick={openMenu} />}
|
{({ openMenu }) => <IconButton name="info-circle" onClick={openMenu} />}
|
||||||
</WithContextMenu>
|
</WithContextMenu>
|
||||||
);
|
);
|
||||||
|
@@ -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) => (
|
||||||
|
<MenuGroup key={`${group.label}${index}`} label={group.label}>
|
||||||
|
{group.items.map((item) => (
|
||||||
|
<MenuItem key={item.label} label={item.label} />
|
||||||
|
))}
|
||||||
|
</MenuGroup>
|
||||||
|
));
|
||||||
|
};
|
@@ -2,7 +2,7 @@ import React, { useState } from 'react';
|
|||||||
|
|
||||||
import { ContextMenu } from '../ContextMenu/ContextMenu';
|
import { ContextMenu } from '../ContextMenu/ContextMenu';
|
||||||
|
|
||||||
interface WithContextMenuProps {
|
export interface WithContextMenuProps {
|
||||||
/** Menu item trigger that accepts openMenu prop */
|
/** Menu item trigger that accepts openMenu prop */
|
||||||
children: (props: { openMenu: React.MouseEventHandler<HTMLElement> }) => JSX.Element;
|
children: (props: { openMenu: React.MouseEventHandler<HTMLElement> }) => JSX.Element;
|
||||||
/** A function that returns an array of menu items */
|
/** A function that returns an array of menu items */
|
||||||
|
Reference in New Issue
Block a user