This commit is contained in:
Chris Wanstrath 2025-12-26 22:05:23 -08:00
parent 454750047c
commit 890fac1afc
2 changed files with 7 additions and 5 deletions

View File

@ -1,5 +1,4 @@
import { define } from '../src' import { define } from '../src'
import { Layout } from './helpers' import { Layout } from './helpers'
const P = define('P', { const P = define('P', {
@ -46,10 +45,12 @@ const ExampleCard = define('ExampleCard', {
}, },
render({ props: { title, desc }, parts: { Root, H2, P } }) { render({ props: { title, desc }, parts: { Root, H2, P } }) {
return <Root> return (
<H2>{title}</H2> <Root>
<P>{desc}</P> <H2>{title}</H2>
</Root> <P>{desc}</P>
</Root>
)
} }
}) })

View File

@ -161,6 +161,7 @@ export function define(nameOrDef: string | TagDef, defIfNamed?: TagDef) {
const name = defIfNamed ? (nameOrDef as string) : `Def${anonComponents++}` const name = defIfNamed ? (nameOrDef as string) : `Def${anonComponents++}`
const def = defIfNamed ?? nameOrDef as TagDef const def = defIfNamed ?? nameOrDef as TagDef
if (styles[name]) throw `${name} is already defined! Must use unique names.`
registerStyles(name, def) registerStyles(name, def)
return (props: Record<string, any>) => { return (props: Record<string, any>) => {