Class: Yattho::Beta::IconButton
- Defined in:
- app/components/yattho/beta/icon_button.rb
Overview
Use ‘IconButton` to render Icon-only buttons without the default button styles.
‘IconButton` will always render with a tooltip unless the tag is `:summary`. `IconButton` will always render with a tooltip unless the tag is `:summary`.
Constant Summary collapse
- DEFAULT_SCHEME =
:default
- SCHEME_MAPPINGS =
{ DEFAULT_SCHEME => "Button--secondary", :danger => "Button--danger", :invisible => "Button--invisible" }.freeze
- SCHEME_OPTIONS =
SCHEME_MAPPINGS.keys
Constants inherited from Component
Component::INVALID_ARIA_LABEL_TAGS
Constants included from Status::Dsl
Constants included from ViewHelper
Constants included from TestSelectorHelper
TestSelectorHelper::TEST_SELECTOR_TAG
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::InvalidValueError
Instance Method Summary collapse
-
#initialize(icon:, scheme: DEFAULT_SCHEME, wrapper_arguments: {}, show_tooltip: true, tooltip_direction: Yattho::Alpha::Tooltip::DIRECTION_DEFAULT, size: Yattho::Beta::Button::DEFAULT_SIZE, **system_arguments) ⇒ IconButton
constructor
A new instance of IconButton.
Methods inherited from Component
Methods included from JoinStyleArgumentsHelper
Methods included from TestSelectorHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?
Methods included from ClassNameHelper
Constructor Details
#initialize(icon:, scheme: DEFAULT_SCHEME, wrapper_arguments: {}, show_tooltip: true, tooltip_direction: Yattho::Alpha::Tooltip::DIRECTION_DEFAULT, size: Yattho::Beta::Button::DEFAULT_SIZE, **system_arguments) ⇒ IconButton
Returns a new instance of IconButton.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/components/yattho/beta/icon_button.rb', line 60 def initialize(icon:, scheme: DEFAULT_SCHEME, wrapper_arguments: {}, show_tooltip: true, tooltip_direction: Yattho::Alpha::Tooltip::DIRECTION_DEFAULT, size: Yattho::Beta::Button::DEFAULT_SIZE, **system_arguments) @icon = icon @wrapper_arguments = wrapper_arguments @show_tooltip = show_tooltip @system_arguments = system_arguments @system_arguments[:id] ||= self.class.generate_id @system_arguments[:classes] = class_names( "Button", "Button--iconOnly", SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME)], Yattho::Beta::Button::SIZE_MAPPINGS[fetch_or_fallback(Yattho::Beta::Button::SIZE_OPTIONS, size, Yattho::Beta::Button::DEFAULT_SIZE)], system_arguments[:classes] ) validate_aria_label @aria_label = aria("label", @system_arguments) @aria_description = aria("description", @system_arguments) @tooltip_arguments = { for_id: @system_arguments[:id], direction: tooltip_direction } # If we have both an `aria-label` and a `aria-description`, we create a `Tooltip` with the description type and keep the `aria-label` in the button. # Otherwise, the `aria-label` is used as the tooltip text, which is the `aria-labelled-by` of the button, so we don't set it in the button. if @aria_label.present? && @aria_description.present? @system_arguments.delete(:'aria-description') @system_arguments[:aria].delete(:description) if @system_arguments.include?(:aria) @tooltip_arguments[:text] = @aria_description @tooltip_arguments[:type] = :description else @system_arguments.delete(:'aria-label') @system_arguments[:aria].delete(:label) if @system_arguments.include?(:aria) @tooltip_arguments[:text] = @aria_label @tooltip_arguments[:type] = :label end end |