Skip to content

Commit

Permalink
feat: add component preview
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-ub committed Jul 27, 2024
1 parent 66d74f9 commit 61b4c0d
Show file tree
Hide file tree
Showing 11 changed files with 810 additions and 42 deletions.
18 changes: 18 additions & 0 deletions apps/www/.vscode/simple-query.code-snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"query target": {
"scope": "typescriptreact,javascriptreact",
"prefix": "$:target",
"body": [
"data-target={$('$1')}"
]
},
"query ready block": {
"scope": "typescript,javascript",
"prefix": "$:ready",
"body": [
"$.ready(async () => {",
" $1",
"});"
]
}
}
93 changes: 53 additions & 40 deletions apps/www/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,61 @@ import { defineConfig } from "astro/config";
import starlight from "@astrojs/starlight";
import tailwind from "@astrojs/tailwind";
import angular from "@analogjs/astro-angular";

import { siteConfig } from "./src/config/site";
import theme from "./src/lib/highlighter-theme.json";

import simpleStackQuery from "simple-stack-query";

// https://astro.build/config
export default defineConfig({
site: siteConfig.url,
integrations: [
angular(),
starlight({
title: siteConfig.name,
logo: {
dark: "./src/assets/logo-dark.svg",
light: "./src/assets/logo-light.svg",
},
favicon: "./src/assets/logo-dark.svg",
social: {
github: siteConfig.links.github,
"x.com": siteConfig.links.twitter,
},
sidebar: [
{
label: "Getting Started",
autogenerate: {
directory: "docs",
},
},
],
customCss: ["./src/tailwind.css"],
components: {
Header: "./src/components/starlight/header/Header.astro",
PageFrame: "./src/components/starlight/PageFrame.astro",
SiteTitle: "./src/components/starlight/SiteTitle.astro",
SocialIcons: "./src/components/starlight/SocialIcons.astro",
Search: "./src/components/starlight/Search.astro",
Hero: "./src/components/starlight/Hero.astro",
ContentPanel: "./src/components/starlight/ContentPanel.astro",
PageTitle: "./src/components/starlight/PageTitle.astro",
MarkdownContent: "./src/components/starlight/MarkdownContent.astro",
TwoColumnContent: "./src/components/starlight/TwoColumnContent.astro",
Sidebar: "./src/components/starlight/Sidebar.astro",
},
}),
tailwind(),
],
});
integrations: [starlight({
title: siteConfig.name,
expressiveCode: {
themes: [theme]
},
logo: {
dark: "./src/assets/logo-dark.svg",
light: "./src/assets/logo-light.svg"
},
favicon: "./src/assets/logo-dark.svg",
social: {
github: siteConfig.links.github,
"x.com": siteConfig.links.twitter
},
sidebar: [{
label: "Getting Started",
items: [{
label: "Introduction",
slug: "docs"
}]
}, {
label: "Components",
autogenerate: {
directory: "docs/components"
}
}],
customCss: ["./src/tailwind.css"],
components: {
Header: "./src/components/starlight/header/Header.astro",
PageFrame: "./src/components/starlight/PageFrame.astro",
SiteTitle: "./src/components/starlight/SiteTitle.astro",
SocialIcons: "./src/components/starlight/SocialIcons.astro",
Search: "./src/components/starlight/Search.astro",
Hero: "./src/components/starlight/Hero.astro",
ContentPanel: "./src/components/starlight/ContentPanel.astro",
PageTitle: "./src/components/starlight/PageTitle.astro",
MarkdownContent: "./src/components/starlight/MarkdownContent.astro",
TwoColumnContent: "./src/components/starlight/TwoColumnContent.astro",
Sidebar: "./src/components/starlight/Sidebar.astro"
}
}), tailwind(), angular(), simpleStackQuery()],
vite: {
optimizeDeps: {
include: ["@radix-ng/primitives", "@angular/common", "@angular/core", "@angular/cdk", "@ng-icons/core", "@ng-icons/lucide"]
},
ssr: {
noExternal: ["@radix-ng/primitives", "@angular/cdk", "@ng-icons/core", "@ng-icons/lucide"]
}
}
});
2 changes: 2 additions & 0 deletions apps/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@astrojs/starlight-tailwind": "^2.0.3",
"@astrojs/tailwind": "^5.1.0",
"@ng-icons/core": "^29.0.0",
"@ng-icons/lucide": "^29.0.0",
"@ng-icons/radix-icons": "^29.0.0",
"@pagefind/default-ui": "^1.1.0",
"@radix-ng/primitives": "^0.8.2",
Expand All @@ -37,6 +38,7 @@
"lodash.template": "^4.5.0",
"rxjs": "^7.8.1",
"sharp": "^0.32.5",
"simple-stack-query": "^0.1.1",
"tailwind-merge": "^2.4.0",
"tailwindcss": "^3.4.4",
"tslib": "^2.6.3",
Expand Down
107 changes: 107 additions & 0 deletions apps/www/src/components/ComponentPreview.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
import path from "path";
import { styles } from "@/registry/styles";
import { readFileSync } from "fs";
import { Tabs, TabItem, Code } from "@astrojs/starlight/components";
export interface Props {
name: string;
}
const { name } = Astro.props;
const components = await Promise.all(
styles.map(async (style) => {
const filename = path.join(
process.cwd(),
"src",
"registry",
style.name,
"example",
`${name}.ts`
);
const Component = (await import(/* @vite-ignore */ `${filename}`)).default;
const code = readFileSync(`${filename}`)
.toString()
.replace(/export\s+default\s+.*;\s*/, "")
.replace(/@\/registry\/.*\/ui/g, "@/components/ui");
return {
style,
Component,
code,
};
})
);
---

<div class="not-content group relative my-4 flex flex-col space-y-2">
<Tabs>
<TabItem label="Preview">
<div
class="mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 relative rounded-md border"
>
<div class="flex items-center justify-between p-4">
<select
class="flex items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>option]:line-clamp-1 h-7 w-[145px] text-xs [&_svg]:h-4 [&_svg]:w-4"
data-target={$("change-theme")}
>
{
styles.map(({ name, label }, index) => (
<option value={name}>{label}</option>
))
}
</select>
</div>

<div class="w-full" style="--radius: 0.5rem;">
<div
class="preview flex min-h-[350px] w-full justify-center p-10 items-center"
>
{
components.map(({ Component, style }, index) => (
<div
data-target={$("preview-" + style.name)}
hidden={index !== 0}
>
<Component />
</div>
))
}
</div>
</div>
</div>
</TabItem>
<TabItem label="Code">
<div>
{
components.map(({ code, style }, index) => (
<div data-target={$("code-" + style.name)} hidden={index !== 0}>
<Code code={code} lang="angular-ts" />
</div>
))
}
</div>
</TabItem>
</Tabs>
</div>

<script>
import { styles } from "@/registry/styles";

$.ready(async () => {
$("change-theme").addEventListener("change", (event) => {
const value = event.target.value;
hiddeComponents();
$(`preview-${value}`).hidden = false;
$(`code-${value}`).hidden = false;
});

function hiddeComponents() {
styles.forEach(({ name }) => {
$(`preview-${name}`).hidden = true;
$(`code-${name}`).hidden = true;
});
}
});
</script>
7 changes: 5 additions & 2 deletions apps/www/src/components/starlight/PageTitle.astro
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
---
import { cn } from "@/lib/utils";
import { PAGE_TITLE_ID } from "../../constants";
import type { Props } from "@astrojs/starlight/props";
import {} from "@ng-icons/radix-icon";
import { cn } from "@/lib/utils";
import { badgeVariants } from "@/registry/new-york/ui/badge.directive";
import { PAGE_TITLE_ID } from "../../constants";
---

<div
Expand Down
48 changes: 48 additions & 0 deletions apps/www/src/content/docs/docs/components/alert.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: Alert
description: Displays a callout for user attention.
---

import { Tabs, TabItem, Code } from "@astrojs/starlight/components";
import { Steps } from "@astrojs/starlight/components";
import ComponentPreview from "@/components/ComponentPreview.astro";

<ComponentPreview name="alert-demo" />

## Installation

<Tabs>
<TabItem label="CLI">
```bash
npx shadcn-ng@latest add alert
```
</TabItem>

<TabItem label="Manual">
<Steps>
1. Copy and paste the following code into your project.

2. Update the import paths to match your project setup.
</Steps>

</TabItem>
</Tabs>

## Usage

```ts
import {
UbAlertDirective,
UbAlertDescriptionDirective,
UbAlertTitleDirective,
} from "@/components/ui/alert.directive";
```

```angular-html
<div ubAlert>
<h5 ubAlertTitle>Heads up!</h5>
<div ubAlertDescription>
You can add components and dependencies to your app using the cli.
</div>
</div>
```
Loading

0 comments on commit 61b4c0d

Please sign in to comment.