Skip to content

Commit

Permalink
fix(layout): consolidate sticky header (#8781)
Browse files Browse the repository at this point in the history
* fix(layout): consolidate sticky header

use `--sticky-header-height` everywhere

* fix toc for articles

* fix MP-165

* lint

* naming

* printing
  • Loading branch information
fiji-flo authored May 8, 2023
1 parent 9c28eb6 commit 496ab9f
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 42 deletions.
2 changes: 2 additions & 0 deletions client/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
.sidebar,
.top-navigation-main,
.page-footer,
.top-banner,
.place,
ul.prev-next,
.language-menu {
display: none !important;
Expand Down
13 changes: 11 additions & 2 deletions client/src/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,19 @@
--form-elem-height: 2rem;

/* Major Components */
--sticky-header-height: 0;
--top-nav-height: 4rem;
--main-document-header-height: 6rem;
--article-actions-container-height: 2rem;
--icon-size: 1rem;
--sticky-header-height: calc(
var(--top-nav-height) + var(--article-actions-container-height) + 2px
);
}

.top-banner.visible ~ * {
--sticky-header-height: calc(
var(--top-nav-height) + var(--article-actions-container-height) +
var(--top-banner-height) + 2px
);
}

@media screen and (min-width: $screen-md) {
Expand Down
5 changes: 5 additions & 0 deletions client/src/document/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ export function useStickyHeaderHeight() {
// SSR.
return 0;
}
const sidebar = document.querySelector(".sidebar-container");

if (sidebar) {
return parseFloat(getComputedStyle(sidebar).top);
}

const styles = getComputedStyle(document.documentElement);
const stickyHeaderHeight = styles
Expand Down
14 changes: 5 additions & 9 deletions client/src/document/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
@use "../ui/molecules/grids/grids.scss" as *;
@use "../ui/base/typography" as *;

:root {
--sticky-header-height: var(--main-document-header-height);
}

.main-document-header-container {
position: sticky;
top: 0;
Expand Down Expand Up @@ -630,13 +626,13 @@ kbd {
}

.sidebar-container {
--offset: var(--main-document-header-height);
--offset: var(--sticky-header-height);
--max-height: calc(100vh - var(--offset));

@media screen and (max-width: $screen-lg) {
.mdn-cta-container ~ .document-page & {
// minus 3 rem to ~ account for the top banner
--offset: calc(var(--main-document-header-height) + 3rem);
--offset: calc(var(--sticky-header-height) + 3rem);
}
}

Expand All @@ -646,7 +642,7 @@ kbd {
}
max-height: var(--max-height);
position: sticky;
top: 5rem;
top: var(--offset);
@media screen and (min-width: $screen-md) {
.sidebar {
mask-image: linear-gradient(
Expand All @@ -670,7 +666,7 @@ kbd {
display: flex;
flex-direction: column;
gap: 0;
height: calc(100vh - var(--main-document-header-height));
height: calc(100vh - var(--sticky-header-height));
mask-image: linear-gradient(
to bottom,
rgba(0, 0, 0, 0) 0%,
Expand All @@ -679,7 +675,7 @@ kbd {
);
overflow: auto;
position: sticky;
top: var(--main-document-header-height);
top: var(--sticky-header-height);

.place {
margin: 1rem 0;
Expand Down
9 changes: 1 addition & 8 deletions client/src/homepage/static-page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import useSWR from "swr";
import { CRUD_MODE } from "../../env";
import { SidebarContainer } from "../../document/organisms/sidebar";
import { TOC } from "../../document/organisms/toc";
import { DocParent, Toc } from "../../../../libs/types/document";
import { Toc } from "../../../../libs/types/document";
import { PageNotFound } from "../../page-not-found";
import { Loading } from "../../ui/atoms/loading";
import { ArticleActionsContainer } from "../../ui/organisms/article-actions-container";

interface StaticPageDoc {
id: string;
Expand All @@ -19,7 +18,6 @@ interface StaticPageProps {
extraClasses?: string;
locale: string;
slug: string;
parents: DocParent[];
fallbackData?: any;
title?: string;
sidebarHeader?: ReactElement;
Expand All @@ -29,7 +27,6 @@ function StaticPage({
extraClasses = "",
locale,
slug,
parents = [],
fallbackData = undefined,
title = "MDN",
sidebarHeader = <></>,
Expand Down Expand Up @@ -67,10 +64,6 @@ function StaticPage({

return (
<>
<ArticleActionsContainer
parents={[...parents, { uri: baseURL, title: hyData.title }]}
/>

<div className="main-wrapper">
<SidebarContainer doc={hyData}>
{sidebarHeader || null}
Expand Down
17 changes: 4 additions & 13 deletions client/src/plus/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Routes, Route, useLocation, useParams } from "react-router-dom";
import { Routes, Route } from "react-router-dom";

import { useIsServer } from "../hooks";
import { Loading } from "../ui/atoms/loading";
Expand Down Expand Up @@ -60,11 +60,6 @@ export function Plus({ pageTitle, ...props }: { pageTitle?: string }) {
document.title = pageTitle || MDN_PLUS_TITLE;
}, [pageTitle]);

const { locale = "en-US" } = useParams();
const { pathname } = useLocation();

const parents = [{ uri: `/${locale}/plus`, title: MDN_PLUS_TITLE }];

return (
<Routes>
<Route
Expand All @@ -78,27 +73,23 @@ export function Plus({ pageTitle, ...props }: { pageTitle?: string }) {
<Route
path="collections/*"
element={
<Layout
parents={[...parents, { uri: pathname, title: "Collections" }]}
>
<Layout>
<Collections />
</Layout>
}
/>
<Route
path="updates/*"
element={
<Layout parents={[...parents, { uri: pathname, title: "Updates" }]}>
<Layout>
<Updates />
</Layout>
}
/>
<Route
path="/settings"
element={
<Layout
parents={[...parents, { uri: pathname, title: "My Settings" }]}
>
<Layout>
<Settings {...props} />
</Layout>
}
Expand Down
1 change: 0 additions & 1 deletion client/src/plus/plus-docs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ function PlusDocs({ ...props }) {
locale,
slug: `plus/docs/${slug}`,
title: MDN_PLUS_TITLE,
parents: [{ uri: `/${locale}/plus`, title: MDN_PLUS_TITLE }],
sidebarHeader: <PlusDocsNav />,
fallbackData: props.hyData ? props : undefined,
}}
Expand Down
2 changes: 1 addition & 1 deletion client/src/ui/molecules/grids/_document-page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
padding-right: 1rem;

.toc {
--offset: var(--main-document-header-height);
--offset: var(--sticky-header-height);

display: block;
grid-area: toc;
Expand Down
8 changes: 1 addition & 7 deletions client/src/ui/organisms/article-actions-container/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
background-color: var(--background-secondary);
border-bottom: 1px solid var(--border-primary);
margin: 0;
min-height: 2rem;
min-height: var(--article-actions-container-height);
padding: 0;
position: sticky;
top: 0;
Expand Down Expand Up @@ -52,9 +52,3 @@
}
}
}

@media screen and (max-width: $screen-md) {
:root {
--sticky-header-height: 2rem;
}
}
2 changes: 1 addition & 1 deletion client/src/ui/organisms/article-actions/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
bottom: auto;
box-shadow: var(--shadow-02);
left: var(--article-actions-position-left, initial);
max-height: calc(100vh - 12px - var(--main-document-header-height));
max-height: calc(100vh - 12px - var(--sticky-header-height));
padding: 0;
position: absolute;
right: 0;
Expand Down

0 comments on commit 496ab9f

Please sign in to comment.