Skip to content

Commit 7afcb72

Browse files
committed
Add the most basic card component
For now this is basically just a frame. Going forward I expect us to add more details and functionality in order to implement all of the options of https://flowbite.com/docs/components/card/ - but for now the most basic version is a good start.
1 parent 78eab43 commit 7afcb72

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1010
* Button component (first component, wee!)
1111
* Input components
1212
* InputField components
13+
* Basic Card component
1314

1415
### Changes
1516

app/components/flowbite/card.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module Flowbite
2+
# Renders a card element.
3+
#
4+
# See https://flowbite.com/docs/components/cards/
5+
class Card < ViewComponent::Base
6+
class << self
7+
def classes(size: :default, state: :default, style: :default)
8+
style = styles.fetch(style)
9+
style.fetch(state)
10+
end
11+
12+
# rubocop:disable Layout/LineLength
13+
def styles
14+
{
15+
default: Flowbite::Style.new(
16+
default: ["max-w-sm", "p-6", "bg-white", "border", "border-gray-200", "rounded-lg", "shadow-sm", "dark:bg-gray-800", "dark:border-gray-700"]
17+
)
18+
}.freeze
19+
end
20+
# rubocop:enable Layout/LineLength
21+
end
22+
23+
def call
24+
content_tag(:div, class: self.class.classes) do
25+
concat(content_tag(:div, content, class: "font-normal text-gray-700 dark:text-gray-400"))
26+
end
27+
end
28+
end
29+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
class CardPreview < Lookbook::Preview
4+
# Use the following simple card component with a title and description.
5+
def default
6+
render(Flowbite::Card.new) { "Use the following simple card component with a title and description." }
7+
end
8+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require "test_helper"
2+
3+
class Flowbite::CardTest < Minitest::Test
4+
include ViewComponent::TestHelpers
5+
6+
def test_renders_a_default_card
7+
render_inline(Flowbite::Card.new) { "Card Content" }
8+
9+
assert_selector("div.p-6.bg-white.border.border-gray-200.rounded-lg.shadow-sm")
10+
end
11+
end

0 commit comments

Comments
 (0)