Carousel

v0.0.10

v0.0.10StableComponentStatelessJSApache-2.0
Installation mix mishka.ui.gen.component carousel
Source View Source

Slide slot

The slide slot in the Phoenix LiveView Carousel component allows you to define the individual slides for your carousel. This slot accepts various attributes that enable you to customize each slide's appearance and behavior. The image attribute sets the image displayed on the slide and alt its alternative text, while title and description allow for adding text content to the slide. Additionally, you can control the layout using content_position and apply custom styling using classes such as title_class, description_class, and wrapper_class. Moreover, the slot supports multiple navigation options like navigate for internal paths, patch for LiveView patches, and href for external URLs. You can also control whether the slide is active or not using the active attribute.

Slide slot

Images sourced from 500px.com/p/tagargtw.
heex
<!--ADD a UNIQUE id TO Carousel-->
<.carousel id="unique_id">
  <:slide image="/path" />
  <:slide image="/path" />
  <:slide image="/path" />
  <:slide image="/path" />
  <:slide image="/path" />
  <:slide image="/path" />
</.carousel>

Display content on the slide

Each slide in the carousel component allows you to add custom content using attributes such as title and description. The title defines the main heading or label for the slide, while the description provides a short text that elaborates on the content or message of the slide. Additionally, for further customization, the title_class and description_class attributes allow you to apply your own CSS classes, giving you control over the styling and presentation of the title and description on each slide. Furthermore, by using the wrapper_class attribute, you can add custom classes to the entire content wrapper of each slide, ensuring complete control over the layout and design. This flexibility makes it easy to match the slide's content with your design needs.

Display content on the slide

heex
<!--ADD a UNIQUE id TO Carousel-->
<.carousel id="unique_id">
  <:slide
    image="/path"
    title="This is title prop"
  />
  <:slide
    image="/path"
    title="This is title prop"
    description="This is description prop"
  />
  <:slide
    image="/path"
    description="This is description prop"
  />
</.carousel>

Position of content on each slide

The content_position attribute allows you to control the alignment of the content within each slide in the carousel. It accepts various values that determine how the content is positioned horizontally. The "start" value aligns the content to the left, while "end" aligns it to the right. For centered content, you can use "center". Additionally, there are options like "between", which distributes content evenly with space between the items, and "around", which adds equal space around the content. If no value is provided, the default is to center the content, ensuring that it fits well with most design layouts. This flexibility allows you to adjust content placement to suit your specific design needs.

heex
<!--ADD a UNIQUE id TO Carousel-->
<.carousel id="unique_id">
  <:slide
    image="/path"
    title="This is title prop"
    content_position="start"
  />
  <:slide
    image="/path"
    title="This is title prop"
    description="This is description prop"
    content_position="end"
  />
  <:slide
    image="/path"
    description="This is description prop"
    content_position="center"
  />
  <:slide
    image="/path"
    description="This is description prop"
    content_position="between"
  />
  <:slide
    image="/path"
    description="This is description prop"
    content_position="around"
  />
</.carousel>

Slide Active prop

The active prop is a boolean attribute that indicates whether a slide is currently active and visible in the carousel. When set to true, the slide becomes the initial or visible slide, while other slides remain hidden until navigated to. This prop is essential for controlling the display of the starting slide in the carousel.

Slide Active prop

heex
<!--ADD a UNIQUE id TO Carousel-->
<.carousel id="unique_id">
  <:slide image="/path" />
  <:slide image="/path" active />
  <:slide image="/path" />
  <:slide image="/path" />
</.carousel>

<.carousel id="unique_id">
  <:slide image="/path" />
  <:slide image="/path" />
  <:slide image="/path" active />
  <:slide image="/path" />
</.carousel>

Size prop

The size prop in the carousel component controls the overall sizing of the text for the title, description, and the maximum width of the content wrapper. Depending on the size value such as extra_small, small, medium, large, or extra_large, the text and content dimensions are adjusted to fit the design needs. For example, it changes the font size of titles, descriptions, and ensures the wrapper's content width adapts accordingly. By default, the size is set to large.

Size prop

heex
<.carousel id="unique_id" size="extra_small">
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
</.carousel>

<.carousel id="unique_id" size="small">
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
</.carousel>

<.carousel id="unique_id" size="medium">
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
</.carousel>

<.carousel id="unique_id" size="large">
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
</.carousel>

<.carousel id="unique_id" size="extra_large">
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
</.carousel>

Padding prop

The padding prop in the carousel component controls the overall padding of the content wrapper. Depending on the padding value such as extra_small, small, medium, large, or extra_large the padding of content change. It's medium by default.

Padding prop

heex
<.carousel id="unique_id" padding="extra_small">
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
</.carousel>

<.carousel id="unique_id" padding="small">
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
</.carousel>

<.carousel id="unique_id" padding="medium">
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
</.carousel>

<.carousel id="unique_id" padding="large">
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
</.carousel>

<.carousel id="unique_id" padding="extra_large">
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
</.carousel>

Text position prop

The text_position prop in the carousel component allows you to control the alignment of the text content within the description wrapper. You can set the text alignment to start for left-aligned text, end for right-aligned text, or center for centered text. By default, if no value is provided, the text will be aligned to the center. This flexibility allows for better control over the visual presentation and layout of text on each slide.

Text position prop

heex
<.carousel id="unique_id" text_position="start">
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
</.carousel>

<.carousel id="unique_id" text_position="end">
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
</.carousel>

<.carousel id="unique_id" text_position="center">
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
</.carousel>

Indicator prop

The indicator prop is a boolean attribute that, when enabled, displays navigation indicators at the bottom of the carousel component. These indicators provide a visual cue to users about the number of slides in the carousel and allow them to quickly navigate between slides. By default, if the indicator prop is not provided, the carousel will not display indicators, offering a cleaner, simpler design. This feature enhances user experience by making it easier to understand and control the carousel's content.

Indicator prop

heex
<.carousel id="unique_id" indicator>
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path" active />
</.carousel>

Previous and next labels

The previous and next buttons are icons, so each one has an accessible name for screen readers: "Previous slide" and "Next slide" by default, translated through your app's Gettext. Set previous_label and next_label to name them yourself, for example in a language your Gettext does not cover. The control prop, true by default, shows or hides the two buttons.

Previous and next labels

heex
<.carousel id="unique_id" previous_label="Previous photo" next_label="Next photo">
  <:slide image="/path" alt="What the first image shows" />
  <:slide image="/path" alt="What the second image shows" />
</.carousel>

Autoplay prop

The autoplay prop is a boolean attribute that, when enabled, allows the carousel to automatically advance through the slides at a preset interval without user interaction. This functionality is useful for drawing user attention to a sequence of images or messages in a passive viewing experience. If the autoplay prop is not specified or set to false, users must manually navigate through the slides using controls or indicators. This prop adds convenience and can improve content visibility in scenarios like featured content sliders or announcements.

Autoplay prop

heex
<.carousel autoplay>
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path" active />
</.carousel>

Autoplay Interval Prop

The autoplay_interval prop specifies the amount of time (in milliseconds) that the carousel will wait before advancing to the next slide when autoplay is enabled. This value allows you to control the slide transition timing and create a smooth, automatic progression through your slides. The default value is set to 3000, ensuring a three-second interval between transitions.

Autoplay Interval Prop

heex
<.carousel autoplay autoplay_interval={3000}>
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path"/>
  <:slide image="/path" active />
</.carousel>