Skip to content

Commit ed8bf4a

Browse files
ActionMenu: Add fullscreen option to ActionMenu for narrow viewports (#3955)
Co-authored-by: primer-css <primer-css@users.noreply.github.com>
1 parent 8c0019e commit ed8bf4a

12 files changed

Lines changed: 178 additions & 3 deletions

File tree

.changeset/easy-zoos-leave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/view-components': patch
3+
---
4+
5+
ActionMenu: Add fullscreen option to ActionMenu

app/components/primer/alpha/action_menu.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ class ActionMenu < Primer::Component
187187
# @param menu_id [String] Id of the menu.
188188
# @param anchor_align [Symbol] <%= one_of(Primer::Alpha::Overlay::ANCHOR_ALIGN_OPTIONS) %>.
189189
# @param anchor_side [Symbol] <%= one_of(Primer::Alpha::Overlay::ANCHOR_SIDE_OPTIONS) %>.
190+
# @param anchor_when_narrow [Symbol] <%= one_of(Primer::Alpha::Overlay::ANCHOR_WHEN_NARROW_OPTIONS) %>.
190191
# @param size [Symbol] <%= one_of(Primer::Alpha::Overlay::SIZE_OPTIONS) %>.
191192
# @param src [String] Used with an `include-fragment` element to load menu content from the given source URL.
192193
# @param preload [Boolean] When true, and src is present, loads the `include-fragment` on trigger hover.
@@ -200,6 +201,7 @@ def initialize(
200201
menu_id: self.class.generate_id,
201202
anchor_align: Primer::Alpha::Overlay::DEFAULT_ANCHOR_ALIGN,
202203
anchor_side: Primer::Alpha::Overlay::DEFAULT_ANCHOR_SIDE,
204+
anchor_when_narrow: Primer::Alpha::Overlay::DEFAULT_ANCHOR_WHEN_NARROW,
203205
size: Primer::Alpha::Overlay::DEFAULT_SIZE,
204206
src: nil,
205207
preload: DEFAULT_PRELOAD,
@@ -236,6 +238,7 @@ def initialize(
236238
visually_hide_title: true,
237239
anchor_align: anchor_align,
238240
anchor_side: anchor_side,
241+
anchor_when_narrow: anchor_when_narrow,
239242
size: size,
240243
**overlay_arguments
241244
)

app/components/primer/alpha/dialog.pcss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,18 @@ dialog.Overlay:not([open]) {
422422
border-radius: unset !important;
423423
flex-grow: 1;
424424
}
425+
426+
.Overlay--fullscreen-whenNarrow {
427+
position: fixed;
428+
top: 0;
429+
left: 0;
430+
width: 100vw;
431+
max-width: none !important;
432+
height: 100vh;
433+
max-height: none !important;
434+
margin: 0;
435+
border-radius: unset !important;
436+
}
425437
}
426438

427439
@keyframes Overlay--motion-slideDown {

app/components/primer/alpha/overlay.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ class Overlay < Primer::Component
6565

6666
ROLE_OPTIONS = [:dialog, :menu, nil].freeze
6767

68+
DEFAULT_ANCHOR_WHEN_NARROW = :inherit
69+
ANCHOR_WHEN_NARROW_MAPPINGS = {
70+
DEFAULT_ANCHOR_WHEN_NARROW => "",
71+
:bottom => "Overlay--placement-bottom-whenNarrow",
72+
:fullscreen => "Overlay--fullscreen-whenNarrow",
73+
:left => "Overlay--placement-left-whenNarrow",
74+
:right => "Overlay--placement-right-whenNarrow"
75+
}.freeze
76+
ANCHOR_WHEN_NARROW_OPTIONS = ANCHOR_WHEN_NARROW_MAPPINGS.keys
77+
6878
# Optional button to open the Overlay.
6979
#
7080
# @param icon [String] Name of <%= link_to_octicons %> to use instead of text. If provided, a <%= link_to_component(Primer::Beta::IconButton) %> will be rendered. Otherwise a <%= link_to_component(Primer::Beta::Button) %> will be rendered.
@@ -132,6 +142,7 @@ class Overlay < Primer::Component
132142
# @param anchor_align [Symbol] The anchor alignment of the Overlay. <%= one_of(Primer::Alpha::Overlay::ANCHOR_ALIGN_OPTIONS) %>
133143
# @param anchor_side [Symbol] The side to anchor the Overlay to. <%= one_of(Primer::Alpha::Overlay::ANCHOR_SIDE_OPTIONS) %>
134144
# @param anchor_offset [Symbol] The anchor offset to give the Overlay. <%= one_of(Primer::Alpha::Overlay::ANCHOR_OFFSET_OPTIONS) %>
145+
# @param anchor_when_narrow [Symbol] The position of the Overlay when in a narrow viewport. <%= one_of(Primer::Alpha::Overlay::ANCHOR_WHEN_NARROW_OPTIONS) %>
135146
# @param allow_out_of_bounds [Boolean] Allow the Overlay to overflow its container.
136147
# @param visually_hide_title [Boolean] If true will hide the heading title, while still making it available to Screen Readers.
137148
# @param role [String] The ARIA role. <%= one_of(Primer::Alpha::Overlay::ROLE_OPTIONS) %>
@@ -147,6 +158,7 @@ def initialize(
147158
anchor_align: DEFAULT_ANCHOR_ALIGN,
148159
anchor_offset: DEFAULT_ANCHOR_OFFSET,
149160
anchor_side: DEFAULT_ANCHOR_SIDE,
161+
anchor_when_narrow: DEFAULT_ANCHOR_WHEN_NARROW,
150162
allow_out_of_bounds: false,
151163
visually_hide_title: false,
152164
id: self.class.generate_id,
@@ -159,7 +171,8 @@ def initialize(
159171
@system_arguments[:id] = id.to_s
160172
@wrapper_classes = class_names(
161173
"Overlay",
162-
SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)]
174+
SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)],
175+
ANCHOR_WHEN_NARROW_MAPPINGS[fetch_or_fallback(ANCHOR_WHEN_NARROW_OPTIONS, anchor_when_narrow, DEFAULT_ANCHOR_WHEN_NARROW)]
163176
)
164177
@system_arguments[:tag] = "anchored-position"
165178
@system_arguments[:anchor] = anchor || "overlay-show-#{@system_arguments[:id]}"

previews/primer/alpha/action_menu_preview.rb

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ class ActionMenuPreview < ViewComponent::Preview
99
# @param select_variant [Symbol] select [single, multiple, none]
1010
# @param anchor_align [Symbol] select [start, center, end]
1111
# @param anchor_side [Symbol] select [outside_bottom, outside_top, outside_left, outside_right]
12+
# @param anchor_when_narrow [Symbol] select [inherit, bottom, fullscreen, left, right]
1213
# @param size [Symbol] select [auto, small, medium, large, xlarge]
1314
def playground(
1415
select_variant: Primer::Alpha::ActionMenu::DEFAULT_SELECT_VARIANT, anchor_align: Primer::Alpha::Overlay::DEFAULT_ANCHOR_ALIGN, anchor_side: Primer::Alpha::Overlay::DEFAULT_ANCHOR_SIDE,
16+
anchor_when_narrow: Primer::Alpha::Overlay::DEFAULT_ANCHOR_WHEN_NARROW,
1517
size: Primer::Alpha::Overlay::DEFAULT_SIZE
1618
)
17-
render(Primer::Alpha::ActionMenu.new(select_variant: select_variant, anchor_align: anchor_align, anchor_side: anchor_side, size: size)) do |menu|
19+
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|
1820
menu.with_show_button { "Menu" }
1921
menu.with_item(label: "Copy link")
2022
menu.with_item(label: "Quote reply")
@@ -405,6 +407,35 @@ def leading_visual_single_select
405407
# @label Two menus
406408
#
407409
def two_menus; end
410+
411+
# @label Fullscreen when narrow
412+
#
413+
def fullscreen_when_narrow
414+
render(Primer::Alpha::ActionMenu.new(anchor_when_narrow: :fullscreen)) do |menu|
415+
menu.with_show_button do |button|
416+
button.with_trailing_action_icon(icon: :"triangle-down")
417+
"Options"
418+
end
419+
420+
menu.with_item(label: "Edit profile") do |item|
421+
item.with_description.with_content("Update your profile information")
422+
end
423+
424+
menu.with_item(label: "Settings") do |item|
425+
item.with_description.with_content("Configure your preferences")
426+
end
427+
428+
menu.with_item(label: "Notifications") do |item|
429+
item.with_description.with_content("Manage notification settings")
430+
end
431+
432+
menu.with_divider
433+
434+
menu.with_item(label: "Sign out", scheme: :danger) do |item|
435+
item.with_description.with_content("Log out of your account")
436+
end
437+
end
438+
end
408439
end
409440
end
410441
end

static/arguments.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,12 @@
343343
"default": "`:outside_bottom`",
344344
"description": "One of `:inside_bottom`, `:inside_center`, `:inside_left`, `:inside_right`, `:inside_top`, `:outside_bottom`, `:outside_left`, `:outside_right`, or `:outside_top`.."
345345
},
346+
{
347+
"name": "anchor_when_narrow",
348+
"type": "Symbol",
349+
"default": "`:inherit`",
350+
"description": "One of `:bottom`, `:fullscreen`, `:inherit`, `:left`, or `:right`.."
351+
},
346352
{
347353
"name": "size",
348354
"type": "Symbol",
@@ -1910,6 +1916,12 @@
19101916
"default": "`:normal`",
19111917
"description": "The anchor offset to give the Overlay. One of `:normal` or `:spacious`."
19121918
},
1919+
{
1920+
"name": "anchor_when_narrow",
1921+
"type": "Symbol",
1922+
"default": "`:inherit`",
1923+
"description": "The position of the Overlay when in a narrow viewport. One of `:bottom`, `:fullscreen`, `:inherit`, `:left`, or `:right`."
1924+
},
19131925
{
19141926
"name": "allow_out_of_bounds",
19151927
"type": "Boolean",

static/classes.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,9 @@
423423
"Overlay--full-whenNarrow": [
424424
"Primer::Alpha::Dialog"
425425
],
426+
"Overlay--fullscreen-whenNarrow": [
427+
"Primer::Alpha::Dialog"
428+
],
426429
"Overlay--hidden": [
427430
"Primer::Alpha::Dialog"
428431
],

static/constants.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,11 +579,26 @@
579579
"outside_left",
580580
"outside_right"
581581
],
582+
"ANCHOR_WHEN_NARROW_MAPPINGS": {
583+
"inherit": "",
584+
"bottom": "Overlay--placement-bottom-whenNarrow",
585+
"fullscreen": "Overlay--fullscreen-whenNarrow",
586+
"left": "Overlay--placement-left-whenNarrow",
587+
"right": "Overlay--placement-right-whenNarrow"
588+
},
589+
"ANCHOR_WHEN_NARROW_OPTIONS": [
590+
"inherit",
591+
"bottom",
592+
"fullscreen",
593+
"left",
594+
"right"
595+
],
582596
"Body": "Primer::Alpha::Overlay::Body",
583597
"DEFAULT_ALIGN_CONTENT": "end",
584598
"DEFAULT_ANCHOR_ALIGN": "start",
585599
"DEFAULT_ANCHOR_OFFSET": "normal",
586600
"DEFAULT_ANCHOR_SIDE": "outside_bottom",
601+
"DEFAULT_ANCHOR_WHEN_NARROW": "inherit",
587602
"DEFAULT_PADDING": "normal",
588603
"DEFAULT_POPOVER": "auto",
589604
"DEFAULT_SIZE": "auto",

static/info_arch.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,12 @@
12031203
"default": "`:outside_bottom`",
12041204
"description": "One of `:inside_bottom`, `:inside_center`, `:inside_left`, `:inside_right`, `:inside_top`, `:outside_bottom`, `:outside_left`, `:outside_right`, or `:outside_top`.."
12051205
},
1206+
{
1207+
"name": "anchor_when_narrow",
1208+
"type": "Symbol",
1209+
"default": "`:inherit`",
1210+
"description": "One of `:bottom`, `:fullscreen`, `:inherit`, `:left`, or `:right`.."
1211+
},
12061212
{
12071213
"name": "size",
12081214
"type": "Symbol",
@@ -1763,6 +1769,19 @@
17631769
"color-contrast"
17641770
]
17651771
}
1772+
},
1773+
{
1774+
"preview_path": "primer/alpha/action_menu/fullscreen_when_narrow",
1775+
"name": "fullscreen_when_narrow",
1776+
"snapshot": "false",
1777+
"skip_rules": {
1778+
"wont_fix": [
1779+
"region"
1780+
],
1781+
"will_fix": [
1782+
"color-contrast"
1783+
]
1784+
}
17661785
}
17671786
],
17681787
"subcomponents": [
@@ -5915,6 +5934,12 @@
59155934
"default": "`:normal`",
59165935
"description": "The anchor offset to give the Overlay. One of `:normal` or `:spacious`."
59175936
},
5937+
{
5938+
"name": "anchor_when_narrow",
5939+
"type": "Symbol",
5940+
"default": "`:inherit`",
5941+
"description": "The position of the Overlay when in a narrow viewport. One of `:bottom`, `:fullscreen`, `:inherit`, `:left`, or `:right`."
5942+
},
59185943
{
59195944
"name": "allow_out_of_bounds",
59205945
"type": "Boolean",

static/previews.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,19 @@
826826
"color-contrast"
827827
]
828828
}
829+
},
830+
{
831+
"preview_path": "primer/alpha/action_menu/fullscreen_when_narrow",
832+
"name": "fullscreen_when_narrow",
833+
"snapshot": "false",
834+
"skip_rules": {
835+
"wont_fix": [
836+
"region"
837+
],
838+
"will_fix": [
839+
"color-contrast"
840+
]
841+
}
829842
}
830843
]
831844
},

0 commit comments

Comments
 (0)