Skip to content

Commit 6cca823

Browse files
joshwoodingoliviertassinari
authored andcommitted
[CircularProgress] Introduce disableShrink property (mui#13430)
* [CircularProgress] added shrinkAnimation prop [docs] added shrinkAnimation example * [docs] Updated Circular Progress API page * [docs] Fixed CircularProgress import * [CircularProgress] changed shrinkAnimation to disableShrinkAnimation [docs] changed shrinkAnimation to disableShrinkAnimation * add new demos
1 parent fa2b154 commit 6cca823

13 files changed

+176
-33
lines changed

.size-limit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = [
2828
name: 'The main docs bundle',
2929
webpack: false,
3030
path: main.path,
31-
limit: '182 KB',
31+
limit: '183 KB',
3232
},
3333
{
3434
name: 'The docs home page',

docs/src/pages/demos/progress/CircularDeterminate.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,8 @@ class CircularDeterminate extends React.Component {
3939
<CircularProgress
4040
className={classes.progress}
4141
variant="determinate"
42-
size={50}
4342
value={this.state.completed}
44-
/>
45-
<CircularProgress
46-
className={classes.progress}
4743
color="secondary"
48-
variant="determinate"
49-
value={this.state.completed}
50-
/>
51-
<CircularProgress
52-
className={classes.progress}
53-
color="secondary"
54-
variant="determinate"
55-
size={50}
56-
value={this.state.completed}
5744
/>
5845
</div>
5946
);

docs/src/pages/demos/progress/CircularIndeterminate.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import { withStyles } from '@material-ui/core/styles';
44
import CircularProgress from '@material-ui/core/CircularProgress';
5-
import purple from '@material-ui/core/colors/purple';
65

76
const styles = theme => ({
87
progress: {
@@ -15,9 +14,7 @@ function CircularIndeterminate(props) {
1514
return (
1615
<div>
1716
<CircularProgress className={classes.progress} />
18-
<CircularProgress className={classes.progress} size={50} />
1917
<CircularProgress className={classes.progress} color="secondary" />
20-
<CircularProgress className={classes.progress} style={{ color: purple[500] }} thickness={7} />
2118
</div>
2219
);
2320
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react';
2+
import CircularProgress from '@material-ui/core/CircularProgress';
3+
4+
function CircularUnderLoad() {
5+
return <CircularProgress disableShrink />;
6+
}
7+
8+
export default CircularUnderLoad;
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { withStyles } from '@material-ui/core/styles';
4+
import CircularProgress from '@material-ui/core/CircularProgress';
5+
import Paper from '@material-ui/core/Paper';
6+
import LinearProgress from '@material-ui/core/LinearProgress';
7+
8+
const styles = theme => ({
9+
root: {
10+
flexGrow: 1,
11+
},
12+
progress: {
13+
margin: theme.spacing.unit * 2,
14+
color: '#00695c',
15+
},
16+
linearColorPrimary: {
17+
backgroundColor: '#b2dfdb',
18+
},
19+
linearBarColorPrimary: {
20+
backgroundColor: '#00695c',
21+
},
22+
// Reproduce the Facebook spinners.
23+
facebook: {
24+
margin: theme.spacing.unit * 2,
25+
position: 'relative',
26+
},
27+
facebook1: {
28+
color: '#eef3fd',
29+
},
30+
facebook2: {
31+
color: '#6798e5',
32+
animationDuration: '550ms',
33+
position: 'absolute',
34+
left: 0,
35+
},
36+
});
37+
38+
function CustomizedProgress(props) {
39+
const { classes } = props;
40+
return (
41+
<Paper className={classes.root}>
42+
<CircularProgress className={classes.progress} size={30} thickness={5} />
43+
<LinearProgress
44+
classes={{
45+
colorPrimary: classes.linearColorPrimary,
46+
barColorPrimary: classes.linearBarColorPrimary,
47+
}}
48+
/>
49+
<div className={classes.facebook}>
50+
<CircularProgress
51+
variant="determinate"
52+
value={100}
53+
className={classes.facebook1}
54+
size={24}
55+
thickness={4}
56+
/>
57+
<CircularProgress
58+
variant="indeterminate"
59+
disableShrink
60+
className={classes.facebook2}
61+
size={24}
62+
thickness={4}
63+
/>
64+
</div>
65+
</Paper>
66+
);
67+
}
68+
69+
CustomizedProgress.propTypes = {
70+
classes: PropTypes.object.isRequired,
71+
};
72+
73+
export default withStyles(styles)(CustomizedProgress);

docs/src/pages/demos/progress/LinearIndeterminate.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ const styles = {
77
root: {
88
flexGrow: 1,
99
},
10-
colorPrimary: {
11-
backgroundColor: '#B2DFDB',
12-
},
13-
barColorPrimary: {
14-
backgroundColor: '#00695C',
15-
},
1610
};
1711

1812
function LinearIndeterminate(props) {
@@ -22,10 +16,6 @@ function LinearIndeterminate(props) {
2216
<LinearProgress />
2317
<br />
2418
<LinearProgress color="secondary" />
25-
<br />
26-
<LinearProgress
27-
classes={{ colorPrimary: classes.colorPrimary, barColorPrimary: classes.barColorPrimary }}
28-
/>
2919
</div>
3020
);
3121
}

docs/src/pages/demos/progress/progress.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ The progress components accept a value in the range 0 - 100. This simplifies thi
6767
```jsx
6868
// MIN = Minimum expected value
6969
// MAX = Maximium expected value
70-
7170
// Function to normalise the values (MIN / MAX could be integrated)
7271
const normalise = value => (value - MIN) * 100 / (MAX - MIN);
7372

@@ -91,11 +90,20 @@ After 1.0 second, you can display a loader to keep user's flow of thought uninte
9190

9291
{{"demo": "pages/demos/progress/DelayingAppearance.js"}}
9392

93+
## Customized Progress
94+
95+
The last demo demonstrates how you can build a Facebook like spinner.
96+
97+
{{"demo": "pages/demos/progress/CustomizedProgress.js"}}
98+
9499
## Limitations
95100

96101
Under heavy load, you might lose the stroke dash animation or see random CircularProgress ring widths.
97102
You should run processor intensive operations in a web worker or by batch in order not to block the main rendering thread.
98103

99104
![heavy load](/static/images/progress/heavy-load.gif)
100105

106+
When it's not possible, you can leverage the `disableShrink` property to mitigate the issue.
101107
See https://github.com/mui-org/material-ui/issues/10327
108+
109+
{{"demo": "pages/demos/progress/CircularUnderLoad.js"}}

packages/material-ui/src/CircularProgress/CircularProgress.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { StandardProps } from '..';
44
export interface CircularProgressProps
55
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, CircularProgressClassKey> {
66
color?: 'primary' | 'secondary' | 'inherit';
7+
disableShrink?: boolean;
78
size?: number | string;
89
thickness?: number;
910
value?: number;
@@ -19,7 +20,8 @@ export type CircularProgressClassKey =
1920
| 'svg'
2021
| 'circle'
2122
| 'circleStatic'
22-
| 'circleIndeterminate';
23+
| 'circleIndeterminate'
24+
| 'circleDisableShrink';
2325

2426
declare const CircularProgress: React.ComponentType<CircularProgressProps>;
2527

packages/material-ui/src/CircularProgress/CircularProgress.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
33
import classNames from 'classnames';
44
import withStyles from '../styles/withStyles';
55
import { capitalize } from '../utils/helpers';
6+
import chainPropTypes from '../utils/chainPropTypes';
67

78
const SIZE = 44;
89

@@ -82,6 +83,10 @@ export const styles = theme => ({
8283
strokeDashoffset: '-120px',
8384
},
8485
},
86+
/* Styles applied to the `circle` svg path if `disableShrink={true}`. */
87+
circleDisableShrink: {
88+
animation: 'none',
89+
},
8590
});
8691

8792
/**
@@ -92,7 +97,18 @@ export const styles = theme => ({
9297
* attribute to `true` on that region until it has finished loading.
9398
*/
9499
function CircularProgress(props) {
95-
const { classes, className, color, size, style, thickness, value, variant, ...other } = props;
100+
const {
101+
classes,
102+
className,
103+
color,
104+
disableShrink,
105+
size,
106+
style,
107+
thickness,
108+
value,
109+
variant,
110+
...other
111+
} = props;
96112

97113
const circleStyle = {};
98114
const rootStyle = {};
@@ -135,6 +151,7 @@ function CircularProgress(props) {
135151
className={classNames(classes.circle, {
136152
[classes.circleIndeterminate]: variant === 'indeterminate',
137153
[classes.circleStatic]: variant === 'static',
154+
[classes.circleDisableShrink]: disableShrink,
138155
})}
139156
style={circleStyle}
140157
cx={SIZE}
@@ -162,6 +179,21 @@ CircularProgress.propTypes = {
162179
* The color of the component. It supports those theme colors that make sense for this component.
163180
*/
164181
color: PropTypes.oneOf(['primary', 'secondary', 'inherit']),
182+
/**
183+
* If `true`, the shrink animation is disabled.
184+
* This only works if variant is `indeterminate`.
185+
*/
186+
disableShrink: chainPropTypes(PropTypes.bool, props => {
187+
/* istanbul ignore if */
188+
if (props.disableShrink && props.variant !== 'indeterminate') {
189+
return new Error(
190+
'Material-UI: you have provided the `disableShrink` property ' +
191+
'with a variant other than `indeterminate`. This will have no effect.',
192+
);
193+
}
194+
195+
return null;
196+
}),
165197
/**
166198
* The size of the circle.
167199
*/
@@ -188,6 +220,7 @@ CircularProgress.propTypes = {
188220

189221
CircularProgress.defaultProps = {
190222
color: 'primary',
223+
disableShrink: false,
191224
size: 40,
192225
thickness: 3.6,
193226
value: 0,

packages/material-ui/src/CircularProgress/CircularProgress.test.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,38 @@ describe('<CircularProgress />', () => {
105105
assert.strictEqual(wrapper.hasClass(classes.root), true);
106106
const svg = wrapper.childAt(0);
107107
const style = svg.childAt(0).props().style;
108-
assert.strictEqual(style.strokeDasharray, '126.920', 'should have strokeDasharray set');
109-
assert.strictEqual(style.strokeDashoffset, '11.423px', 'should have strokeDashoffset set');
108+
assert.strictEqual(style.strokeDasharray, '126.920');
109+
assert.strictEqual(style.strokeDashoffset, '11.423px');
110110
assert.strictEqual(wrapper.props()['aria-valuenow'], 70);
111111
});
112112
});
113+
114+
describe('prop: disableShrink ', () => {
115+
it('should default to false', () => {
116+
const wrapper = shallow(<CircularProgress variant="indeterminate" />);
117+
assert.strictEqual(wrapper.hasClass(classes.root), true);
118+
const svg = wrapper.childAt(0);
119+
const circle = svg.childAt(0);
120+
assert.strictEqual(circle.name(), 'circle');
121+
assert.strictEqual(circle.hasClass(classes.circleDisableShrink), false);
122+
});
123+
124+
it('should render without disableShrink class when set to false', () => {
125+
const wrapper = shallow(<CircularProgress variant="indeterminate" disableShrink={false} />);
126+
assert.strictEqual(wrapper.hasClass(classes.root), true);
127+
const svg = wrapper.childAt(0);
128+
const circle = svg.childAt(0);
129+
assert.strictEqual(circle.name(), 'circle');
130+
assert.strictEqual(circle.hasClass(classes.circleDisableShrink), false);
131+
});
132+
133+
it('should render with disableShrink class when set to true', () => {
134+
const wrapper = shallow(<CircularProgress variant="indeterminate" disableShrink />);
135+
assert.strictEqual(wrapper.hasClass(classes.root), true);
136+
const svg = wrapper.childAt(0);
137+
const circle = svg.childAt(0);
138+
assert.strictEqual(circle.name(), 'circle');
139+
assert.strictEqual(circle.hasClass(classes.circleDisableShrink), true);
140+
});
141+
});
113142
});

pages/api/circular-progress.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ attribute to `true` on that region until it has finished loading.
2525
|:-----|:-----|:--------|:------------|
2626
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> |   | Override or extend the styles applied to the component. See [CSS API](#css-api) below for more details. |
2727
| <span class="prop-name">color</span> | <span class="prop-type">enum:&nbsp;'primary'&nbsp;&#124;<br>&nbsp;'secondary'&nbsp;&#124;<br>&nbsp;'inherit'<br></span> | <span class="prop-default">'primary'</span> | The color of the component. It supports those theme colors that make sense for this component. |
28+
| <span class="prop-name">disableShrink</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the shrink animation is disabled. This only works if variant is `indeterminate`. |
2829
| <span class="prop-name">size</span> | <span class="prop-type">union:&nbsp;number&nbsp;&#124;<br>&nbsp;string<br></span> | <span class="prop-default">40</span> | The size of the circle. |
2930
| <span class="prop-name">thickness</span> | <span class="prop-type">number</span> | <span class="prop-default">3.6</span> | The thickness of the circle. |
3031
| <span class="prop-name">value</span> | <span class="prop-type">number</span> | <span class="prop-default">0</span> | The value of the progress indicator for the determinate and static variants. Value between 0 and 100. |
@@ -49,6 +50,7 @@ This property accepts the following keys:
4950
| <span class="prop-name">circle</span> | Styles applied to the `circle` svg path.
5051
| <span class="prop-name">circleStatic</span> | Styles applied to the `circle` svg path if `variant="static"`.
5152
| <span class="prop-name">circleIndeterminate</span> | Styles applied to the `circle` svg path if `variant="indeterminate"`.
53+
| <span class="prop-name">circleDisableShrink</span> | Styles applied to the `circle` svg path if `disableShrink={true}`.
5254

5355
Have a look at [overriding with classes](/customization/overrides/#overriding-with-classes) section
5456
and the [implementation of the component](https://github.com/mui-org/material-ui/tree/master/packages/material-ui/src/CircularProgress/CircularProgress.js)

pages/demos/progress.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ module.exports = require('fs')
7070
raw: preval`
7171
module.exports = require('fs')
7272
.readFileSync(require.resolve('docs/src/pages/demos/progress/DelayingAppearance'), 'utf8')
73+
`,
74+
},
75+
'pages/demos/progress/CustomizedProgress.js': {
76+
js: require('docs/src/pages/demos/progress/CustomizedProgress').default,
77+
raw: preval`
78+
module.exports = require('fs')
79+
.readFileSync(require.resolve('docs/src/pages/demos/progress/CustomizedProgress'), 'utf8')
80+
`,
81+
},
82+
'pages/demos/progress/CircularUnderLoad.js': {
83+
js: require('docs/src/pages/demos/progress/CircularUnderLoad').default,
84+
raw: preval`
85+
module.exports = require('fs')
86+
.readFileSync(require.resolve('docs/src/pages/demos/progress/CircularUnderLoad'), 'utf8')
7387
`,
7488
},
7589
}}

pages/getting-started/installation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
55
const req = require.context('markdown', true, /.md$/);
66

77
function Page(props) {
8-
return <MarkdownDocs markdown={req(`./installation${props.lang}.md`)} />;
8+
return <MarkdownDocs disableAd markdown={req(`./installation${props.lang}.md`)} />;
99
}
1010

1111
export default withRoot(Page);

0 commit comments

Comments
 (0)