Material Design spinner components for React.js.
See demo page: https://tsuyoshiwada.github.io/react-md-spinner/
You can install the react-md-spinner from npm.
$ npm install react-md-spinner
- You can start using with zero configuration!
- Support to change of color, size, border and animation speed.
- It can also be used in single color.
- Support Server-Side Rendering.
Because it is made of 100% inline styles, you can start using it right away without setting.
import React, { Component } from "react";
import MDSpinner from "react-md-spinner";
export default class SpinnerExample extends Component {
render() {
return (
<div>
<MDSpinner />
</div>
);
}
}
The following is an example of Server-Side Rendering.
Please checkout examples directory for details.
The point is to use ssrBehavior
and specify userAgent
.
Note: It is a different code from the actual example.
Client-Side:
import React from "react";
import { render } from "react-dom";
import App from "./App";
render(
<App userAgent={window.navigator.userAgent} />,
document.getElementById("app")
);
Server-Side:
import { ssrBehavior } from "react-md-spinner";
// ...
const html = (root, userAgent) => `<!DOCTYPE html>
<html lang="en">
<head>
${ssrBehavior.getStylesheetString(userAgent)}
</head>
<body>
<div id="app">${renderToString(root)}</div>
<script src="./bundle.js"></script>
</body>
</html>`;
app.get("/", (req, res) => {
const userAgent = req.headers["user-agent"];
res.status(200).send(html(
<App userAgent={userAgent} />,
userAgent
));
});
App:
class App extends Component {
render() {
return <MDSpinner
userAgent={this.props.userAgent}
/>;
}
}
You can set the following properties.
In Server-Side Rendering you need to inject @keyframes
inside the <head>
.
react-md-spinner
provides utilities to handle them.
ssrBehavior.getStylesheetString([userAgent: string]): string
ssrBehavior.getStylesheetComponent([userAgent: string]): React.Component
import { ssrBehavior } from "react-md-spinner";
const html = userAgent => `<!DOCTYPE html>
<head>
${ssrBehavior.getStylesheetString(userAgent)}
</head>
<body>
<div id="app">
// React stuff here
</div>
</body>
</html>`;
// ...
html(/* User-Agent */);
import { ssrBehavior } from "react-md-spinner";
const HTML = userAgent => (
<html>
<head>
{ssrBehavior.getStylesheetComponent(userAgent)}
</head>
<body>
<div id="app">
// React stuff here
</div>
</body>
</html>
);
// ...
HTML(/* User-Agent */);
Released under the MIT License
See CHANGELOG.md
Initialization of the project.
$ cd /your/project/dir
$ git clone https://github.com/tsuyoshiwada/react-md-spinner.git
Install some dependencies.
$ npm install
Start the development and can you see demo page (access to the http://localhost:3000/
).
$ npm start
Run lint and testing.
$ npm test
Generates build file.
$ npm run build
Thank you for your interest in react-md-spinner.js.
Bugs, feature requests and comments are more than welcome in the issues.
Before you open a PR:
Be careful to follow the code style of the project. Run npm test
after your changes and ensure you do not introduce any new errors or warnings.
All new features and changes need documentation.
Thanks!