From dee74d3470f926db027fb18cb5dedddb169e3e77 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Sat, 23 Nov 2024 15:02:02 -0800 Subject: [PATCH] docs: add syntax highlighting for component API --- docs/package-lock.json | 3 +- docs/src/components/ComponentApi.svelte | 110 ++++++++++++++++--- docs/src/components/PreviewTypeScript.svelte | 60 ++++++++++ docs/src/global.css | 1 + 4 files changed, 154 insertions(+), 20 deletions(-) create mode 100644 docs/src/components/PreviewTypeScript.svelte diff --git a/docs/package-lock.json b/docs/package-lock.json index 163a1e2e..67f622c3 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -24,8 +24,7 @@ } }, "..": { - "name": "carbon-components-svelte", - "version": "0.85.4", + "version": "0.86.1", "dev": true, "hasInstallScript": true, "license": "Apache-2.0", diff --git a/docs/src/components/ComponentApi.svelte b/docs/src/components/ComponentApi.svelte index a355a00c..600ec7f6 100644 --- a/docs/src/components/ComponentApi.svelte +++ b/docs/src/components/ComponentApi.svelte @@ -8,7 +8,9 @@ }; import { + Button, OutboundLink, + Modal, StructuredList, StructuredListHead, StructuredListRow, @@ -17,10 +19,10 @@ UnorderedList, ListItem, Tag, - CodeSnippet, } from "carbon-components-svelte"; import InlineSnippet from "./InlineSnippet.svelte"; - + import PreviewTypeScript from "./PreviewTypeScript.svelte"; + import Code from "carbon-icons-svelte/lib/Code.svelte"; const mdn_api = "https://developer.mozilla.org/en-US/docs/Web/API/"; const typeMap = { string: "string", @@ -30,6 +32,9 @@ Date: "JavaScript Date", }; + let full_code = null; + let full_code_prop = null; + $: source = `https://github.com/carbon-design-system/carbon-components-svelte/tree/master/${component.filePath}`; $: forwarded_events = component.events.filter( (event) => event.type === "forwarded", @@ -55,7 +60,7 @@ Prop name Type - Default value + Default value Description @@ -95,18 +100,65 @@ {type} {:else if type in typeMap} - {typeMap[type]} +
20 + ? "break-word" + : "normal"} + > + +
{:else if type.startsWith("(")} - {type} +
+ +
{:else} - +
20 + ? "break-word" + : "normal"} + > + +
{/if} {/each} - {prop.value} + + {#if /\s+/.test(prop.value)} + {#if prop.value.length > 100} +
+
+ {:else} + + {/if} + {:else if prop.value === undefined} + undefined + {:else} + + {/if} +
{#if prop.description} {#each prop.description.split("\n") as line} @@ -133,12 +185,7 @@

Typedefs

{#if component.typedefs.length > 0} - + t.ts).join(";\n\n")} /> {:else}

No typedefs.

{/if} @@ -173,7 +220,9 @@ Event name - event.detail type + + + {#if hasDescription} Description {/if} @@ -186,7 +235,7 @@ on:{event.name}
- {event.detail} + restProps{/if} + { + full_code = null; + full_code_prop = null; + }} +> + {#if full_code_prop} + Default value for {full_code_prop}. + {/if} + {#if full_code} + + {/if} + + diff --git a/docs/src/components/PreviewTypeScript.svelte b/docs/src/components/PreviewTypeScript.svelte new file mode 100644 index 00000000..267bd9e8 --- /dev/null +++ b/docs/src/components/PreviewTypeScript.svelte @@ -0,0 +1,60 @@ + + + + +{#if type === "multi"} +
+ + {@html highlightedCode} + +
+{/if} + +{#if type === "inline"} + + {@html highlightedCode} + +{/if} diff --git a/docs/src/global.css b/docs/src/global.css index 113aae3f..b46622d5 100644 --- a/docs/src/global.css +++ b/docs/src/global.css @@ -45,6 +45,7 @@ html[theme="g90"] .code-override { color: #6ea6ff; } +.token.builtin, .token.attr-name { color: #3ddbd9; /* teal 30 */ }