Card
Displays a card with header, content, and footer.
Usage
Card with image
You might like "RubyUI"
@joeldrapper
Card(class: 'w-96') do CardHeader do CardTitle { 'You might like "RubyUI"' } CardDescription { "@joeldrapper" } end CardContent do AspectRatio(aspect_ratio: "16/9", class: "rounded-md overflow-hidden border") do img( alt: "Placeholder", loading: "lazy", src: helpers.image_url('pattern.jpg') ) end end CardFooter(class: 'flex justify-end gap-x-2') do Button(variant: :outline) { "See more" } Button(variant: :primary) { "Buy now" } end end
Copied!
Copy failed!
Card with full-width image
Introducing RubyUI
Kickstart your project today!
Card(class: 'w-96 overflow-hidden') do AspectRatio(aspect_ratio: "16/9", class: "border-b") do img( alt: "Placeholder", loading: "lazy", src: helpers.image_url('pattern.jpg') ) end CardHeader do CardTitle { 'Introducing RubyUI' } CardDescription { "Kickstart your project today!" } end CardFooter(class: 'flex justify-end') do Button(variant: :outline) { "Get started" } end end
Copied!
Copy failed!
Account balance
Current Balance
$2,602
**** 4620
Card(class: 'w-96 overflow-hidden') do CardHeader do div(class: 'w-10 h-10 rounded-xl flex items-center justify-center bg-violet-100 text-violet-700 -rotate-6') do cash_icon end end CardContent(class: 'space-y-1') do CardDescription(class: 'font-medium') { "Current Balance" } h5(class: 'font-semibold text-4xl') { '$2,602' } end CardFooter do Text(size: "2", class: "text-muted-foreground") { "**** 4620" } end end
Copied!
Copy failed!
Installation
Using RubyUI CLI
Run the install command
rails g ruby_ui:component Card
Copied!
Copy failed!
Manual installation
1
Add RubyUI::Card
to app/components/ruby_ui/card.rb
# frozen_string_literal: true module RubyUI class Card < Base def view_template(&) div(**attrs, &) end private def default_attrs { class: "rounded-xl border bg-background shadow" } end end end
Copied!
Copy failed!
2
Add RubyUI::CardContent
to app/components/ruby_ui/card/card_content.rb
# frozen_string_literal: true module RubyUI class CardContent < Base def view_template(&) div(**attrs, &) end private def default_attrs { class: "p-6 pt-0" } end end end
Copied!
Copy failed!
3
Add RubyUI::CardDescription
to app/components/ruby_ui/card/card_description.rb
# frozen_string_literal: true module RubyUI class CardDescription < Base def view_template(&) p(**attrs, &) end private def default_attrs { class: "text-sm text-muted-foreground" } end end end
Copied!
Copy failed!
4
Add RubyUI::CardFooter
to app/components/ruby_ui/card/card_footer.rb
# frozen_string_literal: true module RubyUI class CardFooter < Base def view_template(&) div(**attrs, &) end private def default_attrs { class: "items-center p-6 pt-0" } end end end
Copied!
Copy failed!
5
Add RubyUI::CardHeader
to app/components/ruby_ui/card/card_header.rb
# frozen_string_literal: true module RubyUI class CardHeader < Base def view_template(&) div(**attrs, &) end private def default_attrs { class: "flex flex-col space-y-1.5 p-6" } end end end
Copied!
Copy failed!
6
Add RubyUI::CardTitle
to app/components/ruby_ui/card/card_title.rb
# frozen_string_literal: true module RubyUI class CardTitle < Base def view_template(&) h3(**attrs, &) end private def default_attrs { class: "font-semibold leading-none tracking-tight" } end end end
Copied!
Copy failed!
Components
Component | Built using | Source |
---|---|---|
Card | Phlex | |
CardContent | Phlex | |
CardDescription | Phlex | |
CardFooter | Phlex | |
CardHeader | Phlex | |
CardTitle | Phlex |