Class: Flowbite::Card

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

Overview

Renders a card element.

See flowbite.com/docs/components/cards/

Defined Under Namespace

Classes: Title

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class: [], options: {}, title: {}) ⇒ 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.

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

    An optional title for the card. If provided, it will be rendered at the top of the card in a h5 tag using the Card::Title component. The hash can contain:

    • ‘content`: The text content of the title

    • ‘options`: Additional HTML options to pass to the title element

    Alternatively, you can use the ‘title` slot to provide the entire title element yourself.



43
44
45
46
47
# File 'app/components/flowbite/card.rb', line 43

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

Class Method Details

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



11
12
13
14
# File 'app/components/flowbite/card.rb', line 11

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

.stylesObject

rubocop:disable Layout/LineLength



17
18
19
20
21
22
23
24
25
# File 'app/components/flowbite/card.rb', line 17

def styles
  Flowbite::Styles.from_hash(
    {
      default: {
        default: ["p-6", "bg-neutral-primary-soft", "border", "border-default", "rounded-base", "shadow-xs"]
      }
    }.freeze
  )
end