Class: Avo::ButtonComponent
- Inherits:
-
BaseComponent
- Object
- BaseComponent
- Avo::ButtonComponent
- Defined in:
- app/components/avo/button_component.rb
Overview
A button/link can have the following settings: style: primary/outline/text size: :sm, :md, :lg padding: nil (default), :sm or :xs for tighter, equal padding rounded: nil (default, uses the standard radius), :full for a pill shape color: nil, :primary, :accent, :gray, :red, :green, :blue, or any other tailwind color icon: "tabler/outline/paperclip" as specified in the docs (https://docs.avohq.io/3.0/icons.html)
Instance Method Summary collapse
- #args ⇒ Object
- #button_classes ⇒ Object
- #call ⇒ Object
- #is_link? ⇒ Boolean
- #output_button ⇒ Object
- #output_link ⇒ Object
Instance Method Details
#args ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/components/avo/button_component.rb', line 29 def args if @args[:loading] @args[:"data-controller"] = "loading-button" @args[:"data-action"] = "click->loading-button#attemptSubmit" end @args[:class] = @args[:aria] = @aria @args end |
#button_classes ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/components/avo/button_component.rb', line 41 def base_classes = [ "button", "button--size-#{@size}", "button--style-#{@style}", @class, "button--color-#{@color}": @color.present?, "button--padding-#{@padding}": @padding.present?, "button--rounded-#{@rounded}": @rounded.present? ] base_classes << "button--loading" if @args[:loading] class_names(*base_classes.compact) end |
#call ⇒ Object
60 61 62 63 64 65 66 |
# File 'app/components/avo/button_component.rb', line 60 def call if is_link? output_link else end end |
#is_link? ⇒ Boolean
56 57 58 |
# File 'app/components/avo/button_component.rb', line 56 def is_link? @is_link end |
#output_button ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/components/avo/button_component.rb', line 74 def if args.dig(:method).present? || args.dig(:data, :turbo_method).present? args[:url], **args do render_content end else (**args) do render_content end end end |
#output_link ⇒ Object
68 69 70 71 72 |
# File 'app/components/avo/button_component.rb', line 68 def output_link link_to @path, **args do render_content end end |