-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add group support to ActionMenu (#2340)
Co-authored-by: camertron <[email protected]>
- Loading branch information
Showing
39 changed files
with
1,381 additions
and
823 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@primer/view-components': minor | ||
--- | ||
|
||
Add group support to ActionMenu |
Binary file added
BIN
+44.1 KB
...shots/snapshots.test.ts-snapshots/primer/alpha/action_menu/with_groups/dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+44.6 KB
...hots.test.ts-snapshots/primer/alpha/action_menu/with_groups/dark_colorblind.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+47.1 KB
...napshots.test.ts-snapshots/primer/alpha/action_menu/with_groups/dark_dimmed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+43.3 KB
...s.test.ts-snapshots/primer/alpha/action_menu/with_groups/dark_high_contrast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+33.6 KB
...ts/snapshots.test.ts-snapshots/primer/alpha/action_menu/with_groups/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+33.6 KB
...ts/snapshots.test.ts-snapshots/primer/alpha/action_menu/with_groups/focused.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+42.8 KB
...hots/snapshots.test.ts-snapshots/primer/alpha/action_menu/with_groups/light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+42.8 KB
...ots.test.ts-snapshots/primer/alpha/action_menu/with_groups/light_colorblind.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+42.5 KB
....test.ts-snapshots/primer/alpha/action_menu/with_groups/light_high_contrast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+23.2 KB
...shots.test.ts-snapshots/primer/alpha/action_menu/with_items_and_groups/dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+23.3 KB
...ts-snapshots/primer/alpha/action_menu/with_items_and_groups/dark_colorblind.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+25.8 KB
...est.ts-snapshots/primer/alpha/action_menu/with_items_and_groups/dark_dimmed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+22.4 KB
...snapshots/primer/alpha/action_menu/with_items_and_groups/dark_high_contrast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+30.9 KB
...ts.test.ts-snapshots/primer/alpha/action_menu/with_items_and_groups/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+30.9 KB
...ts.test.ts-snapshots/primer/alpha/action_menu/with_items_and_groups/focused.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+21.8 KB
...hots.test.ts-snapshots/primer/alpha/action_menu/with_items_and_groups/light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+21.8 KB
...s-snapshots/primer/alpha/action_menu/with_items_and_groups/light_colorblind.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+21.8 KB
...napshots/primer/alpha/action_menu/with_items_and_groups/light_high_contrast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
module Primer | ||
module Alpha | ||
class ActionMenu | ||
# This component is part of <%= link_to_component(Primer::Alpha::ActionMenu) %> and should not be | ||
# used as a standalone component. | ||
class Group < Primer::Alpha::ActionList | ||
# Heading text rendered above the list of items. | ||
# | ||
# @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::ActionMenu::Heading) %>. | ||
def with_heading(**system_arguments, &block) | ||
super(component_klass: Primer::Alpha::ActionMenu::Heading, **system_arguments, &block) | ||
end | ||
|
||
def with_divider | ||
raise "ActionMenu groups cannot have dividers" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module Primer | ||
module Alpha | ||
class ActionMenu | ||
# Heading used to describe groups within an action menu. | ||
class Heading < Primer::Alpha::ActionList::Heading | ||
def initialize(**) | ||
super | ||
|
||
# Headings don't make sense in a menu context, so use div instead | ||
@tag = :div | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= render(@list) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
module Primer | ||
module Alpha | ||
class ActionMenu | ||
# This component is part of <%= link_to_component(Primer::Alpha::ActionMenu) %> and should not be | ||
# used as a standalone component. | ||
class ListWrapper < Primer::Alpha::ActionList | ||
add_polymorphic_slot_type( | ||
slot_name: :items, | ||
type: :group, | ||
callable: lambda { |**system_arguments| | ||
Primer::Alpha::ActionMenu::Group.new( | ||
**system_arguments, | ||
role: :group, | ||
select_variant: @select_variant | ||
) | ||
} | ||
) | ||
|
||
# @param menu_id [String] ID of the parent menu. | ||
# @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::ActionList) %> | ||
def initialize(menu_id:, **system_arguments) | ||
@menu_id = menu_id | ||
|
||
system_arguments[:aria] = merge_aria( | ||
system_arguments, | ||
{ aria: { labelledby: "#{@menu_id}-button" } } | ||
) | ||
|
||
system_arguments[:role] = :menu | ||
system_arguments[:scheme] = :inset | ||
system_arguments[:id] = "#{@menu_id}-list" | ||
|
||
super(**system_arguments) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
module Primer | ||
# :nodoc: | ||
module ExperimentalRenderHelpers | ||
def self.included(base) | ||
base.include(InstanceMethods) | ||
end | ||
|
||
# :nodoc: | ||
module InstanceMethods | ||
def evaluate_block(*args, **kwargs, &block) | ||
# Prevent double renders by using the capture method on the component | ||
# that originally received the block. | ||
# | ||
# Handle blocks that originate from C code such as `&:method` by checking | ||
# source_location. Such blocks don't allow access to their receiver. | ||
return unless block | ||
|
||
return yield(*args, **kwargs) if block&.source_location.nil? | ||
|
||
block_context = block.binding.receiver | ||
|
||
if block_context.class < ActionView::Base | ||
block_context.capture(*args, &block) | ||
else | ||
capture(*args, &block) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module Primer | ||
# :nodoc: | ||
module ExperimentalSlotHelpers | ||
def self.included(base) | ||
base.extend(ClassMethods) | ||
end | ||
|
||
# :nodoc: | ||
module ClassMethods | ||
def add_polymorphic_slot_type(slot_name:, type:, callable:) | ||
slot_def = registered_slots[slot_name] | ||
raise "Unknown slot '#{slot_name}'" unless slot_def | ||
|
||
poly_def = define_slot( | ||
type, | ||
collection: slot_def[:collection], | ||
callable: callable | ||
) | ||
|
||
registered_slots[slot_name][:renderable_hash][type] = poly_def | ||
|
||
define_method(:"with_#{type}") do |**system_arguments, &block| | ||
set_slot(slot_name, poly_def, **system_arguments, &block) | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.