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

Commit 0ceb2de

Browse files
wbrgssalexcjohnson
andauthored
Allow parent_className and parent_style attributes on dcc.Loading components (#840)
* Allow for className on parent of completed loading children, add parent_style prop * (suggestion) avoid unnecessary mergeRight call in ternary eval Co-authored-by: alexcjohnson <[email protected]> * Add parent_className prop and only apply className to Spinner * Test new loading style attributes * black * Loading component graph test * Prop description * extra comma * remove print statements * fix integration tests by removing explicit keyword args * update CHANGELOG Co-authored-by: alexcjohnson <[email protected]>
1 parent 543a5c9 commit 0ceb2de

File tree

4 files changed

+405
-233
lines changed

4 files changed

+405
-233
lines changed

Diff for: CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [Unreleased]
6+
### Added
7+
- [#840](https://github.com/plotly/dash-table/pull/840) Add styling properties to `dcc.Loading` component
8+
+ `parent_className`: Add CSS class for the outermost `dcc.Loading` parent div DOM node
9+
+ `parent_style`: Add CSS style property for the outermost `dcc.Loading` parent div DOM node
10+
+ provides a workaround for the previous behaviour the of `className` property, which changed in [#740](https://github.com/plotly/dash-core-components/pull/740). `parent_className` (or inline styles in `parent_style`) now allow CSS rules to be applied to the outermost `dcc.Loading` div, which is no longer covered by `className` on loading completion as of Dash Core Components `>= 1.9.1` (Dash `>= 1.11.0`).
11+
512
## [1.10.2] - 2020-07-27
613
- [#835](https://github.com/plotly/dash-core-components/pull/835)
714
- Upgraded Plotly.js to [1.54.7](https://github.com/plotly/plotly.js/releases/tag/v1.54.7)

Diff for: src/components/Loading.react.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import DefaultSpinner from '../fragments/Loading/spinners/DefaultSpinner.jsx';
55
import CubeSpinner from '../fragments/Loading/spinners/CubeSpinner.jsx';
66
import CircleSpinner from '../fragments/Loading/spinners/CircleSpinner.jsx';
77
import DotSpinner from '../fragments/Loading/spinners/DotSpinner.jsx';
8+
import {mergeRight} from 'ramda';
89

910
function getSpinner(spinnerType) {
1011
switch (spinnerType) {
@@ -44,6 +45,8 @@ export default class Loading extends Component {
4445
color,
4546
className,
4647
style,
48+
parent_className,
49+
parent_style,
4750
fullscreen,
4851
debug,
4952
type: spinnerType,
@@ -53,7 +56,14 @@ export default class Loading extends Component {
5356
const Spinner = isLoading && getSpinner(spinnerType);
5457

5558
return (
56-
<div style={isLoading ? hiddenContainer : {}}>
59+
<div
60+
className={parent_className}
61+
style={
62+
isLoading
63+
? mergeRight(hiddenContainer, parent_style)
64+
: parent_style
65+
}
66+
>
5767
{this.props.children}
5868
<div style={isLoading ? coveringSpinner : {}}>
5969
{isLoading && (
@@ -117,11 +127,21 @@ Loading.propTypes = {
117127
*/
118128
className: PropTypes.string,
119129

130+
/**
131+
* Additional CSS class for the outermost dcc.Loading parent div DOM node
132+
*/
133+
parent_className: PropTypes.string,
134+
120135
/**
121136
* Additional CSS styling for the spinner root DOM node
122137
*/
123138
style: PropTypes.object,
124139

140+
/**
141+
* Additional CSS styling for the outermost dcc.Loading parent div DOM node
142+
*/
143+
parent_style: PropTypes.object,
144+
125145
/**
126146
* Primary colour used for the loading spinners
127147
*/

Diff for: tests/integration/loading/test_loading_component.py

+85
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,88 @@ def get_graph_visibility():
278278
assert len(dash_dcc.find_elements(".js-plotly-plot .bars path")) == 4
279279
assert dash_dcc.driver.execute_script(test_identity)
280280
assert get_graph_visibility() == "visible"
281+
282+
283+
def test_ldcp007_class_and_style_props(dash_dcc):
284+
lock = Lock()
285+
286+
app = dash.Dash(__name__)
287+
288+
app.layout = html.Div(
289+
[
290+
html.Button("click", id="btn"),
291+
dcc.Loading(
292+
id="loading",
293+
className="spinner-class",
294+
parent_className="parent-class",
295+
style={"background-color": "rgb(255,192,203)"},
296+
# rgb(240, 248, 255) = aliceblue
297+
parent_style={"border": "3px solid rgb(240, 248, 255)"},
298+
children=html.Div(id="loading-child"),
299+
),
300+
]
301+
)
302+
303+
@app.callback(Output("loading-child", "children"), [Input("btn", "n_clicks")])
304+
def updateDiv(n_clicks):
305+
if n_clicks is None:
306+
return
307+
308+
with lock:
309+
return "sample text content"
310+
311+
dash_dcc.start_server(app)
312+
313+
dash_dcc.wait_for_style_to_equal(
314+
".parent-class", "border-color", "rgb(240, 248, 255)"
315+
)
316+
317+
with lock:
318+
button = dash_dcc.find_element("#btn")
319+
button.click()
320+
dash_dcc.wait_for_style_to_equal(
321+
".spinner-class", "background-color", "rgba(255, 192, 203, 1)"
322+
)
323+
324+
assert not dash_dcc.get_logs()
325+
326+
327+
def test_ldcp008_graph_in_loading_fits_container_height(dash_dcc):
328+
lock = Lock()
329+
330+
app = dash.Dash(__name__)
331+
332+
app.layout = html.Div(
333+
className="outer-container",
334+
children=[
335+
html.Div(
336+
dcc.Loading(
337+
parent_style={"height": "100%"},
338+
children=dcc.Graph(
339+
style={"height": "100%"},
340+
figure={
341+
"data": [
342+
{
343+
"x": [1, 2, 3, 4],
344+
"y": [4, 1, 6, 9],
345+
"line": {"shape": "spline"},
346+
}
347+
]
348+
},
349+
),
350+
),
351+
)
352+
],
353+
style={"display": "flex", "height": "300px"},
354+
)
355+
356+
dash_dcc.start_server(app)
357+
358+
with lock:
359+
dash_dcc.wait_for_style_to_equal(".js-plotly-plot", "height", "300px")
360+
361+
assert dash_dcc.wait_for_element(".js-plotly-plot").size.get(
362+
"height"
363+
) == dash_dcc.wait_for_element(".outer-container").size.get("height")
364+
365+
assert not dash_dcc.get_logs()

0 commit comments

Comments
 (0)