Class: Avo::ButtonComponent

Inherits:
BaseComponent show all
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 color: nil, :primary, :accent, :gray, :red, :green, :blue, or any other tailwind color icon: “heroicons/outline/paperclip” as specified in the docs (docs.avohq.io/3.0/icons.html)

Constant Summary

Constants included from Concerns::FindAssociationField

Concerns::FindAssociationField::ASSOCIATIONS

Instance Method Summary collapse

Methods inherited from BaseComponent

#component_name

Methods included from ApplicationHelper

#a_button, #a_link, #body_classes, #chart_color, #container_classes, #d, #decode_filter_params, #e, #editor_file_path, #editor_url, #empty_state, #encode_filter_params, #frame_id, #get_model_class, #input_classes, #mount_path, #number_to_social, #possibly_rails_authentication?, #render_license_warning, #root_path_without_url, #rtl?, #text_direction, #ui, #wrap_in_modal

Methods included from ResourcesHelper

#field_wrapper, #filter_wrapper, #index_field_wrapper, #item_selector_data_attributes, #record_path, #record_title, #resource_for_record, #resource_grid, #resource_show_path, #resource_table

Methods included from Concerns::FindAssociationField

#find_association_field

Instance Method Details

#argsObject



22
23
24
25
26
27
28
29
30
31
32
# File 'app/components/avo/button_component.rb', line 22

def args
  if @args[:loading]
    @args[:"data-controller"] = "loading-button"
    @args[:"data-action"] = "click->loading-button#attemptSubmit"
  end

  @args[:class] = button_classes
  @args[:aria] = @aria

  @args
end

#button_classesObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/components/avo/button_component.rb', line 34

def button_classes
  base_classes = [
    "button",
    "button--size-#{@size}",
    "button--style-#{@style}",
    @class,
    "button--color-#{@color}": @color.present?
  ]
  base_classes << "button--loading" if @args[:loading]

  class_names(*base_classes.compact)
end

#callObject



51
52
53
54
55
56
57
# File 'app/components/avo/button_component.rb', line 51

def call
  if is_link?
    output_link
  else
    output_button
  end
end

#is_link?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/components/avo/button_component.rb', line 47

def is_link?
  @is_link
end

#output_buttonObject



65
66
67
68
69
70
71
72
73
74
75
# File 'app/components/avo/button_component.rb', line 65

def output_button
  if args.dig(:method).present? || args.dig(:data, :turbo_method).present?
    button_to args[:url], **args do
      render_content
    end
  else
    button_tag(**args) do
      render_content
    end
  end
end


59
60
61
62
63
# File 'app/components/avo/button_component.rb', line 59

def output_link
  link_to @path, **args do
    render_content
  end
end