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

@librarymarket/zodiac

v1.0.0-alpha5

Published

A carousel written in TypeScript.

Downloads

5

Readme

Zodiac

Zodiac is a dependency-free carousel written in TypeScript.

What makes Zodiac unique is that it handles responsive options with plain media queries, backed by the matchMedia() function. Click here for an overview of media query options made available by Zodiac.

Usage

Installation

We recommend installing Zodiac via NPM in most cases:

npm i @librarymarket/zodiac

Zodiac can also be manually downloaded from its releases page.

The dist directory contains transpiled JavaScript and CSS for Zodiac, in addition to minified and ES module versions.

<html>
  <head>
    <!-- ... -->
    <link href="node_modules/@librarymarket/zodiac/dist/zodiac.css" rel="stylesheet">
  </head>
  <body>
    <div id="zodiac" class="zodiac">
      <!-- ... -->
    </div>

    <script src="node_modules/@librarymarket/zodiac/dist/zodiac.js"></script>
    <script>
      new Zodiac('#zodiac').mount();
    </script>
  </body>
</html>

HTML

Zodiac uses zodiac, zodiac-inner and zodiac-track CSS classes for styling and DOM manipulation. The below snippet demonstrates Zodiac's markup:

<div id="zodiac" class="zodiac">
  <div class="zodiac-inner">
    <div class="zodiac-track">
      <div>1.</div>
      <div>2.</div>
      <div>3.</div>
      <div>4.</div>
      <div>5.</div>
      <div>6.</div>
      <div>7.</div>
      <div>8.</div>
    </div>
  </div>
</div>

Options are available to modify these classes; click here for more information about these options.

Controls

One or more <button> elements with a data-zodiac-direction attribute can be added anywhere within the initialized carousel for left or right navigation:

<div id="zodiac" class="zodiac">
  <div class="zodiac-inner">
    <button data-zodiac-direction="left" type="button">Left</button>
    <div class="zodiac-track">
      <div class="zodiac-item">1.</div>
      <div class="zodiac-item">2.</div>
      <div class="zodiac-item">3.</div>
      <div class="zodiac-item">4.</div>
      <div class="zodiac-item">5.</div>
      <div class="zodiac-item">6.</div>
      <div class="zodiac-item">7.</div>
      <div class="zodiac-item">8.</div>
    </div>
    <button data-zodiac-direction="right" type="button">Right</button>
  </div>
</div>

JavaScript

To initialize Zodiac, create a new Zodiac class instance, specifying a selector targeting a carousel element and any desired options:

// Example using default options:
window.addEventListener('load', () => {
  new Zodiac('#zodiac').mount();
});

// Example with custom options:
window.addEventListener('load', () => {
  new Zodiac('#zodiac-with-options', {
    autoplay: false,
    itemsPerView: 2,
    mediaQueryOptions: {
      "(min-width: 768px)": {
        itemsPerView: 3,
      },
      "(min-width: 992px)": {
        itemsPerView: 4,
      },
      "(min-width: 1200px)": {
        itemsPerView: 5,
      },
      "(min-width: 1400px)": {
        itemsPerView: 6,
      },
    },
  }).mount();
});

Options

| Name | Datatype | Default Value | Description | |-------------------|--------------------------------------------------------------|--------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | autoplay | boolean | true | Whether or not the slider should autoplay. | | autoplaySpeed | boolean | 5000 | The delay before the carousel will transition. | | classes | ClassesInterface | See Classes Interface table | A collection of classes used by the slider to identify specific elements. These settings are not available in the media query options. | | enableLiveRegion | boolean | true | Enables the live region element. This setting is not available in the media query options. | | gap | number | 8 | The gap between slides. | | infiniteScrolling | boolean | true | Allows the slider to transition endlessly. | | itemsPerView | number | 5 | The total number of items to display per view. | | liveRegionText | string | 'Slide @position of @total @title' | The text template used for the live region updates. @position is the index of the active slide. @total is the total number of slider items. @title is the text used for the title of the slider item. The title is derived from the data-zodiac-live-region-title attribute within or on an item. This setting is not available in the media query options. | | mediaQueryOptions | MediaQueryOptionsInterface | None by default | A collection of options applied at a specific media query. | | pauseOnHover | boolean | true | Whether or not autoplay should pause on hover. | | transitionSpeed | number | 500 | The speed at which slides will transition. |

Classes Interface

The classes interface is an object that defines which classes Zodiac will use to target specific carousel elements.

| Name | Datatype | Default Value | Description | |----------|----------|-------------------|-----------------------------------------------------------| | controls | string | zodiac-controls | The classes used by the slider controls. | | inner | string | zodiac-inner | The class used for the inner slider container. | | items | string | zodiac-item | The class used by the slider items. | | track | string | zodiac-track | The class for the track slider div surrounding the items. |

Media Query Options Interface

The media query options interface is an object that allows for a media query to define a set of options. When using an option, Zodiac will locate the first passing media query and use its options, falling back to the carousel's global options.

new Zodiac('#zodiac', {
  // Display 2 items per view by default, ...
  itemsPerView: 2,
  mediaQueryOptions: {
    // But display 3 items per view if the screen width is >= 768px.
    "(min-width: 768px)": {
      itemsPerView: 3,
    },
  },
});

It's optimal to use a homogeneous set of media query conditions (i.e., only min-width conditions). Mixing conditions may prevent Zodiac from evaluating media query option sets.

Accessibility

Zodiac adds elements and attributes to make a carousel accessible out of the box. The LiveRegion component creates a live region that announces the current slide's position and title to screen readers.

Example

In the example, the first zodiac item is active. As a result, the LiveRegion component updates the zodiac-live-region element's text with the active item's position, and title.

<!-- ... -->
<div class="zodiac-item active" data-zodiac-live-region-title="First Item">First Item</div>
<div class="zodiac-item" data-zodiac-live-region-title="Second Item">Second Item</div>
<!-- ... -->

<div aria-live="polite" aria-atomic="true" class="zodiac-live-region">Slide 1 of 2 First Item</div>