Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Banner legacy classes #1548

Merged
merged 2 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/weak-moose-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

Include legacy flash classes in banners
10 changes: 10 additions & 0 deletions app/components/primer/beta/banner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ class Banner < Primer::Component
:success => "Banner--success"
}.freeze

LEGACY_SCHEME_MAPPINGS = {
DEFAULT_SCHEME => "",
:warning => "flash-warn",
:danger => "flash-error",
:success => "flash-success"
}.freeze

DEFAULT_ICONS = {
default: :bell,
warning: :alert,
Expand Down Expand Up @@ -95,8 +102,11 @@ def initialize(full: false, full_when_narrow: false, dismissible: false, descrip
@system_arguments[:classes] = class_names(
@system_arguments[:classes],
"Banner",
"flash", # legacy
SCHEME_MAPPINGS[@scheme],
LEGACY_SCHEME_MAPPINGS[@scheme],
"Banner--full": full,
"flash-full": full, # legacy
"Banner--full-whenNarrow": full_when_narrow
)

Expand Down
10 changes: 10 additions & 0 deletions test/components/beta/banner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,31 @@ def test_renders
assert_selector(".octicon")
end

def test_includes_legacy_classes
render_inline(Primer::Beta::Banner.new) { "foo" }

assert_selector(".flash")
end

def test_renders_danger_scheme
render_inline(Primer::Beta::Banner.new(scheme: :danger)) { "foo" }

assert_selector(".Banner.Banner--error", text: "foo")
assert_selector(".flash.flash-error", text: "foo") # legacy
end

def test_renders_warning_scheme
render_inline(Primer::Beta::Banner.new(scheme: :warning)) { "foo" }

assert_selector(".Banner.Banner--warning", text: "foo")
assert_selector(".flash.flash-warn", text: "foo") # legacy
end

def test_renders_success_scheme
render_inline(Primer::Beta::Banner.new(scheme: :success)) { "foo" }

assert_selector(".Banner.Banner--success", text: "foo")
assert_selector(".flash.flash-success", text: "foo") # legacy
end

def test_renders_default_icon
Expand Down Expand Up @@ -76,6 +85,7 @@ def test_renders_full_width
render_inline(Primer::Beta::Banner.new(full: true)) { "foo" }

assert_selector(".Banner.Banner--full", text: "foo")
assert_selector(".flash.flash-full", text: "foo") # legacy
end

def test_renders_full_width_when_narrow
Expand Down