Class: Ariadne::BaseButton
- Defined in:
- app/components/ariadne/base_button.rb
Overview
Use ‘BaseButton` to render an unstyled `<button>` tag that can be customized.
Constant Summary collapse
- DEFAULT_TAG =
:button- TAG_OPTIONS =
[DEFAULT_TAG, :a, :summary].freeze
- DEFAULT_TYPE =
:button- TYPE_OPTIONS =
[DEFAULT_TYPE, :reset, :submit].freeze
- SIZE_CLASS_MAPPINGS =
{ xs: "inline-flex items-center px-2.5 py-1.5 text-xs font-medium rounded", s: "inline-flex items-center px-3 py-2 text-sm leading-4 font-medium rounded-m", m: "inline-flex items-center px-4 py-2 text-sm font-medium rounded-md", l: "inline-flex items-center px-4 py-2 text-base font-medium rounded-md", xl: "inline-flex items-center px-6 py-3 text-base font-medium rounded-md", }.freeze
- VALID_SIZES =
SIZE_CLASS_MAPPINGS.keys.freeze
- DEFAULT_CLASSES =
"inline-flex items-center px-4 py-2 text-sm border border-gray-300 shadow-sm text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"- DEFAULT_SIZE =
:m
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, FetchOrFallbackHelper::TRUE_OR_FALSE
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(tag: DEFAULT_TAG, type: DEFAULT_TYPE, size: DEFAULT_SIZE, classes: "", attributes: {}) ⇒ BaseButton
constructor
A new instance of BaseButton.
Methods included from LoggerHelper
#logger, #silence_deprecations?, #silence_warnings?
Methods included from JoinStyleArgumentsHelper
Methods included from TestSelectorHelper
Methods included from FetchOrFallbackHelper
#check_incoming_attribute, #check_incoming_tag, #check_incoming_value, #fetch_or_raise, #fetch_or_raise_boolean
Methods included from ClassNameHelper
Constructor Details
#initialize(tag: DEFAULT_TAG, type: DEFAULT_TYPE, size: DEFAULT_SIZE, classes: "", attributes: {}) ⇒ BaseButton
Returns a new instance of BaseButton.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/components/ariadne/base_button.rb', line 37 def initialize( tag: DEFAULT_TAG, type: DEFAULT_TYPE, size: DEFAULT_SIZE, classes: "", attributes: {} ) @attributes = attributes @tag = fetch_or_raise(TAG_OPTIONS, tag) @size = fetch_or_raise(VALID_SIZES, size) @attributes[:type] = fetch_or_raise(TYPE_OPTIONS, type) if @classes = class_names(DEFAULT_CLASSES, SIZE_CLASS_MAPPINGS[@size], classes) end |
Instance Method Details
#call ⇒ Object
52 53 54 |
# File 'app/components/ariadne/base_button.rb', line 52 def call render(Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes)) { content } end |