npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

svelte-slidy

v2.8.7

Published

SLIDY - simple, configurable & reusable carousel component built with SvelteJS

Downloads

286

Readme

SLIDY

Simple, configurable & reusable carousel component built with SvelteJS.

Try the demo.

Getting started

The package is available via npm:

npm i svelte-slidy

REPL is available here.

Usage

To use Slidy use named import. The only required props are slides - an array of objects with image related data:

<script>
    import { Slidy } from "svelte-slidy";

    const slides = [
        {
            id: 1,
            src: "static/img/some-image.webp"
        }
    ];
</script>

<Slidy {slides} />

Options

Component's behaviour can be customized with object. All settings are broken into 4 categories. Most of the options are self-explanatory. Each Slidy instance should have it's own options.

Example with all available options and their default values:

<script>
    import { Slidy } from "svelte-slidy";

    const options = {
        slides: [],
        wrap: {
            id: "",
            width: "100%",
            height: "50%",
            padding: "0",
            align: "middle",
            alignmargin: 50,
        },
        slide: {
            gap: 50,
            class: "",
            width: "50%",
            height: "100%",
            backimg: true,
            imgsrckey: "src",
            objectfit: "cover",
            overflow: "hidden",
        },
        controls: {
            dots: true,
            dotsnum: true,
            dotsarrow: true,
            dotspure: false,
            arrows: true,
            keys: true,
            drag: true,
            wheel: true,
        },
        options: {
            axis: "x",
            loop: false,
            duration: 550,
        },
    };
</script>

<Slidy {...options} />;

Custom styling

To customize default Slidy nodes markup styles, provide an id use :global() to get necessary specifity.

<script>
    import { Slidy } from "svelte-slidy";

    const options = {
        slides: [],
        id: "slidy-id"
    };
</script>

<Slidy {...options} />

<style>
    :global(#slidy-id) {
        /* your CSS styling */
    }
</style>

Slidy's markup structure with it's classes:

<section id="yours custom #id" class="slidy">
    <ul class="slidy-ul">
        <!-- slides node -->
    </ul>
    <button class="arrow-left">
        <!-- previous slide control node -->
    </button>
    <button class="arrow-right">
        <!-- next slide control node -->
    </button>
    <ul class="slidy-dots">
        <li class="dots-arrow-left">
            <!-- next slide dots control node -->
        </li>
    <li>
        <!-- dots node -->
    </li>
        <li class="dots-arrow-left">
            <!-- previous slide dots control node -->
        </li>
    </ul>
</section>

For example, to override styles of specific section, use the classes described above:

<style>
    :global("slidy-instance-id" .dots-arrow-left) {
        /* your custom CSS styles */
    }
</style>

External controls

It is possible to control Slidy instance from parent component. Declare the variable to hold the index and bind it to the Slidy instance to control the slides navigation.

<script>
    import { Slidy } from "svelte-slidy";

    const slides = [];

    let index = 0;
</script>

<button on:click={() => index += 1}>
    Next slide
</button>

<Slidy
    bind:index
    slides
/>

Custom slides

Sometimes the default markup is not enough. For custom slides markup use let:item directive:

<script>
    import { Slidy } from "svelte-slidy";

    const slides = [
        {
            id: 1,
            src: "/img.webp",
            figcaption: "Some text here"
        }
    ];
</script>

<Slidy slides let:item>
    <figure>
        <img src={item.src} alt={item.figcaption}>
        <figcaption>
            {item.figcaption}
        </figcaption>
    </figure>
</Slidy>

Custom nodes

Slidy supports customization of it's nodes via slots:

  • <slot /> for slides;
  • <slot name="loader" /> for loading indicator;
  • <slot name="arrow-left"> for the previous slide control;
  • <slot name="arrow-right"> for the next slide control;
  • <slot name="dots-arrow-left"> for previous slide control at dots;
  • <slot name="dots-arrow-right"> for next slide control at dots;
  • <slot name="dots"> for custom dots controls.

Example:

<script>
    import { Slidy } from "svelte-slidy";

    const slides = [];
</script>

<Slidy slides>
    <!-- custom dots indicators -->
    <button slot="dot" />
</Slidy>

SvelteKit

Important note: slots are not SSR compatible yet. Check if the code runs in the browser before render.

Example for svelte\kit users:

<script>
    import { Slidy } from "svelte-slidy";
    import { browser } from "$app/env";

    const slides = [];
</script>

{#if browser}
    <Slidy slides>
        <!-- custom dots indicators -->
        <button slot="dot" />
    </Slidy>
{/if}

License

MIT © Valexr