preact-material-components
Version:
preact wrapper for "Material Components for the web"
115 lines • 3.98 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { MDCDialog } from '@material/dialog/';
import { bind } from 'bind-decorator';
import { h } from 'preact';
import MaterialComponent from '../Base/MaterialComponent';
import { Button } from '../Button';
export class DialogHeader extends MaterialComponent {
constructor() {
super(...arguments);
this.componentName = 'dialog__header';
this.mdcProps = [];
}
materialDom(props) {
return (h("header", Object.assign({}, props),
h("h2", { className: "mdc-dialog__header__title" }, props.children)));
}
}
__decorate([
bind
], DialogHeader.prototype, "materialDom", null);
export class DialogBody extends MaterialComponent {
constructor() {
super(...arguments);
this.componentName = 'dialog__body';
this.mdcProps = ['scrollable'];
}
materialDom(props) {
return h("section", Object.assign({}, props), props.children);
}
}
__decorate([
bind
], DialogBody.prototype, "materialDom", null);
export class DialogFooter extends MaterialComponent {
constructor() {
super(...arguments);
this.componentName = 'dialog__footer';
this.mdcProps = [];
}
materialDom(props) {
return h("footer", Object.assign({}, props), props.children);
}
}
__decorate([
bind
], DialogFooter.prototype, "materialDom", null);
export class DialogFooterButton extends Button {
constructor() {
super(...arguments);
this.componentName = 'dialog__footer__button';
this.mdcProps = ['cancel', 'accept'];
}
materialDom(props) {
return (h("button", Object.assign({}, props, { className: "mdc-button", ref: this.setControlRef }), props.children));
}
}
__decorate([
bind
], DialogFooterButton.prototype, "materialDom", null);
export class Dialog extends MaterialComponent {
constructor() {
super(...arguments);
this.componentName = 'dialog';
this.mdcProps = [];
}
componentDidMount() {
super.componentDidMount();
if (this.control) {
this.MDComponent = new MDCDialog(this.control);
this.MDComponent.listen('MDCDialog:accept', this.onAccept);
this.MDComponent.listen('MDCDialog:cancel', this.onCancel);
}
}
componentWillUnmount() {
super.componentWillUnmount();
if (this.MDComponent) {
this.MDComponent.unlisten('MDCDialog:accept', this.onAccept);
this.MDComponent.unlisten('MDCDialog:cancel', this.onCancel);
this.MDComponent.destroy();
}
}
onAccept(e) {
if (this.props.onAccept) {
this.props.onAccept(e);
}
}
onCancel(e) {
if (this.props.onCancel) {
this.props.onCancel(e);
}
}
materialDom(props) {
return (h("dialog", Object.assign({ role: 'alertdialog', ref: this.setControlRef }, props),
h("div", { className: "mdc-dialog__surface" }, props.children),
h("div", { className: "mdc-dialog__backdrop" })));
}
}
__decorate([
bind
], Dialog.prototype, "onAccept", null);
__decorate([
bind
], Dialog.prototype, "onCancel", null);
export default class default_1 extends Dialog {
}
default_1.Header = DialogHeader;
default_1.Body = DialogBody;
default_1.Footer = DialogFooter;
default_1.FooterButton = DialogFooterButton;
//# sourceMappingURL=index.js.map