Class: Jav::ButtonComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Jav::ButtonComponent
- Defined in:
- app/components/jav/button_component.rb
Overview
A button/link can have the following settings: style: primary/outline/text size: :xs :sm, :md, :lg
Instance Method Summary collapse
- #args ⇒ Object
- #button_classes ⇒ Object
- #call ⇒ Object
- #full_content ⇒ Object
-
#initialize(path = nil, size: :md, style: :outline, color: :gray, icon: nil, icon_class: '', is_link: false, rounded: true, compact: false, **args) ⇒ ButtonComponent
constructor
A new instance of ButtonComponent.
- #is_link? ⇒ Boolean
- #output_button ⇒ Object
- #output_link ⇒ Object
Constructor Details
#initialize(path = nil, size: :md, style: :outline, color: :gray, icon: nil, icon_class: '', is_link: false, rounded: true, compact: false, **args) ⇒ ButtonComponent
Returns a new instance of ButtonComponent.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/components/jav/button_component.rb', line 7 def initialize(path = nil, size: :md, style: :outline, color: :gray, icon: nil, icon_class: '', is_link: false, rounded: true, compact: false, **args) super # Main settings @size = size @style = style @color = color # Other things that appear in the button @path = path @icon = icon @icon_class = icon_class @rounded = rounded @compact = compact # Other settings @class = args[:class] @is_link = is_link @args = args || {} end |
Instance Method Details
#args ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/components/jav/button_component.rb', line 28 def args if @args[:loading] @args[:'data-controller'] = 'loading-button' @args[:'data-loading-button-confirmed-value'] = false @args[:'data-action'] = 'click->loading-button#attemptSubmit' @args[:'data-loading-button-confirmation-message-value'] = @args.delete(:confirm) if @args[:confirm] end @args[:class] = @args end |
#button_classes ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/components/jav/button_component.rb', line 42 def classes = "button-component inline-flex flex-grow-0 items-center font-semibold leading-6 fill-current whitespace-nowrap transition duration-100 transform transition duration-100 cursor-pointer disabled:cursor-not-allowed disabled:opacity-70 border justify-center active:outline active:outline-1 #{@class}" classes += ' rounded-sm' if @rounded.present? classes += style_classes classes += horizontal_padding_classes classes += vertical_padding_classes classes += text_size_classes classes end |
#call ⇒ Object
74 75 76 77 78 79 80 |
# File 'app/components/jav/button_component.rb', line 74 def call if is_link? output_link else end end |
#full_content ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/components/jav/button_component.rb', line 58 def full_content result = '' icon_classes = @icon_class # space out the icon from the text if text is present icon_classes += ' mr-1' if content.present? # add the icon height icon_classes += icon_size_classes # Add the icon result += helpers.svg(@icon, class: icon_classes) if @icon.present? result += "<span>#{content}</span>" if content.present? result.html_safe end |
#is_link? ⇒ Boolean
54 55 56 |
# File 'app/components/jav/button_component.rb', line 54 def is_link? @is_link end |
#output_button ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/components/jav/button_component.rb', line 88 def if args[:method].present? || args.dig(:data, :turbo_method).present? args[:url], **args do full_content end else (**args) do full_content end end end |
#output_link ⇒ Object
82 83 84 85 86 |
# File 'app/components/jav/button_component.rb', line 82 def output_link link_to @path, **args do full_content end end |