Class: BetterUi::General::Input::Pin::Component

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/better_ui/general/input/pin/component.rb

Constant Summary collapse

PIN_THEME =

Costanti con classi Tailwind dirette

{
  default: 'border-gray-300 focus:border-blue-500 focus:ring-blue-500',
  white: 'border-gray-300 bg-white focus:border-gray-900 focus:ring-gray-900',
  red: 'border-red-300 focus:border-red-500 focus:ring-red-500',
  rose: 'border-rose-300 focus:border-rose-500 focus:ring-rose-500',
  orange: 'border-orange-300 focus:border-orange-500 focus:ring-orange-500',
  green: 'border-green-300 focus:border-green-500 focus:ring-green-500',
  blue: 'border-blue-300 focus:border-blue-500 focus:ring-blue-500',
  yellow: 'border-yellow-300 focus:border-yellow-500 focus:ring-yellow-500',
  violet: 'border-violet-300 focus:border-violet-500 focus:ring-violet-500'
}.freeze
PIN_SIZE =
{
  small: 'w-8 h-8 text-sm',
  medium: 'w-12 h-12 text-base',
  large: 'w-16 h-16 text-lg'
}.freeze
PIN_GAP =
{
  small: 'gap-2',
  medium: 'gap-3',
  large: 'gap-4'
}.freeze
PIN_BASE_CLASSES =
'rounded-md border text-center font-mono focus:outline-none focus:ring-2 focus:ring-offset-1 transition-colors'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, value: '', length: 6, placeholder: '•', required: false, disabled: false, theme: :default, size: :medium, form: nil, classes: '', **options) ⇒ Component

Returns a new instance of Component.

Parameters:

  • name (String)

    Nome del campo pin (obbligatorio)

  • value (String) (defaults to: '')

    Valore del pin preimpostato

  • length (Integer) (defaults to: 6)

    Numero di campi pin (4-8, default: 6)

  • placeholder (String) (defaults to: '•')

    Placeholder per campi vuoti (default: ‘•’)

  • required (Boolean) (defaults to: false)

    Se il campo è obbligatorio

  • disabled (Boolean) (defaults to: false)

    Se il campo è disabilitato

  • theme (Symbol) (defaults to: :default)

    Tema del componente (:default, :white, :red, :rose, :orange, :green, :blue, :yellow, :violet)

  • size (Symbol) (defaults to: :medium)

    Dimensione del componente (:small, :medium, :large)

  • form (ActionView::Helpers::FormBuilder, nil) (defaults to: nil)

    Form builder Rails opzionale

  • classes (String) (defaults to: '')

    Classi CSS aggiuntive

  • options (Hash)

    Opzioni aggiuntive per attributi HTML



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/components/better_ui/general/input/pin/component.rb', line 49

def initialize(name:, value: '', length: 6, placeholder: '', required: false, disabled: false,
               theme: :default, size: :medium, form: nil, classes: '', **options)
  @name = name
  @value = value.to_s
  @length = length.to_i
  @placeholder = placeholder
  @required = required
  @disabled = disabled
  @theme = theme.to_sym
  @size = size.to_sym
  @form = form
  @classes = classes
  @options = options

  validate_params
end

Instance Attribute Details

#classesObject (readonly)

Returns the value of attribute classes.



35
36
37
# File 'app/components/better_ui/general/input/pin/component.rb', line 35

def classes
  @classes
end

#disabledObject (readonly)

Returns the value of attribute disabled.



35
36
37
# File 'app/components/better_ui/general/input/pin/component.rb', line 35

def disabled
  @disabled
end

#formObject (readonly)

Returns the value of attribute form.



35
36
37
# File 'app/components/better_ui/general/input/pin/component.rb', line 35

def form
  @form
end

#lengthObject (readonly)

Returns the value of attribute length.



35
36
37
# File 'app/components/better_ui/general/input/pin/component.rb', line 35

def length
  @length
end

#nameObject (readonly)

Returns the value of attribute name.



35
36
37
# File 'app/components/better_ui/general/input/pin/component.rb', line 35

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



35
36
37
# File 'app/components/better_ui/general/input/pin/component.rb', line 35

def options
  @options
end

#placeholderObject (readonly)

Returns the value of attribute placeholder.



35
36
37
# File 'app/components/better_ui/general/input/pin/component.rb', line 35

def placeholder
  @placeholder
end

#requiredObject (readonly)

Returns the value of attribute required.



35
36
37
# File 'app/components/better_ui/general/input/pin/component.rb', line 35

def required
  @required
end

#sizeObject (readonly)

Returns the value of attribute size.



35
36
37
# File 'app/components/better_ui/general/input/pin/component.rb', line 35

def size
  @size
end

#themeObject (readonly)

Returns the value of attribute theme.



35
36
37
# File 'app/components/better_ui/general/input/pin/component.rb', line 35

def theme
  @theme
end

#valueObject (readonly)

Returns the value of attribute value.



35
36
37
# File 'app/components/better_ui/general/input/pin/component.rb', line 35

def value
  @value
end