forked from primer/view_components
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction_menu_preview.rb
More file actions
516 lines (459 loc) · 17.9 KB
/
Copy pathaction_menu_preview.rb
File metadata and controls
516 lines (459 loc) · 17.9 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
# frozen_string_literal: true
module Primer
module Alpha
# @label ActionMenu
class ActionMenuPreview < ViewComponent::Preview
# @label Playground
#
# @param select_variant [Symbol] select [single, multiple, none]
# @param anchor_align [Symbol] select [start, center, end]
# @param anchor_side [Symbol] select [outside_bottom, outside_top, outside_left, outside_right]
# @param anchor_when_narrow [Symbol] select [inherit, bottom, fullscreen, left, right]
# @param size [Symbol] select [auto, small, medium, large, xlarge]
def playground(
select_variant: Primer::Alpha::ActionMenu::PrimaryMenu::DEFAULT_SELECT_VARIANT,
anchor_align: Primer::Alpha::Overlay::DEFAULT_ANCHOR_ALIGN,
anchor_side: Primer::Alpha::Overlay::DEFAULT_ANCHOR_SIDE,
anchor_when_narrow: Primer::Alpha::Overlay::DEFAULT_ANCHOR_WHEN_NARROW,
size: Primer::Alpha::Overlay::DEFAULT_SIZE
)
render(Primer::Alpha::ActionMenu.new(select_variant: select_variant, anchor_align: anchor_align, anchor_side: anchor_side, anchor_when_narrow: anchor_when_narrow, size: size)) do |menu|
menu.with_show_button { "Menu" }
menu.with_item(label: "Copy link")
menu.with_item(label: "Quote reply")
menu.with_item(label: "Reference in new issue")
menu.with_divider
menu.with_item(label: "Edit")
menu.with_item(label: "Delete", scheme: :danger)
end
end
# @label Content labels
#
def content_labels; end
# @label Default
#
# @snapshot interactive
def default
render(Primer::Alpha::ActionMenu.new(menu_id: "menu-1")) do |menu|
menu.with_show_button do |button|
button.with_trailing_action_icon(icon: :"triangle-down")
"Menu"
end
menu.with_item(label: "Copy link")
menu.with_item(label: "Quote reply")
menu.with_item(label: "Reference in new issue")
menu.with_divider
menu.with_item(label: "Edit") do |item|
item.with_description.with_content("Change settings")
end
menu.with_item(label: "Delete", scheme: :danger) do |item|
item.with_description.with_content("Sayonara")
end
end
end
# @label With groups
#
# @snapshot interactive
# @param nest_in_sub_menu toggle
def with_groups(nest_in_sub_menu: false)
contents = -> (menu) {
menu.with_group do |group|
group.with_heading(title: "Battlestar Galactica")
group.with_item(label: "William Adama")
group.with_item(label: 'Kara "Starbuck" Thrace')
group.with_item(label: 'Sharon "Boomer" Valerii')
group.with_item(label: "Gaius Baltar")
end
menu.with_group do |group|
group.with_heading(title: "Star Trek")
group.with_item(label: "Capt. Jean-luc Picard")
group.with_item(label: "Capt. Kathryn M. Janeway")
group.with_item(label: "Capt. Benjamin L. Sisko")
group.with_item(label: "Capt. James T. Kirk")
end
menu.with_group do |group|
group.with_heading(title: "Star Wars")
group.with_item(label: "Leia Organa")
group.with_item(label: "Luke Skywalker")
group.with_item(label: "Han Solo")
group.with_item(label: "Chewbacca")
end
}
render(Primer::Alpha::ActionMenu.new(menu_id: "menu-1")) do |menu|
menu.with_show_button do |button|
button.with_trailing_action_icon(icon: :"triangle-down")
"Favorite character"
end
if nest_in_sub_menu
menu.with_sub_menu_item(label: "Sub-menu") do |sub_menu_item|
contents.call(sub_menu_item)
end
else
contents.call(menu)
end
end
end
# @label With items and groups
#
# @snapshot interactive
def with_items_and_groups
render(Primer::Alpha::ActionMenu.new(menu_id: "menu-1")) do |menu|
menu.with_show_button do |button|
button.with_trailing_action_icon(icon: :"triangle-down")
"Meal preference"
end
menu.with_item(label: "Meat option")
menu.with_divider
menu.with_group do |group|
group.with_heading(title: "Vegetarian options")
group.with_item(label: "Grilled portbello mushroom")
group.with_item(label: "Polenta")
group.with_item(label: "Seitan")
end
menu.with_divider
menu.with_item(label: "Fish option")
end
end
# @label Wide
#
# @snapshot interactive
def wide
render(Primer::Alpha::ActionMenu.new(select_variant: :single, size: :medium)) do |menu|
menu.with_show_button do |button|
button.with_trailing_action_icon(icon: :"triangle-down")
"A wider menu"
end
menu.with_item(label: "Default", active: true, value: "default") do |item|
item.with_trailing_visual_label(scheme: :accent, inline: true).with_content("Recommended")
item.with_description { "This is an example for wide ActionMenus" }
end
menu.with_item(label: "Extended", active: false, value: "extended") do |item|
item.with_description { "It allows for extended descriptions with extra afforance for additional visuals" }
end
end
end
# @label With icon button
#
def with_icon_button
render(Primer::Alpha::ActionMenu.new) do |menu|
menu.with_show_button(icon: :star, "aria-label": "Menu")
menu.with_item(label: "Does something")
menu.with_item(label: "Does something else")
end
end
# @label Single select
#
def single_select
render(Primer::Alpha::ActionMenu.new(select_variant: :single)) do |menu|
menu.with_show_button { "Menu" }
menu.with_item(label: "Fast forward", item_id: :fast_forward)
menu.with_item(label: "Recursive", item_id: :recursive)
menu.with_item(label: "Ours", item_id: :ours)
menu.with_item(label: "Resolve", item_id: :resolve)
menu.with_item(label: "Disabled", disabled: true, item_id: :disabled)
menu.with_item(label: "Hidden", hidden: true, disabled: true, item_id: :hidden)
end
end
# @label Multiple select
#
# @param nest_in_sub_menu toggle
def multiple_select(nest_in_sub_menu: false)
content = -> (menu) {
menu.with_avatar_item(
src: "https://avatars.githubusercontent.com/u/18661030?v=4",
username: "langermank",
full_name: "Katie Langerman",
full_name_scheme: :inline,
avatar_arguments: { shape: :square },
item_id: :katie
)
menu.with_avatar_item(
src: "https://avatars.githubusercontent.com/u/54012?s=96&v=4",
username: "jonrohan",
full_name: "Jon Rohan",
full_name_scheme: :inline,
avatar_arguments: { shape: :square },
item_id: :jon
)
menu.with_avatar_item(
src: "https://avatars.githubusercontent.com/u/1446503?v=4",
username: "broccolinisoup",
full_name: "Armağan Ersöz",
full_name_scheme: :inline,
avatar_arguments: { shape: :square },
item_id: :armagan
)
}
render(Primer::Alpha::ActionMenu.new(select_variant: :multiple)) do |menu|
menu.with_show_button { "Menu" }
if nest_in_sub_menu
menu.with_sub_menu_item(label: "Sub-menu") do |sub_menu|
content.call(sub_menu)
end
else
content.call(menu)
end
end
end
# @label Links
#
def links
render(Primer::Alpha::ActionMenu.new) do |menu|
menu.with_show_button { "Menu" }
menu.with_item(label: "Settings", href: "/")
menu.with_item(label: "Your repositories", href: "/")
menu.with_item(label: "Disabled", href: "/", disabled: true)
end
end
# @label Single item selected
#
# @snapshot interactive
def single_selected_item
render(Primer::Alpha::ActionMenu.new(select_variant: :single)) do |menu|
menu.with_show_button { "Menu" }
menu.with_item(label: "Copy link")
menu.with_item(label: "Quote reply", active: true)
menu.with_item(label: "Reference in new issue")
end
end
# @label Single Select with Internal Label
#
# @snapshot interactive
# @param nest_in_sub_menu toggle
def single_select_with_internal_label(nest_in_sub_menu: false)
contents = -> (menu) {
menu.with_item(label: "Copy link") do |item|
item.with_trailing_visual_label(scheme: :accent, inline: true).with_content("Recommended")
end
menu.with_item(label: "Quote reply", active: true)
menu.with_item(label: "Reference in new issue")
}
render(Primer::Alpha::ActionMenu.new(select_variant: :single, dynamic_label: true, dynamic_label_prefix: "Menu")) do |menu|
menu.with_show_button do |button|
button.with_trailing_action_icon(icon: :"triangle-down")
"Menu"
end
if nest_in_sub_menu
menu.with_sub_menu_item(label: "Sub-menu") do |sub_menu_item|
contents.call(sub_menu_item)
end
else
contents.call(menu)
end
end
end
# @label Multiple items selected
#
# @snapshot interactive
def multiple_selected_items
render(Primer::Alpha::ActionMenu.new(select_variant: :multiple)) do |menu|
menu.with_show_button { "Menu" }
menu.with_avatar_item(
src: "https://avatars.githubusercontent.com/u/18661030?v=4",
username: "langermank",
full_name: "Katie Langerman",
full_name_scheme: :inline,
active: true
)
menu.with_avatar_item(
src: "https://avatars.githubusercontent.com/u/54012?s=96&v=4",
username: "jonrohan",
full_name: "Jon Rohan",
full_name_scheme: :inline
)
menu.with_avatar_item(
src: "https://avatars.githubusercontent.com/u/1446503?v=4",
username: "broccolinisoup",
full_name: "Armağan Ersöz",
full_name_scheme: :inline,
active: true
)
end
end
# @label With deferred content
#
# @param nest_in_sub_menu toggle
def with_deferred_content(nest_in_sub_menu: false)
render_with_template(locals: { nest_in_sub_menu: nest_in_sub_menu })
end
# @label With deferred content near the bottom of the viewport
#
# @hidden
def with_deferred_content_near_bottom_of_viewport
render_with_template
end
# @label With deferred preloaded content
#
def with_deferred_preloaded_content
render(Primer::Alpha::ActionMenu.new(menu_id: "deferred-preload", preload: true, src: UrlHelpers.primer_view_components.action_menu_deferred_preload_path)) do |menu|
menu.with_show_button { "Menu with deferred and preloaded content" }
end
end
# @label With actions
#
# @param disable_items toggle
# @param nest_in_sub_menu toggle
def with_actions(disable_items: false, nest_in_sub_menu: false, route_format: :html)
render_with_template(locals: {
disable_items: disable_items,
nest_in_sub_menu: nest_in_sub_menu,
route_format: route_format
})
end
# @label Single select form
#
def single_select_form(route_format: :html)
render_with_template(locals: { route_format: route_format })
end
# @label Single select form items
#
# @param nest_in_sub_menu toggle
def single_select_form_items(route_format: :html, nest_in_sub_menu: false)
render_with_template(locals: { route_format: route_format, nest_in_sub_menu: nest_in_sub_menu })
end
# @label Multiple select form
#
# @param nest_in_sub_menu toggle
def multiple_select_form(route_format: :html, nest_in_sub_menu: false)
render_with_template(locals: { route_format: route_format, nest_in_sub_menu: nest_in_sub_menu })
end
# @label With disabled items
#
def with_disabled_items
render(Primer::Alpha::ActionMenu.new) do |component|
component.with_show_button { "Trigger" }
component.with_item(label: "Does something", tag: :button, disabled: true)
component.with_item(label: "Site", tag: :a, href: "/", disabled: true)
end
end
# @label Opens a dialog
#
# @param nest_in_sub_menu toggle
def opens_dialog(menu_id: "menu-1", nest_in_sub_menu: false)
render_with_template(locals: {
menu_id: menu_id,
nest_in_sub_menu: nest_in_sub_menu
})
end
# @label In Scoll container
#
def in_scroll_container
render_with_template
end
# @label Align end
#
def align_end(menu_id: "menu-1")
render_with_template(locals: {
menu_id: menu_id
})
end
# @label [Item] Block description
#
def block_description
render(Primer::Alpha::ActionMenu.new(menu_id: "menu-1")) do |menu|
menu.with_show_button do |button|
button.with_trailing_action_icon(icon: :"triangle-down")
"Menu"
end
menu.with_item(label: "Item label") do |item|
item.with_description.with_content("Block description")
end
end
end
# @label [Item] Submitting Forms
#
def submitting_forms
render_with_template(locals: {})
end
# @label [Item] Inline description
#
def inline_description
render(Primer::Alpha::ActionMenu.new(menu_id: "menu-1")) do |menu|
menu.with_show_button do |button|
button.with_trailing_action_icon(icon: :"triangle-down")
"Menu"
end
menu.with_item(label: "Item label", description_scheme: :inline) do |item|
item.with_description.with_content("Inline description")
end
end
end
# @label [Item] Leading visual
#
def leading_visual
render(Primer::Alpha::ActionMenu.new(menu_id: "menu-1")) do |menu|
menu.with_show_button do |button|
button.with_trailing_action_icon(icon: :"triangle-down")
"Menu"
end
menu.with_item(label: "Item label", description_scheme: :inline) do |item|
item.with_leading_visual_icon(icon: :gear)
item.with_description.with_content("Inline description")
end
end
end
# @label [Item] Leading visual single select
#
def leading_visual_single_select
render(Primer::Alpha::ActionMenu.new(menu_id: "menu-1", select_variant: :single)) do |menu|
menu.with_show_button do |button|
button.with_trailing_action_icon(icon: :"triangle-down")
"Menu"
end
menu.with_item(label: "Item label", description_scheme: :inline) do |item|
item.with_leading_visual_icon(icon: :gear)
item.with_description.with_content("Inline description")
end
end
end
# @label Two menus
#
def two_menus; end
# @label Fullscreen when narrow
#
def fullscreen_when_narrow
render(Primer::Alpha::ActionMenu.new(anchor_when_narrow: :fullscreen)) do |menu|
menu.with_show_button do |button|
button.with_trailing_action_icon(icon: :"triangle-down")
"Options"
end
menu.with_item(label: "Edit profile") do |item|
item.with_description.with_content("Update your profile information")
end
menu.with_item(label: "Settings") do |item|
item.with_description.with_content("Configure your preferences")
end
menu.with_item(label: "Notifications") do |item|
item.with_description.with_content("Manage notification settings")
end
menu.with_divider
menu.with_item(label: "Sign out", scheme: :danger) do |item|
item.with_description.with_content("Log out of your account")
end
end
end
# @label Sub-menus
#
# @param anchor_align [Symbol] select [start, center, end]
# @param anchor_side [Symbol] select [outside_bottom, outside_top, outside_left, outside_right]
# @param anchor_when_narrow [Symbol] select [inherit, bottom, fullscreen, left, right]
# @param sub_menu_anchor_align [Symbol] select [start, center, end]
# @param sub_menu_anchor_side [Symbol] select [outside_bottom, outside_top, outside_left, outside_right]
def sub_menus(
anchor_align: Primer::Alpha::ActionMenu::PrimaryMenu::DEFAULT_ANCHOR_ALIGN,
anchor_side: Primer::Alpha::ActionMenu::PrimaryMenu::DEFAULT_ANCHOR_SIDE,
anchor_when_narrow: Primer::Alpha::ActionMenu::SubMenu::DEFAULT_ANCHOR_WHEN_NARROW,
sub_menu_anchor_align: Primer::Alpha::ActionMenu::SubMenu::DEFAULT_ANCHOR_ALIGN,
sub_menu_anchor_side: Primer::Alpha::ActionMenu::SubMenu::DEFAULT_ANCHOR_SIDE
)
render_with_template(locals: {
anchor_align: anchor_align.to_sym,
anchor_side: anchor_side.to_sym,
anchor_when_narrow: anchor_when_narrow.to_sym,
sub_menu_anchor_align: sub_menu_anchor_align,
sub_menu_anchor_side: sub_menu_anchor_side
})
end
end
end
end