Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 280691f

Browse files
committed
first version
1 parent cdb17a0 commit 280691f

File tree

11 files changed

+7144
-0
lines changed

11 files changed

+7144
-0
lines changed

‎.babelrc‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["react", "env"]
3+
}

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ typings/
5757
# dotenv environment variables file
5858
.env
5959

60+
dist/
61+
.cache/
62+

‎README.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,25 @@
11
# React-UI-Blocker
22
A Body Blocker with Cool Animations for React Apps
3+
4+
It is simple to use
5+
First
6+
`import UIBlocker from 'react-ui-blocker';`
7+
8+
And use it with one of these themes,
9+
10+
`
11+
<UIBlocker
12+
theme="cubeGrid" // default
13+
isVisible={true}
14+
message="Loading.. or your custom message"
15+
/>
16+
`
17+
18+
Props
19+
=====
20+
21+
| Name | Type | Default | Available Values |
22+
|----------- |--------- |------------ |-------------------------------------------------------------- |
23+
| theme | String | cubeGrid | cubeGrid, rect, cube, bounce, dot, foldingCube, fadingCircle |
24+
| isVisible | Boolean | false | true / false |
25+
| message | String | Loading... | Any string |

‎build/index.js‎

Lines changed: 2585 additions & 0 deletions
Large diffs are not rendered by default.

‎example/index.html‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>React UI Blocker</title>
5+
</head>
6+
<body>
7+
<div id="react-root"> </div>
8+
<script type="text/javascript" src="./index.js"></script>
9+
</body>
10+
</html>

‎example/index.js‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import UIBlocker from '../src/index';
4+
5+
class App extends React.Component {
6+
constructor(props) {
7+
super(props);
8+
this.state = {
9+
isVisible: false,
10+
loadingType: 'cubeGrid'
11+
};
12+
this.handleShowLoading = this.handleShowLoading.bind(this);
13+
}
14+
15+
renderDropDown() {
16+
return (<select onChange={(e) => this.setState({ loadingType: e.target.value }) }>
17+
<option>cubeGrid</option>
18+
<option>rect</option>
19+
<option>cube</option>
20+
<option>bounce</option>
21+
<option>circle</option>
22+
<option>dot</option>
23+
<option>foldingCube</option>
24+
<option>fadingCircle</option>
25+
</select>)
26+
}
27+
28+
handleShowLoading(e) {
29+
clearTimeout(this.timeout);
30+
this.setState({ isVisible: true });
31+
this.timeout = setTimeout(() => this.setState({ isVisible: false }), 3000);
32+
}
33+
34+
render() {
35+
const { isVisible, loadingType } = this.state;
36+
return (<div>
37+
<label>Loading Type</label>
38+
{this.renderDropDown()}
39+
<button onClick={this.handleShowLoading}>Show Loading</button>
40+
<UIBlocker
41+
theme={loadingType}
42+
isVisible={isVisible}
43+
message="Loading.. or your custom message"
44+
/>
45+
</div>);
46+
}
47+
}
48+
49+
const reactRoot = document.getElementById('react-root');
50+
ReactDOM.render(<App />, reactRoot);

‎package.json‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "react-ui-blocker",
3+
"version": "1.0.0",
4+
"description": "Simpe UI Blocker for React Apps",
5+
"main": "build/index.js",
6+
"repository": "https://github.com/sbayd/React-UI-Blocker.git",
7+
"author": "Berkay Aydin <sbayd06@gmail.com>",
8+
"license": "MIT",
9+
"private": false,
10+
"scripts": {
11+
"start": "parcel example/index.html",
12+
"productionForExamples": "parcel build example/index.html -d dist/ --no-minify",
13+
"production": "parcel build src/index.js -d build/ --no-minify"
14+
},
15+
"dependencies": {
16+
"react": "^16.2.0",
17+
"react-dom": "^16.2.0"
18+
},
19+
"devDependencies": {
20+
"babel-preset-env": "^1.6.1",
21+
"babel-preset-react": "^6.24.1",
22+
"eslint": "^4.13.0",
23+
"eslint-plugin-react": "^7.5.1",
24+
"mocha": "^4.0.1",
25+
"parcel-bundler": "^1.1.0",
26+
"postcss-modules": "^1.1.0"
27+
}
28+
}

‎src/index.js‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import LoadingTypes from './loadingTypes';
4+
import minimizedStyles from './styles';
5+
6+
export default class UIBlocker extends React.Component {
7+
8+
get stylesClassName() {
9+
return 'react_ui_blocker_styles';
10+
}
11+
12+
get styleContainer() {
13+
const stylesClassName = this.stylesClassName;
14+
const headContainer = this.getHeadContainer();
15+
if (headContainer && headContainer.getElementsByClassName) {
16+
const [ found ] = headContainer.getElementsByClassName(stylesClassName);
17+
if (found) { return found; }
18+
const container = document.createElement('style');
19+
container.type = 'text/css';
20+
container.className = stylesClassName;
21+
headContainer.appendChild(container);
22+
return container;
23+
}
24+
}
25+
26+
getHeadContainer() {
27+
if (global && global.document && global.document.head) {
28+
return global.document.head;
29+
} else if (window && window.document && window.document.head) {
30+
return window.document.head;
31+
} else if (document && document.querySelector) {
32+
return document.querySelector('head');
33+
}
34+
}
35+
36+
componentWillMount() {
37+
const { styleContainer } = this;
38+
if (styleContainer) {
39+
styleContainer.innerHTML = minimizedStyles;
40+
}
41+
}
42+
43+
shouldComponentUpdate(nextProps) {
44+
const { theme, message, isVisible } = nextProps;
45+
if (theme !== this.props.theme || message !== this.props.message || isVisible !== this.props.isVisible) {
46+
return true;
47+
}
48+
return false;
49+
}
50+
51+
renderContent(theme) {
52+
const structureString = LoadingTypes[theme] || loadingTypes['cubeGrid'];
53+
const [ wrapperClass, childClasses ] = structureString.split('|>');
54+
const childeren = childClasses.split('|').map((childName, childIndex) => {
55+
return (<div className={childName} key={childName} />);
56+
});
57+
return (<div className={wrapperClass} >{childeren}</div>);
58+
}
59+
60+
render() {
61+
const { theme, message, isVisible } = this.props;
62+
const content = this.renderContent(theme);
63+
return (
64+
<div id="holdon-overlay" style = {{ display: isVisible ? 'block' : 'none' }}>
65+
<div id="holdon-content-overlay">
66+
<div id="holdon-content">{content}</div>
67+
<div id="holdon-message">{message}</div>
68+
</div>
69+
</div>
70+
);
71+
}
72+
}
73+
74+
UIBlocker.defaultProps = {
75+
isVisible: false,
76+
message: 'Loading..',
77+
theme: 'cubeGrid'
78+
};
79+
80+
UIBlocker.propTypes = {
81+
theme: PropTypes.string.isRequired,
82+
message: PropTypes.string,
83+
isVisible: PropTypes.bool.isRequired
84+
};

‎src/loadingTypes.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export const loadingTypes = {
2+
dot: 'sk-dot|>sk-dot1|sk-dot2',
3+
rect: 'sk-rect|>rect1|rect2|rect3|rect4|rect5',
4+
cube: 'sk-cube|>sk-cube1|sk-cube2',
5+
bounce: 'sk-bounce|>bounce1|bounce2|bounce3',
6+
circle: 'sk-circle|>sk-circle1 sk-child|sk-circle2 sk-child|sk-circle3 sk-child|sk-circle4 sk-child|sk-circle5 sk-child|sk-circle6 sk-child|sk-circle7 sk-child|sk-circle8 sk-child|sk-circle9 sk-child|sk-circle10 sk-child|sk-circle11 sk-child|sk-circle12 sk-child',
7+
cubeGrid: 'sk-cube-grid|>sk-cube-child sk-cube-grid1|sk-cube-child sk-cube-grid2|sk-cube-child sk-cube-grid3|sk-cube-child sk-cube-grid4|sk-cube-child sk-cube-grid5|sk-cube-child sk-cube-grid6|sk-cube-child sk-cube-grid7|sk-cube-child sk-cube-grid8|sk-cube-child sk-cube-grid9',
8+
foldingCube: 'sk-folding-cube|>sk-cubechild1 sk-cube-parent|sk-cubechild2 sk-cube-parent|sk-cubechild3 sk-cube-parent',
9+
fadingCircle: 'sk-fading-circle|>sk-fading-circle1 sk-circle-child|sk-fading-circle2 sk-circle-child|sk-fading-circle3 sk-circle-child|sk-fading-circle4 sk-circle-child|sk-fading-circle5 sk-circle-child|sk-fading-circle6 sk-circle-child\sk-fading-circle7 sk-circle-child|sk-fading-circle8 sk-circle-child|sk-fading-circle9 sk-circle-child|sk-fading-circle10 sk-circle-child|sk-fading-circle11 sk-circle-child|sk-fading-circle12 sk-circle-child'
10+
};
11+
12+
13+
export default loadingTypes;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /