UNPKG

@hackoregon/component-library

Version:

Official repo for Hack Oregon React component library

153 lines (126 loc) 7.48 kB
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _templateObject2() { var data = _taggedTemplateLiteral(["\n display: none;\n position: absolute;\n right: 0;\n width: auto;\n z-index: 99999;\n\n @media (max-width: 640px) {\n display: block;\n color: rgba(255, 255, 255, 0.65);\n border: none;\n font-family: \"Rubik\", sans-serif;\n font-size: 1.25rem;\n font-weight: 500;\n padding: 2rem;\n }\n"]); _templateObject2 = function _templateObject2() { return data; }; return data; } function _templateObject() { var data = _taggedTemplateLiteral(["\n position: relative;\n min-width: 320px;\n\n & ul {\n display: flex;\n list-style: none;\n align-items: center;\n justify-content: center;\n\n & > li {\n flex: 1 1 100%;\n\n & span i {\n margin-left: 10px;\n }\n }\n }\n\n & .nav-item {\n color: white;\n flex: 1;\n display: block;\n font-family: \"Rubik\", sans-serif;\n font-size: 1.25rem;\n border: none;\n text-transform: uppercase;\n text-decoration: none;\n padding: 1rem;\n text-align: center;\n\n &:hover {\n color: rgba(255, 255, 255, 0.85);\n text-decoration: none;\n }\n }\n\n @media (max-width: 640px) {\n position: absolute;\n z-index: 10001;\n height: 100%;\n width: 100%;\n margin: 0 !important;\n padding: 0 !important;\n top: 0;\n left: 0;\n background-color: rgb(34, 15, 37);\n\n & ul {\n display: block;\n position: relative;\n margin: 0;\n padding-top: 80px;\n\n & > li {\n color: #fff;\n display: block;\n text-align: center;\n text-decoration: none;\n transition: all 0.25s ease-in-out;\n margin: 0;\n padding: 0;\n flex: none;\n }\n }\n }\n"]); _templateObject = function _templateObject() { return data; }; return data; } function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); } import React, { Component } from "react"; import { css } from "emotion"; import PropTypes from "prop-types"; import NavSubMenu from "./NavSubMenu"; import NavLink from "./NavRouterLink"; import Icon from "../Icon/Icon"; var defaultMenu = [{ name: "Collections", path: "/", nestedMenu: [{ name: "Disaster Resilience", path: "/cities/portland/disaster" }, { name: "Housing Affordability", path: "/cities/portland/housing" }, { name: "Local Elections", path: "/cities/portland/elections" }, { name: "Neighborhood Development", path: "/cities/portland/neighborhood" }, { name: "Transportation Systems", path: "/cities/portland/transportation" }] }, { name: "Sandbox", path: "/sandbox" }]; var navClass = css(_templateObject()); var exClass = css(_templateObject2()); var Nav = function (_Component) { _inherits(Nav, _Component); function Nav() { var _this; _classCallCheck(this, Nav); _this = _possibleConstructorReturn(this, _getPrototypeOf(Nav).call(this)); _defineProperty(_assertThisInitialized(_this), "handleClick", function (name, menu, e) { e.preventDefault(); var items = menu; _this.setState(function () { return { menuActive: !_this.state.menuActive, items: items }; }); }); _this.state = { menuActive: false, items: [] }; return _this; } _createClass(Nav, [{ key: "render", value: function render() { var _this$props = this.props, _this$props$menu = _this$props.menu, menu = _this$props$menu === void 0 ? defaultMenu : _this$props$menu, _this$props$toggleNes = _this$props.toggleNestedMenu, toggleNestedMenu = _this$props$toggleNes === void 0 ? this.handleClick : _this$props$toggleNes; return React.createElement("div", { className: navClass }, React.createElement("a", { className: exClass }, React.createElement(Icon, { key: "nav-ex", className: "fa fa-times", handleClick: this.props.toggleSubNav })), React.createElement("ul", null, menu.map(function (item, idx) { return item.nestedMenu ? React.createElement("li", { key: idx, onClick: function onClick(e) { return toggleNestedMenu(item.name, item.nestedMenu, e); } }, React.createElement("a", { className: "nav-item" }, item.name, React.createElement(Icon, { className: "fa fa-angle-down" }))) : React.createElement(NavLink, { key: idx, name: item.name, path: item.path }); })), React.createElement(NavSubMenu, { isVisible: this.state.menuActive, items: this.state.items })); } }]); return Nav; }(Component); Nav.propTypes = { menu: PropTypes.arrayOf(PropTypes.shape({ name: PropTypes.string, path: PropTypes.string })), toggleNestedMenu: PropTypes.func, toggleSubNav: PropTypes.func }; export default Nav;