UNPKG

preact-material-components

Version:
127 lines (99 loc) 3.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _preact = require("preact"); var _MaterialComponent = _interopRequireDefault(require("../MaterialComponent")); var _toolbar = require("@material/toolbar"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } /** * @prop fixed = false * @prop fixed-lastrow-only = false * @prop waterfall = false * @prop flexible = false * @prop flexible-default-behavior = false */ class Toolbar extends _MaterialComponent.default { constructor() { super(); this.componentName = 'toolbar'; this._mdcProps = ['fixed', 'fixed-lastrow-only', 'waterfall', 'flexible', 'flexible-default-behavior']; this._onChange = this._onChange.bind(this); } _onChange(e) { if (this.props.onChange) { this.props.onChange(e); } } componentDidMount() { this.MDComponent = new _toolbar.MDCToolbar(this.control); this.MDComponent.listen('MDCToolbar:change', this._onChange); } componentWillUnmount() { this.MDComponent.unlisten('MDCToolbar:change', this._onChange); this.MDComponent.destroy && this.MDComponent.destroy(); } materialDom(props) { return (0, _preact.h)("header", _extends({ ref: this.setControlRef }, props), props.children); } } class ToolbarRow extends _MaterialComponent.default { constructor() { super(); this.componentName = 'toolbar__row'; } } /** * @prop align-end = false * @prop align-start = false * @prop shrink-to-fit = false */ class ToolbarSection extends _MaterialComponent.default { constructor() { super(); this.componentName = 'toolbar__section'; this._mdcProps = ['align-start', 'align-end', 'shrink-to-fit']; } materialDom(props) { return (0, _preact.h)("section", props, props.children); } } /** * @prop menu = false */ class ToolbarIcon extends _MaterialComponent.default { constructor(props) { super(); this.componentName = 'toolbar__icon'; if (props.menu) { this.componentName = 'toolbar__menu-icon'; } } materialDom(props) { return (0, _preact.h)("a", _extends({ className: "material-icons" }, props), props.children || 'menu'); } } /** * @prop title = '' */ class ToolbarTitle extends _MaterialComponent.default { constructor() { super(); this.componentName = 'toolbar__title'; } materialDom(props) { return (0, _preact.h)("span", props, props.children); } } Toolbar.Section = ToolbarSection; Toolbar.Icon = ToolbarIcon; Toolbar.Title = ToolbarTitle; Toolbar.Row = ToolbarRow; var _default = Toolbar; exports.default = _default;