Description
Why
I believe that documenting components is an important process for the proper re-usability of components. This can only be done if the code is the source of truth I think.
That's why I would like to see metadata around the API bits exposed by Svelte components.
Properties
<script>
export let name = 'world';
</script>
<h1>Hello {name}!</h1>
Properties need the following data to be documented:
- Exposed (done by the export keyword)
- Required
- Default (done by init)
- Description of the property
- Type(s)
- Validation
Some of these metadata:
- Required
- Type
- Validation
Can automatically reject invalid input data in property with very pretty much no code
What is available elsewhere:
- Stencil decorators @prop() https://stenciljs.com/docs/properties/
- Facebook (React) prop-types https://github.com/facebook/prop-types
Slots
Slots are part of the API of the component exposed to the user/dev.
Slots would need the following metadata at least:
- Slot Name (option)
- Description
- Default value (Just the innerHTML of the
<slot>
basicaly)
Events
I'm not too familiar with events in Svelte, but again it's part of the API exposed by the component.
- Event name
- Description
- Params[]
CSS custom properties
Maybe optional. OK.
But they go through Shadow DOM fences. Used to style compoments from the outside.
Will likely be replace by ::part
spec coming up...