Class: Ariadne::UI::Button::Component

Inherits:
BaseComponent
  • Object
show all
Includes:
Behaviors::Tooltipable
Defined in:
app/components/ariadne/ui/button/component.rb

Overview

Used to initiate actions on a page or form.

You can call ‘as_icon` to render a button with only an icon.

Constant Summary collapse

DEFAULT_SCHEME =
:primary
SCHEME_OPTIONS =
[DEFAULT_SCHEME, :outline, :secondary, :nude, :danger, :none].freeze
DEFAULT_SIZE =
:md

Constants inherited from BaseComponent

BaseComponent::ACCEPT_ANYTHING

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from AttributesHelper

AttributesHelper::PLURAL_ARIA_ATTRIBUTES, AttributesHelper::PLURAL_DATA_ATTRIBUTES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Behaviors::Tooltipable

#with_tooltip

Methods inherited from BaseComponent

audited_at, #class_for, #component, component_id, #component_id, component_name, generate_id, #html_attributes, i18n_scope, #merge_data_attributes, #merge_tailwind_classes, #options, stimulus_name, translate, #validate_aria_label!

Methods included from AttributesHelper

#aria, #data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes, #prepend_action, #prepend_controller, #prepend_data_attribute

Methods included from ViewComponent::StyleVariants

#merged_styles

Instance Attribute Details

#icon_onlyObject (readonly)

Returns the value of attribute icon_only.



15
16
17
# File 'app/components/ariadne/ui/button/component.rb', line 15

def icon_only
  @icon_only
end

Instance Method Details

#as_icon(**options) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/components/ariadne/ui/button/component.rb', line 77

def as_icon(**options)
  validate_aria_label!(html_attrs)

  @icon_only = true
  @aria_label = aria(html_attrs, "label")
  @aria_description = aria(html_attrs, "description")

  options[:size] = @size

  if options[:svg]
    @svg = options[:svg]
  else
    @icon = Ariadne::UI::Heroicon::Component.new(**options)
  end

  self
end

#icon_or_svgObject



95
96
97
98
99
# File 'app/components/ariadne/ui/button/component.rb', line 95

def icon_or_svg
  return @svg if @svg

  render(@icon)
end