File tree Expand file tree Collapse file tree 3 files changed +49
-2
lines changed
Expand file tree Collapse file tree 3 files changed +49
-2
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,33 @@ Add Flowbite to your Tailwind CSS configuration. In your `app/assets/tailwind/ap
147147) %>
148148```
149149
150+ ## How to customize components
151+
152+ ### Add specific CSS classes
153+
154+ A common use case for customizing a component is to add more CSS classes when
155+ rendering it, fx to change the size or spacing. flowbite-components is optimized
156+ for this case and all you need to do is specify the extra classes:
157+
158+ ``` erb
159+ <%= render(Flowbite::Card.new(class: "w-full my-8")) { "Content" } %>
160+ ```
161+ renders
162+ ``` html
163+ <div class =" ... all the usual classes... w-full my-8" >
164+ ```
165+
166+ If you want to fully replace the existing classes, you can pass an entirely new
167+ ` class ` attribute via options:
168+
169+ ``` erb
170+ <%= render(Flowbite::Card.new(options: {class: "w-full my-8"})) { "Content" } %>
171+ ```
172+ renders
173+ ``` html
174+ <div class =" w-full my-8" >
175+ ```
176+
150177## Available Components
151178
152179### Form Components
Original file line number Diff line number Diff line change @@ -21,15 +21,22 @@ def styles
2121 end
2222
2323 def call
24- content_tag ( :div , { class : self . class . classes } . merge ( @options ) ) do
24+ card_options = { }
25+ card_options [ :class ] = self . class . classes + @class
26+
27+ content_tag ( :div , card_options . merge ( @options ) ) do
2528 concat ( content_tag ( :div , content , class : "font-normal text-gray-700 dark:text-gray-400" ) )
2629 end
2730 end
2831
32+ # @param class [Array<String>] Additional CSS classes for the card
33+ # container.
34+ #
2935 # @param options [Hash] Additional HTML options for the card container
3036 # (e.g., custom classes, data attributes). These options are merged into
3137 # the card's root element.
32- def initialize ( options : { } )
38+ def initialize ( class : [ ] , options : { } )
39+ @class = Array ( binding . local_variable_get ( :class ) ) || [ ]
3340 @options = options || { }
3441 end
3542 end
Original file line number Diff line number Diff line change @@ -14,4 +14,17 @@ def test_passes_options_to_the_card_as_attributes
1414
1515 assert_selector ( "div#card-1" )
1616 end
17+
18+ def test_adds_the_classes_to_the_default_classes
19+ render_inline ( Flowbite ::Card . new ( class : "custom-class another" ) ) { "Card Content" }
20+
21+ assert_selector ( "div.p-6.bg-white.border.border-gray-200.rounded-lg.shadow-sm.custom-class.another" )
22+ end
23+
24+ def test_overrides_the_default_classes
25+ render_inline ( Flowbite ::Card . new ( options : { class : "custom-class another" } ) ) { "Card Content" }
26+
27+ assert_no_selector ( "div.p-6.bg-white.border.border-gray-200.rounded-lg.shadow-sm" )
28+ assert_selector ( "div.custom-class.another" )
29+ end
1730end
You can’t perform that action at this time.
0 commit comments