"""
end
attr(:ctx, :map, required: true)
attr(:index, :integer, required: true)
attr(:rest, :global)
slot(:inner_block, required: false)
def carousel_indicator(assigns) do
ind = %Indicator{
id: assigns.ctx.id,
index: assigns.index,
orientation: assigns.ctx.orientation,
dir: assigns.ctx.dir,
page: assigns.ctx.page
}
assigns = assign(assigns, :ind, ind)
~H"""
"""
end
@doc type: :api
@doc """
Starts or resumes carousel autoplay from the client. Returns a `Phoenix.LiveView.JS` command.
"""
def play(carousel_id) when is_binary(carousel_id) do
JS.dispatch("corex:carousel:play", to: "##{carousel_id}", detail: %{}, bubbles: false)
end
@doc type: :api
@doc """
Pauses carousel autoplay from the client.
"""
def pause(carousel_id) when is_binary(carousel_id) do
JS.dispatch("corex:carousel:pause", to: "##{carousel_id}", detail: %{}, bubbles: false)
end
@doc type: :api
def play(socket, carousel_id)
when is_struct(socket, Phoenix.LiveView.Socket) and is_binary(carousel_id) do
LiveView.push_event(socket, "carousel_play", %{"id" => carousel_id})
end
@doc type: :api
def pause(socket, carousel_id)
when is_struct(socket, Phoenix.LiveView.Socket) and is_binary(carousel_id) do
LiveView.push_event(socket, "carousel_pause", %{"id" => carousel_id})
end
@doc type: :api
@doc """
Scrolls to the next page from the client.
"""
def scroll_next(carousel_id) when is_binary(carousel_id), do: scroll_next(carousel_id, false)
@doc type: :api
@doc """
Scrolls to the next page from the client. Pass `true` for `instant` to skip animation.
"""
def scroll_next(carousel_id, instant) when is_binary(carousel_id) and is_boolean(instant) do
JS.dispatch("corex:carousel:scroll-next",
to: "##{carousel_id}",
detail: scroll_detail(instant),
bubbles: false
)
end
@doc type: :api
def scroll_next(socket, carousel_id)
when is_struct(socket, Phoenix.LiveView.Socket) and is_binary(carousel_id) do
scroll_next(socket, carousel_id, false)
end
@doc type: :api
def scroll_next(socket, carousel_id, instant)
when is_struct(socket, Phoenix.LiveView.Socket) and is_binary(carousel_id) and
is_boolean(instant) do
LiveView.push_event(socket, "carousel_scroll_next", scroll_payload(carousel_id, instant))
end
@doc type: :api
@doc """
Scrolls to the previous page from the client.
"""
def scroll_prev(carousel_id) when is_binary(carousel_id), do: scroll_prev(carousel_id, false)
@doc type: :api
def scroll_prev(carousel_id, instant) when is_binary(carousel_id) and is_boolean(instant) do
JS.dispatch("corex:carousel:scroll-prev",
to: "##{carousel_id}",
detail: scroll_detail(instant),
bubbles: false
)
end
@doc type: :api
def scroll_prev(socket, carousel_id)
when is_struct(socket, Phoenix.LiveView.Socket) and is_binary(carousel_id) do
scroll_prev(socket, carousel_id, false)
end
@doc type: :api
def scroll_prev(socket, carousel_id, instant)
when is_struct(socket, Phoenix.LiveView.Socket) and is_binary(carousel_id) and
is_boolean(instant) do
LiveView.push_event(socket, "carousel_scroll_prev", scroll_payload(carousel_id, instant))
end
defp scroll_detail(false), do: %{}
defp scroll_detail(true), do: %{instant: true}
defp scroll_payload(carousel_id, instant) do
base = %{"id" => carousel_id}
if instant, do: Map.put(base, "instant", true), else: base
end
end