Class: Shadcn::Button::Component
- Inherits:
-
ApplicationViewComponent
- Object
- ViewComponent::Base
- ApplicationViewComponent
- Shadcn::Button::Component
- Defined in:
- app/components/shadcn/button/component.rb
Overview
Port of registry/new-york-v4/ui/button.tsx
Direct Known Subclasses
Attachment::Action::Component, InputGroup::Button::Component, MessageScroller::Button::Component
Constant Summary
Constants inherited from ApplicationViewComponent
ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
Attributes inherited from ApplicationViewComponent
Class Method Summary collapse
-
.variant_classes(variant: :default, size: :default, class: nil) ⇒ Object
Ruby equivalent of shadcn's exported
buttonVariants— other components (pagination links, dialog footers, …) borrow the button's classes.
Instance Method Summary collapse
- #element_attributes(**defaults) ⇒ Object
-
#initialize(variant: :default, size: :default, **attributes) ⇒ Component
constructor
A new instance of Component.
- #style_variants ⇒ Object
Methods inherited from ApplicationViewComponent
#call, #css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #tag_name
Constructor Details
#initialize(variant: :default, size: :default, **attributes) ⇒ Component
Returns a new instance of Component.
70 71 72 73 74 |
# File 'app/components/shadcn/button/component.rb', line 70 def initialize(variant: :default, size: :default, **attributes) @variant = variant&.to_sym || :default @size = size&.to_sym || :default super(**attributes) end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
68 69 70 |
# File 'app/components/shadcn/button/component.rb', line 68 def size @size end |
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
68 69 70 |
# File 'app/components/shadcn/button/component.rb', line 68 def variant @variant end |
Class Method Details
.variant_classes(variant: :default, size: :default, class: nil) ⇒ Object
Ruby equivalent of shadcn's exported buttonVariants — other components
(pagination links, dialog footers, …) borrow the button's classes.
59 60 61 62 63 64 65 66 |
# File 'app/components/shadcn/button/component.rb', line 59 def self.variant_classes(variant: :default, size: :default, class: nil) style_config.compile( default_style_name.to_sym, variant: variant&.to_sym, size: size&.to_sym, class: binding.local_variable_get(:class) ) end |
Instance Method Details
#element_attributes(**defaults) ⇒ Object
80 81 82 |
# File 'app/components/shadcn/button/component.rb', line 80 def element_attributes(**defaults) super(**{ "data-variant" => variant, "data-size" => size }.merge(defaults)) end |
#style_variants ⇒ Object
76 77 78 |
# File 'app/components/shadcn/button/component.rb', line 76 def style_variants { variant:, size: } end |