Sha256: b6f3862d1857fffe2f1aec2eae7b9b01c1269fb5c7be52e2f006d23d9e9bdc6b

Contents?: true

Size: 1.96 KB

Versions: 8

Compression:

Stored size: 1.96 KB

Contents

# typed: false
# frozen_string_literal: true

module Ariadne
  module Form
    module Checkbox
      class Component < Ariadne::Form::BaseInputComponent
        option :name
        option :value
        option :label, default: proc { false }

        # renders_one :leading_visual, BaseComponent::ACCEPT_ANYTHING
        # renders_one :trailing_visual, BaseComponent::ACCEPT_ANYTHING

        def before_render
          raise ArgumentError, "Cannot have both `label` and content block" if @label.present? && content.present?
          raise ArgumentError, "Must have either `label` or content block" if @label.blank? && content.blank?
        end

        option :theme, default: proc { :primary }
        option :size, default: proc { :base }
        option :width, default: proc { :narrow }

        accepts_html_attributes do |html_attrs|
          html_attrs[:class] = style(theme:, size:, width:)
          html_attrs[:type] = @type
          html_attrs[:value] = @value

          html_attrs
        end

        def type
          :check_box
        end

        def focusable?
          true
        end

        def generic_name
          @name.sub(/\[[^\]]*\]$/, "")
        end

        style do
          base do
            [
              "ariadne-h-4",
              "ariadne-w-4",
              "ariadne-p-px",
              "ariadne-inline-flex",
              "ariadne-justify-center",
              "ariadne-rounded",
              "ariadne-border",
              "ariadne-border-solid",
              "ariadne-border-zinc-300",
              "dark:ariadne-border-zinc-700",
              "peer-checked:ariadne-border-transparent",
              "ariadne-bg-foreground",
              "dark:ariadne-bg-foreground-dark",
              "ariadne-text-transparent",
              "peer-checked:ariadne-text-white",
              "peer-checked:ariadne-bg-indigo-600",
              "peer-checked:dark:ariadne-bg-indigo-500",
            ]
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.85 app/components/ariadne/form/checkbox/component.rb
ariadne_view_components-0.0.84 app/components/ariadne/form/checkbox/component.rb
ariadne_view_components-0.0.83.3 app/components/ariadne/form/checkbox/component.rb
ariadne_view_components-0.0.83.2 app/components/ariadne/form/checkbox/component.rb
ariadne_view_components-0.0.83.1 app/components/ariadne/form/checkbox/component.rb
ariadne_view_components-0.0.83 app/components/ariadne/form/checkbox/component.rb
ariadne_view_components-0.0.82 app/components/ariadne/form/checkbox/component.rb
ariadne_view_components-0.0.81 app/components/ariadne/form/checkbox/component.rb