Class: BetterUi::General::Input::Textarea::Component

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/better_ui/general/input/textarea/component.rb

Constant Summary collapse

TEXTAREA_THEME =

Temi supportati per il Textarea

{
  default: 'border-gray-300 focus:border-blue-500 focus:ring-blue-500',
  white: 'border-white focus:border-gray-300 focus:ring-gray-300 bg-white',
  red: 'border-red-300 focus:border-red-500 focus:ring-red-500',
  rose: 'border-rose-300 focus:border-rose-500 focus:ring-rose-500',
  orange: 'border-orange-300 focus:border-orange-500 focus:ring-orange-500',
  green: 'border-green-300 focus:border-green-500 focus:ring-green-500',
  blue: 'border-blue-300 focus:border-blue-500 focus:ring-blue-500',
  yellow: 'border-yellow-300 focus:border-yellow-500 focus:ring-yellow-500',
  violet: 'border-violet-300 focus:border-violet-500 focus:ring-violet-500'
}.freeze
TEXTAREA_SIZES =

Dimensioni supportate per il Textarea

{
  small: 'px-2 py-1 text-xs',
  medium: 'px-3 py-2 text-sm',
  large: 'px-4 py-3 text-base'
}.freeze
TEXTAREA_RADIUS =

Border radius supportati per il Textarea

{
  none: 'rounded-none',
  small: 'rounded-sm',
  medium: 'rounded-md',
  large: 'rounded-lg',
  full: 'rounded-2xl'
}.freeze
TEXTAREA_BASE_CLASSES =

Classi base per il Textarea

'block w-full border shadow-sm disabled:bg-gray-100 disabled:cursor-not-allowed focus:outline-none focus:ring-1 resize-y'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, value: nil, placeholder: nil, required: false, disabled: false, rows: 3, theme: :default, size: :medium, rounded: :medium, classes: '', form: nil, **options) ⇒ Component

Returns a new instance of Component.

Parameters:

  • name (String)

    Nome del campo textarea

  • value (String) (defaults to: nil)

    Valore del campo

  • placeholder (String) (defaults to: nil)

    Placeholder del campo

  • required (Boolean) (defaults to: false)

    Se il campo è obbligatorio

  • disabled (Boolean) (defaults to: false)

    Se il campo è disabilitato

  • rows (Integer) (defaults to: 3)

    Numero di righe per la textarea

  • theme (Symbol) (defaults to: :default)

    Tema del componente (:default, :white, :red, :rose, :orange, :green, :blue, :yellow, :violet)

  • size (Symbol) (defaults to: :medium)

    Dimensione del componente (:small, :medium, :large)

  • rounded (Symbol) (defaults to: :medium)

    Border radius (:none, :small, :medium, :large, :full)

  • classes (String) (defaults to: '')

    Classi CSS aggiuntive

  • form (ActionView::Helpers::FormBuilder) (defaults to: nil)

    Form builder Rails opzionale

  • options (Hash)

    Opzioni aggiuntive per la textarea



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/components/better_ui/general/input/textarea/component.rb', line 55

def initialize(name:, value: nil, placeholder: nil, required: false, disabled: false, 
               rows: 3, theme: :default, size: :medium, rounded: :medium, classes: '', form: nil, **options)
  @name = name
  @value = value
  @placeholder = placeholder
  @required = required
  @disabled = disabled
  @rows = rows
  @theme = theme
  @size = size
  @rounded = rounded
  @classes = classes
  @form = form
  @options = options

  validate_params
  super()
end

Instance Attribute Details

#classesObject (readonly)

Returns the value of attribute classes.



8
9
10
# File 'app/components/better_ui/general/input/textarea/component.rb', line 8

def classes
  @classes
end

#disabledObject (readonly)

Returns the value of attribute disabled.



8
9
10
# File 'app/components/better_ui/general/input/textarea/component.rb', line 8

def disabled
  @disabled
end

#formObject (readonly)

Returns the value of attribute form.



8
9
10
# File 'app/components/better_ui/general/input/textarea/component.rb', line 8

def form
  @form
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'app/components/better_ui/general/input/textarea/component.rb', line 8

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'app/components/better_ui/general/input/textarea/component.rb', line 8

def options
  @options
end

#placeholderObject (readonly)

Returns the value of attribute placeholder.



8
9
10
# File 'app/components/better_ui/general/input/textarea/component.rb', line 8

def placeholder
  @placeholder
end

#requiredObject (readonly)

Returns the value of attribute required.



8
9
10
# File 'app/components/better_ui/general/input/textarea/component.rb', line 8

def required
  @required
end

#roundedObject (readonly)

Returns the value of attribute rounded.



8
9
10
# File 'app/components/better_ui/general/input/textarea/component.rb', line 8

def rounded
  @rounded
end

#rowsObject (readonly)

Returns the value of attribute rows.



8
9
10
# File 'app/components/better_ui/general/input/textarea/component.rb', line 8

def rows
  @rows
end

#sizeObject (readonly)

Returns the value of attribute size.



8
9
10
# File 'app/components/better_ui/general/input/textarea/component.rb', line 8

def size
  @size
end

#themeObject (readonly)

Returns the value of attribute theme.



8
9
10
# File 'app/components/better_ui/general/input/textarea/component.rb', line 8

def theme
  @theme
end

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'app/components/better_ui/general/input/textarea/component.rb', line 8

def value
  @value
end

Instance Method Details

#form_textarea_attributesObject

Attributi per l’elemento textarea con form builder



89
90
91
92
93
94
95
96
97
# File 'app/components/better_ui/general/input/textarea/component.rb', line 89

def form_textarea_attributes
  {
    class: build_classes,
    placeholder: @placeholder,
    required: @required,
    disabled: @disabled,
    rows: @rows
  }.merge(@options)
end

#textarea_attributesObject

Attributi per l’elemento textarea standalone



75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/components/better_ui/general/input/textarea/component.rb', line 75

def textarea_attributes
  {
    name: @name,
    id: @name,
    value: @value,
    placeholder: @placeholder,
    required: @required,
    disabled: @disabled,
    rows: @rows,
    class: build_classes
  }.merge(@options)
end