-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add examples to the registry and update ComponentPreview
- Loading branch information
Showing
3 changed files
with
47 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { styles } from "@/registry/styles" | ||
|
||
export const examples: Record<string, Record<string, any>> = {}; | ||
|
||
const components = import.meta.glob(`../registry/**/example/*.ts`); | ||
|
||
for (const path in components) { | ||
const component = components[path]; | ||
const name = path.split('/')[2]; | ||
const componentName = path.split('/').pop()?.replace('.ts', ''); | ||
if (!componentName || !name) { | ||
continue; | ||
} | ||
|
||
if (!examples[name]) { | ||
examples[name] = {}; | ||
} | ||
|
||
examples[name][componentName] = { | ||
name: componentName, | ||
type: "components:example", | ||
registryDependencies: [name], | ||
component, | ||
source: "", | ||
files: [path], | ||
category: "undefined", | ||
subcategory: "undefined", | ||
chunks: [] | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,29 @@ | ||
import { Component, computed, input } from '@angular/core'; | ||
import { AsyncPipe, NgComponentOutlet } from '@angular/common'; | ||
|
||
import { examples } from '@/__registry__/examples' | ||
|
||
@Component({ | ||
standalone: true, | ||
imports: [NgComponentOutlet, AsyncPipe], | ||
template: ` | ||
<ng-container *ngComponentOutlet="component() | async" /> | ||
@let componentRender = this.component() | async; | ||
@if(!componentRender || !componentRender.default) { | ||
<div>Loading...</div> | ||
} @else { | ||
<ng-container *ngComponentOutlet="componentRender.default" /> | ||
} | ||
` | ||
}) | ||
export class ComponentPeviewComponent { | ||
path = input.required<string>(); | ||
styleName = input<string>(); | ||
nameExample = input<string>(); | ||
examples = examples; | ||
|
||
component = computed(async () => { | ||
if (!this.styleName() || !this.nameExample()) return null; | ||
|
||
protected component = computed(async () => { | ||
return (await import(/* @vite-ignore */ this.path())).default; | ||
return await examples[this.styleName()!][this.nameExample()!].component(); | ||
}); | ||
} |