From ab19540a525d2cb6ceb72e91cd82d6e514a067e0 Mon Sep 17 00:00:00 2001 From: Rowan Cockett Date: Tue, 24 Sep 2024 10:36:28 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=8D=20Make=20document=20outline=20coll?= =?UTF-8?q?apsible=20(#373)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Angus Hollands --- .changeset/heavy-bees-ring.md | 7 + packages/search-minisearch/package.json | 2 - packages/search/package.json | 2 - .../site/src/components/DocumentOutline.tsx | 355 +++++++++++++----- themes/article/app/components/Article.tsx | 10 +- themes/book/app/components/ArticlePage.tsx | 10 +- 6 files changed, 275 insertions(+), 111 deletions(-) create mode 100644 .changeset/heavy-bees-ring.md diff --git a/.changeset/heavy-bees-ring.md b/.changeset/heavy-bees-ring.md new file mode 100644 index 00000000..52132c7a --- /dev/null +++ b/.changeset/heavy-bees-ring.md @@ -0,0 +1,7 @@ +--- +"@myst-theme/site": patch +"@myst-theme/article": patch +"@myst-theme/book": patch +--- + +🔍 Make document outline collapsible diff --git a/packages/search-minisearch/package.json b/packages/search-minisearch/package.json index 02fb299f..1d8da2e5 100644 --- a/packages/search-minisearch/package.json +++ b/packages/search-minisearch/package.json @@ -13,8 +13,6 @@ "clean": "rimraf dist", "lint": "eslint \"src/**/*.ts*\" -c ./.eslintrc.cjs", "lint:format": "prettier --check \"src/**/*.{ts,tsx,md}\"", - "test": "vitest run", - "test:watch": "vitest watch", "build:esm": "tsc --project ./tsconfig.json --module Node16 --outDir dist --declaration", "build": "npm-run-all -l clean -p build:esm" }, diff --git a/packages/search/package.json b/packages/search/package.json index 20f7ccf4..ea3d9a4a 100644 --- a/packages/search/package.json +++ b/packages/search/package.json @@ -13,8 +13,6 @@ "clean": "rimraf dist", "lint": "eslint \"src/**/*.ts*\" -c ./.eslintrc.cjs", "lint:format": "prettier --check \"src/**/*.{ts,tsx,md}\"", - "test": "vitest run", - "test:watch": "vitest watch", "build:esm": "tsc --project ./tsconfig.json --module Node16 --outDir dist --declaration", "build": "npm-run-all -l clean -p build:esm" }, diff --git a/packages/site/src/components/DocumentOutline.tsx b/packages/site/src/components/DocumentOutline.tsx index 494bca3a..d3cd63a3 100644 --- a/packages/site/src/components/DocumentOutline.tsx +++ b/packages/site/src/components/DocumentOutline.tsx @@ -8,10 +8,12 @@ import { useNavigation } from '@remix-run/react'; import classNames from 'classnames'; import throttle from 'lodash.throttle'; import React, { useCallback, useEffect, useRef, useState } from 'react'; +import type { RefObject } from 'react'; import { DocumentChartBarIcon } from '@heroicons/react/24/outline'; +import { ChevronRightIcon } from '@heroicons/react/24/solid'; +import * as Collapsible from '@radix-ui/react-collapsible'; const SELECTOR = [1, 2, 3, 4].map((n) => `main h${n}`).join(', '); -const HIGHLIGHT_CLASS = 'highlight'; const onClient = typeof document !== 'undefined'; @@ -25,15 +27,13 @@ export type Heading = { type Props = { headings: Heading[]; - selector: string; activeId?: string; - highlight?: () => void; }; /** * This renders an item in the table of contents list. * scrollIntoView is used to ensure that when a user clicks on an item, it will smoothly scroll. */ -const Headings = ({ headings, activeId, highlight, selector }: Props) => ( +const Headings = ({ headings, activeId }: Props) => (