Skip to content
Search
Search the documentation
Props Table
GitHub
3 min read

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:

Badge
variant 'default''primary''secondary''success''warning''danger''outline' default 'default'
Visual intent.
href string
Renders the badge as a link.
external boolean default false
For a linked badge, open in a new tab with rel="noopener noreferrer".
children required Snippet
The badge label.

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:

			<script>
	import { PropsTable } from 'svelte-docsmith';
	import buttonProps from '#lib/button.svelte?props';
</script>

<PropsTable of={buttonProps} />
		

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 ButtonVariant shows its values, not its name.
  • Descriptions are the JSDoc on each prop, with markdown rendered.
  • Defaults come from the $props() destructuring. A @default tag wins, for defaults the code can’t say plainly.
  • Every prop gets a row, snippets and callbacks included. $bindable() props are marked bindable, @deprecated ones deprecated, and @internal ones are left out.
  • Inherited attributes collapse to one line. A component typed Props & HTMLButtonAttributes reads “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.

			<!--
@component
A short message that slides in and leaves on its own.

@since 0.2
-->
<script lang="ts">
	const { duration = 4000 }: {
		/**
		 * How long it stays, in milliseconds.
		 * @since 0.3
		 */
		duration?: number;
	} = $props();
</script>
		

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:

Toast since 0.2
message required string
What the toast says.
duration since 0.3 number default 4000
How long it stays, in milliseconds.
position ToastPosition default { edge: 'bottom' }
Where it appears.
Fields
edge required 'top''bottom'
The edge it slides in from.
offset number default 16
Distance from that edge, in pixels.
action since 0.4 ToastAction
One thing the reader can do from the toast.
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

Generated tables need TypeScript: 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

Generated props tables sit outside the 1.0 stability promise while authors try them for real.

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'
Visual intent of the component.
href required string
Turns the element into a link.
			<script>
	import { PropsTable, Prop } from 'svelte-docsmith';
</script>

<PropsTable>
	<Prop name="variant" type="'default' | 'primary'" default="'default'">
		Visual intent of the component.
	</Prop>
	<Prop name="href" type="string" required>
		Turns the element into a link.
	</Prop>
</PropsTable>
		

API reference

PropsTable

PropsTable
title string
Caption. Defaults to the component's name when of is given.
of ExtractedProps
A props import (import props from './button.svelte?props'): renders the rows from the component's own source instead of children.
Fields
name required string
Component name derived from the file name, e.g. FileTree.
typeParameters required string[]
Type parameter names of a generic component, e.g. ['T'].
since string
The component's @since, from its `<!--
props required ExtractedProp[]
Declared props, in declaration order.
Fields
name required string
type string
Resolved type, e.g. 'a' | 'b'. Absent when the props are untyped.
default string
Source text of the default value, e.g. 'default'.
required required boolean
bindable required boolean
Declared with $bindable().
deprecated string
Present when tagged @deprecated: the tag's text as inline HTML, or ''.
description string
JSDoc description rendered to inline HTML.
control PropControl
How a props playground edits this prop, from its type. Absent when the type has no control (snippets, callbacks, objects, generics) or the prop is deprecated.
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
The default as a value, when its source text is a literal ('a', false, -1).
since string
@since text: the release the prop first appeared in.
fields ExtractedFieldGroup[]
What the prop's type opens into when it is one of the library's own object types: one group for an object or a list of them, one per object in a union.
Fields
label string
fields required ExtractedField[]
Fields
name required string
type string
default string
The @default tag's text.
required required boolean
deprecated string
Present when tagged @deprecated: the tag's text as inline HTML, or ''.
description string
JSDoc description rendered to inline HTML.
since string
fields ExtractedFieldGroup[]
inherited required InheritedAttributes[]
What the component also accepts by spreading its remaining props.
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
Hand-written <Prop> rows.

Prop

Prop
name required string
Property name.
type string
Type signature, shown as code.
required boolean default false
Mark the property as required.
bindable boolean default false
Mark the property as bindable with bind:.
deprecated stringboolean
Mark the property as deprecated; a string says what to use instead.
since string
The release the property first appeared in, shown as "Since 0.4".
default string
Default value, shown alongside the type.
children Snippet
Description.
fields Snippet
What the property's type opens into: nested <Prop> rows for an object's fields, shown collapsed under the description.

Was this page helpful?