module ViewComponent::SlotableV2

def renders_one(slot_name, callable = nil)

<% end %>
<% end %>

Bar


<%= component.header(classes: "Foo") do %>
<%= render_inline(MyComponent.new) do |component| %>

helper method with the same name as the slot.
Consumers of the component can render a sub-component by calling a

= Setting sub-component content


<% end %>
My header title
<%= header do %>



helper method with the same name as the sub-component.
The component's sidecar template can access the sub-component by calling a

= Rendering sub-component content


<%= content %>


and has the following template:

end
end
@classes = classes
def initialize(classes:)
class HeaderComponent < ViewComponent::Base

where `HeaderComponent` is defined as:

renders_one :header, HeaderComponent

# OR

end
HeaderComponent.new(classes: classes)
renders_one :header -> (classes:) do

= Example

Registers a sub-component
#

def renders_one(slot_name, callable = nil)
  validate_slot_name(slot_name)
  define_method slot_name do |*args, **kwargs, &block|
    if args.empty? && kwargs.empty? && block.nil?
      get_slot(slot_name)
    else
      set_slot(slot_name, *args, **kwargs, &block)
    end
  end
  register_slot(slot_name, collection: false, callable: callable)
end