Sha256: ce9c9a176146f7c011f0f2ada5866ccf4a2d8cbb82d156765d4bdd09f249273e

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

module Playbook
  module PbTextInput
    class TextInput < Playbook::KitBase
      prop :autocomplete, type: Playbook::Props::Boolean,
                          default: true
      prop :disabled, type: Playbook::Props::Boolean,
                      default: false
      prop :error
      prop :label
      prop :name
      prop :placeholder
      prop :required, type: Playbook::Props::Boolean,
                      default: false
      prop :type, default: "text"
      prop :validation, type: Playbook::Props::Hash,
                        default: {}
      prop :value
      prop :add_on, type: Playbook::Props::NestedProps,
                    nested_kit: Playbook::PbTextInput::AddOn

      def classname
        generate_classname("pb_text_input_kit") + error_class
      end

      def input_tag
        tag(:input, input_options)
      end

      def has_add_on?
        add_on.present?
      end

      def add_on_class
        has_add_on? ? 'text_input_wrapper_add_on' : nil
      end

      def add_on_props
        { dark: dark }.merge(add_on || {})
      end

    private

      def input_options
        {
          autocomplete: autocomplete ? nil : "off",
          class: "text_input",
          data: validation_data,
          disabled: disabled,
          id: id,
          name: name,
          pattern: validation_pattern,
          placeholder: placeholder,
          required: required,
          type: type,
          value: value
        }
      end

      def validation_message
        validation[:message] || ""
      end

      def validation_pattern
        validation[:pattern] || nil
      end

      def validation_data
        fields = {}
        fields[:message] = validation_message unless validation_message.blank?
        fields
      end

      def error_class
        error ? " error" : ""
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
playbook_ui-9.12.0.pre.text.addon app/pb_kits/playbook/pb_text_input/text_input.rb