Skip to content

Commit

Permalink
fix(menu): adjust switches and controls
Browse files Browse the repository at this point in the history
- Remove dividers control for single menu item story, which isn't meant
to show dividers
- Add values to Menu Item Only Chromatic testing preview
- Add control to add custom value to Menu Item Only
- Move hasAction (switches) controls to menu item only
- hasDividers control only exists on Menu with variants story
- selectionMode control removed from Collapsible, Tray Submenu stories
- Add isTraySubmenu control
  • Loading branch information
rise-erpelding committed May 22, 2024
1 parent 2be1c45 commit 2460b61
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 22 deletions.
119 changes: 97 additions & 22 deletions components/menu/stories/menu.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,38 +51,17 @@ export default {
control: "text",
if: { arg: "shouldTruncate", truthy: true },
},
hasActions: {
name: "Has switches",
description: "If multiple selection is enabled, show switches instead of checkboxes to show which items have been selected",
type: { name: "boolean" },
table: {
type: { summary: "boolean" },
category: "Selection",
},
control: "boolean",
if: { arg: "selectionMode", eq: "multiple" },
},
labelledby: { table: { disable: true } },
items: { table: { disable: true } },
role: { table: { disable: true } },
subrole: { table: { disable: true } },
hasDividers: {
name: "Has dividers",
description: "Shows dividers between sections",
table: {
type: { summary: "boolean" },
category: "Component",
},
control: "boolean",
},
},
args: {
rootClass: "spectrum-Menu",
selectionMode: "none",
size: "m",
shouldTruncate: false,
maxInlineSize: "150px",
hasDividers: false,
},
parameters: {
actions: {
Expand Down Expand Up @@ -167,12 +146,22 @@ const ChromaticMenuWithVariants = (args) => {

export const MenuWithVariants = (args) => window.isChromatic() ?
ChromaticMenuWithVariants(args) : Template(args);
MenuWithVariants.argTypes = {
hasDividers: {
name: "Has dividers",
description: "Shows dividers between sections",
table: {
type: { summary: "boolean" },
category: "Component",
},
control: "boolean",
},
};
MenuWithVariants.args = {
role: "listbox",
subrole: "option",
customStyles: { maxWidth: "400px" },
selectionMode: "none",
hasActions: false,
hasDividers: false,
items: [
{
Expand Down Expand Up @@ -288,6 +277,9 @@ MenuWithVariants.args = {
};

export const Collapsible = Template.bind({});
Collapsible.argTypes = {
selectionMode: { table: { disable: true } },
};
Collapsible.args = {
shouldTruncate: true,
items: [
Expand Down Expand Up @@ -358,6 +350,18 @@ Collapsible.args = {
};

export const TraySubmenu = Template.bind({});
TraySubmenu.argTypes = {
selectionMode: { table: { disable: true } },
isTraySubmenu: {
name: "Is tray submenu",
type: { name: "boolean" },
table: {
type: { summary: "boolean" },
category: "Component",
},
control: "boolean",
}
};
TraySubmenu.args = {
selectionMode: "multiple",
customStyles: {
Expand Down Expand Up @@ -481,6 +485,41 @@ const MultiCheckboxSelectedStates = (args) => {
`;
};

const WithValueStates = (args) => {
const baseValueArgs = {...args, hasValue: true, singleItemValue: "Value"};
const valueData = [
{
stateTitle: "With value",
args: { ...baseValueArgs },
},
{
stateTitle: "With value, disabled",
args: { ...baseValueArgs, isDisabled: true },
},
{
stateTitle: "With value and switch",
args: { ...baseValueArgs, hasActions: true },
},
{
stateTitle: "With value, truncated label",
args: { ...baseValueArgs, shouldTruncate: true, maxInlineSize: "195px", items: [{ label: "Truncated label on menu item" }] },
},
];

return valueData.map((valueItem) => html`
<div>
${Typography({
semantics: "detail",
size: "s",
content: [ valueItem.stateTitle ],
})}
<div>
${Template({ ...args, ...valueItem.args })}
</div>
</div>
`);
};

const ChromaticMenuItem = (args) => {
const sectionData = [
{
Expand Down Expand Up @@ -515,6 +554,10 @@ const ChromaticMenuItem = (args) => {
sectionTitle: "Multi-selection with switches and switch label",
sectionMarkup: MultiCheckboxSelectedStates({...args, selectionMode: "multiple", hasActions: true, items: [{ label: "Menu item", value: "switch label"}]}),
},
{
sectionTitle: "With values",
sectionMarkup: WithValueStates(args),
},
{
sectionTitle: "Sizes",
sectionMarkup: Sizes({ ...args, selectionMode: "single", items: [{ label: "With sizing", isSelected: true, iconName: "Share" }] }),
Expand Down Expand Up @@ -549,13 +592,15 @@ MenuItemOnly.args = {
},
],
hasActions: false,
hasValue: false,
hasItemDescription: false,
isDisabled: false,
isItemActive: false,
isItemFocused: false,
isItemHovered: false,
isItemSelected: false,
singleItemDescription: "Menu item description",
singleItemValue: "Value",
};
MenuItemOnly.argTypes = {
isItemActive: { table: { disable: true } },
Expand Down Expand Up @@ -594,6 +639,17 @@ MenuItemOnly.argTypes = {
control: "boolean",
},
},
hasActions: {
name: "Has switches",
description: "If multiple selection is enabled, show switches instead of checkboxes to show which items have been selected",
type: { name: "boolean" },
table: {
type: { summary: "boolean" },
category: "Selection",
},
control: "boolean",
if: { arg: "selectionMode", eq: "multiple" },
},
singleItemDescription: {
name: "Menu item description for single menu item",
type: { name: "text", required: true },
Expand All @@ -604,6 +660,25 @@ MenuItemOnly.argTypes = {
control: "text",
if: { arg: "hasItemDescription", truthy: true },
},
hasValue: {
name: "Has value text",
type: { name: "boolean" },
table: {
type: { summary: "boolean" },
category: "Content",
control: "boolean",
},
},
singleItemValue: {
name: "Menu item value for single menu item",
type: { name: "text", required: true },
table: {
type: { summary: "text" },
category: "Content",
},
control: "text",
if: { arg: "hasValue", truthy: true },
},
};

// story used in Picker component
Expand Down
2 changes: 2 additions & 0 deletions components/menu/stories/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ export const Template = ({
rootClass = "spectrum-Menu",
selectionMode = "none",
singleItemDescription,
singleItemValue,
shouldTruncate,
size,
subrole = "menuitem",
Expand Down Expand Up @@ -360,6 +361,7 @@ export const Template = ({
selectionMode,
shouldTruncate,
size,
value: singleItemValue || i.value,
});
})}
</ul>
Expand Down

0 comments on commit 2460b61

Please sign in to comment.