mc-react-header 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,7 +15,7 @@ jobs:
15
15
  - name: Set up Node.js
16
16
  uses: actions/setup-node@v3
17
17
  with:
18
- node-version: "16"
18
+ node-version: "22"
19
19
  registry-url: "https://registry.npmjs.org/"
20
20
 
21
21
  - name: Install project dependencies
@@ -6,7 +6,6 @@ ul.mc-breadcrumb {
6
6
  border-radius: 2px;
7
7
  border: 1px solid #d6d6d6;
8
8
  font-size: 16px;
9
- font-weight: 300;
10
9
  font-family: "Open Sans", sans-serif;
11
10
  text-align: left;
12
11
  margin: 6px;
@@ -21,11 +20,10 @@ ul.mc-breadcrumb {
21
20
  align-items: center;
22
21
  }
23
22
 
24
-
25
23
  /* Display list items side by side */
26
24
  ul.mc-breadcrumb li {
27
25
  display: inline;
28
- line-height: 1.0;
26
+ line-height: 1;
29
27
  margin-right: 46px;
30
28
  position: relative;
31
29
  }
@@ -40,7 +38,6 @@ ul.mc-breadcrumb li a {
40
38
  /* z-index: 3; */
41
39
  }
42
40
 
43
-
44
41
  /* Add a color on mouse-over, if the <a> has href defined */
45
42
  ul.mc-breadcrumb li a[href]:hover {
46
43
  text-decoration: underline;
@@ -98,4 +95,3 @@ ul.mc-breadcrumb li a:not([href]):hover {
98
95
  border: 0;
99
96
  display: none;
100
97
  }
101
-
@@ -4,19 +4,19 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _react = _interopRequireDefault(require("react"));
8
7
  require("./Breadcrumbs.css");
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- function Breadcrumbs(props) {
11
- return /*#__PURE__*/_react.default.createElement("ul", {
8
+ const Breadcrumbs = _ref => {
9
+ let {
10
+ breadcrumbsPath
11
+ } = _ref;
12
+ return /*#__PURE__*/React.createElement("ul", {
12
13
  className: "mc-breadcrumb"
13
- }, props.breadcrumbsPath.map(function (el, i) {
14
- return /*#__PURE__*/_react.default.createElement("li", {
14
+ }, breadcrumbsPath.map((el, i) => {
15
+ return /*#__PURE__*/React.createElement("li", {
15
16
  key: i
16
- }, /*#__PURE__*/_react.default.createElement("a", {
17
+ }, /*#__PURE__*/React.createElement("a", {
17
18
  href: el.link
18
19
  }, el.name));
19
20
  }));
20
- }
21
- var _default = Breadcrumbs;
22
- exports.default = _default;
21
+ };
22
+ var _default = exports.default = Breadcrumbs;
package/dist/Navbar.css CHANGED
@@ -76,7 +76,6 @@
76
76
  .dropdown-content a {
77
77
  float: none;
78
78
  color: #455860;
79
- font-weight: 300;
80
79
  padding: 10px 14px;
81
80
  text-decoration: none;
82
81
  display: block;
package/dist/Navbar.js CHANGED
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
@@ -8,21 +7,9 @@ exports.default = void 0;
8
7
  require("./Navbar.css");
9
8
  var _mcloud_logo = _interopRequireDefault(require("./assets/mcloud_logo.png"));
10
9
  require("font-awesome/css/font-awesome.min.css");
11
- var _react = _interopRequireDefault(require("react"));
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14
- 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, _toPropertyKey(descriptor.key), descriptor); } }
15
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
16
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
17
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
18
- 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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
19
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
20
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
21
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
22
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
23
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
24
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
25
- var mainSections = {
10
+ var _react = require("react");
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ const mainSections = {
26
13
  learn: {
27
14
  name: "LEARN",
28
15
  link: "https://www.materialscloud.org/learn"
@@ -44,7 +31,7 @@ var mainSections = {
44
31
  link: "https://www.materialscloud.org/archive"
45
32
  }
46
33
  };
47
- var dropdownSections = {
34
+ const dropdownSections = {
48
35
  policies: {
49
36
  name: "Policies",
50
37
  link: "https://www.materialscloud.org/policies"
@@ -74,119 +61,69 @@ var dropdownSections = {
74
61
  link: "https://www.materialscloud.org/explore/connect"
75
62
  }
76
63
  };
77
- var DropdownMenu = /*#__PURE__*/function (_React$Component) {
78
- _inherits(DropdownMenu, _React$Component);
79
- var _super = _createSuper(DropdownMenu);
80
- function DropdownMenu(props) {
81
- var _this;
82
- _classCallCheck(this, DropdownMenu);
83
- _this = _super.call(this, props);
84
- _this.state = {
85
- dropdownOpen: false
86
- };
87
- _this.toggleDropdown = _this.toggleDropdown.bind(_assertThisInitialized(_this));
88
- _this.setWrapperRef = _this.setWrapperRef.bind(_assertThisInitialized(_this));
89
- _this.handleClickOutside = _this.handleClickOutside.bind(_assertThisInitialized(_this));
90
- return _this;
91
- }
92
- _createClass(DropdownMenu, [{
93
- key: "componentDidMount",
94
- value: function componentDidMount() {
95
- document.addEventListener("mousedown", this.handleClickOutside);
96
- }
97
- }, {
98
- key: "componentWillUnmount",
99
- value: function componentWillUnmount() {
100
- document.removeEventListener("mousedown", this.handleClickOutside);
101
- }
102
- }, {
103
- key: "setWrapperRef",
104
- value: function setWrapperRef(node) {
105
- this.wrapperRef = node;
106
- }
107
- }, {
108
- key: "handleClickOutside",
109
- value: function handleClickOutside(event) {
110
- if (this.wrapperRef && !this.wrapperRef.contains(event.target)) {
111
- if (this.state.dropdownOpen) {
112
- this.setState({
113
- dropdownOpen: false
114
- });
115
- }
64
+ const DropdownMenu = _ref => {
65
+ let {
66
+ activeSection
67
+ } = _ref;
68
+ const [dropdownOpen, setDropdownOpen] = (0, _react.useState)(false);
69
+ const wrapperRef = (0, _react.useRef)(null);
70
+ (0, _react.useEffect)(() => {
71
+ function handleClickOutside(event) {
72
+ if (wrapperRef.current && !wrapperRef.current.contains(event.target)) {
73
+ setDropdownOpen(false);
116
74
  }
117
75
  }
118
- }, {
119
- key: "toggleDropdown",
120
- value: function toggleDropdown() {
121
- this.setState({
122
- dropdownOpen: !this.state.dropdownOpen
123
- });
124
- }
125
- }, {
126
- key: "render",
127
- value: function render() {
128
- var _this2 = this;
129
- var dropdownContentClass = "dropdown-content";
130
- if (this.state.dropdownOpen) {
131
- dropdownContentClass += " dropdown-open";
132
- }
133
- return /*#__PURE__*/_react.default.createElement("div", {
134
- ref: this.setWrapperRef,
135
- className: "more-dropdown"
136
- }, /*#__PURE__*/_react.default.createElement("a", {
137
- className: "more-btn",
138
- onClick: this.toggleDropdown
139
- }, "More ", /*#__PURE__*/_react.default.createElement("i", {
140
- className: "fa fa-caret-down"
141
- })), /*#__PURE__*/_react.default.createElement("div", {
142
- className: dropdownContentClass
143
- }, Object.keys(dropdownSections).map(function (element, i) {
144
- var cname = "";
145
- if (element == _this2.props.activeSection) cname = "active";
146
- return /*#__PURE__*/_react.default.createElement("a", {
147
- key: i,
148
- className: cname,
149
- href: dropdownSections[element].link
150
- }, dropdownSections[element].name);
151
- })));
152
- }
153
- }]);
154
- return DropdownMenu;
155
- }(_react.default.Component);
156
- var Navbar = /*#__PURE__*/function (_React$Component2) {
157
- _inherits(Navbar, _React$Component2);
158
- var _super2 = _createSuper(Navbar);
159
- function Navbar() {
160
- _classCallCheck(this, Navbar);
161
- return _super2.apply(this, arguments);
162
- }
163
- _createClass(Navbar, [{
164
- key: "render",
165
- value: function render() {
166
- var _this3 = this;
167
- return /*#__PURE__*/_react.default.createElement("div", {
168
- className: "mc-navbar"
169
- }, /*#__PURE__*/_react.default.createElement("a", {
170
- className: "mc-navbrand",
171
- href: "https://www.materialscloud.org/home"
172
- }, /*#__PURE__*/_react.default.createElement("img", {
173
- src: _mcloud_logo.default,
174
- height: "50",
175
- alt: "MC logo"
176
- })), Object.keys(mainSections).map(function (key, i) {
177
- var cname = "mc-navlink";
178
- if (key == _this3.props.activeSection) cname += " active";
179
- return /*#__PURE__*/_react.default.createElement("a", {
180
- key: i,
181
- className: cname,
182
- href: mainSections[key].link
183
- }, mainSections[key].name);
184
- }), /*#__PURE__*/_react.default.createElement(DropdownMenu, {
185
- activeSection: this.props.activeSection
186
- }));
187
- }
188
- }]);
189
- return Navbar;
190
- }(_react.default.Component);
191
- var _default = Navbar;
192
- exports.default = _default;
76
+ document.addEventListener("mousedown", handleClickOutside);
77
+ return () => document.removeEventListener("mousedown", handleClickOutside);
78
+ }, []);
79
+ const toggleDropdown = () => setDropdownOpen(prev => !prev);
80
+ const dropdownContentClass = "dropdown-content" + (dropdownOpen ? " dropdown-open" : "");
81
+ return /*#__PURE__*/React.createElement("div", {
82
+ ref: wrapperRef,
83
+ className: "more-dropdown"
84
+ }, /*#__PURE__*/React.createElement("span", {
85
+ className: "more-btn",
86
+ onClick: toggleDropdown
87
+ }, "More ", /*#__PURE__*/React.createElement("i", {
88
+ className: "fa fa-caret-down"
89
+ })), /*#__PURE__*/React.createElement("div", {
90
+ className: dropdownContentClass
91
+ }, Object.keys(dropdownSections).map((element, i) => {
92
+ const {
93
+ link,
94
+ name
95
+ } = dropdownSections[element];
96
+ const cname = element === activeSection ? "active" : "";
97
+ return /*#__PURE__*/React.createElement("a", {
98
+ key: i,
99
+ className: cname,
100
+ href: link
101
+ }, name);
102
+ })));
103
+ };
104
+ const Navbar = _ref2 => {
105
+ let {
106
+ activeSection
107
+ } = _ref2;
108
+ return /*#__PURE__*/React.createElement("div", {
109
+ className: "mc-navbar"
110
+ }, /*#__PURE__*/React.createElement("a", {
111
+ className: "mc-navbrand",
112
+ href: "https://www.materialscloud.org/home"
113
+ }, /*#__PURE__*/React.createElement("img", {
114
+ src: _mcloud_logo.default,
115
+ height: "50",
116
+ alt: "MC logo"
117
+ })), Object.keys(mainSections).map((key, i) => {
118
+ let cname = "mc-navlink";
119
+ if (key === activeSection) cname += " active";
120
+ return /*#__PURE__*/React.createElement("a", {
121
+ key: i,
122
+ className: cname,
123
+ href: mainSections[key].link
124
+ }, mainSections[key].name);
125
+ }), /*#__PURE__*/React.createElement(DropdownMenu, {
126
+ activeSection: activeSection
127
+ }));
128
+ };
129
+ var _default = exports.default = Navbar;
package/dist/index.js CHANGED
@@ -1,49 +1,27 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.default = void 0;
8
- var _react = _interopRequireDefault(require("react"));
9
7
  require("./index.css");
10
8
  var _Navbar = _interopRequireDefault(require("./Navbar"));
11
9
  var _Breadcrumbs = _interopRequireDefault(require("./Breadcrumbs"));
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14
- 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, _toPropertyKey(descriptor.key), descriptor); } }
15
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
16
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
17
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
18
- 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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
19
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
20
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
21
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
22
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
23
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
24
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
25
- var MaterialsCloudHeader = /*#__PURE__*/function (_React$Component) {
26
- _inherits(MaterialsCloudHeader, _React$Component);
27
- var _super = _createSuper(MaterialsCloudHeader);
28
- function MaterialsCloudHeader(props) {
29
- _classCallCheck(this, MaterialsCloudHeader);
30
- return _super.call(this, props);
31
- }
32
- _createClass(MaterialsCloudHeader, [{
33
- key: "render",
34
- value: function render() {
35
- return /*#__PURE__*/_react.default.createElement("div", {
36
- className: "main-container"
37
- }, /*#__PURE__*/_react.default.createElement(_Navbar.default, {
38
- activeSection: this.props.activeSection
39
- }), /*#__PURE__*/_react.default.createElement("div", {
40
- className: "content-container"
41
- }, /*#__PURE__*/_react.default.createElement(_Breadcrumbs.default, {
42
- breadcrumbsPath: this.props.breadcrumbsPath
43
- }), this.props.children));
44
- }
45
- }]);
46
- return MaterialsCloudHeader;
47
- }(_react.default.Component);
48
- var _default = MaterialsCloudHeader;
49
- exports.default = _default;
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ const MaterialsCloudHeader = _ref => {
12
+ let {
13
+ activeSection,
14
+ breadcrumbsPath,
15
+ children
16
+ } = _ref;
17
+ return /*#__PURE__*/React.createElement("div", {
18
+ className: "main-container"
19
+ }, /*#__PURE__*/React.createElement(_Navbar.default, {
20
+ activeSection: activeSection
21
+ }), /*#__PURE__*/React.createElement("div", {
22
+ className: "content-container"
23
+ }, /*#__PURE__*/React.createElement(_Breadcrumbs.default, {
24
+ breadcrumbsPath: breadcrumbsPath
25
+ }), children));
26
+ };
27
+ var _default = exports.default = MaterialsCloudHeader;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mc-react-header",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "author": "Kristjan Eimre <kristjan.eimre@epfl.ch>",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -17,7 +17,7 @@
17
17
  "font-awesome": "^4.7.0",
18
18
  "react": "^18.2.0",
19
19
  "react-dom": "^18.2.0",
20
- "react-scripts": "5.0.1",
20
+ "react-scripts": "^5.0.1",
21
21
  "web-vitals": "^2.1.4"
22
22
  },
23
23
  "scripts": {
@@ -6,7 +6,6 @@ ul.mc-breadcrumb {
6
6
  border-radius: 2px;
7
7
  border: 1px solid #d6d6d6;
8
8
  font-size: 16px;
9
- font-weight: 300;
10
9
  font-family: "Open Sans", sans-serif;
11
10
  text-align: left;
12
11
  margin: 6px;
@@ -21,11 +20,10 @@ ul.mc-breadcrumb {
21
20
  align-items: center;
22
21
  }
23
22
 
24
-
25
23
  /* Display list items side by side */
26
24
  ul.mc-breadcrumb li {
27
25
  display: inline;
28
- line-height: 1.0;
26
+ line-height: 1;
29
27
  margin-right: 46px;
30
28
  position: relative;
31
29
  }
@@ -40,7 +38,6 @@ ul.mc-breadcrumb li a {
40
38
  /* z-index: 3; */
41
39
  }
42
40
 
43
-
44
41
  /* Add a color on mouse-over, if the <a> has href defined */
45
42
  ul.mc-breadcrumb li a[href]:hover {
46
43
  text-decoration: underline;
@@ -98,4 +95,3 @@ ul.mc-breadcrumb li a:not([href]):hover {
98
95
  border: 0;
99
96
  display: none;
100
97
  }
101
-
@@ -1,19 +1,15 @@
1
- import React from "react";
2
-
3
1
  import "./Breadcrumbs.css";
4
2
 
5
- function Breadcrumbs(props) {
6
- return (
7
- <ul className="mc-breadcrumb">
8
- {props.breadcrumbsPath.map((el, i) => {
9
- return (
10
- <li key={i}>
11
- <a href={el.link}>{el.name}</a>
12
- </li>
13
- );
14
- })}
15
- </ul>
16
- );
17
- }
3
+ const Breadcrumbs = ({ breadcrumbsPath }) => (
4
+ <ul className="mc-breadcrumb">
5
+ {breadcrumbsPath.map((el, i) => {
6
+ return (
7
+ <li key={i}>
8
+ <a href={el.link}>{el.name}</a>
9
+ </li>
10
+ );
11
+ })}
12
+ </ul>
13
+ );
18
14
 
19
15
  export default Breadcrumbs;
@@ -76,7 +76,6 @@
76
76
  .dropdown-content a {
77
77
  float: none;
78
78
  color: #455860;
79
- font-weight: 300;
80
79
  padding: 10px 14px;
81
80
  text-decoration: none;
82
81
  display: block;
@@ -3,7 +3,7 @@ import "./Navbar.css";
3
3
  import Logo from "./assets/mcloud_logo.png";
4
4
 
5
5
  import "font-awesome/css/font-awesome.min.css";
6
- import React from "react";
6
+ import { useEffect, useRef, useState } from "react";
7
7
 
8
8
  const mainSections = {
9
9
  learn: { name: "LEARN", link: "https://www.materialscloud.org/learn" },
@@ -44,88 +44,61 @@ const dropdownSections = {
44
44
  },
45
45
  };
46
46
 
47
- class DropdownMenu extends React.Component {
48
- constructor(props) {
49
- super(props);
50
- this.state = { dropdownOpen: false };
51
- this.toggleDropdown = this.toggleDropdown.bind(this);
52
- this.setWrapperRef = this.setWrapperRef.bind(this);
53
- this.handleClickOutside = this.handleClickOutside.bind(this);
54
- }
47
+ const DropdownMenu = ({ activeSection }) => {
48
+ const [dropdownOpen, setDropdownOpen] = useState(false);
49
+ const wrapperRef = useRef(null);
55
50
 
56
- componentDidMount() {
57
- document.addEventListener("mousedown", this.handleClickOutside);
58
- }
59
-
60
- componentWillUnmount() {
61
- document.removeEventListener("mousedown", this.handleClickOutside);
62
- }
63
-
64
- setWrapperRef(node) {
65
- this.wrapperRef = node;
66
- }
67
-
68
- handleClickOutside(event) {
69
- if (this.wrapperRef && !this.wrapperRef.contains(event.target)) {
70
- if (this.state.dropdownOpen) {
71
- this.setState({ dropdownOpen: false });
51
+ useEffect(() => {
52
+ function handleClickOutside(event) {
53
+ if (wrapperRef.current && !wrapperRef.current.contains(event.target)) {
54
+ setDropdownOpen(false);
72
55
  }
73
56
  }
74
- }
57
+ document.addEventListener("mousedown", handleClickOutside);
58
+ return () => document.removeEventListener("mousedown", handleClickOutside);
59
+ }, []);
75
60
 
76
- toggleDropdown() {
77
- this.setState({ dropdownOpen: !this.state.dropdownOpen });
78
- }
79
- render() {
80
- let dropdownContentClass = "dropdown-content";
81
- if (this.state.dropdownOpen) {
82
- dropdownContentClass += " dropdown-open";
83
- }
84
- return (
85
- <div ref={this.setWrapperRef} className="more-dropdown">
86
- <a className="more-btn" onClick={this.toggleDropdown}>
87
- More <i className="fa fa-caret-down"></i>
88
- </a>
89
- <div className={dropdownContentClass}>
90
- {Object.keys(dropdownSections).map((element, i) => {
91
- let cname = "";
92
- if (element == this.props.activeSection) cname = "active";
93
- return (
94
- <a
95
- key={i}
96
- className={cname}
97
- href={dropdownSections[element].link}
98
- >
99
- {dropdownSections[element].name}
100
- </a>
101
- );
102
- })}
103
- </div>
104
- </div>
105
- );
106
- }
107
- }
61
+ const toggleDropdown = () => setDropdownOpen((prev) => !prev);
108
62
 
109
- class Navbar extends React.Component {
110
- render() {
111
- return (
112
- <div className="mc-navbar">
113
- <a className="mc-navbrand" href="https://www.materialscloud.org/home">
114
- <img src={Logo} height="50" alt="MC logo" />
115
- </a>
116
- {Object.keys(mainSections).map((key, i) => {
117
- let cname = "mc-navlink";
118
- if (key == this.props.activeSection) cname += " active";
63
+ const dropdownContentClass =
64
+ "dropdown-content" + (dropdownOpen ? " dropdown-open" : "");
65
+
66
+ return (
67
+ <div ref={wrapperRef} className="more-dropdown">
68
+ <span className="more-btn" onClick={toggleDropdown}>
69
+ More <i className="fa fa-caret-down" />
70
+ </span>
71
+ <div className={dropdownContentClass}>
72
+ {Object.keys(dropdownSections).map((element, i) => {
73
+ const { link, name } = dropdownSections[element];
74
+ const cname = element === activeSection ? "active" : "";
119
75
  return (
120
- <a key={i} className={cname} href={mainSections[key].link}>
121
- {mainSections[key].name}
76
+ <a key={i} className={cname} href={link}>
77
+ {name}
122
78
  </a>
123
79
  );
124
80
  })}
125
- <DropdownMenu activeSection={this.props.activeSection} />
126
81
  </div>
127
- );
128
- }
129
- }
82
+ </div>
83
+ );
84
+ };
85
+
86
+ const Navbar = ({ activeSection }) => (
87
+ <div className="mc-navbar">
88
+ <a className="mc-navbrand" href="https://www.materialscloud.org/home">
89
+ <img src={Logo} height="50" alt="MC logo" />
90
+ </a>
91
+ {Object.keys(mainSections).map((key, i) => {
92
+ let cname = "mc-navlink";
93
+ if (key === activeSection) cname += " active";
94
+ return (
95
+ <a key={i} className={cname} href={mainSections[key].link}>
96
+ {mainSections[key].name}
97
+ </a>
98
+ );
99
+ })}
100
+ <DropdownMenu activeSection={activeSection} />
101
+ </div>
102
+ );
130
103
 
131
104
  export default Navbar;
@@ -1,25 +1,16 @@
1
- import React from "react";
2
1
  import "./index.css";
3
2
 
4
3
  import Navbar from "./Navbar";
5
4
  import Breadcrumbs from "./Breadcrumbs";
6
5
 
7
- class MaterialsCloudHeader extends React.Component {
8
- constructor(props) {
9
- super(props);
10
- }
11
-
12
- render() {
13
- return (
14
- <div className="main-container">
15
- <Navbar activeSection={this.props.activeSection} />
16
- <div className="content-container">
17
- <Breadcrumbs breadcrumbsPath={this.props.breadcrumbsPath} />
18
- {this.props.children}
19
- </div>
20
- </div>
21
- );
22
- }
23
- }
6
+ const MaterialsCloudHeader = ({ activeSection, breadcrumbsPath, children }) => (
7
+ <div className="main-container">
8
+ <Navbar activeSection={activeSection} />
9
+ <div className="content-container">
10
+ <Breadcrumbs breadcrumbsPath={breadcrumbsPath} />
11
+ {children}
12
+ </div>
13
+ </div>
14
+ );
24
15
 
25
16
  export default MaterialsCloudHeader;