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

scroll-shadow-element

v2.0.5

Published

A small web component to enhance scrollable elements with dynamic scroll indicators.

Downloads

5,765

Readme

<scroll-shadow> element

npm version bundle size (minified and gzipped)

A small web component to enhance scrollable elements with dynamic scroll indicators.

🔎 See the demo

Installation

npm install scroll-shadow-element

Import the module as part of your app bundle, or with a script tag.

import 'scroll-shadow-element'
<script type="module" src="./node_modules/scroll-shadow-element/dist/index.js"></script>
<!-- unpkg CDN -->
<script type="module" src="https://unpkg.com/scroll-shadow-element"></script>

<!-- Skypack CDN -->
<script type="module" src="https://cdn.skypack.dev/scroll-shadow-element"></script>

<!-- Skypack CDN (minified) -->
<script type="module" src="https://cdn.skypack.dev/scroll-shadow-element?min"></script>

Usage

Wrap any element for dynamically added scroll indicators. For example:

<scroll-shadow>
	<nav>Long navigation…</nav>
</scroll-shadow>

Note When wrapping a non-scrollable <table> element, then its first <tbody> will be used.

Configuration

You can change the default appearance with CSS.

Default

scroll-shadow {
	display: inline-block;
	--scroll-shadow-size: 14;
	--scroll-shadow-top: radial-gradient(farthest-side at 50% 0%, #0003, #0000);
	--scroll-shadow-bottom: radial-gradient(farthest-side at 50% 100%, #0003, #0000);
	--scroll-shadow-left: radial-gradient(farthest-side at 0%, #0003, #0000);
	--scroll-shadow-right: radial-gradient(farthest-side at 100%, #0003, #0000);
}

Example: dark mode

@media (prefers-color-scheme: dark) {
	scroll-shadow {
		--scroll-shadow-top: radial-gradient(farthest-side at 50% 0%, #fff3, #0000);
		--scroll-shadow-bottom: radial-gradient(farthest-side at 50% 100%, #fff3, #0000);
		--scroll-shadow-left: radial-gradient(farthest-side at 0%, #fff3, #0000);
		--scroll-shadow-right: radial-gradient(farthest-side at 100%, #fff3, #0000);
	}
}

CSS custom properties

| Property | Description | Syntax | | :--------------------- | :----------------------------------------------------- | :---------------- | | --scroll-shadow-size | Sets the maximum size of the scroll indicators | <integer> | | --scroll-shadow-top | Controls the appearance of the top scroll indicator | none \| <image> | | --scroll-shadow-bottom | Controls the appearance of the bottom scroll indicator | none \| <image> | | --scroll-shadow-left | Controls the appearance of the left scroll indicator | none \| <image> | | --scroll-shadow-right | Controls the appearance of the right scroll indicator | none \| <image> |

Browser support

scroll-shadow-element works in all major browsers: all browsers that support Custom Elements, Resize Observer and the min() CSS function. In older browsers, the element just won’t add scroll indicators.

The package is written with ES6 syntax. If you need to support older browsers, you can configure your bundler to compile it to ES5 syntax.

Using with Jest

{
	"jest": {
		"moduleNameMapper": {
			"^scroll-shadow-element$": "jest-transform-stub"
		}
	}
}

Jest doesn’t fully support ES modules: Depending on your configuration, you might see SyntaxError: Unexpected token 'export' along with a few hints in the error output. Jest’s "moduleNameMapper" option can be used to stub the module out. You can use any empty module, or jest-transform-stub.

Pure CSS alternative

<scroll-shadow> is inspired by Lea Verou’s great pure CSS scrolling shadows technique with background-attachment: local.

The main motivation to create a custom element was to find a solution to have the shadows above the content and independent of the element’s background. If you don’t have these requirements, the pure CSS technique might work for you too.

Development

  • npm install to install dependencies
  • npm test -- --update-visual-baseline to create local visual regression test baseline images
  • npm test to run tests
  • npm start to open a demo page for manual testing
  • npm run lint to run linting checks
  • npm run lint:fix to fix linting issues
  • npm run build to build

License

Distributed under the terms of the MIT license. See LICENSE for details.