Class: UI::InputOtp
- Inherits:
-
Phlex::HTML
- Object
- Phlex::HTML
- UI::InputOtp
- Includes:
- InputOtpBehavior
- Defined in:
- app/components/ui/input_otp.rb
Overview
InputOtp - Phlex implementation
Accessible one-time password container component. Supports both composition (with Group/Slot/Separator) and auto-generation.
Instance Method Summary collapse
-
#initialize(length: 6, pattern: "\\d", name: nil, id: nil, disabled: false, classes: "", **attributes) ⇒ InputOtp
constructor
A new instance of InputOtp.
- #view_template(&block) ⇒ Object
Methods included from InputOtpBehavior
#input_otp_classes, #input_otp_data_attributes, #input_otp_html_attributes
Constructor Details
#initialize(length: 6, pattern: "\\d", name: nil, id: nil, disabled: false, classes: "", **attributes) ⇒ InputOtp
Returns a new instance of InputOtp.
27 28 29 30 31 32 33 34 35 |
# File 'app/components/ui/input_otp.rb', line 27 def initialize(length: 6, pattern: "\\d", name: nil, id: nil, disabled: false, classes: "", **attributes) @length = length @pattern = pattern @name = name @id = id @disabled = disabled @classes = classes @attributes = attributes end |
Instance Method Details
#view_template(&block) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/components/ui/input_otp.rb', line 37 def view_template(&block) div(**input_otp_html_attributes.merge(@attributes)) do if block_given? yield else # Auto-generate inputs wrapped in Group render Group.new do @length.times do |i| render Slot.new( index: i, name: @name ? "#{@name}[#{i}]" : nil, id: @id ? "#{@id}_#{i}" : nil, disabled: @disabled ) end end end end end |