LedgerUI.Components.Carousel (LedgerUI v0.2.0)

Copy Markdown View Source

Carousels without Swiper: slides on a track, and the LedgerUI.Carousel hook for arrows, pagination, autoplay, keyboard, swipe and effects.

<.carousel id="gallery" navigation slides={3}>
  <.carousel_slide><img class="h-full w-full object-cover" src="/a.jpg" alt="" /></.carousel_slide>
  <.carousel_slide>...</.carousel_slide>
  <.carousel_slide>...</.carousel_slide>
</.carousel>

<.carousel id="promo" pagination="bullets" slides={3} autoplay={2000} loop>...</.carousel>
<.carousel id="flip" effect="flip" navigation>...</.carousel>

effect is slide (the scrolling track), fade, flip, cube, cards, coverflow or creative. pagination is bullets, fraction, progress or scrollbar; it is rendered on the server, so give the number of slides (or one :thumb slot per slide). :thumb slots draw a row of thumbnails under the track that pick the slide.

The server's slide is index; the person moves freely in the browser, and their slide survives patches. on_change (an event name or %JS{}) runs when the slide changes; an event name is pushed with %{"id" => id, "index" => index} to target. From the server, push_event(socket, "ledger:carousel", %{id: "gallery", index: 2}) moves it.

The component renders the track and, as its siblings, the pagination and the thumbnails. The bullets are <i role="button" tabindex="0" aria-label=...> rendered by the server; the hook only moves aria-current and the slides' aria-hidden. Configuration that is not the default travels in data-* attributes of the track's root, which carries phx-hook="LedgerUI.Carousel".

Summary

Functions

carousel(assigns)

Attributes

  • id (:string) (required)
  • index (:integer) - The active slide, zero-based. Defaults to 0.
  • effect (:string) - Defaults to "slide". Must be one of "slide", "fade", "flip", "cube", "cards", "coverflow", or "creative".
  • direction (:string) - Defaults to "horizontal". Must be one of "horizontal", or "vertical".
  • navigation (:any) - The previous and next arrows. Defaults to false. Must be one of true, false, "inside", or "outside".
  • pagination (:string) - Defaults to nil.Must be one of nil, "bullets", "fraction", "progress", or "scrollbar".
  • slides (:integer) - How many slides there are, for the pagination (the :thumb count when omitted). Defaults to nil.
  • autoplay (:integer) - Milliseconds between slides; pauses on hover. Defaults to nil.
  • loop (:boolean) - Defaults to false.
  • gap (:integer) - Pixels between slides. Defaults to nil.
  • zoom (:integer) - Double-click zoom ratio. Defaults to nil.
  • on_change (:any) - Defaults to nil.
  • target (:any) - Defaults to nil.
  • prev_label (:string) - Defaults to "Previous slide".
  • next_label (:string) - Defaults to "Next slide".
  • bullet_label (:string) - Defaults to "Go to slide".
  • label (:string) - Defaults to nil.
  • variant (:string) - Defaults to "canvas". Must be one of "canvas", or "classic".
  • thumb_label (:string) - Defaults to "Show slide".
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • background - Behind the track, for a parallax background.
  • inner_block (required)
  • thumb - A thumbnail per slide, in order.