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

react-ts-loaders

v1.2.1

Published

A react library that provides components for pure CSS loaders. The library has full TypeScript support.

Downloads

372

Readme

React Loaders

A react library that provides components for pure CSS loaders. The library has full TypeScript support.

Key Features

  • Simple to use out of the box.
  • Fully accessible. Includes visually hidden messages and alerts for users with screen readers.
  • Above message can be customized via props.
  • Quickly change the color(s), size, type, and message

NPM

Demo

You can view a demo with live configuration options at https://loaders.royanger.app/

Install

npm install --save react-ts-loaders

Usage

No Configuration

This component is designed to (usually) work right out of the box without needing to set anything up.

import * as React from 'react'
import Loader from 'react-ts-loaders'

const Example = () => {
   return <Loader />
}

Simple Configuration

Passing in a loader type and a color is probably all most people will need or want.

import * as React from 'react'
import Loader from 'react-ts-loaders'

const Example = () => {
   return <Loader type="spinner" color="blue" />
}

Full Configuration

import * as React from 'react'
import Loader from 'react-ts-loaders'

const Example = () => {
   return <Loader type="spinner" color="blue" altColor="lightblue" size={200} className="dark-loader />
}

Context Configuration

Are you planning to use Loaders in many places and want to control their type, colors, size or classes from one location? You can easily use Context to create a base configuration.

import * as React from 'react'
import { LoaderProvider } from '../src/lib/loaderContext'

ReactDOM.render(
   <React.StrictMode>
      <LoaderProvider
         value={{
            type: 'dualring',
            color: 'rgb(0, 128, 58)',
            altColor: 'rgb(241, 25, 213)',
            size: 100,
            className: 'dark-loader',
         }}
      >
         <App />
      </LoaderProvider>

The Context Configuration takes all of the same props as a single <Loader> component. The only required prop is type.

With the exception of className, the props you supply to the Context Configuration can be overridden on a specific instance of the Loader component. IE, you can set all Loaders to be a red, but if you do <Loader color="rgb(0, 128, 58)" /> then that loader will be green. This gives you the flexibility to have one off loaders, while having a default configuration for your application.

As mentioned, className does behave a little differently. It will combine the classes given via Context with those given via the specific component instance. The resulting class list will include all classes.

You can access the Consumer via hooks if you need to. This is purely optional. The component handles consuming the context and applying the settings without anything required in your application. Note: If you do use this hook, be aware there is no check that your are using it inside of a Provider.

import * as React from 'react'
import { useLoaderContext } from './loaderContext'

const context = useLoaderContext()

Props

All props are optional. If you do not specify a type, then the spinner type will be used. If you don't specify any colors then the currentColor for the element will be used and the background will be transparent.

type

Specify the type of loader you want to use. The current options are spinner, ellipsis, dualring, hourglass, dotspinner, pulse, ring, roller, grid, ripple and circle.

color

The color to use for the loader. If no altColor is specified then color is used for all foreground elements and the loader will have one consistent color.

Valid ways to define your color:

  • color="blue" (any HTML Color name)
  • color="rgb(54, 3, 95)"
  • color="rgba(54, 3, 95,.3)"
  • color="hsl(147, 50%, 47%)"
  • color="hsla(147, 50%, 47%,.2)"
  • color="var(--brand-primary)" (CSS variables defined in your application)

altColor

This will define the secondary foreground color for the loader. This will make it into a duotone variation. The altColor can be defined the same way as color above.

size

This number should represent a percent, just without the % sign. It will increase of decrease the size of the loader appropriately.

Examples:

  • size={200} - The loader will be 200% default size
  • size={50} - The loader will be 50% default size

message

By default the loader has a visually hidden message of 'Content is loading.' inside of the loader component. This is paired with an 'role='alert' to alert users with screen readers that content is loading. This prop allows you to customize that message or provide localized messages to your users.

className

Pass any classes you want to the Loader. These will be applied to the outer most div so you can target styling.

Credit

At this time, all of the loaders used in this package from from Loading.io and can be found at Loading.io Pure CSS Loader. These is a great resource and all of the code has been released under the CCO License.

License

MIT © royanger