Class: Embed::Component

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

Constant Summary collapse

ACTIONS =
[:inspect, :open]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scenario:, params: {}, options: {}, **html_attrs) ⇒ Component

Returns a new instance of Component.



7
8
9
10
11
12
13
# File 'app/components/lookbook/embed/component.rb', line 7

def initialize(scenario:, params: {}, options: {}, **html_attrs)
  @scenario = scenario
  @preview = scenario.preview
  @params = params.to_h
  @options = options.to_h
  super(**html_attrs)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'app/components/lookbook/embed/component.rb', line 5

def options
  @options
end

#paramsObject (readonly)

Returns the value of attribute params.



5
6
7
# File 'app/components/lookbook/embed/component.rb', line 5

def params
  @params
end

#previewObject (readonly)

Returns the value of attribute preview.



5
6
7
# File 'app/components/lookbook/embed/component.rb', line 5

def preview
  @preview
end

#scenarioObject (readonly)

Returns the value of attribute scenario.



5
6
7
# File 'app/components/lookbook/embed/component.rb', line 5

def scenario
  @scenario
end

Instance Method Details

#actionsObject



23
24
25
# File 'app/components/lookbook/embed/component.rb', line 23

def actions
  options.fetch(:actions, ACTIONS).map(&:to_s)
end

#panelsObject



19
20
21
# File 'app/components/lookbook/embed/component.rb', line 19

def panels
  options.fetch(:panels, []).map(&:to_s)
end

#params_attrs_strObject



27
28
29
# File 'app/components/lookbook/embed/component.rb', line 27

def params_attrs_str
  params.map { |key, value| "param-#{key}=\"#{value}\"" }.join(" ").strip.html_safe
end

#preview_classObject



15
16
17
# File 'app/components/lookbook/embed/component.rb', line 15

def preview_class
  preview.preview_class.name
end