Skip to content

Commit ecb9fab

Browse files
committed
[docs] Fix custom form
1 parent 595ea64 commit ecb9fab

File tree

12 files changed

+57
-43
lines changed

12 files changed

+57
-43
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<script lang="ts" generics="T">
2+
import { SvelteMap } from "svelte/reactivity";
3+
import Ajv, { type ErrorObject } from "ajv";
4+
import { Form, type FormProps } from "@sjsf/form";
5+
import { translation } from "@sjsf/form/translations/en";
6+
import { theme } from "@sjsf/form/basic-theme";
7+
import {
8+
AjvValidator,
9+
addFormComponents,
10+
DEFAULT_AJV_CONFIG,
11+
} from "@sjsf/ajv8-validator";
12+
13+
type Defaults = "widgets" | "components" | "validator" | "translation";
14+
15+
type Props<T> = Omit<FormProps<T, ErrorObject>, Defaults> &
16+
Partial<Pick<FormProps<T, ErrorObject>, Defaults>>;
17+
18+
let {
19+
value = $bindable(),
20+
form = $bindable(),
21+
isSubmitted = $bindable(false),
22+
errors = $bindable(new SvelteMap()),
23+
validator = new AjvValidator(
24+
addFormComponents(new Ajv(DEFAULT_AJV_CONFIG))
25+
),
26+
...rest
27+
}: Props<T> = $props();
28+
29+
let self: Form<T, ErrorObject>;
30+
31+
export function validate() {
32+
return self.validate();
33+
}
34+
</script>
35+
36+
<Form
37+
bind:this={self}
38+
{translation}
39+
{...theme}
40+
{...rest}
41+
{validator}
42+
bind:value
43+
bind:form
44+
bind:isSubmitted
45+
bind:errors
46+
/>

apps/docs/src/components/custom-form.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

apps/docs/src/content/docs/guides/_errors-list.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import type { Errors } from "@sjsf/form";
44
import { SvelteMap } from 'svelte/reactivity';
55
6-
import { CustomForm } from "@/components/custom-form";
6+
import CustomForm from "@/components/custom-form.svelte";
77
88
import { objectSchema } from './_demo-schemas';
99

apps/docs/src/content/docs/guides/_focus-on-first-error.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import { focusOnFirstError } from "@sjsf/form/focus-on-first-error";
33
4-
import { CustomForm } from "@/components/custom-form";
4+
import CustomForm from "@/components/custom-form.svelte";
55
66
import { objectSchema } from "./_demo-schemas";
77
</script>

apps/docs/src/content/docs/guides/_form-data.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
import type { Schema, Errors } from "@sjsf/form";
55
6-
import { CustomForm } from "@/components/custom-form";
6+
import CustomForm from "@/components/custom-form.svelte";
77
import type { ErrorObject } from "ajv";
88
99
const schema: Schema = {

apps/docs/src/content/docs/guides/_inputs-validation.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import { ON_CHANGE, ON_INPUT, AFTER_SUBMITTED } from "@sjsf/form";
33
4-
import { CustomForm } from "@/components/custom-form";
4+
import CustomForm from "@/components/custom-form.svelte";
55
66
import { objectSchema } from "./_demo-schemas";
77
</script>

apps/docs/src/content/docs/guides/_ui-schema.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import type { Schema, UiSchemaRoot } from "@sjsf/form";
33
4-
import { CustomForm } from "@/components/custom-form";
4+
import CustomForm from "@/components/custom-form.svelte";
55
66
const schema: Schema = {
77
title: "Schema title",

apps/docs/src/content/docs/guides/custom-form.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ sidebar:
66

77
import { Code } from '@astrojs/starlight/components';
88

9-
import customFormCode from '@/components/custom-form?raw';
9+
import customFormCode from '@/components/custom-form.svelte?raw';
1010

1111
Even with a simple setup, resulting code is very verbose.
1212
Therefore, after choosing a theme, validator and translation, it is convenient to create a custom component.
1313

14-
<Code code={customFormCode} lang="typescript" title="custom-form.ts" />
14+
<Code code={customFormCode} lang="svelte" title="custom-form.svelte" />

apps/docs/src/content/docs/themes/_basic-theme.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import { theme } from "@sjsf/form/basic-theme";
33
4-
import { CustomForm } from '@/components/custom-form'
4+
import CustomForm from "@/components/custom-form.svelte";
55
66
import { schema, uiSchema } from "./_demo-schema";
77

apps/docs/src/content/docs/themes/_daisyui-theme.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { theme } from "@sjsf/daisyui-theme";
33
44
import { astroTheme } from "@/theme.svelte";
5-
import { CustomForm } from "@/components/custom-form";
5+
import CustomForm from "@/components/custom-form.svelte";
66
77
import { schema, uiSchema } from "./_demo-schema";
88

0 commit comments

Comments
 (0)