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

@miraidesigns/slider

v1.0.0

Published

Mirai Designs Framework: Slider module

Downloads

8

Readme

Sliders

Sliders allow you to create a carousel of elements, usually used to display images or other media elements.


HTML

<section class="mdf-slider" aria-roledescription="carousel" aria-label="Slider preview">
    <div id="slider-items" class="mdf-slider__slides" aria-live="polite">
        <div class="mdf-slider__slide" role="group" aria-roledescription="slide" aria-label="1 of 3">
            <img class="mdf-slider__media" src="1.jpg" alt="Picture #1">
        </div>

        <div class="mdf-slider__slide" role="group" aria-roledescription="slide" aria-label="2 of 3">
            <img class="mdf-slider__media" src="2.jpg" alt="Picture #2">
        </div>

        <div class="mdf-slider__slide" role="group" aria-roledescription="slide" aria-label="3 of 3">
            <img class="mdf-slider__media" src="3.jpg" alt="Picture #3">
        </div>
    </div>

    <button class="mdf-slider__control mdf-slider__control--prev" data-slider-action="prev" aria-controls="slider-items" aria-label="Previous slide">
        <svg class="mdf-icon" viewBox="0 0 24 24" aria-hidden="true">
            <use href="icons.svg#arrow-keyboard"></use>
        </svg>
    </button>

    <button class="mdf-slider__control mdf-slider__control--next" data-slider-action="next" aria-controls="slider-items" aria-label="Next slide">
        <svg class="mdf-icon" viewBox="0 0 24 24" aria-hidden="true">
            <use href="icons.svg#arrow-keyboard"></use>
        </svg>
    </button>
</section>

Sass

// Include default styles without configuration
@forward '@miraidesigns/slider/styles';
// Configure appearance
@use '@miraidesigns/slider' with (
    $variable: value
);

@include slider.styles();

TypeScript

import { MDFSlider } from '@miraidesigns/slider';

new MDFSlider(document.querySelector('.mdf-slider'));

Implementation

Attributes

Please see the WAI-ARIA page for attributes and best practices regarding carousels.

| Name | Element | Description | | --------------------------- | ---------- | --------------------------------- | | data-slider-action="prev" | <button> | Action to show the previous slide | | data-slider-action="next" | <button> | Action to show the next slide |

Classes

| Name | Type | Description | | ------------------------------ | -------------- | ------------------------------------------------------------------------------------------ | | mdf-slider | Parent | Contains the slider elements | | mdf-slider--is-dragging | Modifier | Changes cursor appearance while dragging a slide | | mdf-slider--has-nav-top | Modifier | Moves the navigation to the top of the slider | | mdf-slider__slides | Parent / Child | Contains the slides. Child to .mdf-slider | | mdf-slider__slide | Parent / Child | Contains any content you want to display for a given slide. Child to .mdf-slider__slides | | mdf-slider__media | Child | Used for images and videos to display correctly. Child to .mdf-slider__slide | | mdf-slider__control | Child | Used to show the previous or next slide. Child to .mdf-slider | | mdf-slider__control--prev | Modifier | Styling for the previous element | | mdf-slider__control--next | Modifier | Styling for the next element | | mdf-slider__nav | Parent / Child | Holds the navigation bullets | | mdf-slider__nav-item | Child | Navigation item element. Added by script based on how many slides we have | | mdf-slider__nav-item--active | Modifier | Styling for the active item element |

Events

| Name | Data | Description | | ------------------- | ------------------------------------ | -------------------------------------------------------------------------------- | | MDFSlider:changed | {index: number, item: HTMLElement} | Fires whenever the active slide changes. Includes the slide itself and its index |

Properties

| Name | Type | Description | | -------------------- | ----------------------- | ----------------------------------------------------- | | .slides | HTMLElement[] | Returns an Array holding all slides | | .slider | HTMLElement | Returns the slider element | | .content | HTMLElement | Returns the slides container element | | .getCurrentSlide() | (): HTMLElement | Returns the active slide | | .getSlide(index) | (number): HTMLElement | Returns the slide with the given index (starts at 0). |

Options

| Name | Type | Default | Description | | ------------------ | ------------ | ------- | ------------------------------------------------------------------------------------------ | | onChange | () => void | null | Function will run whenever the slide changes | | defaultSlide | number | 0 | Index of the first visible slide (starts at 0) | | enableNavigation | boolean | true | Enable slider bullet navigation. Dynamically creates navigation items based on # of slides | | enableSwipe | boolean | true | Enable changing slides by swiping left or right on touch devices | | enableDrag | boolean | true | Enable changing slides by dragging the mouse left or right |