Class: Fluxbit::Form::DropzoneComponent

Inherits:
FieldComponent
  • Object
show all
Includes:
Config::Form::DropzoneComponent
Defined in:
app/components/fluxbit/form/dropzone_component.rb

Overview

The ‘Fluxbit::Form::DropzoneComponent` provides a drag-and-drop file input zone with support for labels, titles, subtitles, icons, validation states, and integration with Rails form builders. It renders a visually rich area that lets users drag files or click to select a file, and is fully customizable via its options and slot for custom content.

Examples:

Basic usage

= render Fluxbit::Form::DropzoneComponent.new(name: :avatar)

See Also:

  • For detailed documentation and examples.

Instance Method Summary collapse

Constructor Details

#initialize(**props) ⇒ DropzoneComponent

Initializes the dropzone component with the given properties.

Parameters:

  • name (String)

    Name of the field (required unless using form builder)

  • label (String)

    Label for the input (optional)

  • title (Boolean, String)

    Title text above the dropzone (true for default, false to hide, or custom string)

  • subtitle (Boolean, String)

    Subtitle text below the title (true for default, false to hide, or custom string)

  • icon (String, Symbol)

    Icon to display above the title (defaults to config)

  • icon_props (Hash)

    Extra props for the icon element

  • height (Integer)

    Height preset (0: auto, 1: h-32, 2: h-64, 3: h-96; default is 0)

  • help_text (String)

    Helper or error text below the field

  • ...

    any other HTML attribute supported by file_field_tag



26
27
28
29
30
31
32
33
34
# File 'app/components/fluxbit/form/dropzone_component.rb', line 26

def initialize(**props)
  super(**props)
  @title = options(@props.delete(:title), default: true)
  @subtitle = options(@props.delete(:subtitle), default: true)
  @icon = @props.delete(:icon) || @@icon
  @icon_props = @props.delete(:icon_props) || { class: styles[:icon] }
  @height = @props.delete(:height) || @@height
  add to: @props, class: "hidden"
end

Instance Method Details

#create_iconObject



36
37
38
# File 'app/components/fluxbit/form/dropzone_component.rb', line 36

def create_icon
  anyicon(icon: @icon, class: styles[:icon])
end