I want to pass @parent_id to render_slot. But I am unable to find in assigns of inner_block. What am i missing?
def accordion(assigns) do
assigns =
assigns
|> create_id("acc")
|> add_class("accordion")
|> add_class_if_present(:flush, "flush")
assigns = assign(assigns, :data, %{parent_id: assigns[:id]})
require Logger
Logger.info("accordion assigns = #{inspect assigns}")
~H"""
<div class={@class} id={@id} >
<%= render_slot(@inner_block, @data) %>
</div>
"""
end
def accordion_item(assigns) do
require Logger
Logger.info("assigns = #{inspect assigns}")
Logger.info("@###@")
assigns =
assigns
|> create_id("aci")
|> add_class("accordion")
|> add_class_if_present(:flush, "flush")
|> create_id(:header_id, "ach")
|> assign_if_present(:show, "show", "")
~H"""
<div class="accordion-item">
<h2 class="accordion-header" id={@header_id}>
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target={"##{@id}"} aria-expanded="true" aria-controls={@id}>
<%= render_slot(@header) %>
</button>
</h2>
<div id={@id} class={"accordion-collapse collapse #{@show}"} aria-labelledby="headingOne" data-bs-parent={"##{@parent_id}"}>
<div class="accordion-body">
<%= render_slot(@body) %>
</div>
</div>
</div>
"""
end
<.accordion>
<.accordion_item show>
<:header>
Accordion Item #1
</:header>
<:body>
<strong>This is the first item's accordion body.</strong> It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
</:body>
</.accordion_item>
</.accordion>