Skip to content
Playground

svelte-jsonschema-form with Shadcn

Svelte 5 library for creating forms based on JSON schema.

Installation

Choose your favorite theme:

Terminal window
npm i @sjsf/form @sjsf/ajv8-validator ajv@8 @sjsf/shadcn-theme

Usage

<script lang="ts">
import { SimpleForm, useForm2 } from "@sjsf/form";
import { translation } from "@sjsf/form/translations/en";
import { theme, setThemeContext } from "@sjsf/shadcn-theme";
import { components } from "@sjsf/shadcn-theme/default";
import { useAstro } from "@/astro.svelte";
import { schema, uiSchema, initialValue } from "./_schema";
import { validator } from "./_validator";
import { onSubmit } from "./_on-submit";
const astro = useAstro();
const form = useForm2({
...theme,
initialValue,
schema,
uiSchema,
validator,
translation,
onSubmit,
});
setThemeContext({ components });
</script>
<SimpleForm {form} class="flex flex-col gap-4 {astro.darkOrLight}" />
<pre style="padding-top: 1rem;">{JSON.stringify(form.value, null, 2)}</pre>

License

This project includes modifications of code from react-jsonschema-form, which is licensed under the Apache License, Version 2.0. The rest of the project is under the MIT license.