Skip to content

Commit 70aaac4

Browse files
mbrookesmnajdovaoliviertassinari
authored
[CircularProgress] Backport simplified determinate style & deprecate static (#22094)
Co-authored-by: Marija Najdova <[email protected]> Co-authored-by: Olivier Tassinari <[email protected]>
1 parent 1d351a8 commit 70aaac4

File tree

9 files changed

+76
-48
lines changed

9 files changed

+76
-48
lines changed

docs/pages/api-docs/circular-progress.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The `MuiCircularProgress` name can be used for providing [default props](/custom
3737
| <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`. |
3838
| <span class="prop-name">size</span> | <span class="prop-type">number<br>&#124;&nbsp;string</span> | <span class="prop-default">40</span> | The size of the circle. If using a number, the pixel unit is assumed. If using a string, you need to provide the CSS unit, e.g '3rem'. |
3939
| <span class="prop-name">thickness</span> | <span class="prop-type">number</span> | <span class="prop-default">3.6</span> | The thickness of the circle. |
40-
| <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. |
40+
| <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 variant. Value between 0 and 100. |
4141
| <span class="prop-name">variant</span> | <span class="prop-type">'determinate'<br>&#124;&nbsp;'indeterminate'<br>&#124;&nbsp;'static'</span> | <span class="prop-default">'indeterminate'</span> | The variant to use. Use indeterminate when there is no progress value. |
4242

4343
The `ref` is forwarded to the root element.
@@ -51,12 +51,14 @@ Any other props supplied will be provided to the root element (native element).
5151
| <span class="prop-name">root</span> | <span class="prop-name">.MuiCircularProgress-root</span> | Styles applied to the root element.
5252
| <span class="prop-name">static</span> | <span class="prop-name">.MuiCircularProgress-static</span> | Styles applied to the root element if `variant="static"`.
5353
| <span class="prop-name">indeterminate</span> | <span class="prop-name">.MuiCircularProgress-indeterminate</span> | Styles applied to the root element if `variant="indeterminate"`.
54+
| <span class="prop-name">determinate</span> | <span class="prop-name">.MuiCircularProgress-determinate</span> | Styles applied to the root element if `variant="determinate"`.
5455
| <span class="prop-name">colorPrimary</span> | <span class="prop-name">.MuiCircularProgress-colorPrimary</span> | Styles applied to the root element if `color="primary"`.
5556
| <span class="prop-name">colorSecondary</span> | <span class="prop-name">.MuiCircularProgress-colorSecondary</span> | Styles applied to the root element if `color="secondary"`.
5657
| <span class="prop-name">svg</span> | <span class="prop-name">.MuiCircularProgress-svg</span> | Styles applied to the `svg` element.
5758
| <span class="prop-name">circle</span> | <span class="prop-name">.MuiCircularProgress-circle</span> | Styles applied to the `circle` svg path.
5859
| <span class="prop-name">circleStatic</span> | <span class="prop-name">.MuiCircularProgress-circleStatic</span> | Styles applied to the `circle` svg path if `variant="static"`.
5960
| <span class="prop-name">circleIndeterminate</span> | <span class="prop-name">.MuiCircularProgress-circleIndeterminate</span> | Styles applied to the `circle` svg path if `variant="indeterminate"`.
61+
| <span class="prop-name">circleDeterminate</span> | <span class="prop-name">.MuiCircularProgress-circleDeterminate</span> | Styles applied to the `circle` svg path if `variant="determinate"`.
6062
| <span class="prop-name">circleDisableShrink</span> | <span class="prop-name">.MuiCircularProgress-circleDisableShrink</span> | Styles applied to the `circle` svg path if `disableShrink={true}`.
6163

6264
You can override the style of the component thanks to one of these customization points:

docs/src/pages/components/progress/CircularStatic.js renamed to docs/src/pages/components/progress/CircularDeterminate.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const useStyles = makeStyles((theme) => ({
1111
},
1212
}));
1313

14-
export default function CircularStatic() {
14+
export default function CircularDeterminate() {
1515
const classes = useStyles();
1616
const [progress, setProgress] = React.useState(0);
1717

@@ -27,11 +27,11 @@ export default function CircularStatic() {
2727

2828
return (
2929
<div className={classes.root}>
30-
<CircularProgress variant="static" value={25} />
31-
<CircularProgress variant="static" value={50} />
32-
<CircularProgress variant="static" value={75} />
33-
<CircularProgress variant="static" value={100} />
34-
<CircularProgress variant="static" value={progress} />
30+
<CircularProgress variant="determinate" value={25} />
31+
<CircularProgress variant="determinate" value={50} />
32+
<CircularProgress variant="determinate" value={75} />
33+
<CircularProgress variant="determinate" value={100} />
34+
<CircularProgress variant="determinate" value={progress} />
3535
</div>
3636
);
3737
}

docs/src/pages/components/progress/CircularStatic.tsx renamed to docs/src/pages/components/progress/CircularDeterminate.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const useStyles = makeStyles((theme: Theme) =>
1313
}),
1414
);
1515

16-
export default function CircularStatic() {
16+
export default function CircularDeterminate() {
1717
const classes = useStyles();
1818
const [progress, setProgress] = React.useState(0);
1919

@@ -29,11 +29,11 @@ export default function CircularStatic() {
2929

3030
return (
3131
<div className={classes.root}>
32-
<CircularProgress variant="static" value={25} />
33-
<CircularProgress variant="static" value={50} />
34-
<CircularProgress variant="static" value={75} />
35-
<CircularProgress variant="static" value={100} />
36-
<CircularProgress variant="static" value={progress} />
32+
<CircularProgress variant="determinate" value={25} />
33+
<CircularProgress variant="determinate" value={50} />
34+
<CircularProgress variant="determinate" value={75} />
35+
<CircularProgress variant="determinate" value={100} />
36+
<CircularProgress variant="determinate" value={progress} />
3737
</div>
3838
);
3939
}

docs/src/pages/components/progress/CircularWithValueLabel.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Box from '@material-ui/core/Box';
77
function CircularProgressWithLabel(props) {
88
return (
99
<Box position="relative" display="inline-flex">
10-
<CircularProgress variant="static" {...props} />
10+
<CircularProgress variant="determinate" {...props} />
1111
<Box
1212
top={0}
1313
left={0}
@@ -28,7 +28,7 @@ function CircularProgressWithLabel(props) {
2828

2929
CircularProgressWithLabel.propTypes = {
3030
/**
31-
* The value of the progress indicator for the determinate and static variants.
31+
* The value of the progress indicator for the determinate variant.
3232
* Value between 0 and 100.
3333
*/
3434
value: PropTypes.number.isRequired,
@@ -39,7 +39,7 @@ export default function CircularStatic() {
3939

4040
React.useEffect(() => {
4141
const timer = setInterval(() => {
42-
setProgress((prevProgress) => (prevProgress >= 100 ? 10 : prevProgress + 10));
42+
setProgress((prevProgress) => (prevProgress >= 100 ? 0 : prevProgress + 10));
4343
}, 800);
4444
return () => {
4545
clearInterval(timer);

docs/src/pages/components/progress/CircularWithValueLabel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Box from '@material-ui/core/Box';
66
function CircularProgressWithLabel(props: CircularProgressProps & { value: number }) {
77
return (
88
<Box position="relative" display="inline-flex">
9-
<CircularProgress variant="static" {...props} />
9+
<CircularProgress variant="determinate" {...props} />
1010
<Box
1111
top={0}
1212
left={0}
@@ -30,7 +30,7 @@ export default function CircularStatic() {
3030

3131
React.useEffect(() => {
3232
const timer = setInterval(() => {
33-
setProgress((prevProgress) => (prevProgress >= 100 ? 10 : prevProgress + 10));
33+
setProgress((prevProgress) => (prevProgress >= 100 ? 0 : prevProgress + 10));
3434
}, 800);
3535
return () => {
3636
clearInterval(timer);

docs/src/pages/components/progress/progress.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ When displaying progress for a sequence of processes, indicate overall progress
2222

2323
### Circular determinate
2424

25-
{{"demo": "pages/components/progress/CircularStatic.js"}}
25+
{{"demo": "pages/components/progress/CircularDeterminate.js"}}
2626

2727
### Interactive integration
2828

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export interface CircularProgressProps
2727
*/
2828
thickness?: number;
2929
/**
30-
* The value of the progress indicator for the determinate and static variants.
30+
* The value of the progress indicator for the determinate variant.
3131
* Value between 0 and 100.
3232
*/
3333
value?: number;
@@ -41,12 +41,14 @@ export interface CircularProgressProps
4141
export type CircularProgressClassKey =
4242
| 'root'
4343
| 'static'
44+
| 'determinate'
4445
| 'indeterminate'
4546
| 'colorPrimary'
4647
| 'colorSecondary'
4748
| 'svg'
4849
| 'circle'
4950
| 'circleStatic'
51+
| 'circleDeterminate'
5052
| 'circleIndeterminate'
5153
| 'circleDisableShrink';
5254

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

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,6 @@ import capitalize from '../utils/capitalize';
77

88
const SIZE = 44;
99

10-
function getRelativeValue(value, min, max) {
11-
return (Math.min(Math.max(min, value), max) - min) / (max - min);
12-
}
13-
14-
function easeOut(t) {
15-
t = getRelativeValue(t, 0, 1);
16-
// https://gist.github.com/gre/1650294
17-
t = (t -= 1) * t * t + 1;
18-
return t;
19-
}
20-
21-
function easeIn(t) {
22-
return t * t;
23-
}
24-
2510
export const styles = (theme) => ({
2611
/* Styles applied to the root element. */
2712
root: {
@@ -35,6 +20,10 @@ export const styles = (theme) => ({
3520
indeterminate: {
3621
animation: '$circular-rotate 1.4s linear infinite',
3722
},
23+
/* Styles applied to the root element if `variant="determinate"`. */
24+
determinate: {
25+
transition: theme.transitions.create('transform'),
26+
},
3827
/* Styles applied to the root element if `color="primary"`. */
3928
colorPrimary: {
4029
color: theme.palette.primary.main,
@@ -64,6 +53,10 @@ export const styles = (theme) => ({
6453
strokeDasharray: '80px, 200px',
6554
strokeDashoffset: '0px', // Add the unit to fix a Edge 16 and below bug.
6655
},
56+
/* Styles applied to the `circle` svg path if `variant="determinate"`. */
57+
circleDeterminate: {
58+
transition: theme.transitions.create('stroke-dashoffset'),
59+
},
6760
'@keyframes circular-rotate': {
6861
'0%': {
6962
// Fix IE 11 wobbly
@@ -122,16 +115,8 @@ const CircularProgress = React.forwardRef(function CircularProgress(props, ref)
122115
const circumference = 2 * Math.PI * ((SIZE - thickness) / 2);
123116
circleStyle.strokeDasharray = circumference.toFixed(3);
124117
rootProps['aria-valuenow'] = Math.round(value);
125-
126-
if (variant === 'static') {
127-
circleStyle.strokeDashoffset = `${(((100 - value) / 100) * circumference).toFixed(3)}px`;
128-
rootStyle.transform = 'rotate(-90deg)';
129-
} else {
130-
circleStyle.strokeDashoffset = `${(easeIn((100 - value) / 100) * circumference).toFixed(
131-
3,
132-
)}px`;
133-
rootStyle.transform = `rotate(${(easeOut(value / 70) * 270).toFixed(3)}deg)`;
134-
}
118+
circleStyle.strokeDashoffset = `${(((100 - value) / 100) * circumference).toFixed(3)}px`;
119+
rootStyle.transform = 'rotate(-90deg)';
135120
}
136121

137122
return (
@@ -140,6 +125,7 @@ const CircularProgress = React.forwardRef(function CircularProgress(props, ref)
140125
classes.root,
141126
{
142127
[classes[`color${capitalize(color)}`]]: color !== 'inherit',
128+
[classes.determinate]: variant === 'determinate',
143129
[classes.indeterminate]: variant === 'indeterminate',
144130
[classes.static]: variant === 'static',
145131
},
@@ -154,6 +140,7 @@ const CircularProgress = React.forwardRef(function CircularProgress(props, ref)
154140
<svg className={classes.svg} viewBox={`${SIZE / 2} ${SIZE / 2} ${SIZE} ${SIZE}`}>
155141
<circle
156142
className={clsx(classes.circle, {
143+
[classes.circleDeterminate]: variant === 'determinate',
157144
[classes.circleIndeterminate]: variant === 'indeterminate',
158145
[classes.circleStatic]: variant === 'static',
159146
[classes.circleDisableShrink]: disableShrink,
@@ -217,15 +204,25 @@ CircularProgress.propTypes = {
217204
*/
218205
thickness: PropTypes.number,
219206
/**
220-
* The value of the progress indicator for the determinate and static variants.
207+
* The value of the progress indicator for the determinate variant.
221208
* Value between 0 and 100.
222209
*/
223210
value: PropTypes.number,
224211
/**
225212
* The variant to use.
226213
* Use indeterminate when there is no progress value.
227214
*/
228-
variant: PropTypes.oneOf(['determinate', 'indeterminate', 'static']),
215+
variant: chainPropTypes(PropTypes.oneOf(['determinate', 'indeterminate', 'static']), (props) => {
216+
const { variant } = props;
217+
218+
if (variant === 'static') {
219+
throw new Error(
220+
'Material-UI: `variant="static"` was deprecated. Use `variant="determinate"` instead.',
221+
);
222+
}
223+
224+
return null;
225+
}),
229226
};
230227

231228
export default withStyles(styles, { name: 'MuiCircularProgress', flip: false })(CircularProgress);

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as React from 'react';
2+
import * as PropTypes from 'prop-types';
23
import { expect } from 'chai';
4+
import { stub } from 'sinon';
35
import { createClientRender } from 'test/utils/createClientRender';
46
import { getClasses } from '@material-ui/core/test-utils';
57
import createMount from 'test/utils/createMount';
@@ -77,6 +79,15 @@ describe('<CircularProgress />', () => {
7779
});
7880

7981
describe('prop: variant="static', () => {
82+
beforeEach(() => {
83+
PropTypes.resetWarningCache();
84+
stub(console, 'error');
85+
});
86+
87+
afterEach(() => {
88+
console.error.restore();
89+
});
90+
8091
it('should set strokeDasharray of circle', () => {
8192
const { container } = render(<CircularProgress variant="static" value={70} />);
8293
const circularProgress = container.firstChild;
@@ -93,6 +104,22 @@ describe('<CircularProgress />', () => {
93104
);
94105
expect(circularProgress).to.have.attribute('aria-valuenow', '70');
95106
});
107+
108+
it('issues a warning for variant="static"', () => {
109+
PropTypes.checkPropTypes(
110+
CircularProgress.Naked.propTypes,
111+
{
112+
variant: 'static',
113+
},
114+
'props',
115+
'Avatar',
116+
);
117+
118+
expect(console.error.callCount).to.equal(1);
119+
expect(console.error.firstCall.args[0]).to.equal(
120+
'Warning: Failed props type: Material-UI: `variant="static"` was deprecated. Use `variant="determinate"` instead.',
121+
);
122+
});
96123
});
97124

98125
describe('prop: variant="determinate"', () => {
@@ -119,7 +146,7 @@ describe('<CircularProgress />', () => {
119146
'should have strokeDasharray set',
120147
);
121148
expect(circle.style.strokeDashoffset).to.equal(
122-
'11.423px',
149+
'38.076px',
123150
'should have strokeDashoffset set',
124151
);
125152
expect(circularProgress).to.have.attribute('aria-valuenow', '70');

0 commit comments

Comments
 (0)