File tree Expand file tree Collapse file tree 4 files changed +50
-10
lines changed
website/src/components/ui Expand file tree Collapse file tree 4 files changed +50
-10
lines changed Original file line number Diff line number Diff line change @@ -2,16 +2,21 @@ import type { FC } from "hono/jsx";
22import type { Func } from "../../types/model" ;
33import { TypeIcon } from "./TypeIcon" ;
44import { genPath } from "./genPath" ;
5- import { type2href } from "./type2href" ;
5+ import { buildParamId , type2href } from "./type2href" ;
66
77type FunctionDefinitionProps = {
88 func : Func ;
9- prefix ?: string ;
9+ /**
10+ * The prefix for parameter IDs
11+ *
12+ * See `buildParamId`.
13+ */
14+ prefix ?: string | undefined ;
1015} ;
1116
1217export const FunctionDefinition : FC < FunctionDefinitionProps > = ( {
1318 func,
14- prefix = "" ,
19+ prefix = undefined ,
1520} ) => {
1621 return (
1722 < div class = "bg-gray-50 p-4 rounded-md border border-gray-100 overflow-x-auto" >
@@ -28,7 +33,7 @@ export const FunctionDefinition: FC<FunctionDefinitionProps> = ({
2833 { ! param . positional && (
2934 < div class = "flex-shrink-0" >
3035 < a
31- href = { `#${ prefix } - ${ func . name } -parameters- ${ param . name } ` }
36+ href = { `#${ buildParamId ( param . name , prefix ) } ` }
3237 class = "text-gray-800 hover:text-blue-500 transition-colors mr-1"
3338 >
3439 < span class = "font-medium" > { param . name } </ span >
Original file line number Diff line number Diff line change @@ -7,13 +7,18 @@ import { HtmlContent } from "./HtmlContent";
77
88type FunctionDisplayProps = {
99 func : Func ;
10- prefix ?: string ;
10+ /**
11+ * The prefix for IDs of function parameters
12+ *
13+ * See `buildParamId`.
14+ */
15+ prefix ?: string | undefined ;
1116 isExampleFolding ?: boolean ;
1217} ;
1318
1419export const FunctionDisplay : FC < FunctionDisplayProps > = ( {
1520 func,
16- prefix = "" ,
21+ prefix = undefined ,
1722 isExampleFolding = true ,
1823} ) => {
1924 return (
Original file line number Diff line number Diff line change @@ -4,16 +4,21 @@ import { ChevronRightIcon } from "../icons";
44import { HtmlContent } from "./HtmlContent" ;
55import { Tooltip } from "./Tooltip" ;
66import { TypeIcon } from "./TypeIcon" ;
7- import { type2href } from "./type2href" ;
7+ import { buildParamId , type2href } from "./type2href" ;
88
99type FunctionParametersProps = {
1010 func : Func ;
11- prefix ?: string ;
11+ /**
12+ * The prefix for IDs
13+ *
14+ * See `buildParamId`.
15+ */
16+ prefix ?: string | undefined ;
1217} ;
1318
1419export const FunctionParameters : FC < FunctionParametersProps > = ( {
1520 func,
16- prefix = "" ,
21+ prefix = undefined ,
1722} ) => {
1823 return (
1924 < div class = "space-y-6" >
@@ -23,7 +28,7 @@ export const FunctionParameters: FC<FunctionParametersProps> = ({
2328 class = "bg-gray-50 rounded-md p-4 border border-gray-100"
2429 >
2530 < h4
26- id = { ` ${ prefix } - ${ func . name } -parameters- ${ param . name } ` }
31+ id = { buildParamId ( param . name , prefix ) }
2732 class = "flex flex-wrap items-center gap-2 mb-3"
2833 >
2934 < code class = "text-base font-medium" > { param . name } </ code >
Original file line number Diff line number Diff line change @@ -58,3 +58,28 @@ export const type2href = (parameterType: string): string | null => {
5858 }
5959 return null ;
6060} ;
61+
62+ /**
63+ * Build the ID of a parameter with prefix
64+ *
65+ * If the parameter belongs to a top-level function on a page, leave `prefix` empty;
66+ * Otherwise, set it to an appropriate prefix.
67+ *
68+ * ## Example values of `prefix`
69+ *
70+ * | Page (kind) | Function | Parameter | `prefix` |
71+ * | ------------------- | ---------------- | ---------- | ----------------------- |
72+ * | `figure` (function) | `figure` | `body` | `undefined` |
73+ * | `figure` (function) | `figure.caption` | `body` | `"definitions-caption"` |
74+ * | `calc` (group) | `calc.abs` | `value` | `"functions-abs"` |
75+ * | `array` (type) | `array.at` | `index` | `"definitions-at"` |
76+ * | `array` (type) | Constructor | `value` | `"constructor"` |
77+ */
78+ export function buildParamId (
79+ parameterName : string ,
80+ prefix : string | undefined ,
81+ ) : string {
82+ return prefix === undefined
83+ ? `parameters-${ parameterName } `
84+ : `${ prefix } -${ parameterName } ` ;
85+ }
You can’t perform that action at this time.
0 commit comments