preact-material-components
Version:
preact wrapper for "Material Components for the web"
88 lines • 3.12 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 { MDCMenu } from '@material/menu';
import { bind } from 'bind-decorator';
import { h } from 'preact';
import MaterialComponent from '../Base/MaterialComponent';
import { List, ListItem } from '../List';
export class MenuAnchor extends MaterialComponent {
constructor() {
super(...arguments);
this.componentName = 'menu-surface--anchor';
this.mdcProps = [];
}
materialDom(props) {
return h("div", Object.assign({}, props), this.props.children);
}
}
export { ListItem as MenuItem } from '../List';
export class Menu extends MaterialComponent {
constructor() {
super(...arguments);
this.componentName = 'menu';
this.mdcProps = [
'open',
'open-from-top-left',
'open-from-top-right',
'open-from-bottom-left',
'open-from-bottom-right'
];
this.mdcNotifyProps = ['open'];
}
componentDidMount() {
super.componentDidMount();
if (this.control) {
this.MDComponent = new MDCMenu(this.control);
this.MDComponent.listen('MDCMenu:selected', this.onSelect);
this.MDComponent.listen('MDCMenu:cancel', this.onCancel);
}
this.afterComponentDidMount();
}
componentWillUnmount() {
super.componentWillUnmount();
if (this.MDComponent) {
this.MDComponent.unlisten('MDCMenu:selected', this.onSelect);
this.MDComponent.unlisten('MDCMenu:cancel', this.onCancel);
this.MDComponent.destroy();
}
}
onSelect(e) {
if (this.props.onSelect) {
this.props.onSelect(e);
}
this.onMenuClosed(e);
}
onCancel(e) {
if (this.props.onCancel) {
this.props.onCancel(e);
}
this.onMenuClosed(e);
}
onMenuClosed(e) {
if (this.props.onMenuClosed) {
this.props.onMenuClosed(e);
}
}
materialDom(props) {
return (h("div", Object.assign({ class: "mdc-menu-surface", tabIndex: "-1" }, props, { ref: this.setControlRef }),
h(List, { className: "mdc-menu__items", role: "menu", "aria-hidden": "true" }, props.children)));
}
}
__decorate([
bind
], Menu.prototype, "onSelect", null);
__decorate([
bind
], Menu.prototype, "onCancel", null);
__decorate([
bind
], Menu.prototype, "onMenuClosed", null);
export default class default_1 extends Menu {
}
default_1.Anchor = MenuAnchor;
default_1.Item = ListItem;
//# sourceMappingURL=index.js.map