mc-react-header 0.2.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.
@@ -1,131 +1,104 @@
1
- import "./Navbar.css";
2
-
3
- import Logo from "./assets/mcloud_logo.png";
4
-
5
- import "font-awesome/css/font-awesome.min.css";
6
- import React from "react";
7
-
8
- const mainSections = {
9
- learn: { name: "LEARN", link: "https://www.materialscloud.org/learn" },
10
- work: { name: "WORK", link: "https://www.materialscloud.org/work" },
11
- discover: {
12
- name: "DISCOVER",
13
- link: "https://www.materialscloud.org/discover",
14
- },
15
- explore: { name: "EXPLORE", link: "https://www.materialscloud.org/explore" },
16
- archive: { name: "ARCHIVE", link: "https://www.materialscloud.org/archive" },
17
- };
18
-
19
- const dropdownSections = {
20
- policies: {
21
- name: "Policies",
22
- link: "https://www.materialscloud.org/policies",
23
- },
24
- dmp: {
25
- name: "Data Management Plan",
26
- link: "https://www.materialscloud.org/dmp",
27
- },
28
- terms: {
29
- name: "Terms of Use",
30
- link: "https://www.materialscloud.org/termssummary",
31
- },
32
- infrastructure: {
33
- name: "Infrastructure",
34
- link: "https://www.materialscloud.org/infrastructure",
35
- },
36
- team: { name: "Team & Contact", link: "https://www.materialscloud.org/team" },
37
- partners: {
38
- name: "Partners",
39
- link: "https://www.materialscloud.org/home#partners",
40
- },
41
- restapi: {
42
- name: "Connect your REST API",
43
- link: "https://www.materialscloud.org/explore/connect",
44
- },
45
- };
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
- }
55
-
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 });
72
- }
73
- }
74
- }
75
-
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
- }
108
-
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";
119
- return (
120
- <a key={i} className={cname} href={mainSections[key].link}>
121
- {mainSections[key].name}
122
- </a>
123
- );
124
- })}
125
- <DropdownMenu activeSection={this.props.activeSection} />
126
- </div>
127
- );
128
- }
129
- }
130
-
131
- export default Navbar;
1
+ import "./Navbar.css";
2
+
3
+ import Logo from "./assets/mcloud_logo.png";
4
+
5
+ import "font-awesome/css/font-awesome.min.css";
6
+ import { useEffect, useRef, useState } from "react";
7
+
8
+ const mainSections = {
9
+ learn: { name: "LEARN", link: "https://www.materialscloud.org/learn" },
10
+ work: { name: "WORK", link: "https://www.materialscloud.org/work" },
11
+ discover: {
12
+ name: "DISCOVER",
13
+ link: "https://www.materialscloud.org/discover",
14
+ },
15
+ explore: { name: "EXPLORE", link: "https://www.materialscloud.org/explore" },
16
+ archive: { name: "ARCHIVE", link: "https://www.materialscloud.org/archive" },
17
+ };
18
+
19
+ const dropdownSections = {
20
+ policies: {
21
+ name: "Policies",
22
+ link: "https://www.materialscloud.org/policies",
23
+ },
24
+ dmp: {
25
+ name: "Data Management Plan",
26
+ link: "https://www.materialscloud.org/dmp",
27
+ },
28
+ terms: {
29
+ name: "Terms of Use",
30
+ link: "https://www.materialscloud.org/termssummary",
31
+ },
32
+ infrastructure: {
33
+ name: "Infrastructure",
34
+ link: "https://www.materialscloud.org/infrastructure",
35
+ },
36
+ team: { name: "Team & Contact", link: "https://www.materialscloud.org/team" },
37
+ partners: {
38
+ name: "Partners",
39
+ link: "https://www.materialscloud.org/home#partners",
40
+ },
41
+ restapi: {
42
+ name: "Connect your REST API",
43
+ link: "https://www.materialscloud.org/explore/connect",
44
+ },
45
+ };
46
+
47
+ const DropdownMenu = ({ activeSection }) => {
48
+ const [dropdownOpen, setDropdownOpen] = useState(false);
49
+ const wrapperRef = useRef(null);
50
+
51
+ useEffect(() => {
52
+ function handleClickOutside(event) {
53
+ if (wrapperRef.current && !wrapperRef.current.contains(event.target)) {
54
+ setDropdownOpen(false);
55
+ }
56
+ }
57
+ document.addEventListener("mousedown", handleClickOutside);
58
+ return () => document.removeEventListener("mousedown", handleClickOutside);
59
+ }, []);
60
+
61
+ const toggleDropdown = () => setDropdownOpen((prev) => !prev);
62
+
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" : "";
75
+ return (
76
+ <a key={i} className={cname} href={link}>
77
+ {name}
78
+ </a>
79
+ );
80
+ })}
81
+ </div>
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
+ );
103
+
104
+ export default Navbar;
@@ -1,15 +1,14 @@
1
- .main-container {
2
- background-color: #f0f6f9;
3
- height: 100%;
4
- padding-bottom: 10px;
5
- }
6
-
7
- .content-container {
8
- background-color: white;
9
- margin: 5px;
10
- margin-top: 30px;
11
- margin-bottom: 10px;
12
- padding: 2px;
13
- padding-bottom: 20px;
14
- border-radius: 2px;
15
- }
1
+ .main-container {
2
+ background-color: #f0f6f9;
3
+ min-height: 100vh;
4
+ }
5
+
6
+ .content-container {
7
+ background-color: white;
8
+ margin: 5px;
9
+ margin-top: 30px;
10
+ margin-bottom: 10px;
11
+ padding: 2px;
12
+ padding-bottom: 20px;
13
+ border-radius: 2px;
14
+ }
@@ -1,25 +1,16 @@
1
- import React from "react";
2
- import "./index.css";
3
-
4
- import Navbar from "./Navbar";
5
- import Breadcrumbs from "./Breadcrumbs";
6
-
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
- }
24
-
25
- export default MaterialsCloudHeader;
1
+ import "./index.css";
2
+
3
+ import Navbar from "./Navbar";
4
+ import Breadcrumbs from "./Breadcrumbs";
5
+
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
+ );
15
+
16
+ export default MaterialsCloudHeader;
package/src/index.css CHANGED
@@ -1,13 +1,13 @@
1
- body {
2
- margin: 0;
3
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4
- 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5
- sans-serif;
6
- -webkit-font-smoothing: antialiased;
7
- -moz-osx-font-smoothing: grayscale;
8
- }
9
-
10
- code {
11
- font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12
- monospace;
13
- }
1
+ body {
2
+ margin: 0;
3
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4
+ 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5
+ sans-serif;
6
+ -webkit-font-smoothing: antialiased;
7
+ -moz-osx-font-smoothing: grayscale;
8
+ }
9
+
10
+ code {
11
+ font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12
+ monospace;
13
+ }
package/src/index.js CHANGED
@@ -1,18 +1,18 @@
1
- import React from "react";
2
- import ReactDOM from "react-dom/client";
3
- import "./index.css";
4
- import App from "./App";
5
- import reportWebVitals from "./reportWebVitals";
6
-
7
- const root = ReactDOM.createRoot(document.getElementById("root"));
8
- document.body.style = "background: white;";
9
- root.render(
10
- <React.StrictMode>
11
- <App />
12
- </React.StrictMode>
13
- );
14
-
15
- // If you want to start measuring performance in your app, pass a function
16
- // to log results (for example: reportWebVitals(console.log))
17
- // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
18
- reportWebVitals();
1
+ import React from "react";
2
+ import ReactDOM from "react-dom/client";
3
+ import "./index.css";
4
+ import App from "./App";
5
+ import reportWebVitals from "./reportWebVitals";
6
+
7
+ const root = ReactDOM.createRoot(document.getElementById("root"));
8
+ document.body.style = "background: white;";
9
+ root.render(
10
+ <React.StrictMode>
11
+ <App />
12
+ </React.StrictMode>
13
+ );
14
+
15
+ // If you want to start measuring performance in your app, pass a function
16
+ // to log results (for example: reportWebVitals(console.log))
17
+ // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
18
+ reportWebVitals();
@@ -1,13 +1,13 @@
1
- const reportWebVitals = onPerfEntry => {
2
- if (onPerfEntry && onPerfEntry instanceof Function) {
3
- import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
4
- getCLS(onPerfEntry);
5
- getFID(onPerfEntry);
6
- getFCP(onPerfEntry);
7
- getLCP(onPerfEntry);
8
- getTTFB(onPerfEntry);
9
- });
10
- }
11
- };
12
-
13
- export default reportWebVitals;
1
+ const reportWebVitals = onPerfEntry => {
2
+ if (onPerfEntry && onPerfEntry instanceof Function) {
3
+ import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
4
+ getCLS(onPerfEntry);
5
+ getFID(onPerfEntry);
6
+ getFCP(onPerfEntry);
7
+ getLCP(onPerfEntry);
8
+ getTTFB(onPerfEntry);
9
+ });
10
+ }
11
+ };
12
+
13
+ export default reportWebVitals;
package/src/setupTests.js CHANGED
@@ -1,5 +1,5 @@
1
- // jest-dom adds custom jest matchers for asserting on DOM nodes.
2
- // allows you to do things like:
3
- // expect(element).toHaveTextContent(/react/i)
4
- // learn more: https://github.com/testing-library/jest-dom
5
- import '@testing-library/jest-dom';
1
+ // jest-dom adds custom jest matchers for asserting on DOM nodes.
2
+ // allows you to do things like:
3
+ // expect(element).toHaveTextContent(/react/i)
4
+ // learn more: https://github.com/testing-library/jest-dom
5
+ import '@testing-library/jest-dom';