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

simplr-loaders

v2.1.2

Published

React CSS loaders with no prerequisites for required styles loading.

Downloads

11

Readme

simplr-loaders

React CSS loaders with no prerequisites for required styles loading.

Get started

$ npm install simplr-loaders --save

Usage

import * as React from "react";
import { BubbleLoader } from "simplr-loaders";

export class MyComponent extends React.Component<{}, {}> {
    render() {
        return <BubbleLoader />;
    }
}

Loaders

This package currently contains two loaders:

  • SpinnerLoader
  • BubbleLoader

If you'd like to see more loaders here feel free to contribute.

Style

Stylesheets

You don't need to import loaders stylesheets. By default they are loaded after first use of a loader component.

If you still want to load css yourself, you can cancel default behavior by setting useDefaultStyle={false}. and load it from stylesheets that are included in this package.

Use of space

We found it useful for loaders to center itself and expand to take all possible area around.

If you want to position loader yourself you can set prop shouldExpand={false}.

Example

  1. Clone this repository
  2. Install packages in simplr-loaders root directory:
$ npm install
  1. Go to 'example' folder and run:
$ npm run example && npm run start

API

LoaderBase

export abstract class LoaderBase<TProps extends BaseProps, TState> extends React.PureComponent<TProps, TState>

LoaderBase is a base class of all loader components in simplr-loaders.

protected abstract LoaderId: string;

Unique identifier of a loader.

protected StylesClass: string;

Default className of a loader component. If not declared, LoaderId will be taken as default className.

protected AppendStyles(styles: string, props: TProps)

Puts stringified stylesheet of a loader into the <head>.

styles: string - stringified stylesheet.

props: TProps - component props.

protected get AggregatedClassName()

Aggregates all classNames of a loader:

  • default className defined in StylesClass
  • props.className
  • className that defines how loader use the space (whether it's size should be expanded or reduced).

BaseProps

Base props of all loader components in simplr-loaders.

export interface BaseProps {
    /**
     * Custom class name of a loader.
     *
     * @type {string}
     * @memberOf BaseProps
     */
    className?: string;
    /**
     * Specifies whether style should be placed in <head>.
     * This is a default behavior you can cancel.
     *
     * @type {boolean}
     * @memberOf BaseProps
     */
    useDefaultStyle?: boolean;
    /**
     * Specifies whether the loader should expand to take all possible area.
     * Default value `true`.
     * Using this prop you can cancel the default behavior.
     * In that case the loader will take an area of a strict size.
     *
     * @type {boolean}
     * @memberOf BaseProps
     */
    shouldExpand?: boolean;
}

Contribution

If you want to add loader to this package you'll need to know basic concepts of:

In src/your-loader-folder should be placed three files:

  • Stylesheet written in SCSS;
  • React component of a loader written in TypeScript;
  • TypeScript file with exported stringified stylesheet of your loader (automatically generated with css-to-ts when building).

Component

Use TypeScript to create component class:

import * as React from "react";

// `MyLoaderStyle` TypeScript file with stringified css will be generated from your stylesheet when build is started.
// But you still have to import it.
import { MyLoaderStyle } from "./spinner-loader-style";                 

import { LoaderBase, BaseProps } from "../abstractions/loader-base";

// Loader MUST extend LoaderBase class.
// Every loader MUST have props that are defined in BaseProps.
// If you need more props, you can create your own interface with BaseProps extended.
export class MyLoader extends LoaderBase<BaseProps, {}> {

    // Load style using `AppendStyles` from LoaderBase. 
    constructor(props: BaseProps, context: any) {
        super(props, context); 
        this.AppendStyles(MyLoaderStyle, props);
    }

    // Define loader id.
    // Id is used to identify style in `<head>`.
    protected LoaderId: string = "my-loader";

    // This property is optional.
    // If you don't define `StylesClass`, `LoaderId` will be taken as 'StylesClass'.
    protected StylesClass: string = "class-name-of-my-loader";

    // Define containers structure that your loader requires.
    render() {
        // Use `AggregatedClassName` from `LoaderBase` to define all classNames of your loader.
        return <div className={this.AggregatedClassName}>
            <div></div>
            <div></div>
        </div>;
    }
}

StyleSheet

Use SCSS to write a loader's stylesheet.

Next to all styles of your loader you should implement two additional classNames:

  • .expanded when loader takes all area of parrent container (default).
  • .reduced when loader takes strict area. Basically it should contain specified height and width.

License

Released under the MIT license.