Skip to content

Commit

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

@doc """
Renders a tag, typically used for displaying labels, categories, or keywords.
## Examples
Plain tag:
<.tag>Well-Trained</.tag>
With icon:
<.tag>
Puppy
<.icon><Heroicons.edit /></icon>
</.tag>
With delete button:
<.tag>
High Energy
<button
phx-click="remove-tag"
phx-value-tag="high-energy"
aria-label="Remove tag"
>
<.icon><Heroicons.x /></icon>
</button>
</.tag>
"""

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

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

attr :shape, :atom, values: [nil, :pill], default: nil

slot :inner_block, required: true

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

## Helpers

defp humanize(atom) when is_atom(atom) do
Expand Down
48 changes: 48 additions & 0 deletions priv/storybook/components/tag.story.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
defmodule Storybook.Components.Tag do
use PhoenixStorybook.Story, :component

def function, do: &Doggo.tag/1

def variations do
[
%Variation{
id: :default,
slots: ["puppy"]
},
%Variation{
id: :pill,
attributes: %{shape: :pill},
slots: ["puppy"]
},
%VariationGroup{
id: :variants,
variations:
for variant <- [
:primary,
:secondary,
:info,
:success,
:warning,
:danger
] do
%Variation{
id: variant,
attributes: %{variant: variant},
slots: [to_string(variant)]
}
end
},
%VariationGroup{
id: :sizes,
variations:
for size <- [:small, :normal, :medium, :large] do
%Variation{
id: size,
attributes: %{size: size},
slots: [to_string(size)]
}
end
}
]
end
end

0 comments on commit ae14d6f

Please sign in to comment.