Skip to content

Commit

Permalink
add badge component
Browse files Browse the repository at this point in the history
  • Loading branch information
woylie committed Dec 26, 2023
1 parent ae14d6f commit ba667d7
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/doggo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,33 @@ defmodule Doggo do
"""
end

@doc """
Renders a badge, typically used for drawing attention to elements like
notification counts.
## Examples
<.badge>8</.badge>
"""

attr :size, :atom,
values: [:small, :normal, :medium, :large],
default: :normal

attr :variant, :atom,
values: [nil, :primary, :secondary, :info, :success, :warning, :danger],
default: nil

slot :inner_block, required: true

def badge(assigns) do
~H"""
<span class={["badge", size_class(@size), variant_class(@variant)]}>
<%= render_slot(@inner_block) %>
</span>
"""
end

@doc """
Renders a box for a section on the page.
Expand Down
47 changes: 47 additions & 0 deletions priv/storybook/components/badge.story.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
defmodule Storybook.Components.Badge do
use PhoenixStorybook.Story, :component

def function, do: &Doggo.badge/1

def variations do
[
%Variation{
id: :default,
slots: ["8"]
},
%Variation{
id: :large_count,
slots: ["+1000"]
},
%VariationGroup{
id: :variants,
variations:
for variant <- [
:primary,
:secondary,
:info,
:success,
:warning,
:danger
] do
%Variation{
id: variant,
attributes: %{variant: variant},
slots: ["8"]
}
end
},
%VariationGroup{
id: :sizes,
variations:
for size <- [:small, :normal, :medium, :large] do
%Variation{
id: size,
attributes: %{size: size},
slots: ["8"]
}
end
}
]
end
end

0 comments on commit ba667d7

Please sign in to comment.