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

@calmdownval/slideshow

v1.0.0-beta.2

Published

Preact scroll slideshows

Downloads

6

Readme

Preact Slideshows

A small (~ 10kB) library for scroll slideshows with Preact.

Installation

Built for Preact v10.

You can install this package using NPM or Yarn. It already contains its own typings and needs no additional dependencies to use with TypeScript.

# using NPM
npm install @calmdownval/slideshow

# using Yarn
yarn add @calmdownval/slideshow

The package also contains a CSS stylesheet which should be imported into your application. The easiest way is to add the following import to your index file:

import '@calmdownval/slideshow/style.css';

Usage

SlideshowProvider Component

A slideshow must be wrapped in a <SlideshowProvider> component. This component manages the state and layout computations of the entire slideshow.

Viewport Component

Every slideshow also needs a viewport. It manages a basic DOM structure that wraps all the slides. It is separated from slideshow provider to allow adding custom components outside of the viewport and still being able to consume the slideshow context.

For user-controllable slideshows make sure to set the viewport's scrollable prop to enable scroll bars.

Slide Components

All that's left is to add some slides into the viewport. Each slide requires a content prop to specify the contents of the slide. The content component will receive a forwarded metadata prop which can be used to pass custom data down to the content component.

By default each slide will be exactly the size of the viewport along the scroll axis. To change this you can set the length prop to any value greater than zero. 1 indicates viewport size, 2 double the size etc.

Slides can dock to the edge of the viewport. To enable this feature set the dock prop to values greater than zero. When such a slide reaches the docking edge the slideshow will stop scrolling for the requested length.

useProgression hook

This hook returns a progression object with values indicating the individual phases of a slide. Each value ranges from zero to one (inclusive).

  • main - from the moment a slide starts entering the screen (0) until it leaves the screen entirely (1).
  • dock - from the start (0) to the end (1) of the docking phase. Always zero when dock is not used.
  • enter - from the moment a slide starts entering the screen (0) until it reaches maximum visible area (1).
  • leave - from the moment a slide starts leaving the screen (0) until it leaves entirely (1).

This hook will automatically update your component when any of the values you're using changes.

Example usage:

import { Progression, useProgression } from '@calmdownval/slideshow';
import { h } from 'preact';

export const MyComponent = () => {
  const phase = useProgression();
  return (
    <div
      class='my-component'
      style={Progression.animate('animation-name', phase.main)}
    />
  );
};

useNavigation hook

This hook returns a navigation object which provides an index of the currently active slide (the uppermost slide with the largest relative visible area) and a list of all slides. It also provides a goTo method which can be used to scroll to a specific slide programmatically.

This hook will automatically update your component when any of the values you're using changes.

Example

This example shows a super simple slideshow

import { Slide, SlideContentProps, SlideshowProvider, Viewport } from '@calmdownval/slideshow';
import { h } from 'preact';

import '@calmdownval/slideshow/style.css';

const TestContent = ({ metadata }: SlideContentProps<string>) => (
  <h2>{metadata}</h2>
);

export const App = () => (
  <SlideshowProvider>
    <Viewport scrollable>
      <Slide content={TestContent} metadata='First' />
      <Slide content={TestContent} metadata='Second' />
      <Slide content={TestContent} metadata='Third' />
    </Viewport>
  </SlideshowProvider>
);