Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 37c7269

Browse files
guguMatt Goo
authored and
Matt Goo
committed
fix(linear-progress): upgrade mdc-web to v1 (#787)
1 parent b6403e6 commit 37c7269

File tree

5 files changed

+54
-35
lines changed

5 files changed

+54
-35
lines changed

package-lock.json

Lines changed: 30 additions & 11 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"@material/icon-button": "^0.41.0",
7575
"@material/layout-grid": "^0.41.0",
7676
"@material/line-ripple": "^1.0.0",
77-
"@material/linear-progress": "^0.41.0",
77+
"@material/linear-progress": "^1.1.0",
7878
"@material/list": "^1.0.0",
7979
"@material/menu-surface": "^1.0.1",
8080
"@material/notched-outline": "^0.41.0",

packages/linear-progress/index.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
import classnames from 'classnames';
2424
import * as React from 'react';
25-
// @ts-ignore no .d.ts file
26-
import {MDCLinearProgressFoundation} from '@material/linear-progress/dist/mdc.linearProgress';
25+
import {MDCLinearProgressFoundation} from '@material/linear-progress/foundation';
26+
import {MDCLinearProgressAdapter} from '@material/linear-progress/adapter';
2727

2828
export interface LinearProgressProps<T> extends React.HTMLProps<T> {
2929
buffer?: number;
@@ -72,10 +72,10 @@ class LinearProgress<T extends {} = HTMLDivElement> extends React.Component<
7272
const {buffer, closed, indeterminate, progress, reversed} = this.props;
7373
this.isComponentMounted = true;
7474
this.foundation.init();
75-
this.foundation.setBuffer(buffer);
75+
this.foundation.setBuffer(buffer!);
7676
this.foundation.setDeterminate(!indeterminate);
77-
this.foundation.setProgress(progress);
78-
this.foundation.setReverse(reversed);
77+
this.foundation.setProgress(progress!);
78+
this.foundation.setReverse(reversed!);
7979
if (closed) {
8080
this.foundation.close();
8181
}
@@ -91,7 +91,7 @@ class LinearProgress<T extends {} = HTMLDivElement> extends React.Component<
9191
} = prevProps;
9292
const {buffer, closed, indeterminate, progress, reversed} = this.props;
9393
if (buffer !== prevBuffer) {
94-
this.foundation.setBuffer(buffer);
94+
this.foundation.setBuffer(buffer!);
9595
}
9696
if (closed && !prevClosed) {
9797
this.foundation.close();
@@ -103,10 +103,10 @@ class LinearProgress<T extends {} = HTMLDivElement> extends React.Component<
103103
this.foundation.setDeterminate(!indeterminate);
104104
}
105105
if (progress !== prevProgress) {
106-
this.foundation.setProgress(progress);
106+
this.foundation.setProgress(progress!);
107107
}
108108
if (reversed !== prevReversed) {
109-
this.foundation.setReverse(reversed);
109+
this.foundation.setReverse(reversed!);
110110
}
111111
}
112112

@@ -115,7 +115,7 @@ class LinearProgress<T extends {} = HTMLDivElement> extends React.Component<
115115
this.foundation.destroy();
116116
}
117117

118-
get adapter() {
118+
get adapter(): MDCLinearProgressAdapter {
119119
return {
120120
addClass: (className: string) => {
121121
if (this.isComponentMounted) {

packages/linear-progress/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"url": "https://github.com/material-components/material-components-web-react.git"
1818
},
1919
"dependencies": {
20-
"@material/linear-progress": "^0.41.0",
20+
"@material/linear-progress": "^1.1.0",
2121
"classnames": "^2.2.6",
2222
"react": "^16.4.2"
2323
},

test/unit/linear-progress/index.test.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,97 +68,97 @@ test('Keeps custom props', () => {
6868
test('#foundation.init gets called when the component mounts', () => {
6969
const wrapper = mount<LinearProgress>(<LinearProgress />);
7070
const instance = wrapper.instance();
71-
instance.foundation.init = td.func();
71+
instance.foundation.init = td.func<() => void>();
7272
instance.componentDidMount();
7373
td.verify(instance.foundation.init(), {times: 1});
7474
});
7575

7676
test('#foundation.setBuffer gets called when the component mounts', () => {
7777
const wrapper = mount<LinearProgress>(<LinearProgress buffer={0.1} />);
7878
const instance = wrapper.instance();
79-
instance.foundation.setBuffer = td.func();
79+
instance.foundation.setBuffer = td.func<(value: number) => void>();
8080
instance.componentDidMount();
8181
td.verify(instance.foundation.setBuffer(0.1), {times: 1});
8282
});
8383

8484
test('#foundation.setDeterminate gets called when the component mounts', () => {
8585
const wrapper = mount<LinearProgress>(<LinearProgress indeterminate={true} />);
8686
const instance = wrapper.instance();
87-
instance.foundation.setDeterminate = td.func();
87+
instance.foundation.setDeterminate = td.func<(isDeterminate: boolean) => void>();
8888
instance.componentDidMount();
8989
td.verify(instance.foundation.setDeterminate(false), {times: 1});
9090
});
9191

9292
test('#foundation.setProgress gets called when the component mounts', () => {
9393
const wrapper = mount<LinearProgress>(<LinearProgress progress={0.1} />);
9494
const instance = wrapper.instance();
95-
instance.foundation.setProgress = td.func();
95+
instance.foundation.setProgress = td.func<(value: number) => null>();
9696
instance.componentDidMount();
9797
td.verify(instance.foundation.setProgress(0.1), {times: 1});
9898
});
9999

100100
test('#foundation.setReverse gets called when the component mounts', () => {
101101
const wrapper = mount<LinearProgress>(<LinearProgress reversed={true} />);
102102
const instance = wrapper.instance();
103-
instance.foundation.setReverse = td.func();
103+
instance.foundation.setReverse = td.func<(isReversed: boolean) => void>();
104104
instance.componentDidMount();
105105
td.verify(instance.foundation.setReverse(true), {times: 1});
106106
});
107107

108108
test('#foundation.close gets called when the component mounts', () => {
109109
const wrapper = mount<LinearProgress>(<LinearProgress closed />);
110110
const instance = wrapper.instance();
111-
instance.foundation.close = td.func();
111+
instance.foundation.close = td.func<() => void>();
112112
instance.componentDidMount();
113113
td.verify(instance.foundation.close(), {times: 1});
114114
});
115115

116116
test('#foundation.setBuffer gets called when props.buffer updates', () => {
117117
const wrapper = mount<LinearProgress>(<LinearProgress buffer={0.1} />);
118-
wrapper.instance().foundation.setBuffer = td.func();
118+
wrapper.instance().foundation.setBuffer = td.func<(value: number) => void>();
119119
wrapper.setProps({buffer: 0.2});
120120
td.verify(wrapper.instance().foundation.setBuffer(0.2), {times: 1});
121121
});
122122

123123
test('#foundation.close gets called when props.closed updates', () => {
124124
const wrapper = mount<LinearProgress>(<LinearProgress closed={false} />);
125-
wrapper.instance().foundation.close = td.func();
125+
wrapper.instance().foundation.close = td.func<() => void>();
126126
wrapper.setProps({closed: true});
127127
td.verify(wrapper.instance().foundation.close(), {times: 1});
128128
});
129129

130130
test('#foundation.open gets called when props.closed updates', () => {
131131
const wrapper = mount<LinearProgress>(<LinearProgress closed={true} />);
132-
wrapper.instance().foundation.open = td.func();
132+
wrapper.instance().foundation.open = td.func<() => void>();
133133
wrapper.setProps({closed: false});
134134
td.verify(wrapper.instance().foundation.open(), {times: 1});
135135
});
136136

137137
test('#foundation.setDeterminate gets called when props.indeterminate updates', () => {
138138
const wrapper = mount<LinearProgress>(<LinearProgress indeterminate={false} />);
139-
wrapper.instance().foundation.setDeterminate = td.func();
139+
wrapper.instance().foundation.setDeterminate = td.func<(isDeterminate: boolean) => void>();
140140
wrapper.setProps({indeterminate: true});
141141
td.verify(wrapper.instance().foundation.setDeterminate(false), {times: 1});
142142
});
143143

144144
test('#foundation.setProgress gets called when props.progress updates', () => {
145145
const wrapper = mount<LinearProgress>(<LinearProgress progress={0.1} />);
146-
wrapper.instance().foundation.setProgress = td.func();
146+
wrapper.instance().foundation.setProgress = td.func<(value: number) => void>();
147147
wrapper.setProps({progress: 0.2});
148148
td.verify(wrapper.instance().foundation.setProgress(0.2), {times: 1});
149149
});
150150

151151
test('#foundation.setReverse gets called when props.reversed updates', () => {
152152
const wrapper = mount<LinearProgress>(<LinearProgress reversed={false} />);
153-
wrapper.instance().foundation.setReverse = td.func();
153+
wrapper.instance().foundation.setReverse = td.func<(isReversed: boolean) => void>();
154154
wrapper.setProps({reversed: true});
155155
td.verify(wrapper.instance().foundation.setReverse(true), {times: 1});
156156
});
157157

158158
test('#foundation.destroy gets called when the component unmounts', () => {
159159
const wrapper = mount<LinearProgress>(<LinearProgress />);
160160
const instance = wrapper.instance();
161-
instance.foundation.destroy = td.func();
161+
instance.foundation.destroy = td.func<() => void>();
162162
wrapper.unmount();
163163
td.verify(instance.foundation.destroy(), {times: 1});
164164
});

0 commit comments

Comments
 (0)