Class: Shadcn::InputOtp::Slot::Component

Inherits:
ApplicationViewComponent show all
Defined in:
app/components/shadcn/input_otp/slot/component.rb

Overview

InputOTPSlot — one box. It holds no state of its own: the character, the active mark and the caret are all written by the controller from the one input's value and selection.

Upstream takes an index; this reads the boxes in the order they appear, which is the same answer without a number for a caller to get wrong.

Constant Summary collapse

CARET_CLASSES =
"pointer-events-none absolute inset-0 flex items-center justify-center"
BAR_CLASSES =
"h-4 w-px animate-caret-blink bg-foreground duration-1000"

Constants inherited from ApplicationViewComponent

ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS

Instance Attribute Summary

Attributes inherited from ApplicationViewComponent

#attributes

Instance Method Summary collapse

Methods inherited from ApplicationViewComponent

#css_classes, default_tag, #initialize, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name

Constructor Details

This class inherits a constructor from Shadcn::ApplicationViewComponent

Instance Method Details

#callObject



37
38
39
# File 'app/components/shadcn/input_otp/slot/component.rb', line 37

def call
  render_element(body: safe_join([ character, caret ]))
end

#element_attributes(**defaults) ⇒ Object



30
31
32
33
34
35
# File 'app/components/shadcn/input_otp/slot/component.rb', line 30

def element_attributes(**defaults)
  super(**{
    "data-active" => "false",
    "data-shadcn--input-otp-target" => "slot"
  }.merge(defaults))
end