@@ -5,6 +5,8 @@ module Flowbite
55 #
66 # See https://flowbite.com/docs/components/cards/
77 class Card < ViewComponent ::Base
8+ renders_one :title
9+
810 class << self
911 def classes ( state : :default , style : :default )
1012 style = styles . fetch ( style )
@@ -22,12 +24,6 @@ def styles
2224 # rubocop:enable Layout/LineLength
2325 end
2426
25- def card_options
26- card_options = { }
27- card_options [ :class ] = self . class . classes + @class
28- card_options . merge ( @options )
29- end
30-
3127 # @param class [Array<String>] Additional CSS classes for the card
3228 # container.
3329 #
@@ -37,15 +33,36 @@ def card_options
3733 #
3834 # @param title [String, nil] An optional title for the card. If provided,
3935 # it will be rendered at the top of the card in a h5 tag using the
40- # Card::Title component.
36+ # Card::Title component. Alternatively, you can use the `title` slot to
37+ # provide the entire title element yourself.
4138 def initialize ( class : [ ] , options : { } , title : nil )
4239 @class = Array ( binding . local_variable_get ( :class ) ) || [ ]
4340 @options = options || { }
4441 @title = title
4542 end
4643
47- def title
44+ protected
45+
46+ def card_options
47+ card_options = { }
48+ card_options [ :class ] = self . class . classes + @class
49+ card_options . merge ( @options )
50+ end
51+
52+ # Returns the HTML to use for the title element if any
53+ def default_title
54+ return nil unless title?
55+
56+ component = Flowbite ::Card ::Title . new . with_content ( default_title_content )
57+ render ( component )
58+ end
59+
60+ def default_title_content
4861 @title
4962 end
63+
64+ def title?
65+ @title . present?
66+ end
5067 end
5168end
0 commit comments