You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for example, we can use @since annotation to get a version this could be in turn used to be displayed in storybook.
i did some hacking around with storyblocks and i got something based on this plugin
annotation example based on shoelace example
/** * A button is used to trigger an action. For more information about a button, click [here](https://unify.nedap.healthcare/42a5b6c3c/p/17c689-button/b/05c6fc) * * @status stable * @since 2.0.0 * * @dependency uc-icon * @dependency uc-badge * **/
the cem plugin
import{parse}from'comment-parser';functionnoDash(string){returnstring.replace(/^\s?-/,'').trim();}exportfunctioncustomTags(){return{name: 'custom-tags',analyzePhase({ts, node, moduleDoc}){switch(node.kind){casets.SyntaxKind.ClassDeclaration: {constclassName=node.name.getText();constclassDoc=moduleDoc?.declarations?.find(declaration=>declaration.name===className);constcustomTags=['aria-rules','deprecated-attribute','dependency','status','since'];letcustomComments='/**';node.jsDoc?.forEach(jsDoc=>{jsDoc?.tags?.forEach(tag=>{consttagName=tag.tagName.getText();if(customTags.includes(tagName)){customComments+=`\n * @${tagName}${tag.comment}`;}});});// This is what allows us to map JSDOC comments to ReactWrappers.classDoc['jsDoc']=node.jsDoc?.map(jsDoc=>jsDoc.getFullText()).join('\n');constparsed=parse(`${customComments}\n */`);parsed[0].tags?.forEach(t=>{switch(t.tag){// custom rule for ariacase'aria-rules':
if(!Array.isArray(classDoc['aria-rules'])){classDoc['aria-rules']=[];}classDoc['aria-rules'].push({name: t.name,description: noDash(t.description),});break;// custom deprecated attribute rulecase'deprecated-attribute':
if(!Array.isArray(classDoc['deprecated-attribute'])){classDoc['deprecated-attribute']=[];}classDoc['deprecated-attribute'].push({name: t.name,description: noDash(t.description),});break;// custom deprecated element rulecase'deprecated':
if(!Array.isArray(classDoc['deprecated'])){classDoc['deprecated']=[];}classDoc['deprecated'].push({description: noDash(t.description),});break;// Dependenciescase'dependency':
if(!Array.isArray(classDoc['dependencies'])){classDoc['dependencies']=[];}classDoc['dependencies'].push(t.name);break;// Value-only metadata tagscase'since':
case'status':
classDoc[t.tag]=t.name;break;// All other tagsdefault:
if(!Array.isArray(classDoc[t.tag])){classDoc[t.tag]=[];}classDoc[t.tag].push({name: t.name,description: t.description,type: t.type||undefined});}});}}}}}
preview.ts
import{setCustomElementsManifest}from"@storybook/web-components";import{setWcStorybookHelpersConfig}from"wc-storybook-helpers";importcustomElementsfrom"custom-elements.json";importDocumentationTemplatefrom"./DocumentationTemplate.mdx";setWcStorybookHelpersConfig({typeRef: "expandedType",hideArgRef: true});setCustomElementsManifest(customElements);constpreview: Preview={// ... more settings and thingsdocs: {page: DocumentationTemplate,},}exportdefaultpreview;
DocumentationTemplate.mdx
import{Meta,Title,Subtitle,Primary,Controls,Stories,Description}from'@storybook/blocks';importMyCustomBlockfrom'./MyCustomBlock';{/* * 👇 The isTemplate property is required to tell Storybook that this is a template * See https://storybook.js.org/docs/api/doc-block-meta * to learn how to use*/}<MetaisTemplate/><Title/><Subtitle/><Description/><MyCustomBlock/>
# Defaultimplementation<Primary/>
## InputsThecomponentacceptsthefollowinginputs(props):
<Controls/>---
## AdditionalvariationsListedbelowareadditionalvariationsofthecomponent.<Stories/>
MyCustomBlock.jsx
importReact,{useContext}from"react";import{DocsContext}from"@storybook/addon-docs/blocks";importcustomElementsfrom"@nedap/unify-components/custom-elements.json";import{getComponentByTagName}from"wc-storybook-helpers/dist/cem-utilities.js";constMyCustomBlock=({ children, ...props})=>{constcontext=useContext(DocsContext);consttag=context.storyById().component;constcomponent=getComponentByTagName(tag,customElements);const{ since, dependencies, status }=component;return(<div{...props}>{since&&<p>Since: {since}</p>}{dependencies&&(<p>
Dependencies:
<ul>{dependencies.map((dep)=>(<li>{dep}</li>))}</ul></p>)}{status&&<p>Status: {status}</p>}{/* Render your custom content or children */}{children}</div>);};exportdefaultMyCustomBlock;
The text was updated successfully, but these errors were encountered:
like discussed on discord :)
the idea is to be able to use custom jsdoc annotations to document things in storybook
based on this work https://github.com/shoelace-style/shoelace/blob/dafb35c6e210193a9ca31efddc3429ba2bb66be3/custom-elements-manifest.config.js
for example, we can use
@since
annotation to get a version this could be in turn used to be displayed in storybook.i did some hacking around with storyblocks and i got something based on this plugin
annotation example based on shoelace example
the cem plugin
preview.ts
DocumentationTemplate.mdx
MyCustomBlock.jsx
The text was updated successfully, but these errors were encountered: