Class: Flowbite::Card

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/flowbite/card.rb

Overview

Renders a card element.

See flowbite.com/docs/components/cards/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class: [], options: {}) ⇒ Card

Returns a new instance of Card.

Parameters:

  • class (Array<String>) (defaults to: [])

    Additional CSS classes for the card container.

  • options (Hash) (defaults to: {})

    Additional HTML options for the card container (e.g., custom classes, data attributes). These options are merged into the card’s root element.



40
41
42
43
# File 'app/components/flowbite/card.rb', line 40

def initialize(class: [], options: {})
  @class = Array(binding.local_variable_get(:class)) || []
  @options = options || {}
end

Class Method Details

.classes(state: :default, style: :default) ⇒ Object



9
10
11
12
# File 'app/components/flowbite/card.rb', line 9

def classes(state: :default, style: :default)
  style = styles.fetch(style)
  style.fetch(state)
end

.stylesObject

rubocop:disable Layout/LineLength



15
16
17
18
19
20
21
# File 'app/components/flowbite/card.rb', line 15

def styles
  {
    default: Flowbite::Style.new(
      default: ["p-6", "bg-white", "border", "border-gray-200", "rounded-lg", "shadow-sm", "dark:bg-gray-800", "dark:border-gray-700"]
    )
  }.freeze
end

Instance Method Details

#callObject



25
26
27
28
29
30
31
32
# File 'app/components/flowbite/card.rb', line 25

def call
  card_options = {}
  card_options[:class] = self.class.classes + @class

  (:div, card_options.merge(@options)) do
    concat((:div, content, class: "font-normal text-gray-700 dark:text-gray-400"))
  end
end