Class: Field::Component
- Inherits:
-
Lookbook::BaseComponent
- Object
- Lookbook::BaseComponent
- Field::Component
- Defined in:
- app/components/lookbook/display_options/field/component.rb,
app/components/lookbook/params/field/component.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#param ⇒ Object
readonly
Returns the value of attribute param.
-
#rendered_input ⇒ Object
readonly
Returns the value of attribute rendered_input.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #before_render ⇒ Object
- #choices ⇒ Object
-
#initialize(param:, index:, **html_attrs) ⇒ Component
constructor
A new instance of Component.
Constructor Details
#initialize(param:, index:, **html_attrs) ⇒ Component
Returns a new instance of Component.
6 7 8 9 10 11 |
# File 'app/components/lookbook/display_options/field/component.rb', line 6 def initialize(name:, opts:, value:, **html_attrs) @name = name @opts = opts @value = value super(**html_attrs) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'app/components/lookbook/display_options/field/component.rb', line 4 def name @name end |
#param ⇒ Object (readonly)
Returns the value of attribute param.
4 5 6 |
# File 'app/components/lookbook/params/field/component.rb', line 4 def param @param end |
#rendered_input ⇒ Object (readonly)
Returns the value of attribute rendered_input.
4 5 6 |
# File 'app/components/lookbook/params/field/component.rb', line 4 def rendered_input @rendered_input end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
4 5 6 |
# File 'app/components/lookbook/display_options/field/component.rb', line 4 def value @value end |
Instance Method Details
#before_render ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/components/lookbook/params/field/component.rb', line 13 def before_render styles, html = StylesExtractor.call(render_input) Editor::Component.add_styles(param.input, styles) escaped_value = json_escape(param.value.to_s).gsub("\n", '\n') wrapper_attrs = { data: {"param-input": param.input}, "x-data": "paramsInputComponent({name: \"#{param.name}\", value: \"#{escaped_value}\"})" } @rendered_input = tag.div(**wrapper_attrs) { html.html_safe } end |
#choices ⇒ Object
13 14 15 |
# File 'app/components/lookbook/display_options/field/component.rb', line 13 def choices @opts.is_a?(Hash) ? @opts[:choices].to_a : @opts end |