Corex.Marquee (Corex v0.1.0-alpha.33)

View Source

Phoenix implementation of Zag.js Marquee.

Examples

<.marquee
  id="logos"
  items={[%{name: "Apple", logo: "🍎"}, %{name: "Banana", logo: "🍌"}]}
  duration={20}
  spacing="2rem"
  pause_on_interaction
>
  <:item :let={%{item: item}}>
    <span>{item.logo}</span>
    <span>{item.name}</span>
  </:item>
</.marquee>

Styling

Target elements via data attributes:

[data-scope="marquee"][data-part="root"] {}
[data-scope="marquee"][data-part="viewport"] {}
[data-scope="marquee"][data-part="content"] {}
[data-scope="marquee"][data-part="item"] {}
[data-scope="marquee"][data-part="edge"] {}

If you wish to use the default Corex styling, you can use the class marquee on the component. This requires to install Mix.Tasks.Corex.Design first and import the component css file.

@import "../corex/main.css";
@import "../corex/tokens/themes/neo/light.css";
@import "../corex/components/marquee.css";

You can then use modifiers

<.marquee class="marquee marquee--accent marquee--lg">

API Control

Use an id on the component for programmatic control.

Client-side

<.action phx-click={Corex.Marquee.pause("my-marquee")}>Pause</.action>
<.action phx-click={Corex.Marquee.resume("my-marquee")}>Resume</.action>
<.action phx-click={Corex.Marquee.toggle_pause("my-marquee")}>Toggle</.action>

Server-side

def handle_event("pause_marquee", _, socket) do
  {:noreply, Corex.Marquee.pause(socket, "my-marquee")}
end

Events

  • on_pause_change / on_pause_change_client - when pause status changes (detail: %{paused: boolean})
  • on_loop_complete / on_loop_complete_client - when one loop completes
  • on_complete / on_complete_client - when all loops complete (finite loops only, loop_count > 0)

Summary

Functions

Pauses the marquee from client-side. Returns a Phoenix.LiveView.JS command.

Pauses the marquee from server-side. Pushes a LiveView event.

Resumes the marquee from client-side. Returns a Phoenix.LiveView.JS command.

Resumes the marquee from server-side. Pushes a LiveView event.

Toggles the pause state from client-side. Returns a Phoenix.LiveView.JS command.

Toggles the pause state from server-side. Pushes a LiveView event.

Components

marquee(assigns)

Attributes

  • id (:string)
  • aria_label (:string) - Accessible name for the marquee region. Defaults to "Marquee: {id}" when omitted. Defaults to nil.
  • items (:list) (required) - List of maps for each marquee item.
  • duration (:integer) (required) - Animation duration in seconds.
  • side (:string) - Defaults to "end". Must be one of "start", "end", "top", or "bottom".
  • speed (:integer) - Defaults to 50.
  • spacing (:string) - Defaults to "1rem".
  • auto_fill (:boolean) - Defaults to true.
  • pause_on_interaction (:boolean) - Defaults to false.
  • default_paused (:boolean) - Defaults to false.
  • delay (:integer) - Defaults to 0.
  • loop_count (:integer) - Defaults to 0.
  • reverse (:boolean) - Defaults to false.
  • respect_reduced_motion (:boolean) - When false, animation runs even when user has prefers-reduced-motion. Defaults to true.
  • dir (:string) - Defaults to nil.Must be one of nil, "ltr", or "rtl".
  • on_pause_change (:string) - Server event when pause status changes. Defaults to nil.
  • on_pause_change_client (:string) - Client event when pause status changes. Defaults to nil.
  • on_loop_complete (:string) - Server event when one loop completes. Defaults to nil.
  • on_loop_complete_client (:string) - Client event when one loop completes. Defaults to nil.
  • on_complete (:string) - Server event when all loops complete (finite loops only). Defaults to nil.
  • on_complete_client (:string) - Client event when all loops complete (finite loops only). Defaults to nil.
  • Global attributes are accepted.

Slots

  • item (required) - Accepts attributes:
    • class (:string)
  • edge_start - Accepts attributes:
    • class (:string)
  • edge_end - Accepts attributes:
    • class (:string)

Functions

pause(marquee_id)

Pauses the marquee from client-side. Returns a Phoenix.LiveView.JS command.

pause(socket, marquee_id)

Pauses the marquee from server-side. Pushes a LiveView event.

resume(marquee_id)

Resumes the marquee from client-side. Returns a Phoenix.LiveView.JS command.

resume(socket, marquee_id)

Resumes the marquee from server-side. Pushes a LiveView event.

toggle_pause(marquee_id)

Toggles the pause state from client-side. Returns a Phoenix.LiveView.JS command.

toggle_pause(socket, marquee_id)

Toggles the pause state from server-side. Pushes a LiveView event.