2022-07-22 17:19:16 +01:00
|
|
|
import { ComponentMeta } from '@storybook/react';
|
2020-10-27 17:18:45 +02:00
|
|
|
import React from 'react';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
2020-10-27 17:18:45 +02:00
|
|
|
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
|
|
|
|
|
import { IconButton } from '../IconButton/IconButton';
|
2021-03-18 12:58:07 +01:00
|
|
|
import { MenuGroup } from '../Menu/MenuGroup';
|
|
|
|
|
import { MenuItem } from '../Menu/MenuItem';
|
2020-10-27 17:18:45 +02:00
|
|
|
|
2022-04-22 14:33:13 +01:00
|
|
|
import { ContextMenu } from './ContextMenu';
|
|
|
|
|
import mdx from './ContextMenu.mdx';
|
|
|
|
|
import { WithContextMenu } from './WithContextMenu';
|
|
|
|
|
|
2022-07-22 17:19:16 +01:00
|
|
|
const meta: ComponentMeta<typeof ContextMenu> = {
|
2020-10-27 17:18:45 +02:00
|
|
|
title: 'General/ContextMenu',
|
|
|
|
|
component: ContextMenu,
|
|
|
|
|
decorators: [withCenteredStory],
|
|
|
|
|
parameters: {
|
|
|
|
|
docs: {
|
|
|
|
|
page: mdx,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2021-03-11 15:35:17 +01:00
|
|
|
const menuItems = [
|
|
|
|
|
{
|
|
|
|
|
label: 'Test',
|
|
|
|
|
items: [
|
|
|
|
|
{ label: 'First', ariaLabel: 'First' },
|
|
|
|
|
{ label: 'Second', ariaLabel: 'Second' },
|
2021-09-20 09:08:46 +01:00
|
|
|
{ label: 'Third', ariaLabel: 'Third' },
|
|
|
|
|
{ label: 'Fourth', ariaLabel: 'Fourth' },
|
|
|
|
|
{ label: 'Fifth', ariaLabel: 'Fifth' },
|
2021-03-11 15:35:17 +01:00
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
];
|
2020-10-27 17:18:45 +02:00
|
|
|
|
2021-03-18 12:58:07 +01:00
|
|
|
const renderMenuItems = () => {
|
2021-09-20 09:08:46 +01:00
|
|
|
return menuItems.map((group, index) => (
|
|
|
|
|
<MenuGroup key={`${group.label}${index}`} label={group.label}>
|
|
|
|
|
{group.items.map((item) => (
|
|
|
|
|
<MenuItem key={item.label} label={item.label} />
|
2021-03-18 12:58:07 +01:00
|
|
|
))}
|
|
|
|
|
</MenuGroup>
|
|
|
|
|
));
|
|
|
|
|
};
|
|
|
|
|
|
2020-10-27 17:18:45 +02:00
|
|
|
export const Basic = () => {
|
2021-03-18 12:58:07 +01:00
|
|
|
return <ContextMenu x={10} y={11} onClose={() => {}} renderMenuItems={renderMenuItems} />;
|
2020-10-27 17:18:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const WithState = () => {
|
|
|
|
|
return (
|
2021-03-18 12:58:07 +01:00
|
|
|
<WithContextMenu renderMenuItems={renderMenuItems}>
|
2020-10-27 17:18:45 +02:00
|
|
|
{({ openMenu }) => <IconButton name="info-circle" onClick={openMenu} />}
|
|
|
|
|
</WithContextMenu>
|
|
|
|
|
);
|
|
|
|
|
};
|
2022-07-22 17:19:16 +01:00
|
|
|
|
|
|
|
|
export default meta;
|