Props Table
Document a component's API in a consistent table, generated from its source.
Document a component’s props the same way on every page: name, type, default
and description in one styled table. Generate it from the component’s own source
and the reference can never drift from the code; write the rows by hand when
there is no component to read. Here is Badge’s, generated:
variant 'default''primary''secondary''success''warning''danger''outline' default 'default'href string external boolean default falserel="noopener noreferrer".children required Snippet Generated from your component
Import the component with the ?props query and pass the result to of. The docsmith() Vite plugin reads the component’s typed $props() at build time,
the same way ?source feeds LiveExample:
Everything comes from the component, so there is nothing to keep in sync on the page:
- Types are read by the TypeScript checker, so an imported alias such as
ButtonVariantshows its values, not its name. - Descriptions are the JSDoc on each prop, with markdown rendered.
- Defaults come from the
$props()destructuring. A@defaulttag wins, for defaults the code can’t say plainly. - Every prop gets a row, snippets and callbacks included.
$bindable()props are markedbindable,@deprecatedonesdeprecated, and@internalones are left out. - Inherited attributes collapse to one line. A component typed
Props & HTMLButtonAttributesreads “Also accepts every<button>attribute” rather than listing hundreds of them.
The caption is the component’s name (Select<T> for a generic component); pass title to change it.
Since
Tag a prop @since 0.3 and its row says when it arrived. The same tag in the
component’s own <!-- @component --> comment goes on the caption. The text is
shown as written, so use whatever your releases are called.
Fields
A prop typed with one of your own object types opens into that object’s
fields: press Fields under the row. Each field has its own type, default
(from a @default tag) and description, and fields open in turn. A list
(Column[]) opens into its item’s fields, and a union of objects shows each
shape under its own name: the type’s name, or the members that tell the shapes
apart (kind: 'link'). Here is a Toast whose position and action open:
message required string duration since 0.3 number default 4000position ToastPosition default { edge: 'bottom' }Fields
edge required 'top''bottom' offset number default 16action since 0.4 ToastAction Fields
kind: 'link'kind required 'link' label required string href required string kind: 'button'kind required 'button' label required string onclick required () => void Types from a library stay closed, Snippet and HTML attributes included, and a
type that refers to itself stops where it repeats. In agent markdown each field
gets its own row, named by its path (position.edge).
Coding agents read the same table. In a page’s agent markdown, which feeds llms-full.txt and the .md pages, a generated props table
is written out as a markdown table with the same rows.
Setup
npm i -D typescript svelte2tsx. Then add /// <reference types="svelte-docsmith/client" /> to src/app.d.ts so ?props (and ?source) imports are
typed. Point the import at your component's source, not a published package:
publishing strips the types out of .svelte files. Anything the plugin
can't read becomes a build warning naming the file, never a failed build.Experimental
Written by hand
Wrap Prop rows in a PropsTable. Give each Prop a name; add type, default, required, bindable, deprecated or since as needed, and put the
description in the body. Nested Prop rows in a fields snippet open under the
row, as generated fields do.
variant 'default''primary' default 'default'href required string API reference
PropsTable
title string of is given.of ExtractedProps import props from './button.svelte?props'): renders
the rows from the component's own source instead of children.Fields
name required string FileTree.typeParameters required string[] ['T'].since string @since, from its `<!--props required ExtractedProp[] Fields
name required string type string 'a' | 'b'. Absent when the props are untyped.default string 'default'.required required boolean bindable required boolean $bindable().deprecated string @deprecated: the tag's text as inline HTML, or ''.description string control PropControl Fields
kind: 'boolean'kind required 'boolean' kind: 'text'kind required 'text' kind: 'number'kind required 'number' kind: 'options'kind required 'options' options required (string | number)[] literalDefault stringnumberboolean 'a', false, -1).since string @since text: the release the prop first appeared in.fields ExtractedFieldGroup[] Fields
label string fields required ExtractedField[] Fields
name required string type string default string @default tag's text.required required boolean deprecated string @deprecated: the tag's text as inline HTML, or ''.description string since string fields ExtractedFieldGroup[] inherited required InheritedAttributes[] Fields
kind required 'element''type' element: native attributes of an HTML element (label is the tag name).
type: every prop of some other type (label is that type, as written).label required string children Snippet <Prop> rows.Prop
name required string type string required boolean default falsebindable boolean default falsebind:.deprecated stringboolean since string default string children Snippet fields Snippet <Prop> rows for an
object's fields, shown collapsed under the description.