Skip to content

Commit b60017d

Browse files
committed
Follow the same patterns as the other components
1 parent 7d34ff7 commit b60017d

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

app/components/flowbite/input/validation_error.rb

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,36 @@
33
module Flowbite
44
module Input
55
class ValidationError < ViewComponent::Base
6+
class << self
7+
def classes(state: :default, style: :default)
8+
style = styles.fetch(style)
9+
style.fetch(state)
10+
end
11+
12+
# rubocop:disable Layout/LineLength
13+
def styles
14+
{
15+
default: Flowbite::Style.new(
16+
default: ["mt-2", "text-sm", "text-red-600", "dark:text-red-500"]
17+
)
18+
}.freeze
19+
end
20+
# rubocop:enable Layout/LineLength
21+
end
22+
623
def call
7-
tag.p(content, class: "mt-2 text-sm text-red-600 dark:text-red-500 #{@class}")
24+
tag.p(content, class: classes)
825
end
926

1027
def initialize(class: nil)
11-
@class = binding.local_variable_get(:class)
28+
@class = Array.wrap(binding.local_variable_get(:class))
29+
end
30+
31+
protected
32+
33+
# Returns the CSS classes to apply to the validation error
34+
def classes
35+
self.class.classes + @class
1236
end
1337
end
1438
end

0 commit comments

Comments
 (0)