UNPKG

@unofficialmc2/arche-controls

Version:

We know that there are a ton of react UI library projects to choose from. Our hope with this one is to provide the next generation of react components that you can use to bootstrap your next project, or as a reference for building a UIKit. Read on to get

249 lines 11.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var React = require("react"); var theming_1 = require("../../../Common/theming"); var theming_2 = require("../../../Common/theming"); var utils_1 = require("../../../Common/utils"); var SvgIcon_1 = require("../SvgIcon"); var Box_1 = require("../../Containers/Box"); var styles_1 = require("./styles"); var classnames = require("classnames"); var lodash_1 = require("lodash"); var Ligne_1 = require("../Ligne"); var colorMap_1 = require("../../../Common/theming/colorMap"); var typestyle_1 = require("typestyle"); var helpers_1 = require("../../../Common/utils/helpers"); var logo = require('./sources/logo-arche.svg'); ; ; var UpMenu = (function (_super) { tslib_1.__extends(UpMenu, _super); function UpMenu(p, c) { var _this = _super.call(this, p, c) || this; _this.toggleMinification = function () { if (_this.isMinifiedControlled && _this.props.onMinifiedChange) { _this.props.onMinifiedChange(!_this.currentMinifiedValue); } else { _this.setState({ minified: !_this.currentMinifiedValue }, function () { if (_this.props.onMinifiedChange) { _this.props.onMinifiedChange(_this.currentMinifiedValue); } }); } }; _this.setMinification = function (minified) { if (_this.isMinifiedControlled && _this.props.onMinifiedChange) { _this.props.onMinifiedChange(minified); } else { _this.setState({ minified: minified }, function () { if (_this.props.onMinifiedChange) { _this.props.onMinifiedChange(minified); } }); } }; _this.handleClick = function (menuitem) { if (_this.currentMinifiedValue && !utils_1.isEmpty(menuitem.childMenuItems)) { _this.setMinification(false); } if (helpers_1.isMobileDevice()) { if (!_this.currentMinifiedValue && utils_1.isEmpty(menuitem.childMenuItems)) { _this.setMinification(true); } } return _this.props.onClick(menuitem.uri, menuitem); }; _this.state = { minified: p.minified || false, }; return _this; } Object.defineProperty(UpMenu.prototype, "isMinifiedControlled", { get: function () { return this.props.minified !== undefined; }, enumerable: true, configurable: true }); Object.defineProperty(UpMenu.prototype, "currentMinifiedValue", { get: function () { return this.isMinifiedControlled ? this.props.minified : this.state.minified; }, enumerable: true, configurable: true }); UpMenu.prototype.render = function () { var _this = this; var _a = this.props, header = _a.header, icon = _a.icon, footer = _a.footer, menuItems = _a.menuItems, children = _a.children, others = tslib_1.__rest(_a, ["header", "icon", "footer", "menuItems", "children"]); var menu = menuItems.map(function (v, i) { if (v.render != null) { var e = v.render(v, others, _this.state); return React.createElement(React.Fragment, { key: i }, e); } return React.createElement(MenuItem, { onClick: _this.handleClick, key: i, title: v.title, icon: v.icon, uri: v.uri, isSelected: v.isSelected, isVisible: v.isVisible, childMenuItems: v.childMenuItems, isSeparator: v.isSeparator }); }); var renderChildren = children; if (children != null && utils_1.isFunction(children)) { renderChildren = children(this.props, this.state); } var renderHeader = header; if (header != null && utils_1.isFunction(header)) { renderHeader = header(this.props, this.state); } else if (this.props.title) { renderHeader = UpMenuDefaultHeader({ title: this.props.title }, this.state); } var renderFooter = footer; if (footer != null && utils_1.isFunction(footer)) { renderFooter = footer(this.props, this.state); } var renderIcon = icon; if (icon != null && utils_1.isFunction(icon)) { renderIcon = icon(this.props, this.state); } return (React.createElement("aside", { className: classnames('up-menu', styles_1.MenuStyles(tslib_1.__assign(tslib_1.__assign({}, this.props), { minified: this.currentMinifiedValue }))) }, React.createElement("section", { className: "up-menu-header" }, renderIcon && React.createElement("section", { className: "up-app-icon-wrapper" }, renderIcon), renderHeader, React.createElement("div", { className: "up-menu-actions" }, !this.props.blocked && React.createElement(SvgIcon_1.default, { width: 25, height: 25, iconName: 'burger', className: "up-menu-toggle", onClick: this.toggleMinification }))), React.createElement("section", { className: "up-menu-nav" }, React.createElement("nav", null, React.createElement("ul", null, menu))), renderChildren && React.createElement("section", { className: "up-menu-content" }, renderChildren), renderFooter && React.createElement("section", { className: "up-menu-footer" }, renderFooter))); }; UpMenu.defaultProps = { theme: theming_2.default, icon: function () { return React.createElement(SvgIcon_1.default, { width: 48, height: 48, iconHtml: logo }); }, width: 300, }; return UpMenu; }(React.Component)); exports.UpMenu = UpMenu; ; ; ; var MenuItem = (function (_super) { tslib_1.__extends(MenuItem, _super); function MenuItem(p, c) { var _this = _super.call(this, p, c) || this; _this.onItemClick = function (e) { var value = _this.props.onClick(_this.props); if (value === false) { e.preventDefault(); e.stopPropagation(); } }; return _this; } MenuItem.prototype.shouldComponentUpdate = function (nextProps) { return !lodash_1.isEqual(this.props, nextProps); }; MenuItem.prototype.render = function () { var hide = this.props.isVisible === false; var active = this.props.isSelected; var hasChilren = !utils_1.isEmpty(this.props.childMenuItems); var isSeparator = this.props.isSeparator; return React.createElement("li", { className: classnames('treeview', { hide: hide, active: active, hasChildren: hasChilren, separator: isSeparator }) }, this.props.uri && React.createElement("a", { onClick: this.onItemClick, href: this.props.uri }, lodash_1.isString(this.props.icon) && React.createElement(SvgIcon_1.default, { title: this.props.title, width: 22, height: 22, iconName: this.props.icon }), utils_1.isFunction(this.props.icon) && this.props.icon(this.props), React.createElement("span", { className: 'up-menu-item-title' }, this.props.title), !utils_1.isEmpty(this.props.childMenuItems) && React.createElement(SvgIcon_1.default, { width: 15, height: 15, style: { marginLeft: 'auto' }, iconName: 'chevron-right' })), !utils_1.isEmpty(this.props.childMenuItems) && React.createElement(SubMenu, { title: this.props.title, onClick: this.props.onClick, childMenuItems: this.props.childMenuItems })); }; return MenuItem; }(React.Component)); exports.MenuItem = MenuItem; ; ; var SubMenu = (function (_super) { tslib_1.__extends(SubMenu, _super); function SubMenu(p, c) { var _this = _super.call(this, p, c) || this; _this.state = {}; return _this; } SubMenu.prototype.shouldComponentUpdate = function (nextProps) { return !lodash_1.isEqual(this.props, nextProps); }; SubMenu.prototype.render = function () { var _this = this; if (this.props.childMenuItems == null || this.props.childMenuItems.length == 0) { return null; } var items = this.props.childMenuItems.map(function (v, i) { return React.createElement(SubItems, { key: i, onClick: _this.props.onClick, uri: v.uri, title: v.title, isVisible: v.isVisible, isSelected: v.isSelected, icon: v.icon, childMenuItems: v.childMenuItems }); }); return React.createElement(React.Fragment, null, React.createElement("ul", { className: "up-sub-menu" }, this.props.title && React.createElement("span", { className: 'up-sub-menu-title' }, this.props.title), items)); }; return SubMenu; }(React.Component)); exports.SubMenu = SubMenu; ; ; ; var SubItems = (function (_super) { tslib_1.__extends(SubItems, _super); function SubItems(p, c) { var _this = _super.call(this, p, c) || this; _this.onClick = function (e) { e.preventDefault(); e.stopPropagation(); _this.setState({ active: !_this.state.active }); return false; }; _this.onClickA = function (e) { var value = _this.props.onClick(_this.props); if (value === false) { e.preventDefault(); e.stopPropagation(); } }; _this.state = { active: false }; return _this; } SubItems.prototype.shouldComponentUpdate = function (nextProps, nextState) { return !lodash_1.isEqual(this.props, nextProps) || !lodash_1.isEqual(this.state, nextState); }; Object.defineProperty(SubItems.prototype, "anyChild", { get: function () { return this.props.childMenuItems != null && this.props.childMenuItems.length != 0; }, enumerable: true, configurable: true }); SubItems.prototype.render = function () { var hide = this.props.isVisible === false ? ' hide' : ''; var active = this.state.active || this.props.isSelected ? 'active' : ''; return React.createElement("li", { className: active + hide }, React.createElement("a", { onClick: this.onClickA, href: this.props.uri }, this.anyChild && React.createElement("i", { onClick: this.onClick, className: (this.state.active ? 'pe-7s-angle-down' : 'pe-7s-angle-right') }), React.createElement("span", { className: 'up-menu-item-title' }, this.props.title)), this.anyChild ? React.createElement(SubMenu, { onClick: this.props.onClick, childMenuItems: this.props.childMenuItems }) : null); }; return SubItems; }(React.Component)); exports.SubItems = SubItems; ; var UpMenuDefaultHeader = function (props, state) { return React.createElement(Box_1.default, { flexDirection: 'row', alignItems: 'center', justifyContent: 'center', style: { height: '100%' } }, !state.minified && React.createElement(Ligne_1.default, { color: colorMap_1.default.white, className: typestyle_1.style({ marginLeft: '8px' }) }, props.title)); }; exports.UpMenuDefaultHeader = UpMenuDefaultHeader; exports.default = theming_1.withTheme(UpMenu); //# sourceMappingURL=UpMenu.js.map