Class: NitroKit::Button
- Defined in:
- app/components/nitro_kit/button.rb
Constant Summary collapse
- BASE =
[ "inline-flex items-center cursor-pointer shrink-0 justify-center rounded-md border gap-2 font-medium", # Disabled "disabled:opacity-70 disabled:pointer-events-none", # Focus "focus:outline-none focus:ring-[3px] focus:ring-offset-2 focus:ring-ring ring-offset-background", # Icon "[&_svg]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0", # If icon only, make square "[&_svg:first-child:last-child]:-mx-2" ].freeze
- VARIANTS =
{ default: [ "bg-background text-foreground", "hover:bg-zinc-50 dark:hover:bg-zinc-900" ], primary: [ "bg-primary text-white dark:text-zinc-950 border-primary", "hover:bg-primary/90 dark:hover:bg-primary/90" ], destructive: [ "bg-destructive text-white border-destructive", "hover:bg-destructive/90 dark:hover:bg-destructive/90", "disabled:text-white/80" ], ghost: [ "bg-transparent text-foreground border-transparent", "hover:bg-zinc-100 dark:hover:bg-zinc-900", "disabled:text-muted-foreground" ] }.freeze
- SIZES =
{ base: "px-4 h-9", sm: "px-2.5 h-7 text-sm", xs: "px-1.5 h-6 text-xs" }.freeze
Instance Attribute Summary collapse
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#icon_right ⇒ Object
readonly
Returns the value of attribute icon_right.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
Attributes inherited from Component
Instance Method Summary collapse
-
#initialize(href: nil, icon: nil, icon_right: nil, size: :base, type: :button, variant: :default, **attrs) ⇒ Button
constructor
A new instance of Button.
- #view_template(&block) ⇒ Object
Methods inherited from Component
Constructor Details
#initialize(href: nil, icon: nil, icon_right: nil, size: :base, type: :button, variant: :default, **attrs) ⇒ Button
Returns a new instance of Button.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/components/nitro_kit/button.rb', line 42 def initialize( href: nil, icon: nil, icon_right: nil, size: :base, type: :button, variant: :default, **attrs ) super(**attrs) @href = href @icon = icon @icon_right = icon_right @size = size @type = type @variant = variant end |
Instance Attribute Details
#href ⇒ Object (readonly)
Returns the value of attribute href.
61 62 63 |
# File 'app/components/nitro_kit/button.rb', line 61 def href @href end |
#icon ⇒ Object (readonly)
Returns the value of attribute icon.
61 62 63 |
# File 'app/components/nitro_kit/button.rb', line 61 def icon @icon end |
#icon_right ⇒ Object (readonly)
Returns the value of attribute icon_right.
61 62 63 |
# File 'app/components/nitro_kit/button.rb', line 61 def icon_right @icon_right end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
61 62 63 |
# File 'app/components/nitro_kit/button.rb', line 61 def size @size end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
61 62 63 |
# File 'app/components/nitro_kit/button.rb', line 61 def type @type end |
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
61 62 63 |
# File 'app/components/nitro_kit/button.rb', line 61 def variant @variant end |
Instance Method Details
#view_template(&block) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/components/nitro_kit/button.rb', line 70 def view_template(&block) class_list = merge( [ BASE, VARIANTS[variant], SIZES[size], attrs[:class] ] ) if href a(href:, **attrs, class: class_list) do contents(&block) end else (type:, **attrs, class: class_list) do contents(&block) end end end |