Skip to content
Playground

Shadcn

Installation

Terminal window
npm i @sjsf/shadcn-theme

Install Shadcn Svelte

Installation - shadcn-svelte

Setup styles

There is two ways to setup styles:

  1. Use tailwindcss config
import { THEME_CONTENT } from '@sjsf/shadcn-theme/preset'
/** @type {import('tailwindcss').Config} */
export default {
content: ['./src/**/*.{html,js,svelte,ts}', THEME_CONTENT],
// other tailwind config
...
}
  1. Inject prepared styles (not recommended)
// Inject them as you like
import shadcnStyles from '@sjsf/shadcn-theme/styles.css?inline';

Components

Since shadcn-svelte is not a component library you should provide your components via setThemeContext.

import { setThemeContext } from '@sjsf/shadcn-theme';
setThemeContext({ components: { ... } })

However, you can use already prepared component sets or mix them with your own components:

  • @sjsf/shadcn-theme/default
  • @sjsf/shadcn-theme/new-york

Demo

<script lang="ts">
import { SimpleForm } from "@sjsf/form";
import { theme, setThemeContext } from "@sjsf/shadcn-theme";
import { components } from "@sjsf/shadcn-theme/default";
import { useAstro } from "@/astro.svelte";
import { useCustomForm } from "@/components/custom-form";
import { schema, uiSchema } from "./_demo-schema";
const astro = useAstro();
const form = useCustomForm({
...theme,
schema,
uiSchema,
});
setThemeContext({ components });
</script>
<SimpleForm {form} novalidate class="flex flex-col gap-4 {astro.darkOrLight}" />
<pre style="padding-top: 1rem;">{JSON.stringify(form.value, null, 2)}</pre>