@@ -7,17 +7,20 @@ import { devtoolsRegistry, UnsupportedComponent } from './registry'
77/**
88 * Render a json-render `Spec` with the DevTools registry, the same way
99 * `ViewJsonRender` does at runtime — including the `UnsupportedComponent`
10- * fallback for any element `type` absent from the registry.
10+ * fallback for any element `type` absent from the registry. Accepts a getter
11+ * instead of a plain `Spec` so stories can rebuild the spec from reactive
12+ * Storybook `args` (e.g. toggling `variant`/`interactive` live via Controls).
1113 */
12- function renderSpec ( spec : Spec ) {
14+ function renderSpec ( specOrGetter : Spec | ( ( ) => Spec ) ) {
1315 return defineComponent ( {
1416 setup ( ) {
15- const initialState = ( spec as any ) . state ?? { }
17+ const getSpec = typeof specOrGetter === 'function' ? specOrGetter : ( ) => specOrGetter
18+ const initialState = ( getSpec ( ) as any ) . state ?? { }
1619 return ( ) => h (
1720 'div' ,
1821 { class : 'max-w-160 p6 bg-base color-base font-sans' } ,
1922 h ( JSONUIProvider , { registry : devtoolsRegistry , handlers : { } , initialState } , {
20- default : ( ) => h ( Renderer , { spec, registry : devtoolsRegistry , fallback : UnsupportedComponent } ) ,
23+ default : ( ) => h ( Renderer , { spec : getSpec ( ) , registry : devtoolsRegistry , fallback : UnsupportedComponent } ) ,
2124 } ) ,
2225 )
2326 } ,
@@ -78,18 +81,39 @@ export const Gallery: Story = {
7881 } as unknown as Spec ) ,
7982}
8083
81- /** A `Card` grouping content under a titled, bordered surface. */
82- export const Card : Story = {
83- render : ( ) => renderSpec ( {
84+ /**
85+ * A `Card` grouping content under a titled, bordered surface. Toggle the
86+ * Controls below to compare today's default (`primary`, non-`interactive` —
87+ * unchanged from before this fix) against the new opt-in look: `variant`
88+ * tints the background (`secondary`/`danger`) or leaves it untouched
89+ * (`primary`/`ghost`); `interactive` strengthens the Card's border on hover
90+ * and tints each row's (`Stack`) background on hover.
91+ */
92+ interface CardArgs {
93+ variant : 'primary' | 'secondary' | 'ghost' | 'danger'
94+ interactive : boolean
95+ }
96+
97+ export const Card : StoryObj < Meta < CardArgs > > = {
98+ argTypes : {
99+ variant : { control : 'select' , options : [ 'primary' , 'secondary' , 'ghost' , 'danger' ] } ,
100+ interactive : { control : 'boolean' } ,
101+ } ,
102+ args : { variant : 'primary' , interactive : false } ,
103+ render : args => renderSpec ( ( ) => ( {
84104 root : 'root' ,
85105 state : { } ,
86106 elements : {
87- root : { type : 'Card' , props : { title : 'Plugin' , collapsible : false } , children : [ 'body' ] } ,
88- body : { type : 'Stack' , props : { direction : 'column' , gap : 8 , padding : 4 } , children : [ 't' , 'badge' ] } ,
107+ root : { type : 'Card' , props : { title : 'Plugin' , collapsible : false , variant : args . variant , interactive : args . interactive } , children : [ 'body' ] } ,
108+ body : { type : 'Stack' , props : { direction : 'column' , gap : 4 , padding : 4 } , children : [ 'row1' , 'row2' ] } ,
109+ row1 : { type : 'Stack' , props : { direction : 'row' , gap : 8 , align : 'center' , interactive : args . interactive } , children : [ 't' , 'badge' ] } ,
89110 t : { type : 'Text' , props : { text : 'vite-plugin-inspect' , variant : 'code' } } ,
90111 badge : { type : 'Badge' , props : { text : 'enabled' , variant : 'success' } } ,
112+ row2 : { type : 'Stack' , props : { direction : 'row' , gap : 8 , align : 'center' , interactive : args . interactive } , children : [ 't2' , 'badge2' ] } ,
113+ t2 : { type : 'Text' , props : { text : 'vite-plugin-vue' , variant : 'code' } } ,
114+ badge2 : { type : 'Badge' , props : { text : 'enabled' , variant : 'success' } } ,
91115 } ,
92- } as unknown as Spec ) ,
116+ } as unknown as Spec ) ) ,
93117}
94118
95119/**
0 commit comments