Class: PandaCms::Admin::ButtonComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- PandaCms::Admin::ButtonComponent
- Defined in:
- app/components/panda_cms/admin/button_component.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#data ⇒ Object
Returns the value of attribute data.
-
#icon ⇒ Object
Returns the value of attribute icon.
-
#link ⇒ Object
Returns the value of attribute link.
-
#size ⇒ Object
Returns the value of attribute size.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(text: "Button", action: nil, data: {}, link: "#", icon: nil, size: :regular, id: nil) ⇒ ButtonComponent
constructor
A new instance of ButtonComponent.
Constructor Details
#initialize(text: "Button", action: nil, data: {}, link: "#", icon: nil, size: :regular, id: nil) ⇒ ButtonComponent
Returns a new instance of ButtonComponent.
8 9 10 11 12 13 14 15 16 |
# File 'app/components/panda_cms/admin/button_component.rb', line 8 def initialize(text: "Button", action: nil, data: {}, link: "#", icon: nil, size: :regular, id: nil) @text = text @action = action @data = data @link = link @icon = icon @size = size @id = id end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
6 7 8 |
# File 'app/components/panda_cms/admin/button_component.rb', line 6 def action @action end |
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'app/components/panda_cms/admin/button_component.rb', line 6 def data @data end |
#icon ⇒ Object
Returns the value of attribute icon.
6 7 8 |
# File 'app/components/panda_cms/admin/button_component.rb', line 6 def icon @icon end |
#link ⇒ Object
Returns the value of attribute link.
6 7 8 |
# File 'app/components/panda_cms/admin/button_component.rb', line 6 def link @link end |
#size ⇒ Object
Returns the value of attribute size.
6 7 8 |
# File 'app/components/panda_cms/admin/button_component.rb', line 6 def size @size end |
#text ⇒ Object
Returns the value of attribute text.
6 7 8 |
# File 'app/components/panda_cms/admin/button_component.rb', line 6 def text @text end |
Instance Method Details
#call ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/components/panda_cms/admin/button_component.rb', line 18 def call @icon = set_icon_from_action(@action) if @action && @icon.nil? icon = content_tag(:i, "", class: "mr-2 fa-regular fa-#{@icon}") if @icon @text = "#{icon} #{@text.titleize}".html_safe classes = "inline-flex items-center rounded-md font-medium shadow-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 " case @size when :small, :sm classes += "gap-x-1.5 px-2.5 py-1.5 text-sm " when :medium, :regular, :md classes += "gap-x-1.5 px-3 py-2 text-base " when :large, :lg classes += "gap-x-2 px-3.5 py-2.5 text-lg " end classes += case @action when :save, :create "text-white bg-active" when :save_inactive "text-white bg-inactive" when :secondary "text-dark border-2 border-dark bg-transparent hover:bg-light transition-all " when :delete, :destroy, :danger "text-error border border-error bg-red-100 hover:bg-red-200 hover:text-error focus-visible:outline-red-300 " else "text-dark border-2 border-dark bg-transparent hover:bg-light transition-all " end content_tag :a, href: @link, class: classes, data: @data, id: @id do @text end end |