UNPKG

preact-material-components

Version:
117 lines (90 loc) 2.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _preact = require("preact"); var _MaterialComponent = _interopRequireDefault(require("../MaterialComponent")); var _topAppBar = require("@material/top-app-bar"); 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); } class TopAppBar extends _MaterialComponent.default { constructor() { super(); this.componentName = 'top-app-bar'; this._mdcProps = ['short', 'short-collapsed', 'fixed', 'prominent']; this._onNav = this._onNav.bind(this); } _onNav(e) { if (this.props.onNav) { this.props.onNav(e); } } componentDidMount() { this.MDComponent = new _topAppBar.MDCTopAppBar(this.control); this.MDComponent.listen('MDCTopAppBar:nav', this._onNav); } componentWillUnmount() { this.MDComponent.unlisten('MDCTopAppBar:nav', this._onNav); this.MDComponent.destroy(); } materialDom(props) { return (0, _preact.h)("header", _extends({ ref: this.setControlRef }, props), props.children); } } class TopAppBarRow extends _MaterialComponent.default { constructor() { super(); this.componentName = 'top-app-bar__row'; } } /** * @prop align-end = false * @prop align-start = false * @prop shrink-to-fit = false */ class TopAppBarSection extends _MaterialComponent.default { constructor() { super(); this.componentName = 'top-app-bar__section'; this._mdcProps = ['align-start', 'align-end']; } materialDom(props) { return (0, _preact.h)("section", props, props.children); } } /** * @prop menu = false */ class TopAppBarIcon extends _MaterialComponent.default { constructor(props) { super(); this.componentName = 'top-app-bar__icon'; } materialDom(props) { const className = props.navigation ? 'material-icons mdc-top-app-bar__navigation-icon' : 'material-icons'; return (0, _preact.h)("a", _extends({ className: className }, props), props.children); } } /** * @prop title = " */ class TopAppBarTitle extends _MaterialComponent.default { constructor() { super(); this.componentName = 'top-app-bar__title'; } materialDom(props) { return (0, _preact.h)("span", props, props.children); } } TopAppBar.Section = TopAppBarSection; TopAppBar.Icon = TopAppBarIcon; TopAppBar.Title = TopAppBarTitle; TopAppBar.Row = TopAppBarRow; var _default = TopAppBar; exports.default = _default;