Class: Keystone::Ui::ButtonComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Keystone::Ui::ButtonComponent
- Defined in:
- app/components/keystone/ui/button_component.rb
Constant Summary collapse
- BASE_CLASSES =
"inline-flex items-center justify-center font-semibold rounded-lg border-0 cursor-pointer no-underline"- VARIANT_CLASSES =
{ secondary: "bg-gray-500 text-white hover:bg-gray-400", danger: "bg-red-600 text-white hover:bg-red-500" }.freeze
- SIZE_CLASSES =
{ sm: "text-sm px-3 py-1.5", md: "text-base px-4 py-2", lg: "text-lg px-5 py-3" }.freeze
Instance Method Summary collapse
- #button? ⇒ Boolean
- #classes ⇒ Object
-
#initialize(label:, href: nil, variant: :primary, size: :md, type: :submit, data: nil) ⇒ ButtonComponent
constructor
A new instance of ButtonComponent.
- #tag_name ⇒ Object
- #tag_options ⇒ Object
Constructor Details
#initialize(label:, href: nil, variant: :primary, size: :md, type: :submit, data: nil) ⇒ ButtonComponent
Returns a new instance of ButtonComponent.
19 20 21 22 23 24 25 26 |
# File 'app/components/keystone/ui/button_component.rb', line 19 def initialize(label:, href: nil, variant: :primary, size: :md, type: :submit, data: nil) @label = label @href = href @variant = variant @size = size @type = type.to_s @data = data end |
Instance Method Details
#button? ⇒ Boolean
52 53 54 |
# File 'app/components/keystone/ui/button_component.rb', line 52 def @href.nil? end |
#classes ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'app/components/keystone/ui/button_component.rb', line 28 def classes variant_css = if @variant == :primary "bg-accent-600 text-white hover:bg-accent-500" else VARIANT_CLASSES.fetch(@variant) end [ BASE_CLASSES, variant_css, SIZE_CLASSES.fetch(@size) ].join(" ") end |
#tag_name ⇒ Object
37 38 39 |
# File 'app/components/keystone/ui/button_component.rb', line 37 def tag_name ? :button : :a end |
#tag_options ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'app/components/keystone/ui/button_component.rb', line 41 def = { class: classes } if [:type] = @type else [:href] = @href end [:data] = @data if @data end |