/
menu.stories.ts
157 lines (150 loc) · 5.12 KB
/
menu.stories.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import type { Meta, StoryObj } from '@storybook/html';
import { withXD } from 'storybook-addon-xd-designs';
import { html, repeat, when } from '@microsoft/fast-element';
import { createRenderer } from '../../utilities/tests/storybook';
import '../index';
import '../../menu-item/index';
import '../../icons/admin';
import '../../icons/logout';
interface MenuArgs {
itemOptions: ItemArgs[];
}
interface ItemArgs {
text: string;
disabled: boolean;
icon: boolean;
type: 'nimble-menu-item' | 'header' | 'hr';
}
const overviewText = `Per [W3C](https://w3c.github.io/aria-practices/#menu) - A menu is a widget that offers a list of choices to the user,
such as a set of actions or functions. Menu widgets behave like native operating system menus, such as the menus that pull down from the
menubars commonly found at the top of many desktop application windows. A menu is usually opened, or made visible, by activating a menu button,
choosing an item in a menu that opens a sub menu, or by invoking a command, such as Shift + F10 in Windows, that opens a context specific menu.
When a user activates a choice in a menu, the menu usually closes unless the choice opened a submenu.`;
const metadata: Meta<MenuArgs> = {
title: 'Menu',
decorators: [withXD],
parameters: {
docs: {
description: {
component: overviewText
}
},
design: {
artboardUrl:
'https://xd.adobe.com/view/8ce280ab-1559-4961-945c-182955c7780b-d9b1/screen/c098395e-30f8-4bd4-b8c5-394326b59919/specs'
},
actions: {
handles: ['change']
}
}
};
export default metadata;
export const menu: StoryObj<MenuArgs> = {
parameters: {
docs: {
description: {
story: 'The `nimble-menu` supports several child elements including `<header>`, `<hr>`, and `<nimble-menu-item>`, and will format them and any `nimble-icons` added as children of `<nimble-menu-item>`.'
}
}
},
// prettier-ignore
render: createRenderer<MenuArgs>(html`
<nimble-menu>
${repeat(x => x.itemOptions, html<ItemArgs>`
${when(x => x.type === 'nimble-menu-item', html<ItemArgs>`
<nimble-menu-item ?disabled="${x => x.disabled}">
${when(x => x.icon, html`<nimble-admin-icon></nimble-admin-icon>`)}
${x => x.text}
</nimble-menu-item>
`)}
${when(x => x.type === 'header', html<ItemArgs>`
<header>
${x => x.text}
</header>
`)}
${when(x => x.type === 'hr', html<ItemArgs>`
<hr>
`)}
`)}
</nimble-menu>
`),
args: {
itemOptions: [
{
text: 'Header 1',
disabled: false,
icon: false,
type: 'header'
},
{
text: 'Item 1',
disabled: false,
icon: false,
type: 'nimble-menu-item'
},
{
text: 'Item 2',
disabled: false,
icon: false,
type: 'nimble-menu-item'
},
{
text: 'Item 3',
disabled: false,
icon: false,
type: 'nimble-menu-item'
},
{
text: 'Divider',
disabled: false,
icon: false,
type: 'hr'
},
{
text: 'Header 2',
disabled: false,
icon: false,
type: 'header'
},
{
text: 'Item 4',
disabled: false,
icon: false,
type: 'nimble-menu-item'
},
{
text: 'Item 5',
disabled: false,
icon: false,
type: 'nimble-menu-item'
},
{
text: 'Item 6',
disabled: false,
icon: false,
type: 'nimble-menu-item'
}
]
}
};
export const customMenu: StoryObj<MenuArgs> = {
parameters: {
docs: {
description: {
story: 'The menu can be configured to display a custom header with arbitrary content. This could include other nimble components, or even custom elements.'
}
}
},
// pre
// prettier-ignore
render: createRenderer(html`
<nimble-menu>
<div style="display: grid; font-family: Source Sans Pro; font-size: 11px;">
<div style="font-weight: bold; color: black;">lvadmin User</div>
<div style="color: gray;">lvadmin</div>
</div>
<nimble-menu-item><nimble-admin-icon></nimble-admin-icon>Account</nimble-menu-item>
<nimble-menu-item><nimble-logout-icon></nimble-logout-icon>Log out</nimble-menu-item>
</nimble-menu>
`)
};