|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +module Flowbite |
| 4 | + class Badge |
| 5 | + # Renders a colored dot indicator for use inside a badge. |
| 6 | + # |
| 7 | + # @param style [Symbol] The color style of the dot (:alternative, :brand, |
| 8 | + # :danger, :gray, :success, :warning). |
| 9 | + class Dot < ViewComponent::Base |
| 10 | + CLASSES = { |
| 11 | + alternative: ["bg-heading", "h-1.5", "me-1", "rounded-full", "w-1.5"], |
| 12 | + brand: ["bg-fg-brand-strong", "h-1.5", "me-1", "rounded-full", "w-1.5"], |
| 13 | + danger: ["bg-fg-danger-strong", "h-1.5", "me-1", "rounded-full", "w-1.5"], |
| 14 | + gray: ["bg-heading", "h-1.5", "me-1", "rounded-full", "w-1.5"], |
| 15 | + success: ["bg-fg-success-strong", "h-1.5", "me-1", "rounded-full", "w-1.5"], |
| 16 | + warning: ["bg-fg-warning", "h-1.5", "me-1", "rounded-full", "w-1.5"] |
| 17 | + }.freeze |
| 18 | + |
| 19 | + attr_reader :style |
| 20 | + |
| 21 | + def initialize(style: :brand) |
| 22 | + @style = style |
| 23 | + end |
| 24 | + |
| 25 | + def call |
| 26 | + content_tag(:span, nil, class: CLASSES.fetch(style)) |
| 27 | + end |
| 28 | + end |
| 29 | + end |
| 30 | +end |
0 commit comments