A modern, customizable slider component built for Svelte 5. (Kinda poorly written)
npm i svelte5-slider
<script lang="ts">
import { Slider } from 'svelte-slider';
import type { SliderItem } from 'svelte-slider';
const cardItems: SliderItem[] = [
{
data: { / your card data / }
}
];
</script>
<Slider {cardItems} {Item} />
{#snippet Item()}
<!-- Ur snippet -->
{/snippet}
The main component that orchestrates the slider functionality.
cardItems
: Array of SliderItem
objectsbuttonProps
: (Optional) Customization options for the slider buttonsItem
: Snippet of your itemsHandles the navigation buttons for the slider.
direction
: 'left' | 'right'containerClasses
: Custom classes for the button containerbuttonClasses
: Custom classes for the button elementiconClasses
: Custom classes for the iconIcon
: Custom icon component (optional)scrollFunc
: Function to handle scroll behaviorContains the scrollable content of the slider.
scrollContainer
: Reference to the container elementcardItems
: Array of items to displayscrollEvent
: Function to handle scroll eventsItem
: Snippet of your items
interface SliderItem {
Item: Snippet<[any]>;
href: string;
data: any;
}
interface ButtonSliderR {
containerClasses?: string;
buttonClasses?: string;
iconClasses?: string;
gradientClasses?: string;
Icon?: typeof IconType; // Lucide Icons type
}
interface SliderProps {
cardItems: SliderItem[];
buttonProps?: ButtonSliderR;
}
The slider comes with default styling using Tailwind CSS, but you can customize the appearance by passing custom classes through the buttonProps
:
<Slider
cardItems={items}
buttonProps={{
containerClasses: "your-custom-container-classes",
buttonClasses: "your-custom-button-classes",
iconClasses: "your-custom-icon-classes",
}}
{Item}
/>
Contributions are welcome! Please feel free to submit a Pull Request.