Sha256: a9ae7b30cbbfc051e56c6dee6e31ae38c6519718b4fac10e313af191d505b7d7
Contents?: true
Size: 1.48 KB
Versions: 66
Compression:
Stored size: 1.48 KB
Contents
# frozen_string_literal: true module Ariadne # Just a checkbox with a label, state managed by toggleable controller class CheckboxComponent < Ariadne::Component 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: {}, } # @example Default # # <%= render(Ariadne::CheckboxComponent.new) { "Example" } %> # # @param tag [Symbol, String] The rendered tag name. # @param classes [String] <%= link_to_classes_docs %> # @param attributes [Hash] <%= link_to_attributes_docs %> 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 end end
Version data entries
66 entries across 66 versions & 1 rubygems