app/components/lookbook/embed/component.rb in lookbook-1.5.5 vs app/components/lookbook/embed/component.rb in lookbook-2.0.0.beta.0

- old
+ new

@@ -1,30 +1,31 @@ module Lookbook class Embed::Component < Lookbook::BaseComponent - def initialize(id:, example:, params: {}, opts: {}, max_height: nil, **html_attrs) - @id = id - @target = example - @params = params - @opts = opts - @max_height = max_height + ACTIONS = [:inspect, :open] + + attr_reader :preview, :scenario, :params, :options + + def initialize(scenario:, params: {}, options: {}, **html_attrs) + @scenario = scenario + @preview = scenario.preview + @params = params.to_h + @options = options.to_h super(**html_attrs) end - protected - - def lookbook_inspect_path(*args) - Lookbook::Engine.routes.url_helpers.lookbook_inspect_path(*args) + def preview_class + preview.preview_class.name end - def lookbook_preview_path(*args) - Lookbook::Engine.routes.url_helpers.lookbook_preview_path(*args) + def panels + options.fetch(:panels, []).map(&:to_s) end - def alpine_data - [alpine_encode(@id), "$store.pages.embeds"].join(",") + def actions + options.fetch(:actions, ACTIONS).map(&:to_s) end - def alpine_component - "embedComponent" + def params_attrs_str + params.map { |key, value| "param-#{key}=\"#{value}\"" }.join(" ").strip.html_safe end end end