0.12.0 • Published 3 years ago

react-spinners-loader-radius v0.12.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

React Spinners

npm version circle ci downloads license Coverage Status

dependencies Status devDependencies Status peerDependencies Status

A collection of loading spinners with React.js based on Halogen.

This package is bootstraped using react-npm-boilerplate

Demo

Demo Page

Installation

With Yarn:

yarn add react-spinners

With npm:

npm install --save react-spinners

Usage

Each loader has their own default properties. You can overwrite the defaults by passing props into the loaders.

Each loader accepts a loading prop as a boolean. The loader will render null if loading is false.

IMPORTANT: This package uses emotion. Remember to add the plugin to .babelrc, for example:

{
    "presets": ["@babel/preset-react", "@babel/preset-env"],
    "plugins": ["@emotion"]
}

Example

import { useState } from "react";
import { css } from "@emotion/react";
import ClipLoader from "react-spinners/ClipLoader";

// Can be a string as well. Need to ensure each key-value pair ends with ;
const override = css`
  display: block;
  margin: 0 auto;
  border-color: red;
`;

function App() {
  let [loading, setLoading] = useState(true);
  let [color, setColor] = useState("#ffffff");

  return (
    <div className="sweet-loading">
      <button onClick={() => setLoading(!loading)}>Toggle Loader</button>
      <input value={color} onChange={(input) => setColor(input.target.value)} placeholder="Color of the loader" />

      <ClipLoader color={color} loading={loading} css={override} size={150} />
    </div>
  );
}

export default App;
import React from "react";
import { css } from "@emotion/react";
import ClipLoader from "react-spinners/ClipLoader";

// Can be a string as well. Need to ensure each key-value pair ends with ;
const override = css`
  display: block;
  margin: 0 auto;
  border-color: red;
`;

class AwesomeComponent extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      loading: true
    };
  }

  render() {
    return (
      <div className="sweet-loading">
        <ClipLoader css={override} size={150} color={"#123abc"} loading={this.state.loading} speedMultiplier={1.5} />
      </div>
    );
  }
}

Available Loaders, PropTypes, and Default Values

Common default props for all loaders:

loading: true;
color: "#000000";
css: "";
speedMultiplier: 1;

color prop

color prop accepts a color hash in the format of #XXXXXX or #XXX. It also accepts basic colors listed below:

maroon, red, orange, yellow, olive, green, purple, white, fuchsia, lime, teal, aqua, blue, navy, black, gray, silver

css prop

css works exactly like the css works with the emotion package. You can directly write your css in css syntax without the dirty camelCase css in jss syntax. We recommend you to use this awesome library in your project. It supports Server side rendering with HTTP2 Stream! More info about using css here

size, height, width, and radius props

The input to these props can be number or string.

  • If value is number, the loader will default to css unit px.
  • If value is string, the loader will verify the unit against valid css units.
    • If unit is valid, return the original value
    • If unit is invalid, output warning console log and default to px.

The table below has the default values for each loader.

Loadersizeheightwidthradiusmargin
BarLoader4100
BeatLoader152
BounceLoader60
CircleLoader50
ClimbingBoxLoader15
ClipLoader35
ClockLoader50
DotLoader602
FadeLoader15522
GridLoader15
HashLoader502
MoonLoader602
PacmanLoader252
PropagateLoader15
PuffLoader60
PulseLoader152
RingLoader602
RiseLoader152
RotateLoader152
ScaleLoader35422
SyncLoader152