Skip to content

Commit be40103

Browse files
fix(menu): adjust switches and controls
- 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
1 parent e120d63 commit be40103

File tree

2 files changed

+99
-22
lines changed

2 files changed

+99
-22
lines changed

components/menu/stories/menu.stories.js

+97-22
Original file line numberDiff line numberDiff line change
@@ -51,38 +51,17 @@ export default {
5151
control: "text",
5252
if: { arg: "shouldTruncate", truthy: true },
5353
},
54-
hasActions: {
55-
name: "Has switches",
56-
description: "If multiple selection is enabled, show switches instead of checkboxes to show which items have been selected",
57-
type: { name: "boolean" },
58-
table: {
59-
type: { summary: "boolean" },
60-
category: "Selection",
61-
},
62-
control: "boolean",
63-
if: { arg: "selectionMode", eq: "multiple" },
64-
},
6554
labelledby: { table: { disable: true } },
6655
items: { table: { disable: true } },
6756
role: { table: { disable: true } },
6857
subrole: { table: { disable: true } },
69-
hasDividers: {
70-
name: "Has dividers",
71-
description: "Shows dividers between sections",
72-
table: {
73-
type: { summary: "boolean" },
74-
category: "Component",
75-
},
76-
control: "boolean",
77-
},
7858
},
7959
args: {
8060
rootClass: "spectrum-Menu",
8161
selectionMode: "none",
8262
size: "m",
8363
shouldTruncate: false,
8464
maxInlineSize: "150px",
85-
hasDividers: false,
8665
},
8766
parameters: {
8867
actions: {
@@ -167,12 +146,22 @@ const ChromaticMenuWithVariants = (args) => {
167146

168147
export const MenuWithVariants = (args) => window.isChromatic() ?
169148
ChromaticMenuWithVariants(args) : Template(args);
149+
MenuWithVariants.argTypes = {
150+
hasDividers: {
151+
name: "Has dividers",
152+
description: "Shows dividers between sections",
153+
table: {
154+
type: { summary: "boolean" },
155+
category: "Component",
156+
},
157+
control: "boolean",
158+
},
159+
};
170160
MenuWithVariants.args = {
171161
role: "listbox",
172162
subrole: "option",
173163
customStyles: { maxWidth: "400px" },
174164
selectionMode: "none",
175-
hasActions: false,
176165
hasDividers: false,
177166
items: [
178167
{
@@ -288,6 +277,9 @@ MenuWithVariants.args = {
288277
};
289278

290279
export const Collapsible = Template.bind({});
280+
Collapsible.argTypes = {
281+
selectionMode: { table: { disable: true } },
282+
};
291283
Collapsible.args = {
292284
shouldTruncate: true,
293285
items: [
@@ -358,6 +350,18 @@ Collapsible.args = {
358350
};
359351

360352
export const TraySubmenu = Template.bind({});
353+
TraySubmenu.argTypes = {
354+
selectionMode: { table: { disable: true } },
355+
isTraySubmenu: {
356+
name: "Is tray submenu",
357+
type: { name: "boolean" },
358+
table: {
359+
type: { summary: "boolean" },
360+
category: "Component",
361+
},
362+
control: "boolean",
363+
}
364+
};
361365
TraySubmenu.args = {
362366
selectionMode: "multiple",
363367
customStyles: {
@@ -481,6 +485,41 @@ const MultiCheckboxSelectedStates = (args) => {
481485
`;
482486
};
483487

488+
const WithValueStates = (args) => {
489+
const baseValueArgs = {...args, hasValue: true, singleItemValue: "Value"};
490+
const valueData = [
491+
{
492+
stateTitle: "With value",
493+
args: { ...baseValueArgs },
494+
},
495+
{
496+
stateTitle: "With value, disabled",
497+
args: { ...baseValueArgs, isDisabled: true },
498+
},
499+
{
500+
stateTitle: "With value and switch",
501+
args: { ...baseValueArgs, hasActions: true },
502+
},
503+
{
504+
stateTitle: "With value, truncated label",
505+
args: { ...baseValueArgs, shouldTruncate: true, maxInlineSize: "195px", items: [{ label: "Truncated label on menu item" }] },
506+
},
507+
];
508+
509+
return valueData.map((valueItem) => html`
510+
<div>
511+
${Typography({
512+
semantics: "detail",
513+
size: "s",
514+
content: [ valueItem.stateTitle ],
515+
})}
516+
<div>
517+
${Template({ ...args, ...valueItem.args })}
518+
</div>
519+
</div>
520+
`);
521+
};
522+
484523
const ChromaticMenuItem = (args) => {
485524
const sectionData = [
486525
{
@@ -515,6 +554,10 @@ const ChromaticMenuItem = (args) => {
515554
sectionTitle: "Multi-selection with switches and switch label",
516555
sectionMarkup: MultiCheckboxSelectedStates({...args, selectionMode: "multiple", hasActions: true, items: [{ label: "Menu item", value: "switch label"}]}),
517556
},
557+
{
558+
sectionTitle: "With values",
559+
sectionMarkup: WithValueStates(args),
560+
},
518561
{
519562
sectionTitle: "Sizes",
520563
sectionMarkup: Sizes({ ...args, items: [{ label: "With sizing", iconName: "Share" }] }),
@@ -549,13 +592,15 @@ MenuItemOnly.args = {
549592
},
550593
],
551594
hasActions: false,
595+
hasValue: false,
552596
hasItemDescription: false,
553597
isDisabled: false,
554598
isItemActive: false,
555599
isItemFocused: false,
556600
isItemHovered: false,
557601
isItemSelected: false,
558602
singleItemDescription: "Menu item description",
603+
singleItemValue: "Value",
559604
};
560605
MenuItemOnly.argTypes = {
561606
isItemActive: { table: { disable: true } },
@@ -594,6 +639,17 @@ MenuItemOnly.argTypes = {
594639
control: "boolean",
595640
},
596641
},
642+
hasActions: {
643+
name: "Has switches",
644+
description: "If multiple selection is enabled, show switches instead of checkboxes to show which items have been selected",
645+
type: { name: "boolean" },
646+
table: {
647+
type: { summary: "boolean" },
648+
category: "Selection",
649+
},
650+
control: "boolean",
651+
if: { arg: "selectionMode", eq: "multiple" },
652+
},
597653
singleItemDescription: {
598654
name: "Menu item description for single menu item",
599655
type: { name: "text", required: true },
@@ -604,6 +660,25 @@ MenuItemOnly.argTypes = {
604660
control: "text",
605661
if: { arg: "hasItemDescription", truthy: true },
606662
},
663+
hasValue: {
664+
name: "Has value text",
665+
type: { name: "boolean" },
666+
table: {
667+
type: { summary: "boolean" },
668+
category: "Content",
669+
control: "boolean",
670+
},
671+
},
672+
singleItemValue: {
673+
name: "Menu item value for single menu item",
674+
type: { name: "text", required: true },
675+
table: {
676+
type: { summary: "text" },
677+
category: "Content",
678+
},
679+
control: "text",
680+
if: { arg: "hasValue", truthy: true },
681+
},
607682
};
608683

609684
// story used in Picker component

components/menu/stories/template.js

+2
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ export const Template = ({
303303
rootClass = "spectrum-Menu",
304304
selectionMode = "none",
305305
singleItemDescription,
306+
singleItemValue,
306307
shouldTruncate,
307308
size,
308309
subrole = "menuitem",
@@ -360,6 +361,7 @@ export const Template = ({
360361
selectionMode,
361362
shouldTruncate,
362363
size,
364+
value: singleItemValue || i.value,
363365
});
364366
})}
365367
</ul>

0 commit comments

Comments
 (0)