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

@jshsj/carousel

v0.0.1

Published

A simple web-component carousel

Downloads

3

Readme

Carousel

Ever needed a carousel?

You probably don't. But you client wants one.

Anyways. This is supposed to make it less painful and it aids you with a bit of accessibility, while still giving you quite a bit of control.

It's build with @github/catalyst, which I think is fantastic.

Setup

Install it. There should be an UMD and an ES version, plus a style sheet for very basic styles.

You then need to build the markup yourself. This is how it works and it's the way I prefer as it gives you quite a bit of control and understanding.

Props are passed through data-attributes. The following exist on the element itself:

  • data-items-to-display: How many items should be displayed per "slide"
  • data-items-to-slide: How many items should be slided per click.

That's it. You then need to provide the following elements:

  • A container with data-target="jshsj-carousel.container, which is the container element around everything.
  • Another slide container with data-target="jshsj-carousel.slideContainer". This hold your slides.
  • Another item container with data-target="jshsj-carousel.itemContainer". This is the last container. I swear.
  • However many items you want. Give them data-targets="jshsj-carousel.items and they will become your slides. Can be images / text or whatever you desire. Should work. If it breaks, it's probably a style issue.

Thats the carousel markup done.

Now you might want: Buttons to control.

Use whatever element you want, but give it data-action="click:jshsj-carousel#previousSlide" for "previous" and data-action="click:jshsj-carousel#nextSlide" for "next". I really recommend buttons, because that's what they were made for.

The last thing is truely optional, but might be nice: Indicators.

You'll need:

  • Another container element. Huh. Give it data-targets="jshsj-carousel.dots.
  • This is new: A template with data-target="jshsj-carousel.dotTemplate" that hold your "dot"-markup. There should be buttons (they're clickable), each having data-targets="jshsj-carousel.dots". They will get an -active class, when they match the shown slides. Clicking them will go to the corresponding slide.

The Template is the only "magic" I'll provide. It will create matching dots for each slide in correspondence to data-items-to-display and data-items-to-slide.

That's it. I hope it works.

Example

This is a fully working example. You need to add a few more styles for the dots and buttons (or leave them out).

<jshsj-carousel data-items-to-display="1" data-items-to-slide="1">
  <div class="" data-target="jshsj-carousel.container">
    <div class="" data-target="jshsj-carousel.slideContainer">
      <div class="" data-target="jshsj-carousel.itemContainer">
        <div class="jshsj-Carousel-item" data-targets="jshsj-carousel.items">
          <img src="https://picsum.photos/400/400?1" />
        </div>
        <div class="jshsj-Carousel-item" data-targets="jshsj-carousel.items">
          <img src="https://picsum.photos/400/400?1" />
        </div>
        <div class="jshsj-Carousel-item" data-targets="jshsj-carousel.items">
          <img src="https://picsum.photos/400/400?1" />
        </div>
        <div class="jshsj-Carousel-item" data-targets="jshsj-carousel.items">
          <img src="https://picsum.photos/400/400?1" />
        </div>
        <div class="jshsj-Carousel-item" data-targets="jshsj-carousel.items">
          <img src="https://picsum.photos/400/400?1" />
        </div>
      </div>
    </div>
    <div class="jshsj-Carousel-arrowContainer">
      <button
        class="CTA-button -icon -secondary"
        data-action="click:jshsj-carousel#previousSlide"
      >
        <svg
          class="icon -left"
          fill="none"
          xmlns="http://www.w3.org/2000/svg"
          viewBox="0 0 43 51"
        >
          <path
            d="m3 4 37 30M3 47.5l37-30"
            stroke="currentColor"
            stroke-width="8"
          />
        </svg>
      </button>
      <button
        class="CTA-button -icon -secondary"
        data-action="click:jshsj-carousel#nextSlide"
      >
        <svg
          fill="none"
          xmlns="http://www.w3.org/2000/svg"
          viewBox="0 0 43 51"
          class="icon"
        >
          <path
            d="m3 4 37 30M3 47.5l37-30"
            stroke="currentColor"
            stroke-width="8"
          />
        </svg>
      </button>
    </div>
    <div
      class="jshsj-Carousel-dotsContainer -centered-bottom"
      data-target="jshsj-carousel.dotContainer"
    ></div>
    <template data-target="jshsj-carousel.dotTemplate">
      <button
        class="jshsj-Carousel-dot"
        data-targets="jshsj-carousel.dots"
      ></button>
    </template>
  </div>
</jshsj-carousel>