Skip to content

Commit 0d61de5

Browse files
committed
Add classes class methods
1 parent 2542ee4 commit 0d61de5

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

app/components/flowbite/badge.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ class Badge < ViewComponent::Base
2828
}.freeze
2929

3030
class << self
31+
def classes(size: :default, state: :default, style: :brand)
32+
styles.fetch(style).fetch(state) + sizes.fetch(size)
33+
end
34+
35+
def sizes
36+
SIZES
37+
end
38+
3139
# rubocop:disable Layout/LineLength
3240
def styles
3341
Flowbite::Styles.from_hash({
@@ -89,16 +97,12 @@ def link?
8997
private
9098

9199
def classes
92-
result = self.class.styles.fetch(@style).fetch(:default) + size_classes
100+
result = self.class.classes(size: @size, state: :default, style: @style)
93101
result += BORDER_CLASSES.fetch(@style) if bordered?
94102
result += ["inline-flex", "items-center"] if dot?
95103
result + @class
96104
end
97105

98-
def size_classes
99-
SIZES.fetch(@size)
100-
end
101-
102106
def tag_name
103107
link? ? :a : :span
104108
end

app/components/flowbite/badge/dot.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@ class Dot < ViewComponent::Base
1616
warning: ["bg-fg-warning", "h-1.5", "me-1", "rounded-full", "w-1.5"]
1717
}.freeze
1818

19+
class << self
20+
def classes(style: :brand)
21+
CLASSES.fetch(style)
22+
end
23+
end
24+
1925
attr_reader :style
2026

2127
def initialize(style: :brand)
2228
@style = style
2329
end
2430

2531
def call
26-
content_tag(:span, nil, class: CLASSES.fetch(style))
32+
content_tag(:span, nil, class: self.class.classes(style: style))
2733
end
2834
end
2935
end

0 commit comments

Comments
 (0)