Skip to content

Commit

Permalink
Add banner variant arg to SelectPanel.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamieshark committed Sep 11, 2024
1 parent b45ef04 commit 645aa25
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/components/primer/alpha/select_panel.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
<% if show_filter? %>
<% header.with_filter do %>
<div data-target="select-panel.bannerErrorElement" hidden>
<%= render Primer::Alpha::Banner.new(scheme: :danger, mb: 2) do %>
<%= render Primer::Alpha::Banner.new(scheme: @banner_variant, mb: 2) do %>
<% if error_content? %>
<%= error_content %>
<% else %>
<h2 class="f6 text-normal">Sorry, something went wrong.</h2>
<h2 class="f6 text-normal <%= @banner_variant == :warning ? "fgColor-attention" : "fgColor-danger" %>">Sorry, something went wrong.</h2>
<% end %>
<% end %>
</div>
Expand Down
14 changes: 14 additions & 0 deletions app/components/primer/alpha/select_panel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ def with_avatar_item(**system_arguments)
:none,
].freeze

DEFAULT_BANNER_VARIANT = :danger
BANNER_VARIANT_OPTIONS = [
DEFAULT_BANNER_VARIANT,
:warning
].freeze

# The URL to fetch search results from.
#
# @return [String]
Expand All @@ -331,6 +337,11 @@ def with_avatar_item(**system_arguments)
# @return [Symbol]
attr_reader :select_variant

# <%= one_of(Primer::Alpha::SelectPanel::BANNER_VARIANT_OPTIONS) %>
#
# @return [Symbol]
attr_reader :banner_variant

# <%= one_of(Primer::Alpha::SelectPanel::FETCH_STRATEGIES) %>
#
# @return [Symbol]
Expand Down Expand Up @@ -368,6 +379,7 @@ def with_avatar_item(**system_arguments)
# @param open_on_load [Boolean] Open the panel when the page loads.
# @param anchor_align [Symbol] The anchor alignment of the Overlay. <%= one_of(Primer::Alpha::Overlay::ANCHOR_ALIGN_OPTIONS) %>
# @param anchor_side [Symbol] The side to anchor the Overlay to. <%= one_of(Primer::Alpha::Overlay::ANCHOR_SIDE_OPTIONS) %>
# @param banner_variant [Symbol] The scheme for the error banner <%= one_of(Primer::Alpha::SelectPanel::BANNER_VARIANT_OPTIONS) %>
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(
src: nil,
Expand All @@ -388,6 +400,7 @@ def initialize(
open_on_load: false,
anchor_align: Primer::Alpha::Overlay::DEFAULT_ANCHOR_ALIGN,
anchor_side: Primer::Alpha::Overlay::DEFAULT_ANCHOR_SIDE,
banner_variant: DEFAULT_BANNER_VARIANT,
**system_arguments
)
raise_if_role_given!(**system_arguments)
Expand All @@ -409,6 +422,7 @@ def initialize(
@dynamic_label = dynamic_label
@dynamic_label_prefix = dynamic_label_prefix
@dynamic_aria_label_prefix = dynamic_aria_label_prefix
@banner_variant = fetch_or_fallback(BANNER_VARIANT_OPTIONS, banner_variant, DEFAULT_BANNER_VARIANT)

@system_arguments = deny_tag_argument(**system_arguments)
@system_arguments[:id] = @panel_id
Expand Down
5 changes: 4 additions & 1 deletion previews/primer/alpha/select_panel_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SelectPanelPreview < ViewComponent::Preview
# @param open_on_load toggle
# @param anchor_align [Symbol] select [start, center, end]
# @param anchor_side [Symbol] select [outside_bottom, outside_top, outside_left, outside_right]
# @param banner_variant [Symbol] select [danger, warning]
# @param selected_items text
def playground(
title: "Sci-fi equipment",
Expand All @@ -31,6 +32,7 @@ def playground(
open_on_load: false,
anchor_align: :start,
anchor_side: :outside_bottom,
banner_variant: :danger,
selected_items: "Phaser"
)
render_with_template(locals: {
Expand All @@ -47,7 +49,8 @@ def playground(
dynamic_aria_label_prefix: dynamic_aria_label_prefix,
open_on_load: open_on_load,
anchor_align: anchor_align,
anchor_side: anchor_side
anchor_side: anchor_side,
banner_variant: banner_variant
}
})
end
Expand Down

0 comments on commit 645aa25

Please sign in to comment.