Skip to content

Commit

Permalink
docs: add registry examples
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-ub committed Oct 27, 2024
1 parent a699e86 commit 50d742e
Show file tree
Hide file tree
Showing 2 changed files with 333 additions and 0 deletions.
83 changes: 83 additions & 0 deletions docs/src/__registry__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import process from 'node:process'
import { registry } from '@/registry'
import { type Style, styles } from '@/registry/registry-styles'
import { type Registry, registrySchema } from '@/registry/schema'

export const Index: Record<Style['name'], any> = {
'default': {},
'new-york': {},
}

async function buildRegistry(registry: Registry): Promise<void> {
for (const style of styles) {
for (const item of registry) {
const resolveFiles = item.files?.map(file => `registry/${style.name}/${typeof file === 'string' ? file : file.path
}`)

if (!resolveFiles) {
continue
}

const type = item.type.split(':')[1]

// TODO: implement source file
const sourceFilename = ''
const chunks: {
name: string
description: string
component: string
file: string
container: {
className: string
}
}[] = []

let componentPath = `../registry/${style.name}/${type}/${item.name}`

if (item.files) {
const files = item.files.map(file =>
typeof file === 'string'
? { type: 'registry:page', path: file }
: file,
)
if (files?.length) {
componentPath = `../registry/${style.name}/${files[0].path}`
}
}

Index[style.name][item.name] = {
name: item.name,
description: item.description ?? '',
type: item.type,
registryDependencies: item.registryDependencies ?? [],
files: resolveFiles.map(file => file),
component: () => import(/* @vite-ignore */componentPath),
source: sourceFilename,
category: item.category ?? '',
chunks: chunks.map(chunk => ({
name: chunk.name,
description: chunk.description ?? 'No description',
component: chunk.component,
file: chunk.file,
container: {
className: chunk.container?.className ?? '',
},
})),
}
}
}
}

try {
const result = registrySchema.safeParse(registry)

if (!result.success) {
console.error(result.error)
process.exit(1)
}

await buildRegistry(result.data)
}
catch (error) {
console.error(error)
}
250 changes: 250 additions & 0 deletions docs/src/registry/registry-examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,254 @@ export const examples: Registry = [
registryDependencies: ['accordion'],
files: ['example/accordion-demo.ts'],
},
{
name: 'alert-demo',
type: 'registry:example',
registryDependencies: ['alert'],
files: ['example/alert-demo.ts'],
},
{
name: 'alert-destructive',
type: 'registry:example',
registryDependencies: ['alert'],
files: ['example/alert-destructive.ts'],
},
{
name: 'aspect-ratio-demo',
type: 'registry:example',
registryDependencies: ['aspect-ratio'],
files: ['example/aspect-ratio-demo.ts'],
},
{
name: 'avatar-demo',
type: 'registry:example',
registryDependencies: ['avatar'],
files: ['example/avatar-demo.ts'],
},
{
name: 'badge-demo',
type: 'registry:example',
registryDependencies: ['badge'],
files: ['example/badge-demo.ts'],
},
{
name: 'badge-destructive',
type: 'registry:example',
registryDependencies: ['badge'],
files: ['example/badge-destructive.ts'],
},
{
name: 'badge-outline',
type: 'registry:example',
registryDependencies: ['badge'],
files: ['example/badge-outline.ts'],
},
{
name: 'badge-secondary',
type: 'registry:example',
registryDependencies: ['badge'],
files: ['example/badge-secondary.ts'],
},
{
name: 'breadcrumb-demo',
type: 'registry:example',
registryDependencies: ['breadcrumb'],
files: ['example/breadcrumb-demo.ts'],
},
{
name: 'button-demo',
type: 'registry:example',
registryDependencies: ['button'],
files: ['example/button-demo.ts'],
},
{
name: 'button-destructive',
type: 'registry:example',
registryDependencies: ['button'],
files: ['example/button-destructive.ts'],
},
{
name: 'button-ghost',
type: 'registry:example',
registryDependencies: ['button'],
files: ['example/button-ghost.ts'],
},
{
name: 'button-icon',
type: 'registry:example',
registryDependencies: ['button'],
files: ['example/button-icon.ts'],
},
{
name: 'button-link',
type: 'registry:example',
registryDependencies: ['button'],
files: ['example/button-link.ts'],
},
{
name: 'button-loading',
type: 'registry:example',
registryDependencies: ['button'],
files: ['example/button-loading.ts'],
},
{
name: 'button-outline',
type: 'registry:example',
registryDependencies: ['button'],
files: ['example/button-outline.ts'],
},
{
name: 'button-secondary',
type: 'registry:example',
registryDependencies: ['button'],
files: ['example/button-secondary.ts'],
},
{
name: 'button-with-icon',
type: 'registry:example',
registryDependencies: ['button'],
files: ['example/button-with-icon.ts'],
},
{
name: 'card-with-form',
type: 'registry:example',
registryDependencies: ['card'],
files: ['example/card-with-form.ts'],
},
{
name: 'collapsible-demo',
type: 'registry:example',
registryDependencies: ['collapsible'],
files: ['example/collapsible-demo.ts'],
},
{
name: 'input-demo',
type: 'registry:example',
registryDependencies: ['input'],
files: ['example/input-demo.ts'],
},
{
name: 'input-disabled',
type: 'registry:example',
registryDependencies: ['input'],
files: ['example/input-disabled.ts'],
},
{
name: 'input-file',
type: 'registry:example',
registryDependencies: ['input'],
files: ['example/input-file.ts'],
},
{
name: 'separator-demo',
type: 'registry:example',
registryDependencies: ['separator'],
files: ['example/separator-demo.ts'],
},
{
name: 'skeleton-card',
type: 'registry:example',
registryDependencies: ['skeleton'],
files: ['example/skeleton-card.ts'],
},
{
name: 'skeleton-demo',
type: 'registry:example',
registryDependencies: ['skeleton'],
files: ['example/skeleton-demo.ts'],
},
{
name: 'sonner-demo',
type: 'registry:example',
registryDependencies: ['sonner'],
files: ['example/sonner-demo.ts'],
},
{
name: 'switch-demo',
type: 'registry:example',
registryDependencies: ['switch'],
files: ['example/switch-demo.ts'],
},
{
name: 'table-demo',
type: 'registry:example',
registryDependencies: ['table'],
files: ['example/table-demo.ts'],
},
{
name: 'tabs-demo',
type: 'registry:example',
registryDependencies: ['tabs'],
files: ['example/tabs-demo.ts'],
},
{
name: 'typography-blockquote',
type: 'registry:example',
files: ['example/typography-blockquote.ts'],
},
{
name: 'typography-demo',
type: 'registry:example',
files: ['example/typography-demo.ts'],
},
{
name: 'typography-h1',
type: 'registry:example',
files: ['example/typography-h1.ts'],
},
{
name: 'typography-h2',
type: 'registry:example',
files: ['example/typography-h2.ts'],
},
{
name: 'typography-h3',
type: 'registry:example',
files: ['example/typography-h3.ts'],
},
{
name: 'typography-h4',
type: 'registry:example',
files: ['example/typography-h4.ts'],
},
{
name: 'typography-inline-code',
type: 'registry:example',
files: ['example/typography-inline-code.ts'],
},
{
name: 'typography-large',
type: 'registry:example',
files: ['example/typography-large.ts'],
},
{
name: 'typography-lead',
type: 'registry:example',
files: ['example/typography-lead.ts'],
},
{
name: 'typography-list',
type: 'registry:example',
files: ['example/typography-list.ts'],
},
{
name: 'typography-muted',
type: 'registry:example',
files: ['example/typography-muted.ts'],
},
{
name: 'typography-p',
type: 'registry:example',
files: ['example/typography-p.ts'],
},
{
name: 'typography-small',
type: 'registry:example',
files: ['example/typography-small.ts'],
},
{
name: 'typography-table',
type: 'registry:example',
files: ['example/typography-table.ts'],
},
]

0 comments on commit 50d742e

Please sign in to comment.