Skip to content

Commit

Permalink
feat(snackbar): MDC Web v1.0.0 (#755)
Browse files Browse the repository at this point in the history
  • Loading branch information
gugu authored and Matt Goo committed Apr 30, 2019
1 parent 9b86474 commit dd95b60
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 103 deletions.
134 changes: 93 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"radio",
"ripple",
"select",
"snackbar",
"top-app-bar",
"switch",
"tab",
Expand Down Expand Up @@ -80,7 +81,7 @@
"@material/radio": "^0.41.0",
"@material/ripple": "^1.0.0",
"@material/select": "^0.40.1",
"@material/snackbar": "^0.43.0",
"@material/snackbar": "^1.0.0",
"@material/switch": "^0.41.0",
"@material/tab": "^1.0.0",
"@material/tab-bar": "^0.41.0",
Expand Down
11 changes: 4 additions & 7 deletions packages/snackbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@
import * as React from 'react';
import classnames from 'classnames';

// TODO: replace with MDC Web types when available
import {IMDCSnackbarAdapter, IMDCSnackbarFoundation} from './types';

// @ts-ignore no .d.ts file
import {MDCSnackbarFoundation} from '@material/snackbar';
import {MDCSnackbarFoundation} from '@material/snackbar/foundation';
import {MDCSnackbarAdapter} from '@material/snackbar/adapter';

export interface Props {
message: string;
Expand All @@ -51,7 +48,7 @@ type State = {
};

export class Snackbar extends React.Component<Props, State> {
foundation: IMDCSnackbarFoundation
foundation: MDCSnackbarFoundation

static defaultProps: Partial<Props> = {
open: true,
Expand Down Expand Up @@ -84,7 +81,7 @@ export class Snackbar extends React.Component<Props, State> {
this.foundation.setCloseOnEscape(closeOnEscape);
}
}
get adapter(): IMDCSnackbarAdapter {
get adapter(): MDCSnackbarAdapter {
return {
addClass: (className: string) => {
const {classes} = this.state;
Expand Down
2 changes: 1 addition & 1 deletion packages/snackbar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"url": "https://github.com/material-components/material-components-web-react.git"
},
"dependencies": {
"@material/snackbar": "^0.43.0",
"@material/snackbar": "^1.0.0",
"classnames": "^2.2.6",
"react": "^16.4.2"
},
Expand Down
49 changes: 0 additions & 49 deletions packages/snackbar/types.tsx

This file was deleted.

14 changes: 10 additions & 4 deletions test/unit/snackbar/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import * as td from 'testdouble';
import {assert} from 'chai';
import {shallow} from 'enzyme';
import {Snackbar} from '../../../packages/snackbar/index';
import {MDCSnackbarAdapter} from '@material/snackbar/adapter';

function getAdapter(instance: Snackbar): MDCSnackbarAdapter {
// @ts-ignore adapter_ is a protected property, we need to override it
return instance.foundation.adapter_;
}

suite('Snackbar');

Expand Down Expand Up @@ -71,7 +77,7 @@ test('opening notification works', () => {
const openingHandler = td.func<() => void>();
const wrapper = shallow<Snackbar>(
<Snackbar open={false} onOpening={openingHandler} message='example' actionText='action' />);
wrapper.instance().foundation.adapter_.notifyOpening();
getAdapter(wrapper.instance()).notifyOpening();
td.verify(openingHandler(), {times: 1});
wrapper.unmount();
});
Expand All @@ -80,7 +86,7 @@ test('open notification works', () => {
const openHandler = td.func<() => void>();
const wrapper = shallow<Snackbar>(
<Snackbar open={false} onOpen={openHandler} message='example' actionText='action' />);
wrapper.instance().foundation.adapter_.notifyOpened();
getAdapter(wrapper.instance()).notifyOpened();
td.verify(openHandler(), {times: 1});
wrapper.unmount();
});
Expand All @@ -89,7 +95,7 @@ test('closing notification works', () => {
const closingHandler = td.func<(reason: string) => void>();
const wrapper = shallow<Snackbar>(
<Snackbar open={false} onClosing={closingHandler} message='example' actionText='action' />);
wrapper.instance().foundation.adapter_.notifyClosing('unit_test');
getAdapter(wrapper.instance()).notifyClosing('unit_test');
td.verify(closingHandler('unit_test'), {times: 1});
wrapper.unmount();
});
Expand All @@ -98,7 +104,7 @@ test('close notification works', () => {
const closeHandler = td.func<(reason: string) => void>();
const wrapper = shallow<Snackbar>(
<Snackbar open={false} onClose={closeHandler} message='example' actionText='action' />);
wrapper.instance().foundation.adapter_.notifyClosed('unit_test');
getAdapter(wrapper.instance()).notifyClosed('unit_test');
td.verify(closeHandler('unit_test'), {times: 1});
wrapper.unmount();
});
Expand Down

0 comments on commit dd95b60

Please sign in to comment.