Shadwire

Search the documentation

Search the documentation and component pages by title and by content.

Get started
Introduction
Installation
shadwire.json
Theming
Dark mode
Tools
CLI
Agent skill
Registry
llms.txt
Guides
Composition
Styling
Forms
Icons
Accessibility
Localisation
Blocks
Overview
Components
Overview
Accordion
Alert
Alert Dialog
Aspect Ratio
Avatar
Badge
Breadcrumb
Button
Button Group
Calendar
Card
Carousel
Chart
Checkbox
Collapsible
Combobox
Command
Context Menu
Data Table
Date Picker
Dialog
Drawer
Dropdown Menu
Empty
Field
Hover Card
Icon
Input
Input Group
Input OTP
Item
Kbd
Label
Menubar
Native Select
Navigation Menu
Pagination
Popover
Progress
Radio Group
Resizable
Scroll Area
Select
Separator
Sheet
Sidebar
Skeleton
Slider
Sonner
Spinner
Switch
Table
Tabs
Textarea
Toggle
Toggle Group
Tooltip

Badge

A compact label for status, categories and short counters.

Installation

Shadwire follows shadcn/ui's open code model: the component's source is copied into your application and becomes yours. Install it with the CLI:

shadwire add badge --yes

The badge registry item installs these files:

  • app/components/ui_component.rb
  • app/components/ui/badge_component.rb
  • app/helpers/ui/badge_helper.rb
  • vendor/shadwire/shadwire.css

Haven't installed the CLI yet? gem install shadwire, then shadwire init.

Usage

<%= ui_badge { "Badge" } %>
<%= ui_badge(variant: :secondary) { "Secondary" } %>

Or render Ui::BadgeComponent directly:

<%= render Ui::BadgeComponent.new(variant: :outline) do %>
  Outline
<% end %>

Examples

Variants

Use variants to signal priority, state or category.

Badge Secondary Destructive Outline
<div class="flex flex-wrap items-center gap-2">
  <%= ui_badge { "Badge" } %>
  <%= ui_badge(variant: :secondary) { "Secondary" } %>
  <%= ui_badge(variant: :destructive) { "Destructive" } %>
  <%= ui_badge(variant: :outline) { "Outline" } %>
</div>

API reference

ui_badge(**options, &block) wraps Ui::BadgeComponent.new(**options).

Argument Type Default Description
variantSymbol/String:default:default, :secondary, :destructive or :outline.
tagSymbol:spanThe element to render; :a with href: for a badge that links. Hover styles apply to links only.
class / class_nameStringnilExtra classes.
**attrsHash{}Free-form HTML attributes for the element.