UNPKG

preact-material-components

Version:
55 lines 1.85 kB
import { MDCSnackbar } from '@material/snackbar/'; import { h } from 'preact'; import MaterialComponent from '../Base/MaterialComponent'; // TODO: Is that needed? function shallowDiffers(a, b) { for (const i in a) { if (!(i in b)) { return true; } } for (const i in b) { // noinspection JSUnfilteredForInLoop if (a[i] !== b[i]) { return true; } } return false; } export class Snackbar extends MaterialComponent { constructor() { super(...arguments); this.componentName = 'snackbar'; this.mdcProps = []; } componentDidMount() { super.componentDidMount(); if (this.control) { this.MDComponent = new MDCSnackbar(this.control); if (this.props.dismissesOnAction === undefined || this.props.dismissesOnAction === null) { this.MDComponent.dismissesOnAction = true; } else { this.MDComponent.dismissesOnAction = this.props.dismissesOnAction; } } } componentWillUnmount() { super.componentWillUnmount(); if (this.MDComponent) { this.MDComponent.destroy(); } } shouldComponentUpdate(props, state) { return (shallowDiffers(this.props, props) || shallowDiffers(this.state, state)); } materialDom(props) { return (h("div", Object.assign({ "aria-live": "assertive", "aria-atomic": "true", "aria-hidden": "true", ref: this.setControlRef }, props), h("div", { className: "mdc-snackbar__text" }), h("div", { className: "mdc-snackbar__action-wrapper" }, h("button", { type: "button", className: "mdc-snackbar__action-button" })))); } } export default Snackbar; //# sourceMappingURL=index.js.map