Skip to content

Commit 65a2fee

Browse files
authored
feat(zIndex): #321 ability to add custom z-index (#367)
1 parent d17e3b1 commit 65a2fee

File tree

5 files changed

+39
-32
lines changed

5 files changed

+39
-32
lines changed

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
node-version: [12.x, 14.x]
10+
node-version: [14.x]
1111
steps:
1212
- uses: actions/[email protected]
1313
- name: Use Node.js ${{ matrix.node-version }}

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ export default App;
5555

5656
<a name="settings"></a>
5757
## The settings of the component
58-
|Parameter|Type|Description|Default|
59-
|--------------------|--------|-----------|-------|
60-
|**background**|string|Sets the color for the background in any format that supports css|``` rgba(255,255,255,.5) ```|
61-
|**color**|string|Sets the color of the spinner|``` #000 ```|
62-
|**promiseTracker**|boolean|You need to set ```usePromiseTracker``` function from the ```react-promise-tracker```|``` false ```|
63-
|**loading**|boolean|If you need to run the loader without tracking promises you should set ```true```|``` false ```|
58+
| Parameter | Type | Description | Default |
59+
|--------------------|---------|---------------------------------------------------------------------------------------|------------------------------|
60+
| **background** | string | Sets the color for the background in any format that supports css | ``` rgba(255,255,255,.5) ``` |
61+
| **color** | string | Sets the color of the spinner | ``` #000 ``` |
62+
| **promiseTracker** | boolean | You need to set ```usePromiseTracker``` function from the ```react-promise-tracker``` | ``` false ``` |
63+
| **loading** | boolean | If you need to run the loader without tracking promises you should set ```true``` | ``` false ``` |
64+
| **zIndex** | number | You can change the z-index to distribute the layers correctly | ``` 999 ``` |
6465

6566
<a name="contributing"></a>
6667
## Contributing

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

specs/__snapshots__/Loader.spec.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ exports[`Loader should render correctly 1`] = `
1111
"position": "absolute",
1212
"right": 0,
1313
"top": 0,
14-
"zIndex": 10,
14+
"zIndex": 999,
1515
}
1616
}
1717
>

src/components/Loader.js

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33

4-
const defaultLoaderStyle = {
5-
position: 'absolute',
6-
top: 0,
7-
left: 0,
8-
right: 0,
9-
bottom: 0,
10-
zIndex: 10,
11-
background: 'rgba(255,255,255,.5)',
12-
backfaceVisibility: 'hidden',
13-
};
4+
const Loader = (props) => {
5+
const {
6+
color, background, loading, promiseTracker, zIndex,
7+
} = props;
148

15-
const defaultSpinnerStyle = {
16-
position: 'absolute',
17-
left: '50%',
18-
top: '50%',
19-
transform: 'translate(-50%, -50%)',
20-
width: 100,
21-
height: 100,
22-
};
9+
const defaultLoaderStyle = {
10+
position: 'absolute',
11+
top: 0,
12+
left: 0,
13+
right: 0,
14+
bottom: 0,
15+
zIndex,
16+
background: 'rgba(255,255,255,.5)',
17+
backfaceVisibility: 'hidden',
18+
};
2319

24-
const Loader = (props) => {
25-
const { promiseInProgress } = props.promiseTracker ? props.promiseTracker() : false;
20+
const defaultSpinnerStyle = {
21+
position: 'absolute',
22+
left: '50%',
23+
top: '50%',
24+
transform: 'translate(-50%, -50%)',
25+
width: 100,
26+
height: 100,
27+
};
28+
29+
const { promiseInProgress } = promiseTracker ? promiseTracker() : false;
2630
const loaderStyle = {
2731
...defaultLoaderStyle,
28-
background: props.background,
32+
background,
2933
};
3034
const spinnerItemsArray = [
3135
{ transform: 'rotate(0 50 50)', begin: '-0.9166666666666666s' },
@@ -42,13 +46,13 @@ const Loader = (props) => {
4246
{ transform: 'rotate(330 50 50)', begin: '0s' },
4347
];
4448
return (
45-
props.loading || promiseInProgress
49+
loading || promiseInProgress
4650
? <div style={loaderStyle}>
4751
<div style={defaultSpinnerStyle}>
4852
<svg className="lds-spinner" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"
4953
viewBox="0 0 100 100" preserveAspectRatio="xMidYMid">
5054
{spinnerItemsArray.map((item) => <g key={item.transform} transform={item.transform}>
51-
<rect x="47" y="24" rx="9.4" ry="4.8" width="6" height="12" fill={props.color}>
55+
<rect x="47" y="24" rx="9.4" ry="4.8" width="6" height="12" fill={color}>
5256
<animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin={item.begin} repeatCount="indefinite"/>
5357
</rect>
5458
</g>)}
@@ -63,13 +67,15 @@ Loader.propTypes = {
6367
loading: PropTypes.bool,
6468
background: PropTypes.string,
6569
promiseTracker: PropTypes.any,
70+
zIndex: PropTypes.number,
6671
};
6772

6873
Loader.defaultProps = {
6974
color: '#000',
7075
loading: false,
7176
background: 'rgba(255,255,255,.5)',
7277
promiseTracker: false,
78+
zIndex: 999,
7379
};
7480

7581
export default Loader;

0 commit comments

Comments
 (0)