UNPKG

rmwc

Version:

A thin React wrapper for Material Design (Web) Components

173 lines (137 loc) 7.13 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.Toolbar = exports.ToolbarIcon = exports.ToolbarMenuIcon = exports.ToolbarFixedAdjust = exports.ToolbarRow = exports.ToolbarSection = exports.ToolbarTitle = exports.ToolbarRoot = undefined; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; var _react = require('react'); var React = _interopRequireWildcard(_react); var _mdc = require('@material/toolbar/dist/mdc.toolbar'); var _Icon = require('../Icon'); var _Base = require('../Base'); var _withFoundation2 = require('../Base/withFoundation'); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var ToolbarRoot = exports.ToolbarRoot = (0, _Base.simpleTag)({ tag: 'header', classNames: function classNames(props) { return ['mdc-toolbar', { 'mdc-toolbar--fixed': props.fixed, 'mdc-toolbar--waterfall': props.waterfall, 'mdc-toolbar--fixed-lastrow-only': props.fixedLastrowOnly, 'mdc-toolbar--flexible': props.flexible, 'mdc-toolbar--flexible-default-behavior': props.flexibleDefaultBehavior }]; }, defaultProps: { fixed: false, waterfall: false, fixedLastrowOnly: false, flexible: false, flexibleDefaultBehavior: false }, consumeProps: ['fixed', 'waterfall', 'fixedLastrowOnly', 'flexible', 'flexibleDefaultBehavior'] }); /** A Toolbar title */ var ToolbarTitle = exports.ToolbarTitle = (0, _Base.simpleTag)({ displayName: 'ToolbarTitle', classNames: 'mdc-toolbar__title' }); var ToolbarSection = exports.ToolbarSection = function (_simpleTag) { _inherits(ToolbarSection, _simpleTag); function ToolbarSection() { _classCallCheck(this, ToolbarSection); return _possibleConstructorReturn(this, (ToolbarSection.__proto__ || Object.getPrototypeOf(ToolbarSection)).apply(this, arguments)); } _createClass(ToolbarSection, [{ key: 'render', value: function render() { return _get(ToolbarSection.prototype.__proto__ || Object.getPrototypeOf(ToolbarSection.prototype), 'render', this).call(this); } }]); return ToolbarSection; }((0, _Base.simpleTag)({ tag: 'section', classNames: function classNames(props) { return ['mdc-toolbar__section', { 'mdc-toolbar__section--align-start': props.alignStart, 'mdc-toolbar__section--align-end': props.alignEnd, 'mdc-toolbar__section--shrink-to-fit': props.shrinkToFit }]; }, defaultProps: { alignStart: false, alignEnd: false, shrinkToFit: false }, consumeProps: ['alignStart', 'alignEnd', 'shrinkToFit'] })); /** A Toolbar row */ Object.defineProperty(ToolbarSection, 'displayName', { enumerable: true, writable: true, value: 'ToolbarSection' }); var ToolbarRow = exports.ToolbarRow = (0, _Base.simpleTag)({ displayName: 'ToolbarRow', classNames: 'mdc-toolbar__row' }); /** * This component can be placed after a fixed Toolbar component to fill in the space. */ var ToolbarFixedAdjust = exports.ToolbarFixedAdjust = (0, _Base.simpleTag)({ displayName: 'ToolbarFixedAdjust', classNames: 'mdc-toolbar-fixed-adjust' }); /** * A Menu Icon For the Toolbar. This is an instance of the Icon component. */ var ToolbarMenuIcon = exports.ToolbarMenuIcon = (0, _Base.simpleTag)({ displayName: 'ToolbarMenuIcon', tag: _Icon.Icon, classNames: 'mdc-toolbar__menu-icon' }); /** * A standard Icon for toolbar actions. This is an instance of the Icon component. */ var ToolbarIcon = exports.ToolbarIcon = (0, _Base.simpleTag)({ displayName: 'ToolbarIcon', tag: _Icon.Icon, classNames: 'mdc-toolbar__icon' }); var Toolbar = exports.Toolbar = function (_withFoundation) { _inherits(Toolbar, _withFoundation); function Toolbar() { _classCallCheck(this, Toolbar); return _possibleConstructorReturn(this, (Toolbar.__proto__ || Object.getPrototypeOf(Toolbar)).apply(this, arguments)); } _createClass(Toolbar, [{ key: 'componentDidMount', value: function componentDidMount() { _get(Toolbar.prototype.__proto__ || Object.getPrototypeOf(Toolbar.prototype), 'componentDidMount', this).call(this); if (this.root_ && this.root_.nextSibling && (this.root_.nextSibling.getAttribute('class') || '').includes('mdc-toolbar-fixed-adjust')) { this.fixedAdjustElement = this.root_.nextSibling; } } }, { key: 'render', value: function render() { var rest = _objectWithoutProperties(this.props, []); var root_ = this.foundationRefs.root_; return React.createElement(ToolbarRoot, Object.assign({ elementRef: root_ }, rest)); } }]); return Toolbar; }((0, _withFoundation2.withFoundation)({ constructor: _mdc.MDCToolbar, adapter: {} })); Object.defineProperty(Toolbar, 'displayName', { enumerable: true, writable: true, value: 'Toolbar' });