Class: Forms::WrappedInput

Inherits:
Phlex::HTML
  • Object
show all
Includes:
PhlexForms::DelegatedField
Defined in:
lib/forms/wrapped_input.rb

Overview

The daisyui v5 "text/icon inside the field" pattern: a <label class="input"> wrapper that owns the visual styling, with leading/trailing content (icons, kbd hints, a text prefix) rendered as siblings of a bare <input>.

f.field(:search).wrapped_input(:primary) do
_lucide("search")             # or any leading content
end

The yielded block renders before the input (leading slot); pass trailing: for content after it. The input itself is bare (no input class) since the wrapping label carries it — this is the daisyui v5 convention.

Constant Summary

Constants included from PhlexForms::DelegatedField

PhlexForms::DelegatedField::IGNORED_MODIFIERS

Instance Method Summary collapse

Constructor Details

#initialize(*modifiers, type: "text", name: nil, id: nil, value: nil, placeholder: nil, error: false, disabled: false, required: false, trailing: nil, **attributes) ⇒ WrappedInput

Returns a new instance of WrappedInput.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/forms/wrapped_input.rb', line 18

def initialize(*modifiers, type: "text", name: nil, id: nil, value: nil,
               placeholder: nil, error: false, disabled: false, required: false,
               trailing: nil, **attributes)
  @modifiers = normalize_modifiers(modifiers)
  @type = type
  @name = name
  @id = id
  @value = value
  @placeholder = placeholder
  @error = error
  @disabled = disabled
  @required = required
  @trailing = trailing
  @full_width = true
  @attributes = attributes
  super()
end

Instance Method Details

#view_template(&leading) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/forms/wrapped_input.rb', line 36

def view_template(&leading)
  render DaisyUI::Label.new(:input, *daisy_modifiers, class: width_class) do
    leading&.call
    input(**bare_input_attributes)
    render_trailing
  end
end