preact-material-components
Version:
preact wrapper for "Material Components for the web"
98 lines • 3.36 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 { MDCToolbar } from '@material/toolbar';
import { bind } from 'bind-decorator';
import { h } from 'preact';
import MaterialComponent from '../Base/MaterialComponent';
export class ToolbarRow extends MaterialComponent {
constructor() {
super(...arguments);
this.componentName = 'toolbar__row';
this.mdcProps = [];
}
materialDom(props) {
return h("div", Object.assign({}, props), this.props.children);
}
}
export class ToolbarSection extends MaterialComponent {
constructor() {
super(...arguments);
this.componentName = 'toolbar__section';
this.mdcProps = ['align-start', 'align-end', 'shrink-to-fit'];
}
materialDom(props) {
return h("section", Object.assign({}, props), props.children);
}
}
export class ToolbarIcon extends MaterialComponent {
constructor(props) {
super();
this.componentName = 'toolbar__icon';
this.mdcProps = [];
if (props.menu) {
this.componentName = 'toolbar__menu-icon';
}
}
materialDom(props) {
return (h("a", Object.assign({ className: "material-icons" }, props), props.children || 'menu'));
}
}
export class ToolbarTitle extends MaterialComponent {
constructor() {
super(...arguments);
this.componentName = 'toolbar__title';
this.mdcProps = [];
}
materialDom(props) {
return h("span", Object.assign({}, props), props.children);
}
}
export class Toolbar extends MaterialComponent {
constructor() {
super(...arguments);
this.componentName = 'toolbar';
this.mdcProps = [
'fixed',
'fixed-lastrow-only',
'waterfall',
'flexible',
'flexible-default-behavior'
];
}
componentDidMount() {
super.componentDidMount();
if (this.control) {
this.MDComponent = new MDCToolbar(this.control);
this.MDComponent.listen('MDCToolbar:change', this.onChange);
}
}
componentWillUnmount() {
super.componentWillUnmount();
if (this.MDComponent) {
this.MDComponent.unlisten('MDCToolbar:change', this.onChange);
this.MDComponent.destroy();
}
}
onChange(e) {
if (this.props.onChange) {
this.props.onChange(e);
}
}
materialDom(props) {
return (h("header", Object.assign({ ref: this.setControlRef }, props), props.children));
}
}
__decorate([
bind
], Toolbar.prototype, "onChange", null);
export default class default_1 extends Toolbar {
}
default_1.Section = ToolbarSection;
default_1.Icon = ToolbarIcon;
default_1.Title = ToolbarTitle;
default_1.Row = ToolbarRow;
//# sourceMappingURL=index.js.map