Class: BetterUi::CardComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- BetterUi::CardComponent
- Defined in:
- app/components/better_ui/card_component.rb
Overview
A flexible card component for displaying content in a styled container.
This component provides a versatile box container with support for multiple color variants, visual styles, sizes, and optional header/footer sections. Perfect for displaying grouped content, information panels, dashboards, and feature highlights.
Constant Summary collapse
- SIZES =
Size configurations for padding, text, and border radius
{ xs: { padding: "p-3", text: "text-xs", radius: "rounded" }, sm: { padding: "p-4", text: "text-sm", radius: "rounded-md" }, md: { padding: "p-6", text: "text-base", radius: "rounded-lg" }, lg: { padding: "p-8", text: "text-lg", radius: "rounded-lg" }, xl: { padding: "p-10", text: "text-xl", radius: "rounded-xl" } }.freeze
- STYLES =
Available visual styles
%i[solid outline ghost soft bordered].freeze
Constants inherited from ApplicationComponent
ApplicationComponent::SHADOWS, ApplicationComponent::VARIANTS, ApplicationComponent::VARIANT_BODY_DIVIDE, ApplicationComponent::VARIANT_DIVIDE, ApplicationComponent::VARIANT_HEADER_BG, ApplicationComponent::VARIANT_HEADER_TEXT, ApplicationComponent::VARIANT_HIGHLIGHTED, ApplicationComponent::VARIANT_HOVERABLE, ApplicationComponent::VARIANT_RING, ApplicationComponent::VARIANT_SORT_ICON, ApplicationComponent::VARIANT_STRIPED
Instance Method Summary collapse
-
#initialize(variant: nil, style: :solid, size: :md, shadow: :sm, header_padding: true, body_padding: true, footer_padding: true, container_classes: nil, header_classes: nil, body_classes: nil, footer_classes: nil, **options) ⇒ CardComponent
constructor
Initializes a new card component.
-
#with_body ⇒ Object
Slot for rendering the main body content of the card.
-
#with_footer ⇒ Object
Slot for rendering optional footer content at the bottom of the card.
-
#with_header ⇒ Object
Slot for rendering optional header content at the top of the card.
Constructor Details
#initialize(variant: nil, style: :solid, size: :md, shadow: :sm, header_padding: true, body_padding: true, footer_padding: true, container_classes: nil, header_classes: nil, body_classes: nil, footer_classes: nil, **options) ⇒ CardComponent
Initializes a new card component.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'app/components/better_ui/card_component.rb', line 130 def initialize( variant: nil, style: :solid, size: :md, shadow: :sm, header_padding: true, body_padding: true, footer_padding: true, container_classes: nil, header_classes: nil, body_classes: nil, footer_classes: nil, ** ) @style = validate_style(style) resolved_variant = variant || default_variant_for_style @variant = validate_variant(resolved_variant) @size = validate_size(size) @shadow = normalize_shadow(shadow) @header_padding = header_padding @body_padding = body_padding @footer_padding = @container_classes = container_classes @header_classes = header_classes @body_classes = body_classes @footer_classes = @options = end |
Instance Method Details
#with_body ⇒ Object
Slot for rendering the main body content of the card. If not provided, the card will render its default content in the body.
71 |
# File 'app/components/better_ui/card_component.rb', line 71 renders_one :body |
#with_footer ⇒ Object
Slot for rendering optional footer content at the bottom of the card. The footer is separated from the body with a divider.
77 |
# File 'app/components/better_ui/card_component.rb', line 77 renders_one :footer |
#with_header ⇒ Object
Slot for rendering optional header content at the top of the card. The header is separated from the body with a divider.
65 |
# File 'app/components/better_ui/card_component.rb', line 65 renders_one :header |