Skip to content

Commit 2542ee4

Browse files
committed
Add Flowbite::Badge::Dot component
1 parent 53ab6b1 commit 2542ee4

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

app/components/flowbite/badge.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,6 @@ class Badge < ViewComponent::Base
2727
warning: ["border", "border-warning-subtle"]
2828
}.freeze
2929

30-
DOT_CLASSES = {
31-
alternative: ["h-1.5", "w-1.5", "bg-heading", "me-1", "rounded-full"],
32-
brand: ["h-1.5", "w-1.5", "bg-fg-brand-strong", "me-1", "rounded-full"],
33-
danger: ["h-1.5", "w-1.5", "bg-fg-danger-strong", "me-1", "rounded-full"],
34-
gray: ["h-1.5", "w-1.5", "bg-heading", "me-1", "rounded-full"],
35-
success: ["h-1.5", "w-1.5", "bg-fg-success-strong", "me-1", "rounded-full"],
36-
warning: ["h-1.5", "w-1.5", "bg-fg-warning", "me-1", "rounded-full"]
37-
}.freeze
38-
3930
class << self
4031
# rubocop:disable Layout/LineLength
4132
def styles
@@ -104,10 +95,6 @@ def classes
10495
result + @class
10596
end
10697

107-
def dot_classes
108-
DOT_CLASSES.fetch(@style)
109-
end
110-
11198
def size_classes
11299
SIZES.fetch(@size)
113100
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<%= content_tag(tag_name, **tag_options) do %>
2-
<% if dot? %><span class="<%= dot_classes.join(" ") %>"></span><% end %>
2+
<% if dot? %><%= render(Flowbite::Badge::Dot.new(style: @style)) %><% end %>
33
<%= content %>
44
<% end %>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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

Comments
 (0)