Sha256: 0f18d3396a390ab7411fa7f8f38aa70a0c49c079134555a1313df967001e35e1

Contents?: true

Size: 947 Bytes

Versions: 2

Compression:

Stored size: 947 Bytes

Contents

# frozen_string_literal: true

module Satis
  module Input
    class Element < ViewComponent::Base
      attr_reader :classes

      def initialize(classes: nil, colored: true)
        @classes = classes || ''
        @classes += ' colored' if colored
      end
    end

    class Component < Satis::ApplicationComponent
      attr_reader :form, :attribute, :options

      renders_one :label
      renders_one :input
      renders_one :hint
      renders_many :prefixes, Element
      renders_many :postfixes, Element

      def initialize(form: nil, attribute: nil, **options)
        @form = form
        @attribute = attribute
        @options = options
      end

      def input_class
        [@options.fetch(:input_html, {}).fetch(:class, ''), 'sts-input__input', form.has_error?(attribute) && 'is-invalid'].join(' ')
      end

      def input_container_class
        form.has_error?(attribute) && 'is-invalid'
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
satis-1.0.67 app/components/satis/input/component.rb
satis-1.0.66 app/components/satis/input/component.rb