Badge
Badge - Phlex implementation
Examples
Default
The default badge style.
Badge
<%= render "ui/badge" do %>Badge<% end %> Badge
<%= render UI::Badge.new { "Badge" } %> Badge
<%= render(UI::BadgeComponent.new) { "Badge" } %>Secondary
A secondary badge style.
Secondary
<%= render "ui/badge", variant: :secondary do %>Secondary<% end %> Secondary
<%= render UI::Badge.new(variant: :secondary) { "Secondary" } %> Secondary
<%= render(UI::BadgeComponent.new(variant: :secondary)) { "Secondary" } %>Destructive
A destructive badge style.
Destructive
<%= render "ui/badge", variant: :destructive do %>Destructive<% end %> Destructive
<%= render UI::Badge.new(variant: :destructive) { "Destructive" } %> Destructive
<%= render(UI::BadgeComponent.new(variant: :destructive)) { "Destructive" } %>Outline
An outline badge style.
Outline
<%= render "ui/badge", variant: :outline do %>Outline<% end %> Outline
<%= render UI::Badge.new(variant: :outline) { "Outline" } %> Outline
<%= render(UI::BadgeComponent.new(variant: :outline)) { "Outline" } %>With Icon
Badge with an icon for visual emphasis.
Verified
<%= render "ui/badge", variant: :secondary, classes: "bg-blue-500 text-white dark:bg-blue-600" do %>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="size-3">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z" clip-rule="evenodd" />
</svg>
Verified
<% end %>
Verified
<%= render UI::Badge.new(variant: :secondary, classes: "bg-blue-500 text-white dark:bg-blue-600") do %>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="size-3">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z" clip-rule="evenodd" />
</svg>
Verified
<% end %>
Verified
<%= render(UI::BadgeComponent.new(variant: :secondary, classes: "bg-blue-500 text-white dark:bg-blue-600")) do %>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="size-3">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z" clip-rule="evenodd" />
</svg>
Verified
<% end %>Notification Badge on Avatar
Badge used as notification count on an avatar.
F
3
<div class="relative inline-block">
<%= render "ui/avatar" do %>
<%= render "ui/avatar/image", src: "https://github.com/fernandes.png", alt: "@fernandes" %>
<%= render "ui/avatar/fallback" do %>F<% end %>
<% end %>
<%= render "ui/badge", classes: "absolute -top-1 -right-1 h-5 min-w-5 p-0 text-[10px]" do %>3<% end %>
</div>
F
3
<div class="relative inline-block">
<%= render UI::Avatar.new do %>
<%= render UI::AvatarImage.new(src: "https://github.com/fernandes.png", alt: "@fernandes") %>
<%= render UI::AvatarFallback.new { "F" } %>
<% end %>
<%= render UI::Badge.new(classes: "absolute -top-1 -right-1 h-5 min-w-5 p-0 text-[10px]") { "3" } %>
</div>
F
3
<div class="relative inline-block">
<%= render UI::AvatarComponent.new do %>
<%= render UI::AvatarImageComponent.new(src: "https://github.com/fernandes.png", alt: "@fernandes") %>
<%= render(UI::AvatarFallbackComponent.new) { "F" } %>
<% end %>
<%= render(UI::BadgeComponent.new(classes: "absolute -top-1 -right-1 h-5 min-w-5 p-0 text-[10px]")) { "3" } %>
</div>Features
- Custom styling with Tailwind classes
- ARIA attributes for accessibility
API Reference
Badge
Displays a badge or a component that looks like a badge.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| variant | Symbol | :default | Visual style variant |