Sha256: f60de44a5242084dc8930cc17c172598d627112dfb73f0acd164b1d2ccabbb6b

Contents?: true

Size: 954 Bytes

Versions: 2

Compression:

Stored size: 954 Bytes

Contents

module Lookbook
  class EmbedCodeDropdown::Component < Lookbook::BaseComponent
    attr_reader :preview, :pages, :params, :target

    def initialize(preview:, target:, pages:, params:, **html_attrs)
      @preview = preview
      @target = target
      @pages = pages
      @params = params.deep_symbolize_keys
      super(**html_attrs)
    end

    def app_path
      helpers.lookbook_home_url
    end

    def preview_name
      preview.preview_class_name
    end

    def external_embed_params
      permitted = params.select { |key, val| key.to_s != "_display" }
      permitted.transform_keys! { |key| "param-#{key}" }
    end

    def embed_code
      embed_tag = content_tag("lookbook-embed",
        app: app_path,
        preview: preview_name,
        scenario: target.name,
        **external_embed_params) { "" }
      escape_once embed_tag
    end

    private

    def alpine_component
      "embedCodeDropdownComponent"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lookbook-2.0.0.beta.1 app/components/lookbook/embed_code_dropdown/component.rb
lookbook-2.0.0.beta.0 app/components/lookbook/embed_code_dropdown/component.rb