Skip to content

Commit b9b067f

Browse files
committed
feat: sidebar and a bunch of other stuff
1 parent 9c82e47 commit b9b067f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2155
-310
lines changed

website/package.json

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,52 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12-
"@teamsupercell/typings-for-css-modules-loader": "^2.5.1",
1312
"clsx": "^1.1.1",
1413
"copy-text-to-clipboard": "^3.0.1",
15-
"glob": "^7.2.0",
16-
"mdast-util-from-markdown": "^1.2.0",
17-
"mdast-util-to-markdown": "^1.3.0",
14+
"mdx-bundler": "^9.0.0",
1815
"next": "12.1.0",
1916
"next-mdx-remote": "^4.0.0",
2017
"prism-react-renderer": "^1.2.1",
2118
"react": "17.0.2",
2219
"react-dom": "17.0.2",
23-
"rehype-katex": "^6.0.2",
24-
"rehype-stringify": "^9.0.3",
25-
"remark-gfm": "^3.0.1",
26-
"remark-math": "^5.1.1",
27-
"remark-parse": "^10.0.0",
28-
"remark-rehype": "^10.1.0",
29-
"remark-stringify": "^10.0.0",
30-
"sass": "^1.49.7",
31-
"unified": "^10.1.0"
20+
"sass": "^1.49.7"
3221
},
3322
"devDependencies": {
23+
"@babel/parser": "^7.17.9",
24+
"@babel/traverse": "^7.17.9",
25+
"@babel/types": "^7.17.0",
26+
"@teamsupercell/typings-for-css-modules-loader": "^2.5.1",
27+
"@types/babel__traverse": "^7.17.0",
28+
"@types/escape-html": "^1.0.2",
3429
"@types/glob": "^7.1.4",
3530
"@types/react": "17.0.27",
31+
"@types/stringify-object": "^4.0.1",
32+
"@types/unist": "^2.0.6",
33+
"esbuild": "^0.14.36",
34+
"escape-html": "^1.0.3",
3635
"eslint": "7.32.0",
3736
"eslint-config-next": "11.1.2",
38-
"typescript": "4.4.3"
37+
"glob": "^8.0.1",
38+
"mdast": "^3.0.0",
39+
"mdast-util-from-markdown": "^1.2.0",
40+
"mdast-util-gfm": "^2.0.1",
41+
"mdast-util-math": "^2.0.1",
42+
"mdast-util-mdxjs-esm": "^1.2.0",
43+
"mdast-util-to-markdown": "^1.3.0",
44+
"mdast-util-to-string": "^3.1.0",
45+
"micromark-extension-gfm": "^2.0.1",
46+
"micromark-extension-math": "^2.0.2",
47+
"micromark-extension-mdxjs-esm": "^1.0.2",
48+
"rehype-katex": "^6.0.2",
49+
"rehype-stringify": "^9.0.3",
50+
"remark-gfm": "^3.0.1",
51+
"remark-math": "^5.1.1",
52+
"remark-parse": "^10.0.1",
53+
"remark-rehype": "^10.1.0",
54+
"remark-stringify": "^10.0.2",
55+
"stringify-object": "^4.0.1",
56+
"typescript": "^4.6.3",
57+
"unified": "^10.1.2",
58+
"unist-util-visit": "^4.1.0"
3959
}
4060
}

website/src/components/Collapsible/index.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const DefaultAnimationEasing = 'ease-in-out';
2626
/**
2727
* This hook is a very thin wrapper around a `useState`.
2828
*/
29-
export function useCollapsible(initialState: boolean | (() => boolean) = false) {
29+
export const useCollapsible = (initialState: boolean | (() => boolean) = false) => {
3030
const [collapsed, setCollapsed] = useState(initialState ?? false);
3131

3232
const toggleCollapsed = useCallback(() => {
@@ -52,7 +52,7 @@ const ExpandedStyles = {
5252
height: 'auto',
5353
} as const;
5454

55-
function applyCollapsedStyle(el: HTMLElement, collapsed: boolean) {
55+
const applyCollapsedStyle = (el: HTMLElement, collapsed: boolean) => {
5656
const collapsedStyles = collapsed ? CollapsedStyles : ExpandedStyles;
5757
el.style.display = collapsedStyles.display;
5858
el.style.overflow = collapsedStyles.overflow;
@@ -65,7 +65,7 @@ is good for a large number of items.
6565
https://material.io/archive/guidelines/motion/duration-easing.html#duration-easing-dynamic-durations
6666
https://github.com/mui-org/material-ui/blob/e724d98eba018e55e1a684236a2037e24bcf050c/packages/material-ui/src/styles/createTransitions.js#L40-L43
6767
*/
68-
function getAutoHeightDuration(height: number) {
68+
const getAutoHeightDuration = (height: number) => {
6969
const constant = height / 36;
7070
return Math.round((4 + 15 * constant ** 0.25 + constant / 5) * 10);
7171
}
@@ -75,21 +75,21 @@ type CollapsibleAnimationConfig = {
7575
easing?: string;
7676
};
7777

78-
function useCollapseAnimation({
78+
const useCollapseAnimation = ({
7979
collapsibleRef,
8080
collapsed,
8181
animation,
8282
}: {
8383
collapsibleRef: RefObject<HTMLElement>;
8484
collapsed: boolean;
8585
animation?: CollapsibleAnimationConfig;
86-
}) {
86+
}) => {
8787
const mounted = useRef(false);
8888

8989
useEffect(() => {
9090
const el = collapsibleRef.current!;
9191

92-
function getTransitionStyles() {
92+
const getTransitionStyles = () => {
9393
const height = el.scrollHeight;
9494
const duration = animation?.duration ?? getAutoHeightDuration(height);
9595
const easing = animation?.easing ?? DefaultAnimationEasing;
@@ -99,7 +99,7 @@ function useCollapseAnimation({
9999
};
100100
}
101101

102-
function applyTransitionStyles() {
102+
const applyTransitionStyles = () => {
103103
const transitionStyles = getTransitionStyles();
104104
el.style.transition = transitionStyles.transition;
105105
el.style.height = transitionStyles.height;
@@ -114,7 +114,7 @@ function useCollapseAnimation({
114114

115115
el.style.willChange = 'height';
116116

117-
function startAnimation() {
117+
const startAnimation = () => {
118118
const animationFrame = requestAnimationFrame(() => {
119119
// When collapsing
120120
if (collapsed) {
@@ -149,7 +149,7 @@ type CollapsibleElementType = React.ElementType<
149149
* Prevent hydration layout shift before animations are handled imperatively
150150
* with JS
151151
*/
152-
function getSSRStyle(collapsed: boolean) {
152+
const getSSRStyle = (collapsed: boolean) => {
153153
if (!canUseDOM) {
154154
return undefined;
155155
}
@@ -181,15 +181,15 @@ type CollapsibleBaseProps = {
181181
disableSSRStyle?: boolean;
182182
};
183183

184-
function CollapsibleBase({
184+
const CollapsibleBase = ({
185185
as: As = 'div',
186186
collapsed,
187187
children,
188188
animation,
189189
onCollapseTransitionEnd,
190190
className,
191191
disableSSRStyle,
192-
}: CollapsibleBaseProps) {
192+
}: CollapsibleBaseProps) => {
193193
// any because TS is a pain for HTML element refs, see https://twitter.com/sebastienlorber/status/1412784677795110914
194194
const collapsibleRef = useRef<any>(null);
195195

@@ -215,7 +215,7 @@ function CollapsibleBase({
215215
);
216216
}
217217

218-
function CollapsibleLazy({collapsed, ...props}: CollapsibleBaseProps) {
218+
const CollapsibleLazy = ({collapsed, ...props}: CollapsibleBaseProps) => {
219219
const [mounted, setMounted] = useState(!collapsed);
220220

221221
useIsomorphicLayoutEffect(() => {
@@ -252,7 +252,9 @@ type CollapsibleProps = CollapsibleBaseProps & {
252252
* component will be invisible (zero height) when collapsed. Doesn't provide
253253
* interactivity by itself: collapse state is toggled through props.
254254
*/
255-
export default function Collapsible({lazy, ...props}: CollapsibleProps): JSX.Element {
255+
const Collapsible = ({lazy, ...props}: CollapsibleProps): JSX.Element => {
256256
const Comp = lazy ? CollapsibleLazy : CollapsibleBase;
257257
return <Comp {...props} />;
258-
}
258+
}
259+
260+
export default Collapsible;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@use "@/styles/utils";
2+
@use "./styles.module.scss" as *;
3+
4+
:export {
5+
navbarHeight: utils.strip-units($navbar-height);
6+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// AUTOGENERATED FILE -- DO NOT EDIT DIRECTLY
2+
3+
declare namespace StylesExportModuleScssNamespace {
4+
export interface IStylesExportModuleScss {
5+
hidden: string;
6+
left: string;
7+
logo: string;
8+
navItem: string;
9+
navbar: string;
10+
navbarHeight: string;
11+
right: string;
12+
}
13+
}
14+
15+
declare const StylesExportModuleScssModule: StylesExportModuleScssNamespace.IStylesExportModuleScss;
16+
17+
export = StylesExportModuleScssModule;

website/src/components/Navbar/styles.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ $navbar-height: 76px;
44

55
.navbar {
66
z-index: 10;
7-
position: sticky;
7+
position: fixed;
88
top: 0;
99
width: 100%;
1010
height: $navbar-height;

website/src/components/Sidebar/styles.module.scss

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
@use "@/styles/colors";
99
@use "@/styles/mixins";
1010

11+
$desktop-sidebar-width: 300px;
12+
1113
.items {
1214
list-style: none;
1315
margin: 0;
1416
padding: 0;
1517

16-
.items {
18+
& & {
1719
flex: 0 0 100%;
1820
margin-top: 0.25rem;
1921
padding-left: 1rem;
@@ -70,15 +72,8 @@ $arrow-icon: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg
7072

7173
/* desktop sidebar */
7274

73-
$desktop-sidebar-width: 300px;
74-
7575
.desktop {
76-
@include mixins.desktop-only(flex) {
76+
@include mixins.desktop-only() {
7777
width: $desktop-sidebar-width;
78-
flex-direction: column;
79-
padding-top: var(--header-height, 0);
80-
overflow-x: hidden;
81-
82-
@include mixins.scrollbar();
8378
}
8479
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE-docusaurus file in the root directory of the website source tree.
6+
*/
7+
8+
import c from "clsx"
9+
10+
import Toc from "."
11+
12+
import { markdown } from "@/mdx/markdown.module.scss"
13+
import s from "./styles.module.scss"
14+
15+
import type { TocProps } from "../Toc"
16+
17+
interface TocDesktopProps extends Omit<TocProps, 'linkClassName' | 'activeClassName'> {}
18+
19+
export default function TocDesktop ({
20+
toc,
21+
minLevel = 2,
22+
maxLevel = 4,
23+
className,
24+
}: TocDesktopProps) {
25+
26+
return (
27+
<nav className={c(s.nav, className)}>
28+
<h2 className={s.heading}>Table of Contents</h2>
29+
<TocDesktopItems
30+
toc={toc}
31+
minLevel={minLevel}
32+
maxLevel={maxLevel}
33+
/>
34+
</nav>
35+
)
36+
}
37+
38+
export const TocDesktopItems = ({
39+
toc,
40+
minLevel = 2,
41+
maxLevel = 4,
42+
className,
43+
linkClassName,
44+
linkActiveClassName,
45+
}: TocProps) => (
46+
<Toc
47+
className={c(markdown, s.items, className)}
48+
toc={toc}
49+
minLevel={minLevel}
50+
maxLevel={maxLevel}
51+
linkClassName={c(s.link, linkClassName)}
52+
linkActiveClassName={c(s.active, linkActiveClassName)}
53+
/>
54+
)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE-docusaurus file in the root directory of the website source tree.
6+
*/
7+
8+
import useTocFilter from "./utils/filter-headings"
9+
import useActiveTocItem from "./utils/active-heading"
10+
11+
import type { FC, MouseEventHandler } from "react"
12+
import type { HeadingLevel, TocItem } from "@/lib/unified/toc/types"
13+
14+
export interface TocProps {
15+
toc: TocItem[]
16+
minLevel?: HeadingLevel
17+
maxLevel?: HeadingLevel
18+
className?: string
19+
linkClassName?: string
20+
linkActiveClassName?: string
21+
onClick?: MouseEventHandler<HTMLAnchorElement>
22+
}
23+
24+
const Toc: FC<TocProps> = ({
25+
toc,
26+
minLevel = 2,
27+
maxLevel = 4,
28+
className,
29+
linkClassName = '',
30+
linkActiveClassName = '',
31+
onClick,
32+
}) => {
33+
const filteredToc = useTocFilter({ toc, minLevel, maxLevel })
34+
35+
useActiveTocItem(filteredToc, {
36+
linkClassName,
37+
linkActiveClassName,
38+
})
39+
40+
return (
41+
<TocItems
42+
toc={filteredToc}
43+
className={className}
44+
linkClassName={linkClassName}
45+
onClick={onClick}
46+
/>
47+
)
48+
}
49+
50+
export default Toc
51+
52+
interface TocItemsProps {
53+
toc: TocItem[]
54+
className?: string
55+
linkClassName?: string
56+
onClick?: MouseEventHandler<HTMLAnchorElement>
57+
}
58+
59+
const TocItems: FC<TocItemsProps> = ({ toc, className, linkClassName, onClick }) => {
60+
return toc.length === 0 ? null : (
61+
<ul className={className}>
62+
{toc.map(({ id, children, value }) => (
63+
<li key={id}>
64+
<a
65+
className={linkClassName}
66+
href={`#${id}`}
67+
onClick={onClick}
68+
// Developer provided the HTML, so assume it's safe.
69+
dangerouslySetInnerHTML={{ __html: value }}
70+
/>
71+
<TocItems
72+
toc={children}
73+
linkClassName={linkClassName}
74+
onClick={onClick}
75+
/>
76+
</li>
77+
))}
78+
</ul>
79+
)
80+
}

0 commit comments

Comments
 (0)