Class: LesliView::Elements::Button
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- LesliView::Elements::Button
- Defined in:
- lib/lesli_view/elements/button.rb
Instance Attribute Summary collapse
-
#css_class ⇒ Object
readonly
Returns the value of attribute css_class.
-
#danger ⇒ Object
readonly
Returns the value of attribute danger.
-
#dispatch ⇒ Object
readonly
Returns the value of attribute dispatch.
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#info ⇒ Object
readonly
Returns the value of attribute info.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#loading ⇒ Object
readonly
Returns the value of attribute loading.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#small ⇒ Object
readonly
Returns the value of attribute small.
-
#solid ⇒ Object
readonly
Returns the value of attribute solid.
-
#success ⇒ Object
readonly
Returns the value of attribute success.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#warning ⇒ Object
readonly
Returns the value of attribute warning.
Instance Method Summary collapse
- #alpine_attributes ⇒ Object
- #button_content ⇒ Object
- #button_variant ⇒ Object
- #html_classes ⇒ Object
- #icon_only? ⇒ Boolean
-
#initialize(label = nil, url: nil, icon: nil, loading: false, solid: false, info: false, success: false, warning: false, danger: false, small: false, dispatch: nil, method: nil, params: nil, css_class: nil) ⇒ Integer
constructor
Adds two numbers together.
- #mode ⇒ Object
Constructor Details
#initialize(label = nil, url: nil, icon: nil, loading: false, solid: false, info: false, success: false, warning: false, danger: false, small: false, dispatch: nil, method: nil, params: nil, css_class: nil) ⇒ Integer
Adds two numbers together.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/lesli_view/elements/button.rb', line 44 def initialize( label=nil, url:nil, icon: nil, loading: false, solid: false, info: false, success: false, warning: false, danger: false, small: false, dispatch:nil, method: nil, params:nil, css_class:nil ) @label = label @url = url @icon = icon @loading = loading @solid = solid @info = info @success = success @warning = warning @danger = danger @small = small @dispatch = dispatch @method = method @params = params @css_class = css_class end |
Instance Attribute Details
#css_class ⇒ Object (readonly)
Returns the value of attribute css_class.
38 39 40 |
# File 'lib/lesli_view/elements/button.rb', line 38 def css_class @css_class end |
#danger ⇒ Object (readonly)
Returns the value of attribute danger.
38 39 40 |
# File 'lib/lesli_view/elements/button.rb', line 38 def danger @danger end |
#dispatch ⇒ Object (readonly)
Returns the value of attribute dispatch.
38 39 40 |
# File 'lib/lesli_view/elements/button.rb', line 38 def dispatch @dispatch end |
#icon ⇒ Object (readonly)
Returns the value of attribute icon.
38 39 40 |
# File 'lib/lesli_view/elements/button.rb', line 38 def icon @icon end |
#info ⇒ Object (readonly)
Returns the value of attribute info.
38 39 40 |
# File 'lib/lesli_view/elements/button.rb', line 38 def info @info end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
38 39 40 |
# File 'lib/lesli_view/elements/button.rb', line 38 def label @label end |
#loading ⇒ Object (readonly)
Returns the value of attribute loading.
38 39 40 |
# File 'lib/lesli_view/elements/button.rb', line 38 def loading @loading end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
38 39 40 |
# File 'lib/lesli_view/elements/button.rb', line 38 def method @method end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
38 39 40 |
# File 'lib/lesli_view/elements/button.rb', line 38 def params @params end |
#small ⇒ Object (readonly)
Returns the value of attribute small.
38 39 40 |
# File 'lib/lesli_view/elements/button.rb', line 38 def small @small end |
#solid ⇒ Object (readonly)
Returns the value of attribute solid.
38 39 40 |
# File 'lib/lesli_view/elements/button.rb', line 38 def solid @solid end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
38 39 40 |
# File 'lib/lesli_view/elements/button.rb', line 38 def success @success end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
38 39 40 |
# File 'lib/lesli_view/elements/button.rb', line 38 def url @url end |
#warning ⇒ Object (readonly)
Returns the value of attribute warning.
38 39 40 |
# File 'lib/lesli_view/elements/button.rb', line 38 def warning @warning end |
Instance Method Details
#alpine_attributes ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/lesli_view/elements/button.rb', line 82 def alpine_attributes return {} unless @dispatch { "x-data": "", "@click": "$dispatch('#{@dispatch}')" } end |
#button_content ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/lesli_view/elements/button.rb', line 112 def if @icon safe_join([ content_tag(:span, content_tag(:span, @icon, class: "material-symbols"), class: "icon #{'is-small' if @small}" ), (@icon_only ? nil : content_tag(:span, @label)) ].compact) else @label end end |
#button_variant ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/lesli_view/elements/button.rb', line 100 def return "is-warning" if warning return "is-success" if success return "is-danger" if danger return "is-info" if info "is-primary" end |
#html_classes ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/lesli_view/elements/button.rb', line 91 def html_classes classes = ["button", ] classes << "is-light" << "is-outlined" unless solid classes << "is-loading" if loading classes << "is-small" if small classes << css_class classes.join(" ") end |
#icon_only? ⇒ Boolean
108 109 110 |
# File 'lib/lesli_view/elements/button.rb', line 108 def icon_only? icon && !label end |
#mode ⇒ Object
76 77 78 79 80 |
# File 'lib/lesli_view/elements/button.rb', line 76 def mode return :button_to if @method.present? return :link if @url.present? :button end |