Skip to content

Commit a889efc

Browse files
committed
Add option to pass attributes to the card
1 parent 7e3a4e9 commit a889efc

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

app/components/flowbite/card.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,16 @@ def styles
2121
end
2222

2323
def call
24-
content_tag(:div, class: self.class.classes) do
24+
content_tag(:div, {class: self.class.classes}.merge(@options)) do
2525
concat(content_tag(:div, content, class: "font-normal text-gray-700 dark:text-gray-400"))
2626
end
2727
end
28+
29+
# @param options [Hash] Additional HTML options for the card container
30+
# (e.g., custom classes, data attributes). These options are merged into
31+
# the card's root element.
32+
def initialize(**options)
33+
@options = options || {}
34+
end
2835
end
2936
end

test/components/flowbite/card_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ def test_renders_a_default_card
88

99
assert_selector("div.p-6.bg-white.border.border-gray-200.rounded-lg.shadow-sm")
1010
end
11+
12+
def test_passes_extra_options_to_the_card_as_attributes
13+
render_inline(Flowbite::Card.new(id: "card-1")) { "Card Content" }
14+
15+
assert_selector("div#card-1")
16+
end
1117
end

0 commit comments

Comments
 (0)