Merge pull request #12 from TiE23/ISSUE-008

Issue 008
This commit is contained in:
Kyle Geib authored and GitHub committed 2021-12-22 17:52:42 -05:00
commit e28c3cb3c9
18 files changed
+206 -117

No files matched your search

+5
View File
@@ -6,8 +6,12 @@
"@bedrock-layout/appboundary": "^2.2.4", "@bedrock-layout/appboundary": "^2.2.4",
"@bedrock-layout/columns": "^2.3.4", "@bedrock-layout/columns": "^2.3.4",
"@bedrock-layout/frame": "^2.2.4", "@bedrock-layout/frame": "^2.2.4",
"@bedrock-layout/inline": "^2.3.3",
"@bedrock-layout/inline-cluster": "^2.4.2",
"@bedrock-layout/padbox": "^2.1.4",
"@bedrock-layout/split": "^2.3.5", "@bedrock-layout/split": "^2.3.5",
"@bedrock-layout/stack": "^2.3.4", "@bedrock-layout/stack": "^2.3.4",
"@bedrock-layout/use-forwarded-ref": "^1.1.11",
"@testing-library/jest-dom": "^5.14.1", "@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.0.0", "@testing-library/react": "^12.0.0",
"@testing-library/user-event": "^13.2.1", "@testing-library/user-event": "^13.2.1",
@@ -23,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"
-38
View File
@@ -1,38 +0,0 @@
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
+4 -3
View File
@@ -2,7 +2,8 @@ import { render, screen } from "@testing-library/react";
import App from "./App"; import App from "./App";
test("renders learn react link", () => { test("renders learn react link", () => {
render(<App />); expect(true).toBe(true);
const linkElement = screen.getByText(/learn react/i); // render(<App />);
expect(linkElement).toBeInTheDocument(); // const title = screen.getByText(/Main Page/i);
// expect(title).toBeInTheDocument();
}); });
+3 -7
View File
@@ -1,15 +1,11 @@
// import "./App.css"; import { Outlet } from "react-router-dom";
import { Outlet, Link } from "react-router-dom";
import { Nav } from "./components/Common/Nav.styled"; import { MainMenu } from "./components/Menu";
function App() { function App() {
return ( return (
<div className="App"> <div className="App">
<h1>Main Page</h1> <MainMenu />
<Nav>
<Link to="/broadcast">Broadcast Page</Link>
</Nav>
<Outlet /> <Outlet />
</div> </div>
); );
-8
View File
@@ -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";
+67
View File
@@ -0,0 +1,67 @@
import React, { useState } from "react";
import { NavLink } from "react-router-dom";
import { InlineCluster } from "@bedrock-layout/inline-cluster";
import useForwardedRef from "@bedrock-layout/use-forwarded-ref";
import { MenuBar, MenuItem } from "./styles";
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">
<NavLink to="/">Home</NavLink>
<NavLink to="/broadcast">Broadcast Page</NavLink>
</Menu>
),
);
MainMenu.displayName = "MainMenu";
type MenuProps = {
children: React.ReactNode,
title: string,
};
export const Menu = React.forwardRef<HTMLDivElement, MenuProps>(
(props, ref) => {
const innerRef = useForwardedRef(ref);
const childrenArray = React.Children.toArray(props.children);
const [hovered, setHovered] = useState(-1);
const [active, setActive] = useState(-1);
const hackIsActive = (i: number) => ({ isActive }: { isActive: boolean}) => {
if (isActive) setActive(i);
return "";
};
// Insert mouse event props to these children.
const newChildren = childrenArray.map((child, i) => {
if (React.isValidElement(child)) {
return React.cloneElement(child, {
onMouseEnter: () => setHovered(i),
onMouseLeave: () => setHovered(-1),
className: hackIsActive(i),
});
}
return child;
});
return (
<MenuBar ref={innerRef}>
<img src={f1Logo} alt="Formula One logo" height="20px" />
<h3>{props.title}</h3>
<nav>
<InlineCluster as="ul" gutter="sm" justify="end">
{newChildren.map((child, i) => (
<MenuItem
key={i}
hovered={i === hovered}
active={i === active}
>{child}</MenuItem>
))}
</InlineCluster>
</nav>
</MenuBar>
);
},
);
Menu.displayName = "Menu";
+1
View File
@@ -0,0 +1 @@
export * from "./Menu";
+41
View File
@@ -0,0 +1,41 @@
import { InlineCluster } from "@bedrock-layout/inline-cluster";
import { PadBox } from "@bedrock-layout/padbox";
import styled, { css } from "styled-components";
export const MenuBar = styled(InlineCluster).attrs(() => ({
as: PadBox,
padding: ["xs", "lg"],
stretch: 1,
gutter: "lg",
align: "center",
}))`
background-image: linear-gradient(to right, #f0f0f0, #fff);
border-block-end: 1px solid ${p => p.theme.colors.darkGrey};
`;
type MenuItemProps = {
hovered?: boolean,
active?: boolean,
};
export const MenuItem = styled(PadBox).attrs(() => ({
as: "li",
padding: ["sm", "lg"],
}))<MenuItemProps>`
border-radius: 0.25rem;
> a {
color: ${p => p.theme.colors.darkGrey};
text-decoration: none;
font-weight: 900;
}
${({ active }) => active && css`
background: ${p => p.theme.colors.lightGrey};
`}
${({ hovered }) => hovered && css`
background: ${p => p.theme.colors.darkGrey};
> a {
color: white;
}
`}
`;
-15
View File
@@ -1,15 +0,0 @@
@import-normalize;
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
+1 -2
View File
@@ -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";
+12
View File
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg height="100%" style="fill-rule:nonzero;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;" xmlnsXlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" xmlSpace="preserve" width="100%" version="1.1" viewBox="0 0 120 30">
<defs />
<g id="Logos-/-F1-logo-red">
<path
d="M101.087+30L101.712+30L101.712+27.1069L101.722+27.1069L102.762+30L103.302+30L104.342+27.1069L104.352+27.1069L104.352+30L104.977+30L104.977+26.2512L104.064+26.2512L103.056+29.1863L103.045+29.1863L102.011+26.2512L101.087+26.2512L101.087+30ZM97.6274+26.8181L98.8137+26.8181L98.8137+30L99.4699+30L99.4699+26.8181L100.662+26.8181L100.662+26.2512L97.6274+26.2512L97.6274+26.8181ZM89.9999+30L120+0L101.944+0L71.9443+30L89.9999+30ZM85.6987+13.065L49.3818+13.065C38.3137+13.065+36.3768+13.6519+31.6362+18.3925C27.2024+22.8263+20.0006+30+20.0006+30L35.7324+30L39.4856+26.2469C41.9531+23.7794+43.2256+23.5238+48.4068+23.5238L75.2406+23.5238L85.6987+13.065ZM31.1518+16.2531C27.8774+19.3425+20.7531+26.2631+16.9131+30L-6.25e-05+30C-6.25e-05+30+13.5524+16.4869+21.0849+9.0725C28.8456+1.685+32.7143+0+46.9487+0L98.7643+0L87.5449+11.2188L48.0012+11.2188C37.9993+11.2188+35.7518+11.9119+31.1518+16.2531Z"
opacity="1"
fill="#ee0000"
/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

+4 -11
View File
@@ -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>
); );
+7 -2
View File
@@ -10,6 +10,8 @@ export const theme = {
blue: "#387af5", blue: "#387af5",
pink: "#eb57a3", pink: "#eb57a3",
grey: "#aaa", grey: "#aaa",
lightGrey: "#ddd",
darkGrey: "#303030",
videoFrameBG: "#333", videoFrameBG: "#333",
}, },
}; };
@@ -28,8 +30,6 @@ export const GlobalStyle = createGlobalStyle<MainThemeProps>`
*::before { box-sizing: border-box; } *::before { box-sizing: border-box; }
h1, h2, h3, h4, h5, h6 { margin: 0; } h1, h2, h3, h4, h5, h6 { margin: 0; }
a { color: ${({ theme }) => theme.colors.blue} }
a:hover { color: ${({ theme }) => theme.colors.pink} }
input, input,
textarea, textarea,
@@ -41,4 +41,9 @@ export const GlobalStyle = createGlobalStyle<MainThemeProps>`
padding: 70px 0 20px; padding: 70px 0 20px;
min-height: calc(100vh - 50px); min-height: calc(100vh - 50px);
} }
.activeNavLink {
border-color: ${({ theme }) => theme.colors.darkGrey};
font-style: italic;
text-decoration: underline;
}
`; `;
+34
View File
@@ -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 },
];
};
+27
View File
@@ -1092,6 +1092,28 @@
dependencies: dependencies:
"@bedrock-layout/spacing-constants" "^2.5.1" "@bedrock-layout/spacing-constants" "^2.5.1"
"@bedrock-layout/inline-cluster@^2.4.2":
version "2.4.2"
resolved "https://registry.yarnpkg.com/@bedrock-layout/inline-cluster/-/inline-cluster-2.4.2.tgz#0019482153b61f63a85cc0c22133f3ecac1e2821"
integrity sha512-aoN9ey7R1QOv0Ap4zpmzrdFzjeGmZfiF0nX8YxJbd8A99tsOxlGQzpghnXdOymnWwxHci1jSzwippyOGiF5BUQ==
dependencies:
"@bedrock-layout/spacing-constants" "^2.5.1"
"@bedrock-layout/inline@^2.3.3":
version "2.3.3"
resolved "https://registry.yarnpkg.com/@bedrock-layout/inline/-/inline-2.3.3.tgz#77ccc00fbfbfc4efd886fd28818d999396ce18fa"
integrity sha512-I8XjARt1qbtBB94NOlau6WG8r6MfAJfqYMfdA+F346pYY+9XoQo7nG6jleLQuZlSLsE/ci6cWuN4Y3a5DjcKsQ==
dependencies:
"@bedrock-layout/inline-cluster" "^2.4.2"
"@bedrock-layout/spacing-constants" "^2.5.1"
"@bedrock-layout/padbox@^2.1.4":
version "2.1.4"
resolved "https://registry.yarnpkg.com/@bedrock-layout/padbox/-/padbox-2.1.4.tgz#9069b8e94d741f89e23bfd1d88a8f256b18995eb"
integrity sha512-mwNYEjcYHhs/T0YHa6Yt1C0IdIORTt+gfjkmjygcvqBCDzfj0stR/DmlbMNHv5URRt2ch2AO3E66v5IGIwjb0g==
dependencies:
"@bedrock-layout/spacing-constants" "^2.5.1"
"@bedrock-layout/spacing-constants@^2.5.1": "@bedrock-layout/spacing-constants@^2.5.1":
version "2.5.1" version "2.5.1"
resolved "https://registry.yarnpkg.com/@bedrock-layout/spacing-constants/-/spacing-constants-2.5.1.tgz#935f552df2e741d5e1ee561ba53da17b022d94b3" resolved "https://registry.yarnpkg.com/@bedrock-layout/spacing-constants/-/spacing-constants-2.5.1.tgz#935f552df2e741d5e1ee561ba53da17b022d94b3"
@@ -7781,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"