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

Commit dd95b60

Browse files
guguMatt Goo
authored and
Matt Goo
committed
feat(snackbar): MDC Web v1.0.0 (#755)
1 parent 9b86474 commit dd95b60

File tree

6 files changed

+110
-103
lines changed

6 files changed

+110
-103
lines changed

package-lock.json

Lines changed: 93 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"radio",
4545
"ripple",
4646
"select",
47+
"snackbar",
4748
"top-app-bar",
4849
"switch",
4950
"tab",
@@ -80,7 +81,7 @@
8081
"@material/radio": "^0.41.0",
8182
"@material/ripple": "^1.0.0",
8283
"@material/select": "^0.40.1",
83-
"@material/snackbar": "^0.43.0",
84+
"@material/snackbar": "^1.0.0",
8485
"@material/switch": "^0.41.0",
8586
"@material/tab": "^1.0.0",
8687
"@material/tab-bar": "^0.41.0",

packages/snackbar/index.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@
2323
import * as React from 'react';
2424
import classnames from 'classnames';
2525

26-
// TODO: replace with MDC Web types when available
27-
import {IMDCSnackbarAdapter, IMDCSnackbarFoundation} from './types';
28-
29-
// @ts-ignore no .d.ts file
30-
import {MDCSnackbarFoundation} from '@material/snackbar';
26+
import {MDCSnackbarFoundation} from '@material/snackbar/foundation';
27+
import {MDCSnackbarAdapter} from '@material/snackbar/adapter';
3128

3229
export interface Props {
3330
message: string;
@@ -51,7 +48,7 @@ type State = {
5148
};
5249

5350
export class Snackbar extends React.Component<Props, State> {
54-
foundation: IMDCSnackbarFoundation
51+
foundation: MDCSnackbarFoundation
5552

5653
static defaultProps: Partial<Props> = {
5754
open: true,
@@ -84,7 +81,7 @@ export class Snackbar extends React.Component<Props, State> {
8481
this.foundation.setCloseOnEscape(closeOnEscape);
8582
}
8683
}
87-
get adapter(): IMDCSnackbarAdapter {
84+
get adapter(): MDCSnackbarAdapter {
8885
return {
8986
addClass: (className: string) => {
9087
const {classes} = this.state;

packages/snackbar/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/snackbar": "^0.43.0",
20+
"@material/snackbar": "^1.0.0",
2121
"classnames": "^2.2.6",
2222
"react": "^16.4.2"
2323
},

packages/snackbar/types.tsx

Lines changed: 0 additions & 49 deletions
This file was deleted.

test/unit/snackbar/index.test.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import * as td from 'testdouble';
33
import {assert} from 'chai';
44
import {shallow} from 'enzyme';
55
import {Snackbar} from '../../../packages/snackbar/index';
6+
import {MDCSnackbarAdapter} from '@material/snackbar/adapter';
7+
8+
function getAdapter(instance: Snackbar): MDCSnackbarAdapter {
9+
// @ts-ignore adapter_ is a protected property, we need to override it
10+
return instance.foundation.adapter_;
11+
}
612

713
suite('Snackbar');
814

@@ -71,7 +77,7 @@ test('opening notification works', () => {
7177
const openingHandler = td.func<() => void>();
7278
const wrapper = shallow<Snackbar>(
7379
<Snackbar open={false} onOpening={openingHandler} message='example' actionText='action' />);
74-
wrapper.instance().foundation.adapter_.notifyOpening();
80+
getAdapter(wrapper.instance()).notifyOpening();
7581
td.verify(openingHandler(), {times: 1});
7682
wrapper.unmount();
7783
});
@@ -80,7 +86,7 @@ test('open notification works', () => {
8086
const openHandler = td.func<() => void>();
8187
const wrapper = shallow<Snackbar>(
8288
<Snackbar open={false} onOpen={openHandler} message='example' actionText='action' />);
83-
wrapper.instance().foundation.adapter_.notifyOpened();
89+
getAdapter(wrapper.instance()).notifyOpened();
8490
td.verify(openHandler(), {times: 1});
8591
wrapper.unmount();
8692
});
@@ -89,7 +95,7 @@ test('closing notification works', () => {
8995
const closingHandler = td.func<(reason: string) => void>();
9096
const wrapper = shallow<Snackbar>(
9197
<Snackbar open={false} onClosing={closingHandler} message='example' actionText='action' />);
92-
wrapper.instance().foundation.adapter_.notifyClosing('unit_test');
98+
getAdapter(wrapper.instance()).notifyClosing('unit_test');
9399
td.verify(closingHandler('unit_test'), {times: 1});
94100
wrapper.unmount();
95101
});
@@ -98,7 +104,7 @@ test('close notification works', () => {
98104
const closeHandler = td.func<(reason: string) => void>();
99105
const wrapper = shallow<Snackbar>(
100106
<Snackbar open={false} onClose={closeHandler} message='example' actionText='action' />);
101-
wrapper.instance().foundation.adapter_.notifyClosed('unit_test');
107+
getAdapter(wrapper.instance()).notifyClosed('unit_test');
102108
td.verify(closeHandler('unit_test'), {times: 1});
103109
wrapper.unmount();
104110
});

0 commit comments

Comments
 (0)