Class: Embed::Inspector::Component
- Inherits:
-
Lookbook::BaseComponent
- Object
- Lookbook::BaseComponent
- Embed::Inspector::Component
- Defined in:
- app/components/lookbook/embed/inspector/component.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#panels ⇒ Object
readonly
Returns the value of attribute panels.
-
#scenarios ⇒ Object
readonly
Returns the value of attribute scenarios.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #data ⇒ Object
- #display_action?(name) ⇒ Boolean
- #display_option_controls? ⇒ Boolean
- #drawer? ⇒ Boolean
- #dynamic_display_options ⇒ Object
- #id ⇒ Object
-
#initialize(target:, context: nil, options: nil, scenarios: nil, panels: nil, actions: nil, **html_attrs) ⇒ Component
constructor
A new instance of Component.
- #params ⇒ Object
- #scenario_select_options ⇒ Object
- #static_display_options ⇒ Object
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 = .to_h @panels = Array(panels) @actions = Array(actions).map(&:to_sym) @scenarios = Array(scenarios) super(**html_attrs) end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
3 4 5 |
# File 'app/components/lookbook/embed/inspector/component.rb', line 3 def actions @actions end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'app/components/lookbook/embed/inspector/component.rb', line 3 def context @context end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'app/components/lookbook/embed/inspector/component.rb', line 3 def @options end |
#panels ⇒ Object (readonly)
Returns the value of attribute panels.
3 4 5 |
# File 'app/components/lookbook/embed/inspector/component.rb', line 3 def panels @panels end |
#scenarios ⇒ Object (readonly)
Returns the value of attribute scenarios.
3 4 5 |
# File 'app/components/lookbook/embed/inspector/component.rb', line 3 def scenarios @scenarios end |
#target ⇒ Object (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
#data ⇒ Object
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
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
46 47 48 |
# File 'app/components/lookbook/embed/inspector/component.rb', line 46 def display_option_controls? .fetch(:display_option_controls, true) end |
#drawer? ⇒ Boolean
50 51 52 |
# File 'app/components/lookbook/embed/inspector/component.rb', line 50 def drawer? panels.any? end |
#dynamic_display_options ⇒ Object
30 31 32 |
# File 'app/components/lookbook/embed/inspector/component.rb', line 30 def context.fetch(:dynamic_display_options, {}).to_h end |
#id ⇒ Object
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}#{.to_json}#{actions.to_json}#{panels.to_json}".hash ) end |
#params ⇒ Object
26 27 28 |
# File 'app/components/lookbook/embed/inspector/component.rb', line 26 def params context.fetch(:params, {}).to_h end |
#scenario_select_options ⇒ Object
42 43 44 |
# File 'app/components/lookbook/embed/inspector/component.rb', line 42 def scenarios.map { |scenario| [scenario.label, helpers.(scenario.lookup_path)] } end |
#static_display_options ⇒ Object
34 35 36 |
# File 'app/components/lookbook/embed/inspector/component.rb', line 34 def context.fetch(:static_display_options, {}).to_h end |