Class: ParamsEditor::Field::Component

Inherits:
Lookbook::BaseComponent
  • Object
show all
Defined in:
app/components/lookbook/params_editor/field/component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input:, name:, default: nil, value: nil, input_type: nil, type: nil, options: nil, **html_attrs) ⇒ Component

Returns a new instance of Component.



5
6
7
8
9
10
11
12
13
14
# File 'app/components/lookbook/params_editor/field/component.rb', line 5

def initialize(input:, name:, default: nil, value: nil, input_type: nil, type: nil, options: nil, **html_attrs)
  @input = input
  @name = name
  @value = value
  @default_value = default
  @input_type = input_type
  @type = type
  @options = options
  super(**html_attrs)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'app/components/lookbook/params_editor/field/component.rb', line 3

def name
  @name
end

Instance Method Details

#field_typeObject



25
26
27
# File 'app/components/lookbook/params_editor/field/component.rb', line 25

def field_type
  @input.to_s
end

#input_typeObject



29
30
31
# File 'app/components/lookbook/params_editor/field/component.rb', line 29

def input_type
  @input_type.nil? && field_type == "text" ? "text" : @input_type
end

#labelObject



16
17
18
# File 'app/components/lookbook/params_editor/field/component.rb', line 16

def label
  name.titleize
end

#valueObject



20
21
22
23
# File 'app/components/lookbook/params_editor/field/component.rb', line 20

def value
  val = @value.presence || @default_value
  @type == "Boolean" ? val == "true" || val == true : val
end