Module: ViewComponentReflex::Dom::Component

Defined in:
lib/view_component_reflex/dom/component.rb

Instance Method Summary collapse

Instance Method Details

#component_controller(opts_or_tag = :div, opts = {}, &blk) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/view_component_reflex/dom/component.rb', line 5

def component_controller(opts_or_tag = :div, opts = {}, &blk)
  initialize_component

  tag = :div
  options = if opts_or_tag.is_a? Hash
    opts_or_tag
  else
    tag = opts_or_tag
    opts
  end

  data = {
    "#{key}_state" => Verifier.generate(state(key)),
    "#{key}_initial" => Verifier.generate(state("#{key}_initial")),
  }

  options[:data] = {
    controller: self.class.stimulus_controller,
    key: key,
    **(options[:data] || {})
  }

   tag, options do
    concat((:span, nil, { data: data, style: "display: none;" }))
    concat(capture(&blk))
  end
end

#reflex_data_attributes(reflex) ⇒ Object



33
34
35
36
37
# File 'lib/view_component_reflex/dom/component.rb', line 33

def reflex_data_attributes(reflex)
  super(reflex).tap do |attr|
    attr["reflex-dataset"] = "*"
  end
end