feat: 본문을 읽는 동안에도 조사 안의 위치가 보인다
레일에는 「이 글에서」만 있었다. 이 글 안의 위치는 알아도 이 조사 안의 위치는 알 수 없었고, 제목 아래의 맥락 덩어리는 화면을 몇 번 넘기면 사라진다. 레일 아래 칸에 프로젝트·주제·종류를 짧게 붙여 따라오게 한다. 관계 목록은 두지 않는다 — 제목 아래에 이미 있고, 같은 목록이 한 화면에 두 번 있으면 목록이 아니라 소음이다. 레일이 둘을 담게 되었으므로 이름도 갈랐다. 「이 글에서」와 「맥락」은 서로 다른 질문에 답한다. 작성자가 확대를 끈 도식도 좁은 화면에서는 확대할 수 있게 했다. 390px 화면에서 폭 1,200px 짜리 도식은 3분의 1 로 눌려 덩어리만 보이고 글자는 읽히지 않는다 — 설명하는 일을 하지 못한다. 기준은 치수다: 본문 폭(720px)보다 넓은 그림은 어디선가 반드시 줄어든다. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015c8cBFUaVr7KLVUx6ujz7D
This commit is contained in:
co-authored by
Claude Opus 5
parent
d3bf3925cf
commit
db4450fe00
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useEffect, useRef, useState, type ReactNode } from "react";
|
||||
|
||||
type HeadingItem = {
|
||||
id: string;
|
||||
@@ -8,9 +8,14 @@ type HeadingItem = {
|
||||
type DocumentTocProps = {
|
||||
headings: ReadonlyArray<HeadingItem>;
|
||||
variant: "desktop" | "mobile";
|
||||
/**
|
||||
* 데스크톱 레일의 아래 칸. 「이 글에서」와 「맥락」은 서로 다른 질문에 답한다 — 앞은 이 글의
|
||||
* 어디인지, 뒤는 이 조사의 어디인지다. 한 레일에 두되 마디를 갈라 둔다.
|
||||
*/
|
||||
context?: ReactNode;
|
||||
};
|
||||
|
||||
export function DocumentToc({ headings, variant }: DocumentTocProps) {
|
||||
export function DocumentToc({ headings, variant, context }: DocumentTocProps) {
|
||||
const [currentId, setCurrentId] = useState(headings[0]?.id ?? "");
|
||||
const empty = headings.length === 0;
|
||||
const detailsRef = useRef<HTMLDetailsElement>(null);
|
||||
@@ -56,7 +61,7 @@ export function DocumentToc({ headings, variant }: DocumentTocProps) {
|
||||
제목이 없는 문서에는 목차를 그리지 않는다. 예전에는 이 컴포넌트가 픽스처 문서 하나에서만
|
||||
쓰여 빈 경우를 만날 일이 없었지만, 이제 모든 Case 가 지나므로 빈 레일이 남을 수 있다.
|
||||
*/
|
||||
if (empty) return null;
|
||||
if (empty && !(variant === "desktop" && context)) return null;
|
||||
|
||||
if (variant === "mobile") {
|
||||
const current =
|
||||
@@ -86,20 +91,27 @@ export function DocumentToc({ headings, variant }: DocumentTocProps) {
|
||||
}
|
||||
|
||||
return (
|
||||
<aside className="document-toc" aria-label="문서 목차">
|
||||
<p>이 글에서</p>
|
||||
<nav>
|
||||
{headings.map((heading) => (
|
||||
<a
|
||||
href={`#${heading.id}`}
|
||||
key={heading.id}
|
||||
aria-current={heading.id === currentId ? "location" : undefined}
|
||||
onClick={() => select(heading.id)}
|
||||
>
|
||||
{heading.label}
|
||||
</a>
|
||||
))}
|
||||
</nav>
|
||||
/*
|
||||
레일은 이제 둘을 담는다 — 이 글의 어디인지(「이 글에서」)와 이 조사의 어디인지(「맥락」).
|
||||
서로 다른 질문에 답하므로 이름도 따로 준다. 레일 전체의 이름은 그 둘을 아우른다.
|
||||
*/
|
||||
<aside className="document-toc" aria-label="문서 안내">
|
||||
{empty ? null : (
|
||||
<nav aria-label="이 글에서">
|
||||
<p>이 글에서</p>
|
||||
{headings.map((heading) => (
|
||||
<a
|
||||
href={`#${heading.id}`}
|
||||
key={heading.id}
|
||||
aria-current={heading.id === currentId ? "location" : undefined}
|
||||
onClick={() => select(heading.id)}
|
||||
>
|
||||
{heading.label}
|
||||
</a>
|
||||
))}
|
||||
</nav>
|
||||
)}
|
||||
{context}
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user