diff --git a/website/src/components/templates/FuncTemplate.tsx b/website/src/components/templates/FuncTemplate.tsx index d86f1a63e0..7c8f032d1b 100644 --- a/website/src/components/templates/FuncTemplate.tsx +++ b/website/src/components/templates/FuncTemplate.tsx @@ -57,7 +57,7 @@ export const FuncTemplate: FC = ({
- +
{content.example && ( @@ -67,7 +67,7 @@ export const FuncTemplate: FC = ({ )}
- +
{content.scope.length > 0 && ( diff --git a/website/src/components/templates/GroupTemplate.tsx b/website/src/components/templates/GroupTemplate.tsx index a1dea70c83..d704f01b3b 100644 --- a/website/src/components/templates/GroupTemplate.tsx +++ b/website/src/components/templates/GroupTemplate.tsx @@ -41,7 +41,7 @@ export const GroupTemplate: FC = ({ {content.functions.map((method, index) => (
-

+

{method.name}
{method.element && } @@ -50,7 +50,7 @@ export const GroupTemplate: FC = ({

diff --git a/website/src/components/ui/FunctionDefinition.tsx b/website/src/components/ui/FunctionDefinition.tsx index 5d66a9d925..5a356d0666 100644 --- a/website/src/components/ui/FunctionDefinition.tsx +++ b/website/src/components/ui/FunctionDefinition.tsx @@ -2,16 +2,21 @@ import type { FC } from "hono/jsx"; import type { Func } from "../../types/model"; import { TypeIcon } from "./TypeIcon"; import { genPath } from "./genPath"; -import { type2href } from "./type2href"; +import { buildParamId, type2href } from "./type2href"; type FunctionDefinitionProps = { func: Func; - prefix?: string; + /** + * The prefix for parameter IDs + * + * See `buildParamId`. + */ + prefix?: string | undefined; }; export const FunctionDefinition: FC = ({ func, - prefix = "", + prefix = undefined, }) => { return (
@@ -28,7 +33,7 @@ export const FunctionDefinition: FC = ({ {!param.positional && (
{param.name} diff --git a/website/src/components/ui/FunctionDisplay.tsx b/website/src/components/ui/FunctionDisplay.tsx index 4e089f91a7..358be1831d 100644 --- a/website/src/components/ui/FunctionDisplay.tsx +++ b/website/src/components/ui/FunctionDisplay.tsx @@ -7,13 +7,18 @@ import { HtmlContent } from "./HtmlContent"; type FunctionDisplayProps = { func: Func; - prefix?: string; + /** + * The prefix for IDs of function parameters + * + * See `buildParamId`. + */ + prefix?: string | undefined; isExampleFolding?: boolean; }; export const FunctionDisplay: FC = ({ func, - prefix = "", + prefix = undefined, isExampleFolding = true, }) => { return ( diff --git a/website/src/components/ui/FunctionParameters.tsx b/website/src/components/ui/FunctionParameters.tsx index f86c52aa8b..cd9d20d455 100644 --- a/website/src/components/ui/FunctionParameters.tsx +++ b/website/src/components/ui/FunctionParameters.tsx @@ -4,16 +4,21 @@ import { ChevronRightIcon } from "../icons"; import { HtmlContent } from "./HtmlContent"; import { Tooltip } from "./Tooltip"; import { TypeIcon } from "./TypeIcon"; -import { type2href } from "./type2href"; +import { buildParamId, type2href } from "./type2href"; type FunctionParametersProps = { func: Func; - prefix?: string; + /** + * The prefix for IDs + * + * See `buildParamId`. + */ + prefix?: string | undefined; }; export const FunctionParameters: FC = ({ func, - prefix = "", + prefix = undefined, }) => { return (
@@ -23,7 +28,7 @@ export const FunctionParameters: FC = ({ class="bg-gray-50 rounded-md p-4 border border-gray-100" >

{param.name} diff --git a/website/src/components/ui/common/TableOfContents.tsx b/website/src/components/ui/common/TableOfContents.tsx index dc3680183d..23d44aa6ae 100644 --- a/website/src/components/ui/common/TableOfContents.tsx +++ b/website/src/components/ui/common/TableOfContents.tsx @@ -4,6 +4,30 @@ export type TableOfContentsProps = { outline: OutlineItem[]; }; +const PlainTableOfContents = ({ + outline, + topLevel = false, +}: TableOfContentsProps & { topLevel?: boolean }) => { + return ( + // Indent for succeeding levels +
    + {outline.map((item) => ( +
  1. + + {item.name} + + {item.children.length > 0 && ( + + )} +
  2. + ))} +
+ ); +}; + export const TableOfContents = ({ outline }: TableOfContentsProps) => { if (outline.length === 0) { return null; @@ -17,18 +41,7 @@ export const TableOfContents = ({ outline }: TableOfContentsProps) => { 目次 -
    - {outline.map((item) => ( -
  1. - - {item.name} - -
  2. - ))} -
+ ); }; diff --git a/website/src/components/ui/type2href.ts b/website/src/components/ui/type2href.ts index ff68b2c782..da9a1887f4 100644 --- a/website/src/components/ui/type2href.ts +++ b/website/src/components/ui/type2href.ts @@ -58,3 +58,28 @@ export const type2href = (parameterType: string): string | null => { } return null; }; + +/** + * Build the ID of a parameter with prefix + * + * If the parameter belongs to a top-level function on a page, leave `prefix` empty; + * Otherwise, set it to an appropriate prefix. + * + * ## Example values of `prefix` + * + * | Page (kind) | Function | Parameter | `prefix` | + * | ------------------- | ---------------- | ---------- | ----------------------- | + * | `figure` (function) | `figure` | `body` | `undefined` | + * | `figure` (function) | `figure.caption` | `body` | `"definitions-caption"` | + * | `calc` (group) | `calc.abs` | `value` | `"functions-abs"` | + * | `array` (type) | `array.at` | `index` | `"definitions-at"` | + * | `array` (type) | Constructor | `value` | `"constructor"` | + */ +export function buildParamId( + parameterName: string, + prefix: string | undefined, +): string { + return prefix === undefined + ? `parameters-${parameterName}` + : `${prefix}-${parameterName}`; +}