-
-
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 component preview and source
- Loading branch information
Showing
8 changed files
with
161 additions
and
16 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
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,69 @@ | ||
--- | ||
import path from "path"; | ||
import { styles } from "@/registry/styles"; | ||
import { ui } from "@/registry/ui"; | ||
import { readFileSync } from "fs"; | ||
import { Code } from "@astrojs/starlight/components"; | ||
export interface Props { | ||
name: string; | ||
} | ||
const { name } = Astro.props; | ||
const componentUi = ui.find((value) => value.name === name); | ||
const allComponents = componentUi?.files.flatMap((file) => { | ||
return styles.map((style) => { | ||
const filename = path.join( | ||
process.cwd(), | ||
"src", | ||
"registry", | ||
style.name, | ||
file | ||
); | ||
const code = readFileSync(`${filename}`) | ||
.toString() | ||
.replace(/export\s+default\s+.*;\s*/, "") | ||
.replace(/@\/registry\/.*\/ui/g, "@/components/ui"); | ||
return { | ||
style, | ||
code, | ||
}; | ||
}); | ||
}); | ||
--- | ||
|
||
{ | ||
allComponents?.map(({ code, style }, index) => ( | ||
<div | ||
data-target={$("source-" + style.name)} | ||
class="w-[38rem]" | ||
hidden={index !== 0} | ||
> | ||
<Code code={code} class="w-[38rem]" wrap={true} /> | ||
</div> | ||
)) | ||
} | ||
<script> | ||
import { styles } from "@/registry/styles"; | ||
|
||
$.ready(async () => { | ||
document | ||
.getElementById("change-style") | ||
?.addEventListener("change", (event) => { | ||
// @ts-expect-error | ||
const value = event.target.value; | ||
hiddeComponents(); | ||
$(`source-${value}`).hidden = false; | ||
}); | ||
|
||
function hiddeComponents() { | ||
styles.forEach(({ name }) => { | ||
$(`source-${name}`).hidden = true; | ||
}); | ||
} | ||
}); | ||
</script> |
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
32 changes: 32 additions & 0 deletions
32
apps/www/src/registry/default/example/alert-destructive.ts
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,32 @@ | ||
import { Component } from "@angular/core"; | ||
import { NgIconComponent, provideIcons } from "@ng-icons/core"; | ||
import { lucideTerminal } from "@ng-icons/lucide"; | ||
|
||
import { | ||
UbAlertDirective, | ||
UbAlertTitleDirective, | ||
UbAlertDescriptionDirective, | ||
} from "@/registry/default/ui/alert.directive"; | ||
|
||
@Component({ | ||
standalone: true, | ||
imports: [ | ||
NgIconComponent, | ||
UbAlertDirective, | ||
UbAlertTitleDirective, | ||
UbAlertDescriptionDirective, | ||
], | ||
viewProviders: [provideIcons({ lucideTerminal })], | ||
template: ` | ||
<div ubAlert variant="destructive"> | ||
<ng-icon name="lucideTerminal" class="h-4 w-4" /> | ||
<h5 ubAlertTitle>Heads up!</h5> | ||
<div ubAlertDescription> | ||
You can add components and dependencies to your app using the cli. | ||
</div> | ||
</div> | ||
`, | ||
}) | ||
export class AlertDemoComponent {} | ||
|
||
export default AlertDemoComponent; |
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
32 changes: 32 additions & 0 deletions
32
apps/www/src/registry/new-york/example/alert-destructive.ts
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,32 @@ | ||
import { Component } from "@angular/core"; | ||
import { NgIconComponent, provideIcons } from "@ng-icons/core"; | ||
import { lucideTerminal } from "@ng-icons/lucide"; | ||
|
||
import { | ||
UbAlertDirective, | ||
UbAlertTitleDirective, | ||
UbAlertDescriptionDirective, | ||
} from "@/registry/new-york/ui/alert.directive"; | ||
|
||
@Component({ | ||
standalone: true, | ||
imports: [ | ||
NgIconComponent, | ||
UbAlertDirective, | ||
UbAlertTitleDirective, | ||
UbAlertDescriptionDirective, | ||
], | ||
viewProviders: [provideIcons({ lucideTerminal })], | ||
template: ` | ||
<div ubAlert variant="destructive"> | ||
<ng-icon name="lucideTerminal" class="h-4 w-4" /> | ||
<h5 ubAlertTitle>Heads up!</h5> | ||
<div ubAlertDescription> | ||
You can add components and dependencies to your app using the cli. | ||
</div> | ||
</div> | ||
`, | ||
}) | ||
export class AlertDemoComponent {} | ||
|
||
export default AlertDemoComponent; |
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