Skip to content

Commit

Permalink
Upgrade badge
Browse files Browse the repository at this point in the history
  • Loading branch information
angelikatyborska committed Jul 2, 2024
1 parent c5cb51c commit 0dd5256
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions lib/bitstyles_phoenix/component/badge.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule BitstylesPhoenix.Component.Badge do
use BitstylesPhoenix.Component
alias BitstylesPhoenix.Bitstyles

@moduledoc """
The Badge component.
Expand Down Expand Up @@ -27,6 +28,13 @@ defmodule BitstylesPhoenix.Component.Badge do
...> </.ui_badge>
...> """
''',
"6.0.0": '''
"""
<span class="a-badge u-h6 u-font-medium" data-theme="grayscale">
published
</span>
"""
''',
"5.0.1": '''
"""
<span class="a-badge u-h6 u-font-medium a-badge--text">
Expand All @@ -53,7 +61,14 @@ defmodule BitstylesPhoenix.Component.Badge do
...> </.ui_badge>
...> """
''',
'''
"6.0.0": '''
"""
<span class="a-badge u-h6 u-font-medium" data-theme="brand-1">
new
</span>
"""
''',
"5.0.1": '''
"""
<span class="a-badge u-h6 u-font-medium a-badge--brand-1">
new
Expand All @@ -74,7 +89,7 @@ defmodule BitstylesPhoenix.Component.Badge do
''',
'''
"""
<span class="a-badge u-h6 u-font-medium a-badge--brand-2">
<span class="a-badge u-h6 u-font-medium" data-theme="brand-2">
recommended
</span>
"""
Expand All @@ -93,7 +108,7 @@ defmodule BitstylesPhoenix.Component.Badge do
''',
'''
"""
<span class="a-badge u-h6 u-font-medium a-badge--danger">
<span class="a-badge u-h6 u-font-medium" data-theme="danger">
deleted
</span>
"""
Expand All @@ -112,23 +127,32 @@ defmodule BitstylesPhoenix.Component.Badge do
''',
'''
"""
<span class="a-badge u-h6 u-font-medium a-badge--text extra-class" data-foo="bar">
<span class="a-badge u-h6 u-font-medium extra-class" data-theme="grayscale" data-foo="bar">
published
</span>
"""
'''
)

def ui_badge(assigns) do
variant = assigns[:variant] || "text"
extra = assigns_to_attributes(assigns, [:class, :variant])

{variant_class, extra} =
if Bitstyles.version() >= "6.0.0" do
theme = assigns[:variant] || "grayscale"
{nil, Keyword.put_new(extra, :"data-theme", theme)}
else
variant = assigns[:variant] || "text"
{"a-badge--#{variant}", extra}
end

class =
classnames([
"a-badge u-h6 u-font-medium a-badge--#{variant}",
"a-badge u-h6 u-font-medium",
variant_class,
assigns[:class]
])

extra = assigns_to_attributes(assigns, [:class, :variant])
assigns = assign(assigns, class: class, extra: extra)
~H"<span class={@class} {@extra}><%= render_slot(@inner_block) %></span>"
end
Expand Down

0 comments on commit 0dd5256

Please sign in to comment.