Install react-spinners
mainInstall the react-spinners package using Yarn or npm to use the collection of loading spinners in your React project.
yarn add react-spinners
# or
npm install --save react-spinnersrepository·main·Indexed 25 days ago
https://github.com/davidhu2000/react-spinnersA collection of various React loading spinner components, including ClipLoader, BarLoader, and RingLoader, that can be easily integrated into React applications. Version 0.17.0 provides customizable loaders with props for color, size, speedMultiplier, and cssOverride.
Install the react-spinners package using Yarn or npm to use the collection of loading spinners in your React project.
yarn add react-spinners
# or
npm install --save react-spinnersImport a specific loader component (e.g., ClipLoader) from react-spinners. Each loader accepts a loading prop (boolean); if false, the loader renders null. You can customize loaders by passing props to overwrite their default values.
import { useState, CSSProperties } from "react";
import { ClipLoader } from "react-spinners";
const override: CSSProperties = {
display: "block",
margin: "0 auto",
borderColor: "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}
cssOverride={override}
size={150}
aria-label="Loading Spinner"
data-testid="loader"
/>
</div>
);
}
export default App;cssOverride prop accepts an object of camelCase styles used to create inline styles on the loaders. Any valid HTML CSS property can be used here.The color prop accepts a color hash in the format of #XXXXXX or #XXX. It also accepts the following basic color names:
maroon, red, orange, yellow, olive, green, purple, white, fuchsia, lime, teal, aqua, blue, navy, black, gray, silver
The size, height, width, and radius props accept either a number or a string:
px.px.All loaders in react-spinners share these common props:
loading: true (boolean)color: #000000 (string)cssOverride: {} (object)speedMultiplier: 1 (number)Additionally, all valid HTML props such as aria-* and data-* props are fully supported.
The following table lists the default values for size, height, width, radius, and margin for each available loader.
| Loader | size | height | width | radius |
| ----------------: | :--: | :----: | :----: | :----: |
| BarLoader | | `4` | `100` | |
| BeatLoader | `15` | | | `2` |
| BounceLoader | `60` | | | |
| CircleLoader | `50` | | | |
| ClimbingBoxLoader | `15` | | | |
| ClipLoader | `35` | | | |
| ClockLoader | `50` | | | |
| DotLoader | `60` | | | `2` |
| FadeLoader | | `15` | `5` | `2` |
| GridLoader | `15` | | | |
| HashLoader | `50` | | | `2` |
| MoonLoader | `60` | | | `2` |
| PacmanLoader | `25` | | | |
| PropagateLoader | `15` | | | |
| PuffLoader | `60` | | | |
| PulseLoader | `15` | | | `2` |
| RingLoader | `60` | | | `2` |
| RiseLoader | `15` | | | |
| RotateLoader | `15` | | | `2` |
| ScaleLoader | | `35` | `4` | `2` |
| SyncLoader | `15` | | | `2` |The react-spinners package provides a variety of pre-built loading spinner components. You can import any of the following components directly from the main entry point:
BarLoaderBeatLoaderBounceLoaderCircleLoaderClimbingBoxLoaderClipLoaderClockLoaderDotLoaderFadeLoaderGridLoaderHashLoaderMoonLoaderPacmanLoaderPropagateLoaderPulseLoaderPuffLoaderRingLoaderRiseLoaderRotateLoaderScaleLoaderSkewLoaderSquareLoaderSyncLoaderSpinners support different ways to define their dimensions using LengthType (which accepts number or string, such as 20 or '20px'). Depending on the specific loader component, you can use the following props:
height and width to set specific dimensions.size to set a uniform dimension.radius to define the corner radius.margin to define the spacing around the loader.All loaders in react-spinners share a set of common configuration props. These allow you to control the visual appearance, visibility, and animation speed of the spinner.
color: A string representing the color of the spinner (e.g., #ffffff or red).loading: A boolean to determine if the spinner should be rendered/active.cssOverride: A CSSProperties object used to apply custom inline styles to the spinner element.speedMultiplier: A number to scale the animation speed of the loader.