Class: PhlexKit::Button
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::Button
- Defined in:
- app/components/phlex_kit/button/button.rb
Overview
Button, ported from ruby_ui's RubyUI::Button and matched to shadcn/ui's current button. Renders a
render PhlexKit::Button.new(variant: :primary, **on(:publish)) { "Approve" }
render PhlexKit::Button.new(href: "/login") { "Login" }
Mark leading/trailing glyphs with data-icon: "inline-start"/"inline-end"
to tighten the near-side padding like theirs. icon: true makes the
button square (their icon/icon-xs/… sizes — compose with size:).
:primary is their :default; :xl is a kit extra. VARIANTS.fetch/
SIZES.fetch fail loud on a bad value.
Constant Summary collapse
- VARIANTS =
variant => modifier class. Default is :primary (the filled brand button).
{ primary: "primary", secondary: "secondary", destructive: "destructive", outline: "outline", ghost: "ghost", link: "link" }.freeze
- SIZES =
{ xs: "xs", sm: "sm", md: nil, lg: "lg", xl: "xl" }.freeze
Instance Method Summary collapse
-
#initialize(variant: :primary, size: :md, type: :button, icon: false, href: nil, **attrs) ⇒ Button
constructor
A new instance of Button.
- #view_template(&block) ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(variant: :primary, size: :md, type: :button, icon: false, href: nil, **attrs) ⇒ Button
Returns a new instance of Button.
35 36 37 38 39 40 41 42 |
# File 'app/components/phlex_kit/button/button.rb', line 35 def initialize(variant: :primary, size: :md, type: :button, icon: false, href: nil, **attrs) @variant = variant.to_sym @size = size.to_sym @type = type @icon = icon @href = href @attrs = attrs end |
Instance Method Details
#view_template(&block) ⇒ Object
44 45 46 47 48 49 50 |
# File 'app/components/phlex_kit/button/button.rb', line 44 def view_template(&block) if @href a(**mix({ href: @href, class: classes }, @attrs), &block) else (**mix({ type: @type, class: classes }, @attrs), &block) end end |