Badge

Compact status labels with typed color, variant, and size.

Source
app/components/nitro_kit/badge.rb
API
NitroKit::Badge.new(label, variant:, size:, color:)

Colors

Every semantic color keeps compact state legible without application classes.

Color matrix

Neutral
Neutral
Information
Information
Operational
Operational
Action required
Action required
Failed
Failed
Viewport640 px · sm
Rubytest/dummy/app/components/gallery/components/badge_page.rb
Gallery::Data.badge_colors.each do |badge|
  sample(badge.label, slug: badge.slug) do
    render_badge(badge, id: "gallery-badge-color-#{badge.slug}")
  end
end

Variants and sizes

Both variants and both sizes are closed, visible presentation choices.

Variant matrix

Default
Default
Outline
Outline
Viewport640 px · sm
Rubytest/dummy/app/components/gallery/components/badge_page.rb
Gallery::Data.badge_variants.each do |badge|
  sample(badge.label, slug: badge.slug) do
    render_badge(badge, id: "gallery-badge-variant-#{badge.slug}")
  end
end

Size scale

SmallMedium
Viewport640 px · sm
Rubytest/dummy/app/components/gallery/components/badge_page.rb
Gallery::Data.badge_sizes.each do |badge|
  render_badge(badge, id: "gallery-badge-size-#{badge.slug}")
end

Content modes

Scalar, block, numeric, nested icon, and long product labels use the same label slot.

Label content

Scalar
Ready
Block
Generated from a Phlex block
Numeric
128
Nested icon
Secured
Long label
Awaiting production deployment approval from a workspace administrator
Viewport640 px · sm
Rubytest/dummy/app/components/gallery/components/badge_page.rb
sample("Scalar", slug: "scalar") do
  render NitroKit::Badge.new(
    "Ready",
    id: "gallery-badge-scalar",
    color: :success
  )
end
sample("Block", slug: "block") do
  render NitroKit::Badge.new(
    id: "gallery-badge-block",
    variant: :outline,
    color: :info
  ) { "Generated from a Phlex block" }
end
sample("Numeric", slug: "numeric") do
  render NitroKit::Badge.new(128, id: "gallery-badge-numeric", color: :neutral)
end
sample("Nested icon", slug: "nested-icon") do
  render NitroKit::Badge.new(id: "gallery-badge-nested-icon", color: :success) do
    render NitroKit::Icon.new(:lock, id: "gallery-badge-lock-icon", size: :xs)
    plain " Secured"
  end
end
sample("Long label", slug: "long-label") do
  render NitroKit::Badge.new(
    "Awaiting production deployment approval from a workspace administrator",
    id: "gallery-badge-long-label",
    variant: :outline,
    color: :warning
  )
end

Roster composition

Table, Avatar, and Badge compose into a realistic member-status roster.

Workspace roster

ViewportFull width
Rubytest/dummy/app/components/gallery/components/badge_page.rb
render NitroKit::Table.new(
  id: "gallery-badge-roster-table",
  table_html: { id: "gallery-badge-roster-table-element" }
) do |table|
  table.caption("Workspace roster")
  table.thead do
    table.tr do
      table.th("Person")
      table.th("Role")
      table.th("Status", align: :right)
    end
  end
  table.tbody do
    Gallery::Data.members.each do |member|
      table.tr do
        table.th(scope: :row) do
          render NitroKit::Avatar.new(
            alt: member.name,
            size: :sm,
            id: "gallery-badge-roster-avatar-#{member.id}"
          )
          plain " #{member.name}"
        end
        table.td(member.role.to_s.humanize)
        table.td(align: :right) do
          render NitroKit::Badge.new(
            member.status.to_s.humanize,
            id: "gallery-badge-roster-status-#{member.id}",
            color: member_status_color(member.status),
            size: :sm
          )
        end
      end
    end
  end
end