Class: UI::InputOtpSlotComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
InputOtpSlotBehavior
Defined in:
app/view_components/ui/input_otp_slot_component.rb

Overview

SlotComponent - ViewComponent implementation

Individual OTP input slot for a single character.

Examples:

<%= render UI::SlotComponent.new(index: 0, value: "1") %>

Instance Method Summary collapse

Methods included from InputOtpSlotBehavior

#input_otp_slot_classes, #input_otp_slot_data_attributes, #input_otp_slot_html_attributes

Constructor Details

#initialize(index: 0, value: "", name: nil, id: nil, disabled: false, classes: "", **attributes) ⇒ InputOtpSlotComponent

Returns a new instance of InputOtpSlotComponent.

Parameters:

  • index (Integer) (defaults to: 0)

    Index of the slot in the OTP sequence

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

    Character value to display in the slot

  • name (String) (defaults to: nil)

    Form input name

  • id (String) (defaults to: nil)

    HTML id attribute

  • disabled (Boolean) (defaults to: false)

    Whether input is disabled

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

    Additional CSS classes

  • attributes (Hash)

    Additional HTML attributes



19
20
21
22
23
24
25
26
27
# File 'app/view_components/ui/input_otp_slot_component.rb', line 19

def initialize(index: 0, value: "", name: nil, id: nil, disabled: false, classes: "", **attributes)
  @index = index
  @value = value
  @name = name
  @id = id
  @disabled = disabled
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#callObject



29
30
31
# File 'app/view_components/ui/input_otp_slot_component.rb', line 29

def call
  tag.input(**input_otp_slot_html_attributes.merge(@attributes))
end