Skip to content

Commit 0732243

Browse files
committed
[docs] Add shadcn theme
1 parent 6245499 commit 0732243

File tree

9 files changed

+165
-1
lines changed

9 files changed

+165
-1
lines changed

apps/docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@sjsf/lucide-icons": "workspace:*",
1818
"@sjsf/form": "workspace:*",
1919
"@sjsf/skeleton-theme": "workspace:*",
20+
"@sjsf/shadcn-theme": "workspace:*",
2021
"ajv": "catalog:",
2122
"mermaid": "^11.3.0",
2223
"svg-pan-zoom": "github:bumbu/svg-pan-zoom"

apps/docs/src/content/docs/_npm-with-themes.astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const THEME_PACKAGES = {
1313
daisyui: "@sjsf/daisyui-theme",
1414
flowbite: "@sjsf/flowbite-theme",
1515
skeleton: "@sjsf/skeleton-theme",
16+
shadcn: "@sjsf/shadcn-theme",
1617
} satisfies Record<Theme, string>;
1718
1819
const isBasic = theme === "basic";

apps/docs/src/content/docs/_usage-with-theme.astro

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Tabs, TabItem, Code, Card } from "@astrojs/starlight/components";
33
import daisyuiStyles from '@sjsf/daisyui-theme/styles.css?inline';
44
import flowbiteStyles from '@sjsf/flowbite-theme/styles.css?inline';
55
import skeletonStyles from '@sjsf/skeleton-theme/styles.css?inline';
6+
import shadcnStyles from '@sjsf/shadcn-theme/styles.css?inline';
67
78
import type { Theme } from "@/shared";
89
import { ShadowHost } from "@/components/shadow";
@@ -11,13 +12,15 @@ import WithBasic from "./_with-basic.svelte";
1112
import WithSkeleton from "./_with-skeleton.svelte";
1213
import WithDaisyui from "./_with-daisyui.svelte";
1314
import WithFlowbite from "./_with-flowbite.svelte";
15+
import WithShadcn from "./_with-shadcn.svelte";
1416
1517
import schemaCode from "./_schema?raw";
1618
import validatorCode from './_validator?raw';
1719
import withBasicCode from "./_with-basic.svelte?raw";
1820
import withSkeletonCode from "./_with-skeleton.svelte?raw";
1921
import withDaisyuiCode from "./_with-daisyui.svelte?raw";
2022
import withFlowbiteCode from "./_with-flowbite.svelte?raw";
23+
import withShadcnCode from "./_with-shadcn.svelte?raw";
2124
2225
const theme = (Astro.params.theme ?? "basic") as Theme;
2326
@@ -26,13 +29,15 @@ const STYLES = {
2629
daisyui: daisyuiStyles,
2730
flowbite: flowbiteStyles,
2831
skeleton: skeletonStyles,
32+
shadcn: shadcnStyles
2933
} satisfies Record<Theme, string>;
3034
3135
const CODE = {
3236
basic: withBasicCode,
3337
daisyui: withDaisyuiCode,
3438
flowbite: withFlowbiteCode,
3539
skeleton: withSkeletonCode,
40+
shadcn: withShadcnCode
3641
} satisfies Record<Theme, string>;
3742
---
3843

@@ -59,6 +64,8 @@ const CODE = {
5964
<WithFlowbite client:only="svelte" />
6065
) : theme === "skeleton" ? (
6166
<WithSkeleton client:only="svelte" />
67+
) : theme === "shadcn" ? (
68+
<WithShadcn client:only="svelte" />
6269
) : null
6370
}
6471
</ShadowHost>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<script lang="ts">
2+
import { Form } from "@sjsf/form";
3+
import { translation } from "@sjsf/form/translations/en";
4+
import { theme, setThemeContext } from "@sjsf/shadcn-theme";
5+
import { components } from '@sjsf/shadcn-theme/default'
6+
7+
import { astroTheme } from "@/theme.svelte";
8+
9+
import { schema, uiSchema, initialData } from "./_schema";
10+
import { validator } from "./_validator";
11+
12+
let value = $state(initialData);
13+
14+
const astro = astroTheme();
15+
16+
setThemeContext({ components })
17+
</script>
18+
19+
<Form
20+
class="flex flex-col gap-4 {astro.darkOrLight}"
21+
bind:value
22+
{...theme}
23+
{schema}
24+
{uiSchema}
25+
{validator}
26+
{translation}
27+
onSubmit={console.log}
28+
/>
29+
30+
<pre style="padding-top: 1rem;">{JSON.stringify(value, null, 2)}</pre>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
import themeStyles from '@sjsf/shadcn-theme/styles.css?inline';
3+
4+
import { ShadowHost } from "@/components/shadow";
5+
6+
import ThemeForm from "./_shadcn-theme.svelte";
7+
---
8+
9+
<ShadowHost client:only="svelte" style={themeStyles}>
10+
<ThemeForm client:only="svelte" />
11+
</ShadowHost>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<script lang="ts">
2+
import { theme, setThemeContext } from "@sjsf/shadcn-theme";
3+
import { components } from '@sjsf/shadcn-theme/default'
4+
5+
import { astroTheme } from "@/theme.svelte";
6+
import CustomForm from "@/components/custom-form.svelte";
7+
8+
import { schema, uiSchema } from "./_demo-schema";
9+
10+
const astro = astroTheme();
11+
12+
let value = $state();
13+
14+
setThemeContext({ components })
15+
</script>
16+
17+
<CustomForm
18+
{...theme}
19+
bind:value
20+
{schema}
21+
{uiSchema}
22+
novalidate
23+
onSubmit={console.log}
24+
class="flex flex-col gap-4 {astro.darkOrLight}"
25+
/>
26+
27+
<pre style="padding-top: 1rem;">{JSON.stringify(value, null, 2)}</pre>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
title: Shadcn
3+
sidebar:
4+
order: 4
5+
---
6+
7+
import { Code, Card, LinkButton, Tabs, TabItem } from '@astrojs/starlight/components';
8+
9+
import Npm from '@/components/npm.astro';
10+
11+
import ShadcnTheme from './_shadcn-theme.astro';
12+
import shadcnThemeCode from './_shadcn-theme.svelte?raw';
13+
import demoSchemaCode from './_demo-schema.ts?raw';
14+
15+
## Installation
16+
17+
<Npm pkg="@sjsf/form @sjsf/shadcn-theme" />
18+
19+
:::note
20+
21+
This is `shadcn-svelte@next` based theme.
22+
23+
:::
24+
25+
### Install Shadcn Svelte
26+
27+
<LinkButton href="https://next.shadcn-svelte.com/docs/installation" variant='minimal' target="_blank" icon="external">
28+
Installation - shadcn-svelte
29+
</LinkButton>
30+
31+
### Setup styles
32+
33+
There is two ways to setup styles:
34+
35+
1. Use tailwindcss config
36+
37+
```typescript
38+
import { THEME_CONTENT } from '@sjsf/shadcn-theme/preset'
39+
40+
/** @type {import('tailwindcss').Config} */
41+
export default {
42+
content: ['./src/**/*.{html,js,svelte,ts}', THEME_CONTENT],
43+
// other tailwind config
44+
...
45+
}
46+
```
47+
48+
2. Inject prepared styles (not recommended)
49+
50+
```typescript
51+
// Inject them as you like
52+
import shadcnStyles from '@sjsf/shadcn-theme/styles.css?inline';
53+
```
54+
55+
## Components
56+
57+
Since `shadcn-svelte` is not a component library you should provide your components via `setThemeContext`.
58+
59+
```typescript
60+
import { setThemeContext } from '@sjsf/shadcn-theme';
61+
62+
setThemeContext({ components: { ... } })
63+
```
64+
65+
However, you can use already prepared component sets or mix them with your own components:
66+
67+
- `@sjsf/shadcn-theme/default`
68+
- `@sjsf/shadcn-theme/new-york`
69+
70+
## Demo
71+
72+
<Tabs>
73+
<TabItem label="Form.svelte">
74+
<Code code={shadcnThemeCode} lang="svelte" />
75+
</TabItem>
76+
<TabItem label="_demo-schema.ts">
77+
<Code code={demoSchemaCode} lang="typescript" />
78+
</TabItem>
79+
</Tabs>
80+
81+
<Card>
82+
<ShadcnTheme />
83+
</Card>

apps/docs/src/shared.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const THEMES = ["basic", "daisyui", "flowbite", "skeleton"] as const;
1+
export const THEMES = ["basic", "daisyui", "flowbite", "skeleton", "shadcn"] as const;
22

33
export type Theme = (typeof THEMES)[number];
44

@@ -7,4 +7,5 @@ export const THEME_TTITLES = {
77
daisyui: "DaisyUI",
88
flowbite: "Flowbite",
99
skeleton: "Skeleton",
10+
shadcn: "Shadcn",
1011
} satisfies Record<Theme, string>;

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)