Sha256: 99c0a4073da65ede62446ebc5b26089f25cc59f70210bd0a5660b9ebfc9db785

Contents?: true

Size: 1.28 KB

Versions: 15

Compression:

Stored size: 1.28 KB

Contents

module Lookbook
  module Params
    class Field::Component < Lookbook::BaseComponent
      attr_reader :param, :rendered_input

      def initialize(param:, index:, **html_attrs)
        @param = param
        @index = index
        @rendered_input = nil
        super(**html_attrs)
      end

      def before_render
        styles, html = StylesExtractor.call(render_input)
        Editor::Component.add_styles(param.input, styles)

        escaped_value = json_escape(param.value.to_s)
        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

      protected

      def render_input
        input_options = param.input_options.to_h
        input_options[:id] = "param-#{param.name}"

        render(param.input_partial,
          name: param.name,
          input: param.input,
          value: param.value.to_s,
          value_type: param.value_type,
          value_default: param.value_default,
          input_options: input_options.except(:choices, :opts),
          choices: input_options[:choices])
      end

      def alpine_component
        "paramsFieldComponent"
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
lookbook-1.5.5 app/components/lookbook/params/field/component.rb
lookbook-1.5.4 app/components/lookbook/params/field/component.rb
lookbook-2.0.0.beta.7 app/components/lookbook/params/field/component.rb
lookbook-2.0.0.beta.6 app/components/lookbook/params/field/component.rb
lookbook-2.0.0.beta.5 app/components/lookbook/params/field/component.rb
lookbook-2.0.0.beta.4 app/components/lookbook/params/field/component.rb
lookbook-2.0.0.beta.3 app/components/lookbook/params/field/component.rb
lookbook-2.0.0.beta.2 app/components/lookbook/params/field/component.rb
lookbook-1.5.3 app/components/lookbook/params/field/component.rb
lookbook-2.0.0.beta.1 app/components/lookbook/params/field/component.rb
lookbook-1.5.2 app/components/lookbook/params/field/component.rb
lookbook-2.0.0.beta.0 app/components/lookbook/params/field/component.rb
lookbook-1.5.1 app/components/lookbook/params/field/component.rb
lookbook-1.5.0 app/components/lookbook/params/field/component.rb
lookbook-1.4.5 app/components/lookbook/params/field/component.rb