Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/(talk)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default function TalkRootLayout({
</head>
<body>
<StyledComponentsRegistry>
<Header opacity={0} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use margin-top or padding-top for the page content. We know the height of the header by design, so we should know the space needed for margin/padding. We can define a class this. We could use a css variable for the header height so there's one location for future design changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overrides on browser font settings will result in variable height for the header content. We could use js to determine height on load/resize and update margin-top. We could use a "magic-number" for margin-top that is "good enough" in most situations. We could use position sticky, which is probably what we actually want, but it can have some unintended design consequences if we use any different stacking context. I think that the inclusion of an invisible element is the most consistent and effective way to handle the spacing at top, and is clear in the jsx what the intended purpose is.

<Header />
{children}
</StyledComponentsRegistry>
Expand Down
11 changes: 7 additions & 4 deletions app/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import { links } from "../siteConfig"
import styled from "styled-components"
import { useState } from "react"

export const Header = () => {
export const Header = (props: any) => {
const [isMenuOpen, setIsMenuOpen] = useState(false)
const opacity = props.opacity ?? 1

const toggleMenu = () => {
setIsMenuOpen(!isMenuOpen)
}

return (
<Container>
<Container $opacity={opacity}>
<Nav>
<NavStart>
<MenuButton onClick={toggleMenu}>
Expand Down Expand Up @@ -46,9 +47,11 @@ export const Header = () => {
)
}

const Container = styled.header`
const Container = styled.header<{ $opacity: number }>`
width: 100%;
position: fixed;
opacity: ${(props) => props.$opacity};
position: ${(props) => (props.$opacity === 1 ? "fixed" : "static")};
pointer-events: ${(props) => (props.$opacity === 1 ? "auto" : "none")};
background-color: rgba(0, 0, 0, 0.05);
backdrop-filter: blur(38px);
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
Expand Down