@swirls/sdk 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/form/form.d.ts +1 -38
- package/dist/form/form.js +0 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ import { defineConfig } from '@swirls/sdk/config'
|
|
|
19
19
|
The [`@swirls/sdk/form`](src/form/README.md) subpackage provides a form library for building, validating, and submitting forms.
|
|
20
20
|
|
|
21
21
|
```typescript
|
|
22
|
-
import { useSwirlsFormAdapter
|
|
22
|
+
import { useSwirlsFormAdapter } from '@swirls/sdk/form'
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
## Installation
|
package/dist/form/form.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import React from 'react';
|
|
3
1
|
import { z } from 'zod';
|
|
4
2
|
|
|
5
3
|
type Schema = z.ZodTypeAny;
|
|
@@ -60,40 +58,5 @@ declare function useSwirlsFormAdapter<K extends FormName>(name: K, defaultValues
|
|
|
60
58
|
schema: Schema;
|
|
61
59
|
defaultValues: Value<FormEntry<K>["schema"]>;
|
|
62
60
|
};
|
|
63
|
-
/**
|
|
64
|
-
* Render props component that provides a form adapter for integrating Swirls forms.
|
|
65
|
-
*
|
|
66
|
-
* The adapter is a bridge object that provides validation, submission, and schema information
|
|
67
|
-
* for a specific Swirls form. This component wraps `useSwirlsFormAdapter` and provides the
|
|
68
|
-
* adapter via a render prop, making it convenient for simpler form implementations.
|
|
69
|
-
*
|
|
70
|
-
* **Returns:** Renders the children function with the adapter as an argument.
|
|
71
|
-
*
|
|
72
|
-
* **Access:** The adapter is passed to the `children` render function. Use it within your
|
|
73
|
-
* form JSX to access validation, submission, schema, and defaultValues.
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```tsx
|
|
77
|
-
* <SwirlsForm schemaName="contact-form" defaultValues={{ name: '', email: '' }}>
|
|
78
|
-
* {(adapter) => (
|
|
79
|
-
* <form onSubmit={async (e) => {
|
|
80
|
-
* e.preventDefault()
|
|
81
|
-
* await adapter.submit(formData)
|
|
82
|
-
* }}>
|
|
83
|
-
* {/* ... *\/}
|
|
84
|
-
* </form>
|
|
85
|
-
* )}
|
|
86
|
-
* </SwirlsForm>
|
|
87
|
-
* ```
|
|
88
|
-
*
|
|
89
|
-
* @param name - The name of the form (autocompleted from registered forms)
|
|
90
|
-
* @param defaultValues - Typed default values matching the form schema
|
|
91
|
-
* @param children - Render function that receives the adapter object
|
|
92
|
-
*/
|
|
93
|
-
declare function SwirlsForm<K extends FormName>({ name, defaultValues, children, }: {
|
|
94
|
-
name: K;
|
|
95
|
-
defaultValues: Value<FormEntry<K>['schema']>;
|
|
96
|
-
children: (adapter: ReturnType<typeof useSwirlsFormAdapter<K>>) => React.ReactNode;
|
|
97
|
-
}): react_jsx_runtime.JSX.Element;
|
|
98
61
|
|
|
99
|
-
export { type FormRegistry,
|
|
62
|
+
export { type FormRegistry, registerForm, useSwirlsFormAdapter };
|
package/dist/form/form.js
CHANGED
|
@@ -37,7 +37,6 @@ async function parseResponse(response) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// src/form/form.tsx
|
|
40
|
-
import { Fragment, jsx } from "react/jsx-runtime";
|
|
41
40
|
var formRegistry = {};
|
|
42
41
|
function registerForm(name, form) {
|
|
43
42
|
formRegistry[name] = form;
|
|
@@ -60,16 +59,7 @@ function useSwirlsFormAdapter(name, defaultValues) {
|
|
|
60
59
|
defaultValues
|
|
61
60
|
};
|
|
62
61
|
}
|
|
63
|
-
function SwirlsForm({
|
|
64
|
-
name,
|
|
65
|
-
defaultValues,
|
|
66
|
-
children
|
|
67
|
-
}) {
|
|
68
|
-
const adapter = useSwirlsFormAdapter(name, defaultValues);
|
|
69
|
-
return /* @__PURE__ */ jsx(Fragment, { children: children(adapter) });
|
|
70
|
-
}
|
|
71
62
|
export {
|
|
72
|
-
SwirlsForm,
|
|
73
63
|
registerForm,
|
|
74
64
|
useSwirlsFormAdapter
|
|
75
65
|
};
|