Organisms
TsCarouselBuilder
Overview
The TsCarouselBuilder component is a Builder.io-specific dynamic carousel that enables drag-and-drop functionality for customizing each slide, offering seamless content management and flexible design.
Component Code
<template>
<TsCarouselV2
:id="`carousel-${random_id}`"
:append-class="twMerge('px-0')"
:prev-button-class="twMerge('left-0')"
:next-button-class="twMerge('right-0')"
:navigation="props.navigation || !isMobile"
:pagination="props.pagination"
:direction="props.direction"
:loop="props.loop"
:drag-free="props.dragFree"
:autoplay="props.autoplay"
:autoscroll="props.autoscroll"
>
<TsCarouselSlide
v-for="(slide, index) in props.slides"
:key="`carousel-slide-${random_id}-${index}`"
:append-class="twMerge(
'p-0 lg:p-0',
props.slidesWidth === 'full' && 'w-full p-0 flex-[0_0_calc(100%/1)]',
props.slidesWidth === 'auto' && 'flex-[0_0_auto] min-w-[280px] max-w-max',
props.slidesGap === '8px' && 'p-1 lg:p-1'
)"
>
<Blocks
class="w-full h-full"
:parent="props.builderBlock?.id"
:path="`component.options.slides.${index}.content`"
:blocks="slide.content"
/>
</TsCarouselSlide>
</TsCarouselV2>
</template>
<script setup lang="ts">
import { Blocks } from '@builder.io/sdk-vue';
import { twMerge } from "tailwind-merge";
type Slide = {
content: any[]
}
type Props = {
builderBlock?: object;
slides?: Slide[];
slidesWidth?: "auto" | "full";
slidesGap?: string;
direction?: "ltr" | "rtl";
navigation?: boolean;
pagination?: boolean;
loop?: boolean;
dragFree?: boolean;
autoplay?: boolean;
autoscroll?: boolean;
}
const props = withDefaults(defineProps<Props>(), {
slidesWidth: "full",
direction: "ltr",
pagination: true
});
const { isMobile } = useDevice();
const random_id = ref('')
onMounted(() => {
random_id.value = useRandomUUID()
})
</script>
Usage in Builder
- Go to the
inserttab. - Search
Carouselin search bar. - Hold
Carouselcomponent & drag where you want to use. - Use any component and drag inside the
Carousel Slidesblocks in which you want to add.
Props
| Name | Type | Default | Description |
|---|---|---|---|
| builderBlock | object | "" | builderBlock is used for builderBlock object which set by default when dragging TsCarouselBuilder in builder visual editor. |
| slides | Slide[] | "" | Each slide have the content key which stores the draggable content of the specific slide |
| slidesWidth | auto or full | "full" | auto adopt the max width of content added in slides automatically, full apply the 100% width to each slide |
| slidesGap | string | "" | This is the property is used to add gap between slides, this have default value of 8px as a dropdown. |
| direction | ltr or rtl | "ltr" | ltr is used to add direction of carousel from left-to-right and rtl is used to add direction of carousel from right-to-left. |
| navigation | boolean | false | toggle the visibility of navigation arrow. |
| pagination | boolean | true | toggle the visibility of pagination dots. |
| loop | boolean | false | toggle to enable or disable the loop of carousel |
| dragFree | boolean | false | toggle the carousel slides drag free or not |
| autoplay | boolean | false | toggle the autoplay feature of carousel |
| autoscroll | boolean | false | toggle the autoscroll feature smoothly |