An Interest In:
Web News this Week
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
How I Created My Own React Spinners Library
Ive created an application that uses Airtable as a database. Ive used a spinner to take the place of a dull blank page which would otherwise be presented to the user in the time that it takes for the requested data to arrive and for the page to get rendered accordingly.
I could have used an existing react spinners library, but instead, I decided to use this chance to learn how to build my own spinners and my own React component library. So, in this post, Ill show you my library, and an example of how to use a spinner.
React Spinners Library
So, without further ado, heres my react spinners library (GitHub, Bit). Its based on loading.io CSS loaders. Ive added the option to send color and size as props of the component so that its easier to customize the spinners. Ive exported the spinners (twelve in total) to bit.dev so you may easily view and tweak them in Bits live playground, and install them as packages with NPM or Yarn (or get their source code using Bit import).
JoshK2 / react-spinners-css
Amazing collection of react spinners components of css spinners for ajax or loading animation
React Spinners CSS Loaders (Angular)
Amazing collection of pure CSS react spinners components of css spinners for ajax or loading animation based on loading.io.
Install components and live demo
List of Spinners - PropTypes and Default Props
Each component accepts a color
prop, and few accepts also size
prop.
The default color
prop is #7f58af
.
Component that accepts size
prop have a default size in pixel.
Spinner | Color: string | Size: number |
---|---|---|
Circle Spinner | #7f58af | 64px |
Default Spinner | #7f58af | - |
DualRing Spinner | #7f58af | - |
Ellipsis Spinner | #7f58af | - |
Facebook Spinner | #7f58af | - |
Grid Spinner | #7f58af | - |
Heart Spinner | #7f58af | - |
Hourglass Spinner | #7f58af | - |
Ring Spinner | #7f58af | 80px |
Ripple Spinner | #7f58af | - |
Roller Spinner | #7f58af | - |
Spinner Spinner | #7f58af | - |
Installation
Using npm to install react-spinners-css:
$ npm i --save react-spinners-css
Play and install react spinners with Bit
Install specific react spinner component with bit, npm
For example, this is the circle loader and the component can receive color and size props:
and the code import a very simple CSS code, exactly the same from loading.io CSS loader:
How to use Loader animation in your React.js application?
So, you have a component that sends a request and stores the received data in an array inside your state object. The obvious thing to do is check if the array is empty and if so, display the spinner.
For this example, I used a Facebook spinner with a very simple page that waiting 5 seconds until to show a list of cars.
Its very simple to use and allows you to show a nice animation loader until the data is loaded.
Also, you can use a custom color in any spinner, just send a color inside the color property, like this:
<Facebook color="red" /><Facebook color="#cecece" />
Or be crazy and use a random color with my random color generator component.
<Facebook color={getRandomColor()} />
You can see the result with random color in this live demo facebook react spinner.
If you want to see more react spinners examples, check out my react spinners components collection in bit.dev.
For any issue or missing features, please open an issue on GitHub and Ill do my best.
And of course, if you like it, star it!
JoshK2 / react-spinners-css
Amazing collection of react spinners components of css spinners for ajax or loading animation
React Spinners CSS Loaders (Angular)
Amazing collection of pure CSS react spinners components of css spinners for ajax or loading animation based on loading.io.
Install components and live demo
List of Spinners - PropTypes and Default Props
Each component accepts a color
prop, and few accepts also size
prop.
The default color
prop is #7f58af
.
Component that accepts size
prop have a default size in pixel.
Spinner | Color: string | Size: number |
---|---|---|
Circle Spinner | #7f58af | 64px |
Default Spinner | #7f58af | - |
DualRing Spinner | #7f58af | - |
Ellipsis Spinner | #7f58af | - |
Facebook Spinner | #7f58af | - |
Grid Spinner | #7f58af | - |
Heart Spinner | #7f58af | - |
Hourglass Spinner | #7f58af | - |
Ring Spinner | #7f58af | 80px |
Ripple Spinner | #7f58af | - |
Roller Spinner | #7f58af | - |
Spinner Spinner | #7f58af | - |
Installation
Using npm to install react-spinners-css:
$ npm i --save react-spinners-css
Play and install react spinners with Bit
Install specific react spinner component with bit, npm
And follow me on Twitter to get features updates.
Original Link: https://dev.to/joshk2/how-i-created-my-own-react-spinners-library-4ckn
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To