Class: Ariadne::CheckboxComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/ariadne/checkbox_component.rb

Overview

Just a checkbox with a label, state managed by toggleable controller

Constant Summary collapse

DEFAULT_TAG =
:label
TAG_OPTIONS =
[DEFAULT_TAG].freeze
DEFAULT_CLASSES =
{
  input: "ariadne-mr-2",
  label: "ariadne-flex ariadne-items-center ariadne-cursor-pointer ariadne-w-fit",
}
DEFAULT_ATTRIBUTES =
{
  input: {
    type: "checkbox",
    "data-controller": "toggleable",
    "data-toggleable-synced-attrs-value": '["checked", "aria-checked"]',
    "data-action": "click->toggleable#toggle",
  },
  label: {},
}

Constants inherited from Component

Ariadne::Component::BASE_HIDDEN_CLASS, Ariadne::Component::BASE_MAIN_CLASSES, Ariadne::Component::BASE_WRAPPER_CLASSES, Ariadne::Component::INVALID_ARIA_LABEL_TAGS

Constants included from ActionViewExtensions::FormHelper

ActionViewExtensions::FormHelper::DEFAULT_FORM_CLASSES

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::INTEGER_TYPES, FetchOrFallbackHelper::InvalidValueError, FetchOrFallbackHelper::TRUE_OR_FALSE

Instance Method Summary collapse

Methods included from ActionViewExtensions::FormHelper

#ariadne_form_with

Methods included from ClassNameHelper

#merge_class_names

Methods included from LoggerHelper

#logger, #silence_deprecations?, #silence_warnings?

Methods included from FetchOrFallbackHelper

#check_incoming_attribute, #check_incoming_tag, #check_incoming_value, #fetch_or_raise, #fetch_or_raise_boolean, #fetch_or_raise_integer

Constructor Details

#initialize(tag: DEFAULT_TAG, classes: "", input_classes: "", initial_value: false, input_attributes: {}, attributes: {}) ⇒ CheckboxComponent

Returns a new instance of CheckboxComponent.

Examples:

Default


<%= render(Ariadne::CheckboxComponent.new) { "Example" } %>

Parameters:

  • tag (Symbol, String) (defaults to: DEFAULT_TAG)

    The rendered tag name.

  • classes (String) (defaults to: "")

    <%= link_to_classes_docs %>

  • attributes (Hash) (defaults to: {})

    <%= link_to_attributes_docs %>



31
32
33
34
35
36
37
38
39
40
41
# File 'app/components/ariadne/checkbox_component.rb', line 31

def initialize(tag: DEFAULT_TAG, classes: "", input_classes: "", initial_value: false, input_attributes: {}, attributes: {})
  @tag = @tag = check_incoming_tag(DEFAULT_TAG, tag)

  @label_attributes = DEFAULT_ATTRIBUTES[:label].merge(attributes)
  @label_classes = merge_class_names(DEFAULT_CLASSES[:label], classes)

  @input_classes = merge_class_names(DEFAULT_CLASSES[:input], input_classes)
  @input_attributes = DEFAULT_ATTRIBUTES[:input]
    .merge({ "data-toggleable-state-value": initial_value.to_s })
    .merge(input_attributes)
end