Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MenuGroup: Add Storybook stories #53090

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions packages/components/src/menu-group/stories/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import MenuGroup from '..';
import MenuItem from '../../menu-item';
import MenuItemsChoice from '../../menu-items-choice';

/**
* External dependencies
*/
import type { ComponentMeta, ComponentStory } from '@storybook/react';

const meta: ComponentMeta< typeof MenuGroup > = {
title: 'Components/MenuGroup',
component: MenuGroup,
argTypes: {
children: { control: { type: null } },
},
parameters: {
controls: { expanded: true },
docs: { source: { state: 'open' } },
},
};
export default meta;

const Template: ComponentStory< typeof MenuGroup > = ( args ) => {
return (
<MenuGroup { ...args }>
<MenuItem>Menu Item 1</MenuItem>
<MenuItem>Menu Item 2</MenuItem>
</MenuGroup>
);
};

export const Default: ComponentStory< typeof MenuGroup > = Template.bind( {} );

const MultiGroupsTemplate: ComponentStory< typeof MenuGroup > = ( args ) => {
const [ mode, setMode ] = useState( 'visual' );
const choices = [
{
value: 'visual',
label: 'Visual editor',
},
{
value: 'text',
label: 'Code editor',
},
];

return (
<>
<MenuGroup label={ 'View' }>
<MenuItem>Top Toolbar</MenuItem>
<MenuItem>Spotlight Mode</MenuItem>
<MenuItem>Distraction Free</MenuItem>
</MenuGroup>
<MenuGroup { ...args }>
<MenuItemsChoice
choices={ choices }
value={ mode }
onSelect={ ( newMode: string ) => setMode( newMode ) }
onHover={ () => {} }
/>
</MenuGroup>
</>
);
};

/**
* When other menu items exist above or below a MenuGroup, the group
* should have a divider line between it and the adjacent item.
*/
export const WithSeperator = MultiGroupsTemplate.bind( {} );
WithSeperator.args = {
...Default.args,
hideSeparator: false,
label: 'Editor',
};
Loading