Skip to content

Commit aa2796c

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 e498034 commit aa2796c

File tree

2 files changed

+100
-22
lines changed

2 files changed

+100
-22
lines changed

components/menu/stories/menu.stories.js

+98-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: {
@@ -164,12 +143,22 @@ const ChromaticMenuWithVariants = (args) => {
164143

165144
export const MenuWithVariants = (args) => window.isChromatic() ?
166145
ChromaticMenuWithVariants(args) : Template(args);
146+
MenuWithVariants.argTypes = {
147+
hasDividers: {
148+
name: "Has dividers",
149+
description: "Shows dividers between sections",
150+
table: {
151+
type: { summary: "boolean" },
152+
category: "Component",
153+
},
154+
control: "boolean",
155+
},
156+
};
167157
MenuWithVariants.args = {
168158
role: "listbox",
169159
subrole: "option",
170160
customStyles: { maxWidth: "400px" },
171161
selectionMode: "none",
172-
hasActions: false,
173162
hasDividers: false,
174163
items: [
175164
{
@@ -285,6 +274,9 @@ MenuWithVariants.args = {
285274
};
286275

287276
export const Collapsible = Template.bind({});
277+
Collapsible.argTypes = {
278+
selectionMode: { table: { disable: true } },
279+
};
288280
Collapsible.args = {
289281
shouldTruncate: true,
290282
items: [
@@ -355,6 +347,18 @@ Collapsible.args = {
355347
};
356348

357349
export const TraySubmenu = Template.bind({});
350+
TraySubmenu.argTypes = {
351+
selectionMode: { table: { disable: true } },
352+
isTraySubmenu: {
353+
name: "Is tray submenu",
354+
type: { name: "boolean" },
355+
table: {
356+
type: { summary: "boolean" },
357+
category: "Component",
358+
},
359+
control: "boolean",
360+
}
361+
};
358362
TraySubmenu.args = {
359363
selectionMode: "multiple",
360364
customStyles: {
@@ -478,6 +482,41 @@ const MultiCheckboxSelectedStates = (args) => {
478482
`;
479483
};
480484

485+
const WithValueStates = (args) => {
486+
const baseValueArgs = {...args, hasValue: true, value: "Value"};
487+
const valueData = [
488+
{
489+
stateTitle: "With value",
490+
args: { ...baseValueArgs },
491+
},
492+
{
493+
stateTitle: "With value, disabled",
494+
args: { ...baseValueArgs, isDisabled: true },
495+
},
496+
{
497+
stateTitle: "With value and switch",
498+
args: { ...baseValueArgs, hasActions: true },
499+
},
500+
{
501+
stateTitle: "With value, truncated label",
502+
args: { ...baseValueArgs, shouldTruncate: true, maxInlineSize: "195px", items: [{ label: "Truncated label on menu item" }] },
503+
},
504+
];
505+
506+
return valueData.map((valueItem) => html`
507+
<div>
508+
${Typography({
509+
semantics: "detail",
510+
size: "s",
511+
content: [ valueItem.stateTitle ],
512+
})}
513+
<div>
514+
${Template({ ...args, ...valueItem.args })}
515+
</div>
516+
</div>
517+
`);
518+
};
519+
481520
const ChromaticMenuItem = (args) => {
482521
const sectionData = [
483522
{
@@ -512,6 +551,10 @@ const ChromaticMenuItem = (args) => {
512551
sectionTitle: "Multi-selection with switches and switch label",
513552
sectionMarkup: MultiCheckboxSelectedStates({...args, selectionMode: "multiple", hasActions: true, items: [{ label: "Menu item", value: "switch label"}]}),
514553
},
554+
{
555+
sectionTitle: "With values",
556+
sectionMarkup: WithValueStates(args),
557+
},
515558
{
516559
sectionTitle: "Sizes",
517560
sectionMarkup: Sizes({ ...args, items: [{ label: "With sizing", iconName: "Share" }] }),
@@ -546,13 +589,15 @@ MenuItemOnly.args = {
546589
},
547590
],
548591
hasActions: false,
592+
hasValue: false,
549593
hasItemDescription: false,
550594
isDisabled: false,
551595
isItemActive: false,
552596
isItemFocused: false,
553597
isItemHovered: false,
554598
isItemSelected: false,
555599
singleItemDescription: "Menu item description",
600+
singleItemValue: "Value",
556601
};
557602
MenuItemOnly.argTypes = {
558603
isItemActive: { table: { disable: true } },
@@ -582,6 +627,7 @@ MenuItemOnly.argTypes = {
582627
},
583628
if: { arg: "selectionMode", not: { eq: "none" } },
584629
},
630+
hasDividers: { table: { disable: true } },
585631
hasItemDescription: {
586632
name: "Has menu item description",
587633
type: { name: "boolean" },
@@ -591,6 +637,17 @@ MenuItemOnly.argTypes = {
591637
control: "boolean",
592638
},
593639
},
640+
hasActions: {
641+
name: "Has switches",
642+
description: "If multiple selection is enabled, show switches instead of checkboxes to show which items have been selected",
643+
type: { name: "boolean" },
644+
table: {
645+
type: { summary: "boolean" },
646+
category: "Selection",
647+
},
648+
control: "boolean",
649+
if: { arg: "selectionMode", eq: "multiple" },
650+
},
594651
singleItemDescription: {
595652
name: "Menu item description for single menu item",
596653
type: { name: "text", required: true },
@@ -601,6 +658,25 @@ MenuItemOnly.argTypes = {
601658
control: "text",
602659
if: { arg: "hasItemDescription", truthy: true },
603660
},
661+
hasValue: {
662+
name: "Has value text",
663+
type: { name: "boolean" },
664+
table: {
665+
type: { summary: "boolean" },
666+
category: "Content",
667+
control: "boolean",
668+
},
669+
},
670+
singleItemValue: {
671+
name: "Menu item value for single menu item",
672+
type: { name: "text", required: true },
673+
table: {
674+
type: { summary: "text" },
675+
category: "Content",
676+
},
677+
control: "text",
678+
if: { arg: "hasValue", truthy: true },
679+
},
604680
};
605681

606682
// 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)