-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from x0k/use-form
New `useForm` API
- Loading branch information
Showing
58 changed files
with
924 additions
and
613 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@sjsf/form": minor | ||
--- | ||
|
||
Implement `useForm` API, Add `FormContent` and `SubmitButton` components |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: Deploy to GitHub Pages | ||
on: | ||
release: | ||
types: [published] | ||
|
||
permissions: | ||
id-token: write | ||
contents: write | ||
pages: write | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
steps: | ||
- name: Checkout code repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup pnpm | ||
uses: pnpm/action-setup@v4 | ||
|
||
- name: Setup node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 22 | ||
cache: pnpm | ||
|
||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Cache turbo build setup | ||
uses: actions/cache@v4 | ||
with: | ||
path: .turbo | ||
key: ${{ runner.os }}-turbo-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-turbo- | ||
- name: Build | ||
run: pnpm run build --filter="./apps/*" | ||
|
||
- name: Merge apps build outputs | ||
run: mv apps/playground/dist apps/docs/dist/playground | ||
|
||
- name: Upload Pages Artifact | ||
uses: actions/upload-pages-artifact@v3 | ||
with: | ||
path: "apps/docs/dist/" | ||
|
||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Ajv, { type ErrorObject } from "ajv"; | ||
import { useForm, type UseFormOptions } from "@sjsf/form"; | ||
import { translation } from "@sjsf/form/translations/en"; | ||
import { theme } from "@sjsf/form/basic-theme"; | ||
import { | ||
AjvValidator, | ||
addFormComponents, | ||
DEFAULT_AJV_CONFIG, | ||
} from "@sjsf/ajv8-validator"; | ||
|
||
type Defaults = "widgets" | "components" | "validator" | "translation"; | ||
|
||
export type CustomOptions<T> = Omit<UseFormOptions<T, ErrorObject>, Defaults> & | ||
Partial<Pick<UseFormOptions<T, ErrorObject>, Defaults>>; | ||
|
||
export function useCustomForm<T>(options: CustomOptions<T>) { | ||
const validator = new AjvValidator( | ||
addFormComponents(new Ajv(DEFAULT_AJV_CONFIG)) | ||
); | ||
return useForm( | ||
Object.setPrototypeOf(options, { | ||
...theme, | ||
validator, | ||
translation, | ||
}) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
<script lang="ts"> | ||
import { Form } from "@sjsf/form"; | ||
import { useForm, SimpleForm } from "@sjsf/form"; | ||
import { translation } from "@sjsf/form/translations/en"; | ||
import { theme } from "@sjsf/form/basic-theme"; | ||
import { schema, uiSchema, initialData } from "./_schema"; | ||
import { schema, uiSchema, initialValue } from "./_schema"; | ||
import { validator } from "./_validator"; | ||
let value = $state(initialData); | ||
const form = useForm({ | ||
...theme, | ||
initialValue, | ||
schema, | ||
uiSchema, | ||
validator, | ||
translation, | ||
}); | ||
</script> | ||
|
||
<Form | ||
bind:value | ||
{...theme} | ||
{schema} | ||
{uiSchema} | ||
{validator} | ||
{translation} | ||
onSubmit={console.log} | ||
/> | ||
<SimpleForm {form} style="display: flex; flex-direction: column; gap: 1rem;" /> | ||
|
||
<pre>{JSON.stringify(value, null, 2)}</pre> | ||
<pre>{JSON.stringify(form.value, null, 2)}</pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
<script lang="ts"> | ||
import { Form } from "@sjsf/form"; | ||
import { SimpleForm, useForm } from "@sjsf/form"; | ||
import { translation } from "@sjsf/form/translations/en"; | ||
import { theme } from "@sjsf/daisyui-theme"; | ||
import { astroTheme } from "@/theme.svelte"; | ||
import { useAstro } from "@/astro.svelte"; | ||
import { schema, uiSchema, initialData } from "./_schema"; | ||
import { validator } from './_validator' | ||
import { schema, uiSchema, initialValue } from "./_schema"; | ||
import { validator } from "./_validator"; | ||
let value = $state(initialData); | ||
const astro = useAstro(); | ||
const astro = astroTheme(); | ||
const form = useForm({ | ||
...theme, | ||
initialValue, | ||
schema, | ||
uiSchema, | ||
validator, | ||
translation, | ||
}); | ||
</script> | ||
|
||
<Form | ||
<SimpleForm | ||
{form} | ||
style="background-color: transparent; margin-bottom: 1rem;" | ||
bind:value | ||
{...theme} | ||
{schema} | ||
{uiSchema} | ||
{validator} | ||
{translation} | ||
class="flex flex-col gap-4" | ||
data-theme={astro.darkOrLight} | ||
onSubmit={console.log} | ||
/> | ||
|
||
<pre>{JSON.stringify(value, null, 2)}</pre> | ||
<pre>{JSON.stringify(form.value, null, 2)}</pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,25 @@ | ||
<script lang="ts"> | ||
import { Form } from "@sjsf/form"; | ||
import { SimpleForm, useForm } from "@sjsf/form"; | ||
import { translation } from "@sjsf/form/translations/en"; | ||
import { theme } from "@sjsf/flowbite-theme"; | ||
import { astroTheme } from "@/theme.svelte"; | ||
import { useAstro } from "@/astro.svelte"; | ||
import { schema, uiSchema, initialData } from "./_schema"; | ||
import { schema, uiSchema, initialValue } from "./_schema"; | ||
import { validator } from "./_validator"; | ||
let value = $state(initialData); | ||
const astro = useAstro(); | ||
const astro = astroTheme(); | ||
const form = useForm({ | ||
...theme, | ||
initialValue, | ||
schema, | ||
uiSchema, | ||
validator, | ||
translation, | ||
}); | ||
</script> | ||
|
||
<Form | ||
class="flex flex-col gap-4 mb-4 {astro.darkOrLight}" | ||
bind:value | ||
{...theme} | ||
{schema} | ||
{uiSchema} | ||
{validator} | ||
{translation} | ||
onSubmit={console.log} | ||
/> | ||
<SimpleForm {form} class="flex flex-col gap-4 mb-4 {astro.darkOrLight}" /> | ||
|
||
<pre>{JSON.stringify(value, null, 2)}</pre> | ||
<pre>{JSON.stringify(form.value, null, 2)}</pre> |
Oops, something went wrong.