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 🙏

© 2026 – Pkg Stats / Ryan Hefner

syringe-slider

v1.0.2

Published

An animated SVG syringe slider component for React

Readme

syringe-slider

An animated SVG syringe slider component for React. Fill, drag, step, and inject — all with smooth motion and customizable liquid color.

Features

  • Drag to set — drag the barrel up/down to set a value
  • Click needle to auto-fill — click the needle tip to start auto-filling (accelerates over time); click again to stop
  • Step buttons — increment/decrement by a configurable step via the imperative ref API
  • Push animation — animate the plunger down to zero (inject) via ref or prop
  • Controlled & uncontrolled — works both ways, just like native <input>
  • Customizable — liquid color, max value, step size
  • TypeScript — full type definitions included
  • Zero CSS — fully self-contained SVG, no stylesheet required

Installation

npm install syringe-slider

Peer dependencies (install separately if not already present):

npm install react react-dom

syringe-slider also depends on motion for animations:

npm install motion

Quick start

import SyringeSlider from 'syringe-slider';

export default function App() {
  return (
    <div style={{ width: 80, height: 400 }}>
      <SyringeSlider />
    </div>
  );
}

Sizing: The component renders a pure SVG with viewBox="0 0 200 1000". Give the wrapper a fixed width and height — the SVG will scale to fill it while preserving the aspect ratio.

Usage

Uncontrolled (no value prop)

The component tracks its own internal state. Provide an onChange callback to observe changes.

<SyringeSlider
  max={100}
  stepSize={5}
  liquidColor="#ef4444"
  onChange={(value) => console.log(value)}
/>

Controlled (with value prop)

Lift the value into your own state. The component never changes it on its own.

const [dose, setDose] = useState(0);

<SyringeSlider
  max={10}
  stepSize={0.5}
  liquidColor="#06b6d4"
  value={dose}
  onChange={setDose}
/>

Imperative ref API

Use a ref to call stepUp(), stepDown(), or triggerPush() from outside the component.

import SyringeSlider, { type SyringeSliderRef } from 'syringe-slider';

const ref = useRef<SyringeSliderRef>(null);

<SyringeSlider ref={ref} max={20} stepSize={1} value={value} onChange={setValue} />

<button onClick={() => ref.current?.stepDown()}>−</button>
<button onClick={() => ref.current?.stepUp()}>+</button>
<button onClick={() => ref.current?.triggerPush()}>Inject</button>

Push via prop

Increment pushTrigger to fire the push animation without a ref.

const [pushTrigger, setPushTrigger] = useState(0);

<SyringeSlider
  max={10}
  value={dose}
  onChange={setDose}
  pushTrigger={pushTrigger}
/>

<button onClick={() => setPushTrigger((t) => t + 1)}>Administer</button>

API

Props — SyringeSliderProps

| Prop | Type | Default | Description | |---|---|---|---| | max | number | 10 | Maximum value of the slider. The syringe is full when value === max. | | stepSize | number | 1 | How much stepUp() / stepDown() change the value. Also controls the number of tick marks on the barrel (capped at 20). | | liquidColor | string | "#ec4899" | Any valid CSS color for the liquid fill (hex, rgb, hsl, named). | | value | number | — | Controlled value. When provided, the component is in controlled mode and will not update its internal state. Must be between 0 and max. | | onChange | (value: number) => void | — | Called whenever the value changes (drag, step, push, auto-fill). In uncontrolled mode the value is already committed; in controlled mode you must update value yourself. | | pushTrigger | number | 0 | Increment this number by any amount to trigger a push (inject) animation. The component compares to the previous value and fires once per change. |

Ref API — SyringeSliderRef

Access via useRef<SyringeSliderRef>() and passing the ref to the component.

| Method | Description | |---|---| | stepUp() | Increase the value by stepSize, clamped to max. Animated. | | stepDown() | Decrease the value by stepSize, clamped to 0. Animated. | | triggerPush() | Animate the plunger from the current value down to 0 (inject). |

Interaction model

| Interaction | What happens | |---|---| | Click needle | Start auto-fill (value increases, speed accelerates). Click again to stop. | | Drag barrel | Set value directly by dragging up/down. | | stepUp() / stepDown() | Animated step change. | | triggerPush() / pushTrigger++ | Animated push to zero. |

Examples

The examples/ directory contains ready-to-use snippets:

| File | Description | |---|---| | 01-basic.tsx | Minimal uncontrolled setup | | 02-controlled.tsx | Controlled value with onChange | | 03-ref-api.tsx | stepUp, stepDown, triggerPush via ref | | 04-push-trigger.tsx | Push animation via pushTrigger prop | | 05-multiple.tsx | Multiple syringes with different configs |

Development

# Install dependencies
npm install

# Run demo app (Vite dev server)
npm run dev

# Build the library
npm run build

# Run tests
npm test

# Run tests in watch mode
npm run test:watch

Publishing to npm

# 1. Set your name/email in package.json (author, repository, homepage)
# 2. Login to npm
npm login

# 3. Publish
npm publish

The prepublishOnly script runs npm run build automatically before publishing.

License

MIT