06 · Display

Carousel

effect slide/fade/flip/cube/cards/coverflow/creative · direction · navigation · pagination bullets/fraction/progress/scrollbar · variant

A horizontal strip of cards with arrow navigation and indicators.

effect slide and fade

slide
Promoção de novembro
Novo: NFC-e
Black Friday
Promoção de novembro
fade
Promoção de novembro
Novo: NFC-e
Black Friday
.heex
<div class="grid grid-cols-2 gap-4"><div class="flex flex-col gap-1.5"><span class="font-mono text-xs text-muted">slide</span><.carousel id="car-slide" demo pagination="bullets" slides={3} class="max-w-[560px]"><.carousel_slide :for={{bg, t, d} <- [{"linear-gradient(135deg,#1f9282,#0c4b44)", "Promoção de novembro", "0s"}, {"linear-gradient(135deg,#6a4fd8,#2b3577)", "Novo: NFC-e", "3s"}, {"linear-gradient(135deg,#e8b04a,#b07a2c)", "Black Friday", "6s"}, {"linear-gradient(135deg,#1f9282,#0c4b44)", "Promoção de novembro", "9s"}]} style={"background:#{bg};--dl:#{d}"}>{t}</.carousel_slide></.carousel></div><div class="flex flex-col gap-1.5"><span class="font-mono text-xs text-muted">fade</span><.carousel id="car-fade" demo effect="fade" pagination="bullets" slides={3} class="max-w-[260px]"><.carousel_slide :for={{bg, t, d} <- [{"linear-gradient(135deg,#1f9282,#0c4b44)", "Promoção de novembro", "0s"}, {"linear-gradient(135deg,#6a4fd8,#2b3577)", "Novo: NFC-e", "3s"}, {"linear-gradient(135deg,#e8b04a,#b07a2c)", "Black Friday", "6s"}]} style={"background:#{bg};--dl:#{d}"}>{t}</.carousel_slide></.carousel></div></div>

effect · direction · navigation · pagination · variant

slide fade flip cube cards coverflow creative horizontal vertical navigation inside outside bullets fraction 2/3 progress scrollbar canvas classic
.heex
<div class="flex flex-wrap items-center gap-2.5"><.chip :for={c <- ["slide", "fade", "flip", "cube", "cards", "coverflow", "creative", "horizontal", "vertical", "navigation inside", "outside", "bullets", "fraction 2/3", "progress", "scrollbar", "canvas", "classic"]}>{c}</.chip></div>

API values that complete the parity

Slide 2/3
navigation=true
Slide 2/3 navigation=false
.heex
<div class="grid grid-cols-4 gap-3.5"><div class="flex flex-col items-start gap-1.5"><div class="flex flex-wrap items-center gap-2.5"><.button canvas icon aria-label="Anterior"><.icon name="chevron-left" /></.button><.chip>Slide 2/3</.chip><.button canvas icon aria-label="Próximo"><.icon name="chevron-right" /></.button></div><span class="font-mono text-[11px] text-muted">navigation=true</span></div><div class="flex flex-col items-start gap-1.5"><.chip>Slide 2/3</.chip><span class="font-mono text-[11px] text-muted">navigation=false</span></div></div>

Try it: real arrows and bullets

Promoção da semana
Novos planos
Black Friday
.heex
<div class="max-w-[560px]">
  <.carousel id="car-live" navigation pagination="bullets" slides={3}>
    <.carousel_slide :for={{bg, t} <- [{"linear-gradient(135deg,#1f9282,#0c4b44)", "Promoção da semana"}, {"linear-gradient(135deg,#6366f1,#312e81)", "Novos planos"}, {"linear-gradient(135deg,#f59e0b,#b45309)", "Black Friday"}]}>
      <div class="grid h-[180px] w-full place-items-center text-[18px] font-semibold text-white" style={"background:#{bg}"}>{t}</div>
    </.carousel_slide>
  </.carousel>
</div>

Usage

<.carousel id="tips" items={@tips} />

Rules

  • Indicators are rectangular dashes (radius 2), the current one wider.

API reference

Todos os function components, atributos, valores e slots que este componente cobre.

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" (data-lu-effect and data-lu-direction say what to draw). Styled only with Tailwind utilities; the bullets and thumbnails read aria-current.

<.carousel>

Attr Type Default Values / notes
id (required) :string
index :integer 0 The active slide, zero-based.
effect :string "slide" slide, fade, flip, cube, cards, coverflow, creative
direction :string "horizontal" horizontal, vertical
navigation :any false true, false, inside, outside - The previous and next arrows.
pagination :string nil nil, bullets, fraction, progress, scrollbar
slides :integer nil How many slides there are, for the pagination (the :thumb count when omitted).
autoplay :integer nil Milliseconds between slides; pauses on hover.
loop :boolean false
demo :boolean false The canvas CSS loop (no hook): slide scrolls its track (mo-car, 9s), fade cross-fades the slides (mo-fade3, delay --dl on each slide: 0s, 3s, 6s), and the bullets light up in turn (mo-cdot).
gap :integer nil Pixels between slides.
zoom :integer nil Double-click zoom ratio.
on_change :any nil
target :any nil
prev_label :string "Previous slide"
next_label :string "Next slide"
bullet_label :string "Go to slide"
label :string nil
variant :string "canvas" canvas, classic
thumb_label :string "Show slide"
class :any nil

Any other HTML/phx attribute goes to the root element.

Slots:

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

<.carousel_slide>

Attr Type Default Values / notes
class :any nil

Any other HTML/phx attribute goes to the root element.

Slots:

  • <:inner_block> (required)