ISSUE-008 - Major refactor of the Menu Bar. Utilizing some really fun resize hooks and dropping the ugly route header idea.
This commit is contained in:
1 parent
73ba3b4ddd
commit
f4ccb9b3dd
13 files changed
+76
-73
No files matched your search
@@ -27,6 +27,7 @@
|
|||||||
"react-dom": "^17.0.2",
|
"react-dom": "^17.0.2",
|
||||||
"react-router-dom": "6",
|
"react-router-dom": "6",
|
||||||
"react-scripts": "5.0.0",
|
"react-scripts": "5.0.0",
|
||||||
|
"resize-observer-polyfill": "^1.5.1",
|
||||||
"styled-components": "^5.3.3",
|
"styled-components": "^5.3.3",
|
||||||
"typescript": "^4.4.2",
|
"typescript": "^4.4.2",
|
||||||
"web-vitals": "^2.1.0"
|
"web-vitals": "^2.1.0"
|
||||||
|
|||||||
+3
-8
@@ -1,16 +1,11 @@
|
|||||||
import { Outlet, Link } from "react-router-dom";
|
import { Outlet } from "react-router-dom";
|
||||||
|
|
||||||
import { Menu } from "./components/Menu";
|
import { MainMenu } from "./components/Menu";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
<Menu title="F1 World Broadcast Emulator Project">
|
<MainMenu />
|
||||||
<Link to="/broadcast">Broadcast Page</Link>
|
|
||||||
<Link to="/broadcast">Broadcast Page</Link>
|
|
||||||
<Link to="/broadcast">Broadcast Page</Link>
|
|
||||||
<Link to="/broadcast">Broadcast Page</Link>
|
|
||||||
</Menu>
|
|
||||||
<Outlet />
|
<Outlet />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
import styled from "styled-components";
|
|
||||||
|
|
||||||
export const Nav = styled.nav`
|
|
||||||
border-bottom: solid 1px;
|
|
||||||
padding-bottom: 1rem;
|
|
||||||
padding-left: 1rem;
|
|
||||||
`;
|
|
||||||
Nav.displayName = "Nav";
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
import { HeaderBar } from "./styles";
|
|
||||||
|
|
||||||
type RouteHeaderProps = {
|
|
||||||
title: string,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const RouteHeader = React.forwardRef<HTMLHeadElement, RouteHeaderProps>(
|
|
||||||
(props, ref) => (
|
|
||||||
<HeaderBar ref={ref}>
|
|
||||||
{props.title}
|
|
||||||
</HeaderBar>
|
|
||||||
),
|
|
||||||
);
|
|
||||||
RouteHeader.displayName = "RouteHeader"; // Required due to forwardRef().
|
|
||||||
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from "./RouteHeader";
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import styled from "styled-components";
|
|
||||||
|
|
||||||
export const HeaderBar = styled.header`
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
z-index: 5;
|
|
||||||
padding: 0 0.3em;
|
|
||||||
background-color: ${p => p.theme.colors.grey};
|
|
||||||
height: 20px;
|
|
||||||
font-family: ${p => p.theme.fonts.accent};
|
|
||||||
font-size: 0.8em;
|
|
||||||
`;
|
|
||||||
HeaderBar.displayName = "HeaderBar";
|
|
||||||
@@ -1,22 +1,34 @@
|
|||||||
import { FC, Children } from "react";
|
import React, { Children } from "react";
|
||||||
|
import { Link } from "react-router-dom";
|
||||||
import { InlineCluster } from "@bedrock-layout/inline-cluster";
|
import { InlineCluster } from "@bedrock-layout/inline-cluster";
|
||||||
|
import useForwardedRef from "@bedrock-layout/use-forwarded-ref";
|
||||||
|
|
||||||
import { MenuBar, MenuItem } from "./styles";
|
import { MenuBar, MenuItem } from "./styles";
|
||||||
|
|
||||||
import f1Logo from "../../public/images/logos/f1-logo-red.svg";
|
import f1Logo from "../../public/images/logos/f1-logo-red.svg";
|
||||||
|
|
||||||
|
export const MainMenu = React.forwardRef<HTMLDivElement>(
|
||||||
|
(_, ref) => (
|
||||||
|
<Menu ref={ref} title="F1 World Broadcast Emulator Project">
|
||||||
|
<Link to="/">Home</Link>
|
||||||
|
<Link to="/broadcast">Broadcast Page</Link>
|
||||||
|
</Menu>
|
||||||
|
),
|
||||||
|
);
|
||||||
|
MainMenu.displayName = "MainMenu";
|
||||||
|
|
||||||
type MenuProps = {
|
type MenuProps = {
|
||||||
|
children: React.ReactNode,
|
||||||
title: string,
|
title: string,
|
||||||
};
|
};
|
||||||
export const Menu: FC<MenuProps> = ({
|
export const Menu = React.forwardRef<HTMLDivElement, MenuProps>(
|
||||||
title,
|
(props, ref) => {
|
||||||
children,
|
const innerRef = useForwardedRef(ref);
|
||||||
}) => {
|
const childrenArray = Children.toArray(props.children);
|
||||||
const childrenArray = Children.toArray(children);
|
|
||||||
return (
|
return (
|
||||||
<MenuBar>
|
<MenuBar ref={innerRef}>
|
||||||
<img src={f1Logo} alt="Formula One logo" height="20px"/>
|
<img src={f1Logo} alt="Formula One logo" height="20px" />
|
||||||
<h3>{title}</h3>
|
<h3>{props.title}</h3>
|
||||||
<nav>
|
<nav>
|
||||||
<InlineCluster as="ul" gutter="sm" justify="end">
|
<InlineCluster as="ul" gutter="sm" justify="end">
|
||||||
{childrenArray.map((child, i) => (
|
{childrenArray.map((child, i) => (
|
||||||
@@ -26,4 +38,6 @@ export const Menu: FC<MenuProps> = ({
|
|||||||
</nav>
|
</nav>
|
||||||
</MenuBar>
|
</MenuBar>
|
||||||
);
|
);
|
||||||
};
|
},
|
||||||
|
);
|
||||||
|
Menu.displayName = "Menu";
|
||||||
@@ -10,7 +10,7 @@ export const MenuBar = styled(InlineCluster).attrs(() => ({
|
|||||||
align: "center",
|
align: "center",
|
||||||
}))`
|
}))`
|
||||||
background-image: linear-gradient(to right, #f0f0f0, #fff);
|
background-image: linear-gradient(to right, #f0f0f0, #fff);
|
||||||
border-block-end: 1px solid #303030;
|
border-block-end: 1px solid ${p => p.theme.colors.darkGrey};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
type MenuItemProps = {
|
type MenuItemProps = {
|
||||||
@@ -22,12 +22,12 @@ export const MenuItem = styled(PadBox).attrs(() => ({
|
|||||||
})) <MenuItemProps>`
|
})) <MenuItemProps>`
|
||||||
border-radius: 0.25rem;
|
border-radius: 0.25rem;
|
||||||
> a {
|
> a {
|
||||||
color: #333;
|
color: ${p => p.theme.colors.darkGrey};
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
font-weight: 900;
|
font-weight: 900;
|
||||||
}
|
}
|
||||||
:hover {
|
:hover {
|
||||||
background: #303030;
|
background: ${p => p.theme.colors.darkGrey};
|
||||||
> a {
|
> a {
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -3,8 +3,7 @@ import ReactDOM from "react-dom";
|
|||||||
import { BrowserRouter, Route, Routes } from "react-router-dom";
|
import { BrowserRouter, Route, Routes } from "react-router-dom";
|
||||||
import { ThemeProvider } from "styled-components";
|
import { ThemeProvider } from "styled-components";
|
||||||
|
|
||||||
// import "./index.css";
|
import "./clear.css";
|
||||||
// import "./clear.css";
|
|
||||||
|
|
||||||
import App from "./App";
|
import App from "./App";
|
||||||
import Broadcast from "./routes/BroadcastRoute";
|
import Broadcast from "./routes/BroadcastRoute";
|
||||||
|
|||||||
@@ -1,21 +1,14 @@
|
|||||||
import { useEffect, useRef, useState } from "react";
|
|
||||||
|
|
||||||
import { FullScreenContainer } from "./styles";
|
import { FullScreenContainer } from "./styles";
|
||||||
import { Layout } from "../components/Broadcast/Layout";
|
import { Layout } from "../components/Broadcast/Layout";
|
||||||
import { RouteHeader } from "../components/Common/RouteHeader";
|
import { MainMenu } from "../components/Menu";
|
||||||
|
import { useDimensions } from "../utils/hooks";
|
||||||
|
|
||||||
export default function Broadcast() {
|
export default function Broadcast() {
|
||||||
const [height, setHeight] = useState(0);
|
const [ref, { height }] = useDimensions<HTMLDivElement>();
|
||||||
const ref = useRef < HTMLHeadElement>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (ref?.current != null)
|
|
||||||
setHeight(ref.current.clientHeight);
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FullScreenContainer minHeight={700} minWidth={900}>
|
<FullScreenContainer minHeight={700} minWidth={900}>
|
||||||
<RouteHeader ref={ref} title="Broadcast Page" />
|
<MainMenu ref={ref}/>
|
||||||
<Layout headerHeight={height} />
|
<Layout headerHeight={height} />
|
||||||
</FullScreenContainer>
|
</FullScreenContainer>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export const theme = {
|
|||||||
blue: "#387af5",
|
blue: "#387af5",
|
||||||
pink: "#eb57a3",
|
pink: "#eb57a3",
|
||||||
grey: "#aaa",
|
grey: "#aaa",
|
||||||
|
darkGrey: "#303030",
|
||||||
videoFrameBG: "#333",
|
videoFrameBG: "#333",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
|
import ResizeObserver from "resize-observer-polyfill";
|
||||||
|
|
||||||
|
export const useDimensions = <T extends HTMLElement>() => {
|
||||||
|
const ref = useRef<T>(null);
|
||||||
|
const [width, setWidth] = useState(0);
|
||||||
|
const [height, setHeight] = useState(0);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const element = ref.current;
|
||||||
|
if (element == null) return;
|
||||||
|
const resizeObserver = new ResizeObserver(entries => {
|
||||||
|
if (!Array.isArray(entries)) return;
|
||||||
|
if (!entries.length) return;
|
||||||
|
|
||||||
|
const entry = entries[0];
|
||||||
|
const boundingRect = entry.target.getBoundingClientRect();
|
||||||
|
if (width !== boundingRect.width) setWidth(boundingRect.width);
|
||||||
|
if (height !== boundingRect.height) setHeight(boundingRect.height);
|
||||||
|
});
|
||||||
|
resizeObserver.observe(element);
|
||||||
|
|
||||||
|
return () => resizeObserver.unobserve(element);
|
||||||
|
}, [height, width]);
|
||||||
|
|
||||||
|
// Returning correctly with generics apparently requires type def here.
|
||||||
|
return [
|
||||||
|
ref,
|
||||||
|
{ width, height },
|
||||||
|
] as [
|
||||||
|
React.RefObject<T>,
|
||||||
|
{ height: number, width: number },
|
||||||
|
];
|
||||||
|
};
|
||||||
@@ -7803,6 +7803,11 @@ requires-port@^1.0.0:
|
|||||||
resolved "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz"
|
resolved "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz"
|
||||||
integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=
|
integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=
|
||||||
|
|
||||||
|
resize-observer-polyfill@^1.5.1:
|
||||||
|
version "1.5.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz#0e9020dd3d21024458d4ebd27e23e40269810464"
|
||||||
|
integrity sha512-LwZrotdHOo12nQuZlHEmtuXdqGoOD0OhaxopaNFxWzInpEgaLWoVuAMbTzixuosCx2nEG58ngzW3vxdWoxIgdg==
|
||||||
|
|
||||||
resolve-cwd@^3.0.0:
|
resolve-cwd@^3.0.0:
|
||||||
version "3.0.0"
|
version "3.0.0"
|
||||||
resolved "https://registry.npmjs.org/resolve-cwd/-/resolve-cwd-3.0.0.tgz"
|
resolved "https://registry.npmjs.org/resolve-cwd/-/resolve-cwd-3.0.0.tgz"
|
||||||
|
|||||||
Reference in new issue
Block a user