Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LinearProgress] Add determinate and indeterminate classes to root element #13828

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/material-ui/src/LinearProgress/LinearProgress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export type LinearProgressClassKey =
| 'root'
| 'colorPrimary'
| 'colorSecondary'
| 'determinate'
| 'indeterminate'
| 'buffer'
| 'query'
| 'dashed'
Expand Down
6 changes: 6 additions & 0 deletions packages/material-ui/src/LinearProgress/LinearProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export const styles = theme => ({
colorSecondary: {
backgroundColor: lighten(theme.palette.secondary.light, 0.4),
},
/* Styles applied to the root element if `variant="determinate"`. */
determinate: {},
/* Styles applied to the root element if `variant="indeterminate"`. */
indeterminate: {},
/* Styles applied to the root element if `variant="buffer"`. */
buffer: {
backgroundColor: 'transparent',
Expand Down Expand Up @@ -169,6 +173,8 @@ function LinearProgress(props) {
{
[classes.colorPrimary]: color === 'primary',
[classes.colorSecondary]: color === 'secondary',
[classes.determinate]: variant === 'determinate',
[classes.indeterminate]: variant === 'indeterminate',
[classes.buffer]: variant === 'buffer',
[classes.query]: variant === 'query',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ describe('<LinearProgress />', () => {
assert.strictEqual(wrapper.hasClass(classes.root), true);
});

it('should render intermediate variant by default', () => {
it('should render indeterminate variant by default', () => {
const wrapper = shallow(<LinearProgress />);
assert.strictEqual(wrapper.hasClass(classes.root), true);
assert.strictEqual(wrapper.hasClass(classes.indeterminate), true);
assert.strictEqual(wrapper.childAt(0).hasClass(classes.barColorPrimary), true);
assert.strictEqual(wrapper.childAt(0).hasClass(classes.bar1Indeterminate), true);
assert.strictEqual(wrapper.childAt(1).hasClass(classes.barColorPrimary), true);
Expand All @@ -51,27 +52,31 @@ describe('<LinearProgress />', () => {
it('should render with determinate classes for the primary color by default', () => {
const wrapper = shallow(<LinearProgress value={1} variant="determinate" />);
assert.strictEqual(wrapper.hasClass(classes.root), true);
assert.strictEqual(wrapper.hasClass(classes.determinate), true);
assert.strictEqual(wrapper.childAt(0).hasClass(classes.barColorPrimary), true);
assert.strictEqual(wrapper.childAt(0).hasClass(classes.bar1Determinate), true);
});

it('should render with determinate classes for the primary color', () => {
const wrapper = shallow(<LinearProgress color="primary" value={1} variant="determinate" />);
assert.strictEqual(wrapper.hasClass(classes.root), true);
assert.strictEqual(wrapper.hasClass(classes.determinate), true);
assert.strictEqual(wrapper.childAt(0).hasClass(classes.barColorPrimary), true);
assert.strictEqual(wrapper.childAt(0).hasClass(classes.bar1Determinate), true);
});

it('should render with determinate classes for the secondary color', () => {
const wrapper = shallow(<LinearProgress color="secondary" value={1} variant="determinate" />);
assert.strictEqual(wrapper.hasClass(classes.root), true);
assert.strictEqual(wrapper.hasClass(classes.determinate), true);
assert.strictEqual(wrapper.childAt(0).hasClass(classes.barColorSecondary), true);
assert.strictEqual(wrapper.childAt(0).hasClass(classes.bar1Determinate), true);
});

it('should set width of bar1 on determinate variant', () => {
const wrapper = shallow(<LinearProgress variant="determinate" value={77} />);
assert.strictEqual(wrapper.hasClass(classes.root), true);
assert.strictEqual(wrapper.hasClass(classes.determinate), true);
assert.strictEqual(
wrapper.childAt(0).props().style.transform,
'scaleX(0.77)',
Expand Down
2 changes: 2 additions & 0 deletions pages/api/linear-progress.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ This property accepts the following keys:
| <span class="prop-name">root</span> | Styles applied to the root element.
| <span class="prop-name">colorPrimary</span> | Styles applied to the root & bar2 element if `color="primary"`; bar2 if `variant-"buffer"`.
| <span class="prop-name">colorSecondary</span> | Styles applied to the root & bar2 elements if `color="secondary"`; bar2 if `variant="buffer"`.
| <span class="prop-name">determinate</span> | Styles applied to the root element if `variant="determinate"`.
| <span class="prop-name">indeterminate</span> | Styles applied to the root element if `variant="indeterminate"`.
| <span class="prop-name">buffer</span> | Styles applied to the root element if `variant="buffer"`.
| <span class="prop-name">query</span> | Styles applied to the root element if `variant="query"`.
| <span class="prop-name">dashed</span> | Styles applied to the additional bar element if `variant="buffer"`.
Expand Down