UNPKG

suranadira-menu

Version:
131 lines (111 loc) 4.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "default", { enumerable: true, get: function get() { return _SuranadiraMenu.default; } }); var _SuranadiraMenu = _interopRequireDefault(require("./SuranadiraMenu")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _src = _interopRequireDefault(require("../../suranadira-icon/src")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } // Suranadira Icon var SuranadiraMenu = function SuranadiraMenu(args) { // Defaults var defaults = { name: "suranadiraMenu1", unit: 10, direction: "horizontal", visible: true, paddingLeft: 30, paddingRight: 30, color: "#fff", colorPressed: "#999", background: "#777", position: "relative", left: 0, width: window.innerWidth, height: 80, maxWidth: 900, items: [{ name: "menuItem1", composition: ["Z", "IA", "VI", "I"], onClick: function onClick() {} }], styles: {}, onResize: function onResize() {} }; // Properties var properties = Object.assign(defaults, args); if (typeof args.styles !== "undefined") { properties = Object.assign(properties, args.styles); } // Append new message to the chat script (0, _react.useEffect)(function () { if (properties.direction === "vertical") { properties.onResize({ menu: properties.name, width: properties.width, height: properties.height }); } // eslint-disable-next-line }, [properties.width, properties.height]); // Limit menu width var limitMenuWidth = function limitMenuWidth() { // Limit component's width if (properties.width > properties.maxWidth) properties.width = properties.maxWidth; }; var setMenuHeight = function setMenuHeight() { if (properties.direction === "horizontal") { properties.height = properties.unit * 6; } else { properties.width = properties.unit * 8 + properties.paddingLeft + properties.paddingRight; // 6 } }; setMenuHeight(); limitMenuWidth(); return _react.default.createElement("div", { className: "SuranadiraMenu", style: { background: properties.background, display: properties.visible ? "inline-block" : "none", position: properties.position, zIndex: properties.position === "relative" ? 0 : 1, left: properties.left + "px", // top: 0, // left: 100 + "px", width: properties.width + "px", height: properties.height + "px", textAlign: "left", overflow: "hidden", boxSizing: "border-box", paddingLeft: properties.paddingLeft + "px", paddingRight: properties.paddingRight + "px" } }, properties.items.map(function (item) { return _react.default.createElement(_src.default, { key: item.name, name: item.name, color: typeof item.color === "undefined" ? properties.color : item.color, colorPressed: typeof item.colorPressed === "undefined" ? properties.colorPressed : item.colorPressed, background: typeof item.background === "undefined" ? properties.background : item.background, unit: properties.unit, elementWidth: properties.elementWidth, lineWidth: properties.lineWidth, float: typeof item.float === "undefined" ? "none" : item.float, composition: item.composition, hideIfEmpty: true, onClick: item.onClick }); })); }; var _default = SuranadiraMenu; exports.default = _default;