Class: PhlexKit::InputOtpSlot

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/input_otp/input_otp_slot.rb

Overview

One character cell of an InputOtp. See input_otp.rb.

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(**attrs) ⇒ InputOtpSlot

Returns a new instance of InputOtpSlot.



4
5
6
# File 'app/components/phlex_kit/input_otp/input_otp_slot.rb', line 4

def initialize(**attrs)
  @attrs = attrs
end

Instance Method Details

#view_templateObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/components/phlex_kit/input_otp/input_otp_slot.rb', line 8

def view_template
  base = { type: :text, class: "pk-input-otp-slot" }
  # Defaults only when the caller didn't supply their own — `mix` fuses
  # (e.g. inputmode: "text" for alphanumeric codes).
  base[:inputmode] = "numeric" unless attr_set?(:inputmode)
  base[:autocomplete] = "one-time-code" unless attr_set?(:autocomplete)
  base[:maxlength] = "1" unless attr_set?(:maxlength)
  input(**mix(base, {
    data: {
      phlex_kit__input_otp_target: "slot",
      action: [
        "input->phlex-kit--input-otp#onInput",
        "keydown->phlex-kit--input-otp#onKeydown",
        "paste->phlex-kit--input-otp#onPaste",
        "focus->phlex-kit--input-otp#onFocus"
      ].join(" ")
    }
  }, @attrs))
end