Sha256: f2fb5fd9be904af0c48116dcf4286c05f19b7d7a3f0fdf2cd0b752935f0382b3
Contents?: true
Size: 924 Bytes
Versions: 1
Compression:
Stored size: 924 Bytes
Contents
# frozen_string_literal: true module Phlexi module Form module Components class Base < BaseComponent attr_reader :field, :attributes def initialize(field, **attributes) @field = field @attributes = attributes build_attributes end protected def build_attributes attributes[:id] ||= "#{field.dom.id}_#{component_name}" attributes[:class] = tokens( component_name, attributes[:class], -> { field.required? } => "required", -> { !field.required? } => "optional", -> { field.has_errors? } => "invalid", -> { field.readonly? } => "readonly", -> { field.disabled? } => "disabled" ) end def component_name @component_name ||= self.class.name.demodulize.underscore end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
phlexi-form-0.2.0 | lib/phlexi/form/components/base.rb |