preact-material-components
Version:
preact wrapper for "Material Components for the web"
305 lines (247 loc) • 9.98 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.Tabs = exports.TabIconLabel = exports.Tab = exports.TabBarScrollerTabs = exports.TabBarScroller = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _tabs = require("@material/tabs");
var _bindDecorator = require("bind-decorator");
var _preact = require("preact");
var _MaterialComponent6 = _interopRequireDefault(require("../Base/MaterialComponent"));
var __decorate = void 0 && (void 0).__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 === "undefined" ? "undefined" : (0, _typeof2.default)(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;
};
var __rest = void 0 && (void 0).__rest || function (s, e) {
var t = {};
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
}
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
/*
* Default props for tabs
*/
var defaultProps = {
activeTabIndex: 0
};
var TabBarScroller =
/*#__PURE__*/
function (_MaterialComponent) {
(0, _inherits2.default)(TabBarScroller, _MaterialComponent);
function TabBarScroller() {
var _this;
(0, _classCallCheck2.default)(this, TabBarScroller);
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(TabBarScroller).apply(this, arguments));
_this.componentName = 'tab-bar-scroller';
_this.mdcProps = [];
return _this;
}
(0, _createClass2.default)(TabBarScroller, [{
key: "componentDidMount",
value: function componentDidMount() {
(0, _get2.default)((0, _getPrototypeOf2.default)(TabBarScroller.prototype), "componentDidMount", this).call(this);
if (this.control) {
this.MDComponent = new _tabs.MDCTabBarScroller(this.control);
setActiveTabIndex(defaultProps, this.props, this.MDComponent.tabBar);
}
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
(0, _get2.default)((0, _getPrototypeOf2.default)(TabBarScroller.prototype), "componentWillUnmount", this).call(this);
if (this.MDComponent) {
this.MDComponent.destroy();
}
}
}, {
key: "componentWillReceiveProps",
value: function componentWillReceiveProps(nextProps) {
(0, _get2.default)((0, _getPrototypeOf2.default)(TabBarScroller.prototype), "componentWillReceiveProps", this).call(this, nextProps);
if (this.MDComponent) {
setActiveTabIndex(this.props, nextProps, this.MDComponent.tabBar);
}
}
}, {
key: "materialDom",
value: function materialDom(props) {
return (0, _preact.h)("div", Object.assign({}, 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")));
}
}]);
return TabBarScroller;
}(_MaterialComponent6.default);
exports.TabBarScroller = TabBarScroller;
__decorate([_bindDecorator.bind], TabBarScroller.prototype, "materialDom", null);
var TabBarScrollerTabs =
/*#__PURE__*/
function (_MaterialComponent2) {
(0, _inherits2.default)(TabBarScrollerTabs, _MaterialComponent2);
function TabBarScrollerTabs() {
var _this2;
(0, _classCallCheck2.default)(this, TabBarScrollerTabs);
_this2 = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(TabBarScrollerTabs).apply(this, arguments));
_this2.componentName = 'tab-bar';
_this2.mdcProps = ['icon-tab-bar', 'icons-with-text'];
return _this2;
}
(0, _createClass2.default)(TabBarScrollerTabs, [{
key: "materialDom",
value: function materialDom(_a) {
var className = _a.className,
props = __rest(_a, ["className"]);
return (0, _preact.h)("nav", Object.assign({
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"
}));
}
}]);
return TabBarScrollerTabs;
}(_MaterialComponent6.default);
exports.TabBarScrollerTabs = TabBarScrollerTabs;
__decorate([_bindDecorator.bind], TabBarScrollerTabs.prototype, "materialDom", null);
var Tab =
/*#__PURE__*/
function (_MaterialComponent3) {
(0, _inherits2.default)(Tab, _MaterialComponent3);
function Tab() {
var _this3;
(0, _classCallCheck2.default)(this, Tab);
_this3 = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Tab).apply(this, arguments));
_this3.componentName = 'tab';
_this3.mdcProps = ['active'];
return _this3;
}
(0, _createClass2.default)(Tab, [{
key: "materialDom",
value: function materialDom(props) {
return (0, _preact.h)("a", Object.assign({
role: "tab"
}, props, {
ref: this.setControlRef
}), props.children);
}
}]);
return Tab;
}(_MaterialComponent6.default);
exports.Tab = Tab;
__decorate([_bindDecorator.bind], Tab.prototype, "materialDom", null);
var TabIconLabel =
/*#__PURE__*/
function (_MaterialComponent4) {
(0, _inherits2.default)(TabIconLabel, _MaterialComponent4);
function TabIconLabel() {
var _this4;
(0, _classCallCheck2.default)(this, TabIconLabel);
_this4 = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(TabIconLabel).apply(this, arguments));
_this4.componentName = 'tab__icon-text';
_this4.mdcProps = [];
return _this4;
}
(0, _createClass2.default)(TabIconLabel, [{
key: "materialDom",
value: function materialDom(props) {
return (0, _preact.h)("span", Object.assign({}, props, {
ref: this.setControlRef
}), props.children);
}
}]);
return TabIconLabel;
}(_MaterialComponent6.default);
exports.TabIconLabel = TabIconLabel;
__decorate([_bindDecorator.bind], TabIconLabel.prototype, "materialDom", null);
/*
* Function to add declarative opening/closing to drawer
*/
function setActiveTabIndex(oldprops, newprops, tabs) {
if (oldprops.activeTabIndex && newprops.activeTabIndex && oldprops.activeTabIndex !== newprops.activeTabIndex) {
tabs.activeTabIndex = newprops.activeTabIndex;
}
}
var Tabs =
/*#__PURE__*/
function (_MaterialComponent5) {
(0, _inherits2.default)(Tabs, _MaterialComponent5);
function Tabs() {
var _this5;
(0, _classCallCheck2.default)(this, Tabs);
_this5 = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Tabs).apply(this, arguments));
_this5.componentName = 'tab-bar';
_this5.mdcProps = ['icon-tab-bar', 'icons-with-text'];
_this5.mdcNotifyProps = ['activeTabIndex'];
return _this5;
}
(0, _createClass2.default)(Tabs, [{
key: "componentDidMount",
value: function componentDidMount() {
(0, _get2.default)((0, _getPrototypeOf2.default)(Tabs.prototype), "componentDidMount", this).call(this);
if (this.control) {
this.MDComponent = new _tabs.MDCTabBar(this.control);
}
this.afterComponentDidMount();
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
(0, _get2.default)((0, _getPrototypeOf2.default)(Tabs.prototype), "componentWillUnmount", this).call(this);
if (this.MDComponent) {
this.MDComponent.destroy();
}
}
}, {
key: "materialDom",
value: function materialDom(props) {
return (0, _preact.h)("nav", Object.assign({
role: 'tablist'
}, props, {
ref: this.setControlRef
}), props.children, (0, _preact.h)("span", {
class: "mdc-tab-bar__indicator"
}));
}
}]);
return Tabs;
}(_MaterialComponent6.default);
exports.Tabs = Tabs;
Tabs.TabBarScroller = TabBarScroller;
Tabs.TabBarScrollerTabs = TabBarScrollerTabs;
Tabs.Tab = Tab;
Tabs.TabIconLabel = TabIconLabel;
__decorate([_bindDecorator.bind], Tabs.prototype, "materialDom", null);
var _default = Tabs;
exports.default = _default;
//# sourceMappingURL=index.js.map