Class: Embed::Inspector::Component

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target:, context: nil, options: nil, scenarios: nil, panels: nil, actions: nil, **html_attrs) ⇒ Component

Returns a new instance of Component.



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

def initialize(target:, context: nil, options: nil, scenarios: nil, panels: nil, actions: nil, **html_attrs)
  @target = target
  @context = context.to_h
  @options = options.to_h
  @panels = Array(panels)
  @actions = Array(actions).map(&:to_sym)
  @scenarios = Array(scenarios)
  super(**html_attrs)
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



3
4
5
# File 'app/components/lookbook/embed/inspector/component.rb', line 3

def actions
  @actions
end

#contextObject (readonly)

Returns the value of attribute context.



3
4
5
# File 'app/components/lookbook/embed/inspector/component.rb', line 3

def context
  @context
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'app/components/lookbook/embed/inspector/component.rb', line 3

def options
  @options
end

#panelsObject (readonly)

Returns the value of attribute panels.



3
4
5
# File 'app/components/lookbook/embed/inspector/component.rb', line 3

def panels
  @panels
end

#scenariosObject (readonly)

Returns the value of attribute scenarios.



3
4
5
# File 'app/components/lookbook/embed/inspector/component.rb', line 3

def scenarios
  @scenarios
end

#targetObject (readonly)

Returns the value of attribute target.



3
4
5
# File 'app/components/lookbook/embed/inspector/component.rb', line 3

def target
  @target
end

Instance Method Details

#dataObject



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

def data
  context.fetch(:data, Store.new)
end

#display_action?(name) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/components/lookbook/embed/inspector/component.rb', line 38

def display_action?(name)
  actions.include?(name)
end

#display_option_controls?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'app/components/lookbook/embed/inspector/component.rb', line 46

def display_option_controls?
  options.fetch(:display_option_controls, true)
end

#drawer?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'app/components/lookbook/embed/inspector/component.rb', line 50

def drawer?
  panels.any?
end

#dynamic_display_optionsObject



30
31
32
# File 'app/components/lookbook/embed/inspector/component.rb', line 30

def dynamic_display_options
  context.fetch(:dynamic_display_options, {}).to_h
end

#idObject



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

def id
  Utils.id(
    "embed-inspector",
    "#{scenarios.map(&:name).join}#{options.to_json}#{actions.to_json}#{panels.to_json}".hash
  )
end

#paramsObject



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

def params
  context.fetch(:params, {}).to_h
end

#scenario_select_optionsObject



42
43
44
# File 'app/components/lookbook/embed/inspector/component.rb', line 42

def scenario_select_options
  scenarios.map { |scenario| [scenario.label, helpers.lookbook_embed_path(scenario.lookup_path)] }
end

#static_display_optionsObject



34
35
36
# File 'app/components/lookbook/embed/inspector/component.rb', line 34

def static_display_options
  context.fetch(:static_display_options, {}).to_h
end