├── .codeclimate.yml ├── .eslint ├── .eslintignore ├── .eslintrc ├── .gitignore ├── .jshintrc ├── .npmignore ├── .travis.yml ├── README.md ├── examples └── simple │ ├── .gitignore │ ├── components │ └── App.js │ ├── index.html │ ├── index.js │ ├── package.json │ ├── server.js │ └── webpack.config.js ├── package.json └── src ├── components ├── progress-hud.js └── wrapper.js ├── images.js ├── index.js └── styles.js /.codeclimate.yml: -------------------------------------------------------------------------------- 1 | exclude_paths: 2 | - "examples/*" 3 | - "lib/*" 4 | - "test/*" 5 | -------------------------------------------------------------------------------- /.eslint: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naoufal/react-progress-hud/89bcfb1b654754953cf59f65b14dc1cf1bbbe526/.eslint -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | examples 2 | lib 3 | node_modules 4 | test 5 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "mocha": true, 5 | "node": true, 6 | "es6": true 7 | }, 8 | "ecmaFeatures": { 9 | "modules": true, 10 | "jsx": true 11 | }, 12 | "rules": { 13 | "array-bracket-spacing": [2, "never"], 14 | "brace-style": [2, "1tbs"], 15 | "comma-dangle": [2, "never"], 16 | "comma-spacing": [2, { 17 | "before": false, 18 | "after": true 19 | }], 20 | "comma-style": [2, "last"], 21 | "eol-last": 2, 22 | "func-names": 2, 23 | "func-style": [2, "expression"], 24 | "indent": [2, 2], 25 | "key-spacing": [2, { 26 | "beforeColon": false, 27 | "afterColon": true 28 | }], 29 | "linebreak-style": [2, "unix"], 30 | "max-nested-callbacks": [2, 2], 31 | "new-parens": 2, 32 | "no-nested-ternary": 2, 33 | "no-new-object": 2, 34 | "no-spaced-func": 2, 35 | "no-trailing-spaces": 2, 36 | "no-unneeded-ternary": 2, 37 | "object-curly-spacing": [2, "always"], 38 | "padded-blocks": [2, "never"], 39 | "quote-props": [2, "as-needed"], 40 | "quotes": [2, "double"], 41 | "semi": [2, "always"], 42 | "semi-spacing": [2, { 43 | "before": false, 44 | "after": true 45 | }], 46 | "space-after-keywords": [2, "always"], 47 | "space-before-blocks": [2, "always"], 48 | "space-before-function-paren": [2, "never"], 49 | "space-in-parens": [2, "never"], 50 | "space-infix-ops": 2, 51 | "space-return-throw-case": 2, 52 | "space-unary-ops": [2, { 53 | "words": true, 54 | "nonwords": false 55 | }], 56 | "spaced-comment": [2, "always"], 57 | "wrap-regex": 2 58 | }, 59 | "plugins": [ 60 | "react" 61 | ] 62 | } 63 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | .DS_Store 3 | lib 4 | node_modules 5 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "esnext": true 3 | } 4 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | *.log 2 | .DS_Store 3 | examples 4 | src 5 | test 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "iojs" 4 | script: 5 | - npm test 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React Progress HUD 2 | [![npm](https://img.shields.io/npm/v/react-progress-hud.svg?style=flat-square)](https://www.npmjs.com/package/react-progress-hud) 3 | [![npm downloads](https://img.shields.io/npm/dm/react-progress-hud.svg?style=flat-square)](https://www.npmjs.com/package/react-progress-hud) 4 | [![Travis](https://img.shields.io/travis/naoufal/react-progress-hud.svg?style=flat-square)](https://travis-ci.org/naoufal/react-native-progress-hud) 5 | [![Code Climate](https://img.shields.io/codeclimate/github/naoufal/react-progress-hud.svg?style=flat-square)](https://codeclimate.com/github/naoufal/react-progress-hud) 6 | 7 | React Progress HUD is a [React](https://facebook.github.io/react) port of the popular [`SVProgressHUD`](https://github.com/TransitApp/SVProgressHUD). It is a clean and easy-to-use HUD meant to display the progress of an ongoing task. 8 | 9 | Are you using [React Native](https://facebook.github.io/react-native/)? Check out [React Native Progress HUD](https://github.com/naoufal/react-native-progress-hud). 10 | 11 | ## Install 12 | ```shell 13 | npm i --save react-progress-hud 14 | ``` 15 | 16 | ## Usage 17 | Using the HUD in your app will usually look like this: 18 | ```js 19 | import React, { Component } from "react"; 20 | import { ProgressHUD, Wrapper } from "react-progress-hud"; 21 | 22 | class YourComponent extends Component { 23 | render() { 24 | return ( 25 |
26 | 27 | 32 |
33 | ); 34 | } 35 | } 36 | 37 | export default Wrapper(App); 38 | ``` 39 | 40 | ### Showing the HUD 41 | You can display the HUD by calling: 42 | ```js 43 | this.props.showProgressHUD(); 44 | ``` 45 | 46 | ### Dismissing the HUD 47 | It can be dismissed by calling: 48 | ```js 49 | this.props.dismissProgressHUD(); 50 | ``` 51 | 52 | ## Props 53 | The following props can be used to modify the HUD's style and/or behaviour: 54 | 55 | | Prop | Type | Opt/Required | Default | Note | 56 | |---|---|---|---|---| 57 | |__`isVisible`__|_Boolean_|Required|`N/A`|Displays the HUD when set to true. 58 | |__`clickHandler`__|_Function_|Optional|`() => {}`|Sets a clickHandler on the `ProgressHUD`. 59 | |__`overlayColor`__|_String_|Optional|`rgb(0, 0, 0)`|Sets the color of the overlay. 60 | |__`overlayOpacity`__|_String_|Optional|`0.5`|Sets the opacity of the overlay. 61 | |__`color`__|_String_|Optional|`#000`|Sets the color of the spinner. 62 | 63 | ## License 64 | Copyright (c) 2015, [Naoufal Kadhom](http://naoufal.com) 65 | 66 | Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. 67 | 68 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 69 | -------------------------------------------------------------------------------- /examples/simple/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | -------------------------------------------------------------------------------- /examples/simple/components/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import { ProgressHUD, Wrapper } from "../../../lib/index"; 3 | 4 | let App = React.createClass({ 5 | _renderButton() { 6 | return ( 7 | 8 | ); 9 | }, 10 | 11 | _clickHandler() { 12 | this.props.showProgressHUD(); 13 | }, 14 | 15 | render() { 16 | return ( 17 |
18 |

Progress HUD

19 | {this._renderButton()} 20 | 25 |
26 | ); 27 | } 28 | }); 29 | 30 | export default Wrapper(App); 31 | -------------------------------------------------------------------------------- /examples/simple/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | react-progress-hud-demo 4 | 5 | 6 |
7 |
8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /examples/simple/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import App from './components/App'; 3 | 4 | React.render( 5 | , 6 | document.getElementById('root') 7 | ); 8 | -------------------------------------------------------------------------------- /examples/simple/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-progress-hud-example", 3 | "version": "1.0.0", 4 | "description": "react-progress-hud-example demo", 5 | "main": "server.js", 6 | "scripts": { 7 | "start": "node server.js" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/naoufal/react-progress-hud.git" 12 | }, 13 | "license": "ISC", 14 | "bugs": { 15 | "url": "https://github.com/naoufal/react-progress-hud/issues" 16 | }, 17 | "homepage": "https://github.com/naoufal/react-progress-hud", 18 | "devDependencies": { 19 | "babel-core": "5.8.23", 20 | "babel-loader": "5.1.4", 21 | "node-libs-browser": "0.5.2", 22 | "react": "0.13.3", 23 | "react-hot-loader": "1.2.7", 24 | "webpack": "1.9.11", 25 | "webpack-dev-server": "1.9.0" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/simple/server.js: -------------------------------------------------------------------------------- 1 | var webpack = require('webpack'); 2 | var WebpackDevServer = require('webpack-dev-server'); 3 | var config = require('./webpack.config'); 4 | 5 | new WebpackDevServer(webpack(config), { 6 | publicPath: config.output.publicPath, 7 | hot: true, 8 | historyApiFallback: true, 9 | stats: { 10 | colors: true 11 | } 12 | }).listen(3000, 'localhost', function (err) { 13 | if (err) { 14 | console.log(err); 15 | } 16 | 17 | console.log('Listening at localhost:3000'); 18 | }); 19 | -------------------------------------------------------------------------------- /examples/simple/webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var webpack = require('webpack'); 3 | 4 | module.exports = { 5 | devtool: 'eval', 6 | entry: [ 7 | 'webpack-dev-server/client?http://localhost:3000', 8 | 'webpack/hot/only-dev-server', 9 | './index' 10 | ], 11 | 12 | output: { 13 | path: path.join(__dirname, 'dist'), 14 | filename: 'bundle.js', 15 | publicPath: '/static/' 16 | }, 17 | 18 | plugins: [ 19 | new webpack.HotModuleReplacementPlugin(), 20 | new webpack.NoErrorsPlugin(), 21 | ], 22 | 23 | resolve: { 24 | alias: { 25 | 'react-progress-hud': path.join(__dirname, '..', '..', 'src') 26 | }, 27 | extensions: ['', '.js'] 28 | }, 29 | 30 | module: { 31 | loaders: [ 32 | { 33 | test: /\.(js|jsx)$/, 34 | loaders: ['react-hot', 'babel'], 35 | exclude: /node_modules/, 36 | include: __dirname 37 | }, 38 | { 39 | test: /\.(js|jsx)$/, 40 | loaders: ['babel'], 41 | include: path.join(__dirname, '..', '..', 'src') 42 | } 43 | ] 44 | } 45 | }; 46 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-progress-hud", 3 | "version": "0.1.6", 4 | "description": "A clean and lightweight progress HUD for your React app", 5 | "main": "lib/index.js", 6 | "scripts": { 7 | "build": "./node_modules/.bin/babel --optional runtime src --out-dir lib", 8 | "build:watch": "./node_modules/.bin/babel --optional runtime src --watch --out-dir lib", 9 | "lint": "./node_modules/.bin/eslint .", 10 | "test": "npm run lint" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/naoufal/react-progress-hud" 15 | }, 16 | "keywords": [ 17 | "react", 18 | "progress", 19 | "hud", 20 | "popup", 21 | "loader", 22 | "loading", 23 | "react-component" 24 | ], 25 | "author": "Naoufal Kadhom", 26 | "license": "ISC", 27 | "bugs": { 28 | "url": "https://github.com/naoufal/react-progress-hud/issues" 29 | }, 30 | "homepage": "https://github.com/naoufal/react-progress-hud", 31 | "dependencies": { 32 | "babel-runtime": "5.8.20", 33 | "react-motion": "0.2.7" 34 | }, 35 | "devDependencies": { 36 | "babel": "5.8.23", 37 | "babel-eslint": "4.1.1", 38 | "eslint": "1.3.1", 39 | "eslint-plugin-react": "3.3.1", 40 | "react": "0.13.3" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/components/progress-hud.js: -------------------------------------------------------------------------------- 1 | import React, { Component, PropTypes } from "react"; 2 | import { Spring } from "react-motion"; 3 | 4 | import styles from "../styles"; 5 | import images from "../images"; 6 | 7 | const propTypes = { 8 | clickHandler: PropTypes.func, 9 | color: PropTypes.string, 10 | isVisible: PropTypes.bool.isRequired, 11 | overlayColor: PropTypes.string, 12 | overlayOpacity: PropTypes.string 13 | }; 14 | const defaultProps = { 15 | clickHandler: () => {}, 16 | color: "#000", 17 | overlayColor: "rgb(0, 0, 0)", 18 | overlayOpacity: "0.5" 19 | }; 20 | 21 | export default class ProgressHUD extends Component { 22 | constructor(props) { 23 | super(props); 24 | } 25 | 26 | _getEndValue(prevValue) { 27 | return { 28 | val: prevValue.val === 0 ? 360 : prevValue.val + 360, 29 | config: [100, 100] 30 | }; 31 | } 32 | 33 | render() { 34 | return ( 35 | // jshint ignore:start 36 |
43 |
54 |
55 |
56 | 57 | {interpolated => 58 |
69 | 70 |
76 |
77 |
78 | } 79 | 80 |
81 |
82 | // jshint ignore:end 83 | ); 84 | } 85 | } 86 | 87 | ProgressHUD.propTypes = propTypes; 88 | ProgressHUD.defaultProps = defaultProps; 89 | -------------------------------------------------------------------------------- /src/components/wrapper.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | 3 | export const Wrapper = ComposedComponent => class extends Component { 4 | constructor(props) { 5 | super(props); 6 | 7 | this.state = { isVisible: false }; 8 | } 9 | 10 | showProgressHUD() { 11 | this.setState({ 12 | isVisible: true 13 | }); 14 | } 15 | 16 | dismissProgressHUD() { 17 | this.setState({ 18 | isVisible: false 19 | }); 20 | } 21 | 22 | render() { 23 | return ( 24 | // jshint ignore:start 25 | 31 | // jshint ignore:end 32 | ); 33 | } 34 | }; 35 | 36 | export default Wrapper; 37 | -------------------------------------------------------------------------------- /src/images.js: -------------------------------------------------------------------------------- 1 | const images = { 2 | "1x": "iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAAXNSR0IArs4c6QAABjlJREFUaAWVltuS3EQQRHcAY+AVm3f//+c4+At4gwjAl6VOj44iVdM9kiuip25Z1Zmr0di319fXDy8vL69PztfWy5zYPP2Ib7fb59r/vjC/18GvbLUHXu6VY89H/Ydt821xA6DsZW5M3xiPWbtnzz+dAWWM91g3n/rvCiVRvIdhzLx7e3r6Pd5Kl9yMHIOz+rTGE5EEAGM9y7RZH5x1Y/FXfRJjJvPLcQpxCYRmQqxJXN8FOC+evStLomAy/6Y4hUiIBXzleKnSJDbz1DzMp4nP2izuxH2p9fQzPuAVwmWdQBcjofTMkPdTpUt2IFMTz/KlCOYUsro1xRjrJd//AOxS7Gov9Wekz3oPohACsRkZLsMkTixBRaz8wNa/IeLJZ5aEIZeHnoS7z7kRnz0RL1eMHoLEGssURe1MAJgkI9FZzZ4+MXvchUBgb1bMsNZF0JM8PebMmTkT4z1JkLjn4GY154dXSAqAhCZBFmE+BXJJr/wYWHwcSBRmRpY7FK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tiaWAHoNPrPPsxLjUsxLCjOa+xNpPQePnMi8znnkJdvK9nrMSkjw58YwYc9TZh8eoYbkzY3pDUP5qJWAWJ+Hsp7CsSwCvKSi9oiQPVjF695JrQ0Al9MYTsSl45sFQT09sPpuhlpbkjWcinGG3fWLM3Pvu1XoqsydCM0k7JGm99RmW2soU8cz7dFKAcd/LnsOvVhLrseTTE3s6nsusEWtcip2JYC8YBBFj/Wm4H3942bORMYsyP4vZC6ZbiqA3EyPxFGGt7zvks5/fJJoijPWJ6zGXzMR4+ZmILvpUTL4jXg6BK2STvARzR9aMFWCOt8Y+Y4WkgIxzfuxIIRKjYXzFdzx5Gju6JeGMwZk7oyjymRj6l1/2lSCWn/XArEzSenAZm+f8TMyll70TZal/ZXt5kbEYc7wk9WIyN3aOvNtDbfbVktxVzyWJ7Zeac7nEs2YdL0E9eGNnZrXDExGIT2LGWTfWg9EytgaZXs+acXpmydPYMa35RAAD8pBj5vpZjZ71LXwgbV0vYXLj9NTZm6R7Dka7/Q+G5FcOipn+rwAAAABJRU5ErkJggg==" 3 | }; 4 | 5 | export default images; 6 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import ProgressHUD from "./components/progress-hud"; 2 | import Wrapper from "./components/wrapper"; 3 | 4 | export default { 5 | ProgressHUD, 6 | Wrapper 7 | }; 8 | -------------------------------------------------------------------------------- /src/styles.js: -------------------------------------------------------------------------------- 1 | const styles = { 2 | container: { 3 | position: "fixed", 4 | left: 0, 5 | top: 0, 6 | right: 0, 7 | bottom: 0, 8 | zIndex: 2147483647 9 | }, 10 | overlay: { 11 | position: "absolute", 12 | width: "100%", 13 | height: "100%", 14 | filter: "alpha(opacity = 50)", 15 | }, 16 | content: { 17 | position: "absolute", 18 | left: "calc(50% - 50px)", 19 | top: "calc(50% - 50px)", 20 | display: "block", 21 | width: 100, 22 | height: 100, 23 | borderRadius: 16, 24 | backgroundColor: "#fff", 25 | zIndex: 2147483648 26 | }, 27 | spinner: { 28 | position: "absolute", 29 | left: "calc(50% - 25px)", 30 | top: "calc(50% - 25px)", 31 | width: 50, 32 | height: 50, 33 | borderRadius: 50 / 2, 34 | backgroundColor: "#000" 35 | }, 36 | inner_spinner: { 37 | position: "absolute", 38 | left: 4, 39 | top: 4, 40 | width: 42, 41 | height: 42, 42 | borderRadius: 42 / 2, 43 | backgroundColor: "#fff" 44 | }, 45 | curve: { 46 | position: "absolute", 47 | left: 23, 48 | top: 0, 49 | width: 4, 50 | height: 4, 51 | borderRadius: 2, 52 | backgroundColor: "#000" 53 | } 54 | }; 55 | 56 | export default styles; 57 | --------------------------------------------------------------------------------