Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit ce88242

Browse files
Color prop for Loading component - all spinners except GraphSpinner
1 parent 080d66b commit ce88242

13 files changed

+205
-55
lines changed

dash_core_components/Loading.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Loading(Component):
1414
- fullscreen (boolean; optional): Boolean that determines if the loading spinner will be displayed full-screen or not
1515
- debug (boolean; optional): Boolean that determines if the loading spinner will display the status.prop_name and component_name
1616
- className (string; optional): Additional CSS class for the root DOM node
17+
- color (string; optional): Primary colour used for the loading spinners
1718
- status (optional): Object that holds the status object coming from dash-renderer. status has the following type: dict containing keys 'is_loading', 'prop_name', 'component_name'.
1819
Those keys have the following types:
1920
- is_loading (boolean; optional): Determines if the component is loading or not
@@ -22,13 +23,13 @@ class Loading(Component):
2223
2324
Available events: """
2425
@_explicitize_args
25-
def __init__(self, children=None, id=Component.UNDEFINED, type=Component.UNDEFINED, fullscreen=Component.UNDEFINED, debug=Component.UNDEFINED, className=Component.UNDEFINED, status=Component.UNDEFINED, **kwargs):
26-
self._prop_names = ['children', 'id', 'type', 'fullscreen', 'debug', 'className', 'status']
26+
def __init__(self, children=None, id=Component.UNDEFINED, type=Component.UNDEFINED, fullscreen=Component.UNDEFINED, debug=Component.UNDEFINED, className=Component.UNDEFINED, color=Component.UNDEFINED, status=Component.UNDEFINED, **kwargs):
27+
self._prop_names = ['children', 'id', 'type', 'fullscreen', 'debug', 'className', 'color', 'status']
2728
self._type = 'Loading'
2829
self._namespace = 'dash_core_components'
2930
self._valid_wildcard_attributes = []
3031
self.available_events = []
31-
self.available_properties = ['children', 'id', 'type', 'fullscreen', 'debug', 'className', 'status']
32+
self.available_properties = ['children', 'id', 'type', 'fullscreen', 'debug', 'className', 'color', 'status']
3233
self.available_wildcard_properties = []
3334

3435
_explicit_args = kwargs.pop('_explicit_args')

dash_core_components/dash_core_components.dev.js

Lines changed: 95 additions & 5 deletions
Large diffs are not rendered by default.

dash_core_components/dash_core_components.min.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dash_core_components/metadata.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2142,6 +2142,17 @@
21422142
"required": false,
21432143
"description": "Additional CSS class for the root DOM node"
21442144
},
2145+
"color": {
2146+
"type": {
2147+
"name": "string"
2148+
},
2149+
"required": false,
2150+
"description": "Primary colour used for the loading spinners",
2151+
"defaultValue": {
2152+
"value": "'#119DFF'",
2153+
"computed": false
2154+
}
2155+
},
21452156
"status": {
21462157
"type": {
21472158
"name": "shape",

dash_core_components/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"babel-preset-env": "^1.7.0",
3535
"babel-preset-react": "^6.24.1",
3636
"builder": "3.2.2",
37+
"color": "^3.1.0",
3738
"copyfiles": "^2.0.0",
3839
"cross-env": "^5.2.0",
3940
"css-loader": "^0.28.11",

demo/LoadingDemo.react.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ import {Loading, Tabs, Tab} from '../src';
44

55
const LoadingDemo = () => {
66
const status = {
7-
isLoading: true,
8-
propName: 'layout',
9-
componentName: 'Demo',
7+
is_loading: true,
8+
prop_name: 'layout',
9+
component_name: 'Demo',
1010
};
1111
return (
1212
<Tabs>
13-
<Tab value='tab-1' label='All Spinners (no fullscreen)'>
13+
<Tab value='tab-1' label='All Spinners (custom colors, no fullscreen)'>
1414
<div>
15-
<Loading status={status} type="default" />
16-
<Loading status={status} type="circle" />
17-
<Loading status={status} type="dot" />
18-
<Loading status={status} type="cube" />
15+
<Loading status={status} type="default" color="gold" />
16+
<Loading status={status} type="circle" color="cyan"/>
17+
<Loading status={status} type="dot" color="hotpink"/>
18+
<Loading status={status} type="cube" color="greenyellow"/>
1919
<Loading status={status} type="graph" />
2020
</div>
2121
</Tab>

package-lock.json

Lines changed: 48 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"babel-preset-env": "^1.7.0",
3535
"babel-preset-react": "^6.24.1",
3636
"builder": "3.2.2",
37+
"color": "^3.1.0",
3738
"copyfiles": "^2.0.0",
3839
"cross-env": "^5.2.0",
3940
"css-loader": "^0.28.11",

src/components/Loading/Loading.react.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ import DotSpinner from './spinners/DotSpinner.jsx';
1111
*/
1212
export default class Loading extends Component {
1313
render() {
14-
const { status, fullscreen, debug } = this.props;
14+
const { status, color, fullscreen, debug } = this.props;
1515
if (status && status.is_loading) {
1616
switch (this.props.type) {
1717
case 'graph':
18-
return <GraphSpinner status={status} debug={debug} fullscreen={fullscreen}/>;
18+
return <GraphSpinner status={status} color={color} debug={debug} fullscreen={fullscreen}/>;
1919
case 'cube':
20-
return <CubeSpinner status={status} debug={debug} fullscreen={fullscreen} />;
20+
return <CubeSpinner status={status} color={color} debug={debug} fullscreen={fullscreen} />;
2121
case 'circle':
22-
return <CircleSpinner status={status} debug={debug} fullscreen={fullscreen} />;
22+
return <CircleSpinner status={status} color={color} debug={debug} fullscreen={fullscreen} />;
2323
case 'dot':
24-
return <DotSpinner status={status} debug={debug} fullscreen={fullscreen} />;
24+
return <DotSpinner status={status} color={color} debug={debug} fullscreen={fullscreen} />;
2525
default:
26-
return <DefaultSpinner status={status} debug={debug} fullscreen={fullscreen} />;
26+
return <DefaultSpinner status={status} color={color} debug={debug} fullscreen={fullscreen} />;
2727
}
2828
}
2929
return this.props.children || null;
@@ -32,6 +32,7 @@ export default class Loading extends Component {
3232

3333
Loading.defaultProps = {
3434
type: 'default',
35+
color: '#119DFF'
3536
};
3637

3738
Loading.propTypes = {
@@ -62,6 +63,11 @@ Loading.propTypes = {
6263
*/
6364
className: PropTypes.string,
6465

66+
/**
67+
* Primary colour used for the loading spinners
68+
*/
69+
color: PropTypes.string,
70+
6571
/**
6672
* Object that holds the status object coming from dash-renderer
6773
*/

src/components/Loading/spinners/CircleSpinner.jsx

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

4-
const CircleSpinner = ({status, fullscreen, debug}) => {
4+
const CircleSpinner = ({status, color, fullscreen, debug}) => {
55
let debugTitle;
66
if (debug) {
77
debugTitle = (
@@ -64,7 +64,7 @@ const CircleSpinner = ({status, fullscreen, debug}) => {
6464
margin: 0 auto;
6565
width: 15%;
6666
height: 15%;
67-
background-color: #119DFF;
67+
background-color: ${color};
6868
border-radius: 100%;
6969
-webkit-animation: sk-circleBounceDelay 1.2s infinite ease-in-out both;
7070
animation: sk-circleBounceDelay 1.2s infinite ease-in-out both;
@@ -174,6 +174,7 @@ const CircleSpinner = ({status, fullscreen, debug}) => {
174174

175175
CircleSpinner.propTypes = {
176176
status: PropTypes.object,
177+
color: PropTypes.string,
177178
fullscreen: PropTypes.bool,
178179
debug: PropTypes.bool,
179180
};

src/components/Loading/spinners/CubeSpinner.jsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import changeColor from 'color';
34

4-
const CubeSpinner = ({status, fullscreen, debug}) => {
5+
const CubeSpinner = ({status, color, fullscreen, debug}) => {
56
let debugTitle;
67
if (debug) {
78
debugTitle = (
@@ -11,6 +12,7 @@ const CubeSpinner = ({status, fullscreen, debug}) => {
1112
</h3>
1213
);
1314
}
15+
/* eslint-disable no-magic-numbers */
1416
return (
1517
<div className={fullscreen ? 'dash-spinner-container' : ''}>
1618
{debugTitle}
@@ -64,36 +66,36 @@ const CubeSpinner = ({status, fullscreen, debug}) => {
6466
}
6567
6668
.dash-cube-side--front {
67-
background-color: #119DFF;
69+
background-color: ${color};
6870
animation: blowout-front 4s infinite;
6971
transform: rotateY(0deg) translateZ(40px);
7072
}
7173
.dash-cube-side--back {
72-
background-color: #0D76BF;
74+
background-color: ${changeColor(color).darken(0.2)};
7375
transform: rotateX(180deg) translateZ(40px);
7476
animation: blowout-back 4s infinite;
7577
}
7678
7779
.dash-cube-side--left {
78-
background-color: #0D76BF;
80+
background-color: ${changeColor(color).darken(0.2)};
7981
transform: rotateY(-90deg) translateZ(40px);
8082
animation: blowout-left 4s infinite;
8183
}
8284
8385
.dash-cube-side--right {
84-
background-color: #506784;
86+
background-color: ${changeColor(color).darken(0.4)};
8587
transform: rotateY(90deg) translateZ(40px);
8688
animation: blowout-right 4s infinite;
8789
}
8890
8991
.dash-cube-side--top {
90-
background-color: #0D76BF;
92+
background-color: ${changeColor(color).darken(0.2)};
9193
transform: rotateX(90deg) translateZ(40px);
9294
animation: blowout-top 4s infinite;
9395
}
9496
9597
.dash-cube-side--bottom {
96-
background-color: #119DFF;
98+
background-color: ${changeColor(color).darken(0.4)};
9799
transform: rotateX(-90deg) translateZ(40px);
98100
animation: blowout-bottom 4s infinite;
99101
}
@@ -184,6 +186,7 @@ const CubeSpinner = ({status, fullscreen, debug}) => {
184186

185187
CubeSpinner.propTypes = {
186188
status: PropTypes.object,
189+
color: PropTypes.string,
187190
fullscreen: PropTypes.bool,
188191
debug: PropTypes.bool,
189192
};

src/components/Loading/spinners/DefaultSpinner.jsx

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

4-
const DefaultSpinner = ({status, fullscreen, debug}) => {
4+
const DefaultSpinner = ({status, color, fullscreen, debug}) => {
55
let debugTitle;
6-
window.console.log('debug?', debug)
76
if (debug) {
87
debugTitle = (
98
<h3 className="dash-loading-title">
@@ -48,7 +47,7 @@ const DefaultSpinner = ({status, fullscreen, debug}) => {
4847
}
4948
5049
.spinner-verts > div {
51-
background-color: #119DFF;
50+
background-color: ${color};
5251
height: 100%;
5352
width: 6px;
5453
display: inline-block;
@@ -100,6 +99,7 @@ const DefaultSpinner = ({status, fullscreen, debug}) => {
10099

101100
DefaultSpinner.propTypes = {
102101
status: PropTypes.object,
102+
color: PropTypes.string,
103103
fullscreen: PropTypes.bool,
104104
debug: PropTypes.bool,
105105
};

src/components/Loading/spinners/DotSpinner.jsx

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

4-
const DotSpinner = ({status, fullscreen, debug}) => {
4+
const DotSpinner = ({status, color, fullscreen, debug}) => {
55
let debugTitle;
66
if (debug) {
77
debugTitle = (
@@ -45,7 +45,7 @@ const DotSpinner = ({status, fullscreen, debug}) => {
4545
.dash-dot-spinner > div {
4646
width: 18px;
4747
height: 18px;
48-
background-color: #119DFF;
48+
background-color: ${color};
4949
5050
border-radius: 100%;
5151
display: inline-block;
@@ -85,6 +85,7 @@ const DotSpinner = ({status, fullscreen, debug}) => {
8585

8686
DotSpinner.propTypes = {
8787
status: PropTypes.object,
88+
color: PropTypes.string,
8889
fullscreen: PropTypes.bool,
8990
debug: PropTypes.bool,
9091
};

0 commit comments

Comments
 (0)