UNPKG

preact-material-components

Version:
182 lines (147 loc) 5.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _tabs = require("@material/tabs"); var _MaterialComponent = _interopRequireDefault(require("../MaterialComponent")); var _preact = require("preact"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } 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); } /* * Default props for tabs */ const defaultProps = { activeTabIndex: 0 }; /** * @prop icon-tab-bar = false * @prop icons-with-text = false */ class Tabs extends _MaterialComponent.default { constructor() { super(); this.componentName = 'tab-bar'; this._mdcProps = ['icon-tab-bar', 'icons-with-text']; } componentDidMount() { this.MDComponent = new _tabs.MDCTabBar(this.control); setActiveTabIndex(defaultProps, this.props, this.MDComponent); } componentWillUnmount() { this.MDComponent.destroy && this.MDComponent.destroy(); } componentWillUpdate(nextProps) { setActiveTabIndex(this.props, nextProps, this.MDComponent); } materialDom(props) { return (0, _preact.h)("nav", _extends({ role: "tablist" }, props, { ref: this.setControlRef }), props.children, (0, _preact.h)("span", { "class": "mdc-tab-bar__indicator" })); } } class TabBarScroller extends _MaterialComponent.default { constructor() { super(); this.componentName = 'tab-bar-scroller'; } componentDidMount() { this.MDComponent = new _tabs.MDCTabBarScroller(this.control); setActiveTabIndex(defaultProps, this.props, this.MDComponent.tabBar); } componentWillUnmount() { this.MDComponent.destroy && this.MDComponent.destroy(); } componentWillUpdate(nextProps) { setActiveTabIndex(this.props, nextProps, this.MDComponent.tabBar); } materialDom(props) { return (0, _preact.h)("div", _extends({}, props, { ref: this.setControlRef }), (0, _preact.h)("div", { className: "mdc-tab-bar-scroller__indicator mdc-tab-bar-scroller__indicator--back" }, (0, _preact.h)("a", { className: "mdc-tab-bar-scroller__indicator__inner material-icons", href: "#", "aria-label": "scroll back button" }, "navigate_before")), (0, _preact.h)("div", { className: "mdc-tab-bar-scroller__scroll-frame" }, props.children), (0, _preact.h)("div", { className: "mdc-tab-bar-scroller__indicator mdc-tab-bar-scroller__indicator--forward" }, (0, _preact.h)("a", { className: "mdc-tab-bar-scroller__indicator__inner material-icons", href: "#", "aria-label": "scroll forward button" }, "navigate_next"))); } } /** * @prop icon-tab-bar = false * @prop icons-with-text = false */ class TabBarScrollerTabs extends _MaterialComponent.default { constructor() { super(); this.componentName = 'tab-bar'; this._mdcProps = ['icon-tab-bar', 'icons-with-text']; } materialDom(_ref) { let className = _ref.className, props = _objectWithoutProperties(_ref, ["className"]); return (0, _preact.h)("nav", _extends({ role: "tablist", className: "mdc-tab-bar-scroller__scroll-frame__tabs" }, props, { ref: this.setControlRef }), props.children, (0, _preact.h)("span", { "class": "mdc-tab-bar__indicator" })); } } /** * @prop active = false */ class Tab extends _MaterialComponent.default { constructor() { super(); this.componentName = 'tab'; this._mdcProps = ['active']; } materialDom(props) { return (0, _preact.h)("a", _extends({ role: "tab" }, props, { ref: this.setControlRef }), props.children); } } class TabIconLabel extends _MaterialComponent.default { constructor() { super(); this.componentName = 'tab__icon-text'; } materialDom(props) { return (0, _preact.h)("span", _extends({}, props, { ref: this.setControlRef }), props.children); } } /* * Function to add declarative opening/closing to drawer */ function setActiveTabIndex(oldprops, newprops, tabs) { if ('activeTabIndex' in oldprops && 'activeTabIndex' in newprops && oldprops.activeTabIndex !== newprops.activeTabIndex) { tabs.activeTabIndex = newprops.activeTabIndex; } } Tabs.TabBarScroller = TabBarScroller; Tabs.TabBarScrollerTabs = TabBarScrollerTabs; Tabs.Tab = Tab; Tabs.TabIconLabel = TabIconLabel; var _default = Tabs; exports.default = _default;