@tamagui/form 1.3.0
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/dist/cjs/Form.js +78 -0
- package/dist/cjs/Form.js.map +7 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/esm/Form.js +55 -0
- package/dist/esm/Form.js.map +7 -0
- package/dist/esm/Form.mjs +55 -0
- package/dist/esm/Form.mjs.map +7 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/index.mjs.map +7 -0
- package/dist/jsx/Form.js +51 -0
- package/dist/jsx/Form.js.map +7 -0
- package/dist/jsx/Form.mjs +51 -0
- package/dist/jsx/Form.mjs.map +7 -0
- package/dist/jsx/index.js +2 -0
- package/dist/jsx/index.js.map +7 -0
- package/dist/jsx/index.mjs +2 -0
- package/dist/jsx/index.mjs.map +7 -0
- package/package.json +56 -0
- package/src/Form.tsx +92 -0
- package/src/index.ts +1 -0
- package/types/Form.d.ts +41 -0
- package/types/Form.d.ts.map +1 -0
- package/types/index.d.ts +2 -0
- package/types/index.d.ts.map +1 -0
package/dist/cjs/Form.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var Form_exports = {};
|
|
20
|
+
__export(Form_exports, {
|
|
21
|
+
Form: () => Form,
|
|
22
|
+
FormFrame: () => FormFrame,
|
|
23
|
+
FormProvider: () => FormProvider,
|
|
24
|
+
FormTrigger: () => FormTrigger,
|
|
25
|
+
useFormContext: () => useFormContext
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(Form_exports);
|
|
28
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
29
|
+
var import_core = require("@tamagui/core");
|
|
30
|
+
var import_create_context = require("@tamagui/create-context");
|
|
31
|
+
var import_react = require("react");
|
|
32
|
+
const FORM_NAME = "Form";
|
|
33
|
+
const FormFrame = (0, import_core.styled)(import_core.Stack, {
|
|
34
|
+
name: FORM_NAME,
|
|
35
|
+
tag: "form"
|
|
36
|
+
});
|
|
37
|
+
const [createFormContext] = (0, import_create_context.createContextScope)(FORM_NAME);
|
|
38
|
+
const [FormProvider, useFormContext] = createFormContext(FORM_NAME);
|
|
39
|
+
const TRIGGER_NAME = "FormTrigger";
|
|
40
|
+
const FormTriggerFrame = (0, import_core.styled)(import_core.Stack, {
|
|
41
|
+
name: TRIGGER_NAME
|
|
42
|
+
});
|
|
43
|
+
const FormTrigger = FormTriggerFrame.extractable(
|
|
44
|
+
(0, import_react.forwardRef)(
|
|
45
|
+
(props, forwardedRef) => {
|
|
46
|
+
const { __scopeForm, children, ...triggerProps } = props;
|
|
47
|
+
const context = useFormContext(TRIGGER_NAME, __scopeForm);
|
|
48
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
49
|
+
FormTriggerFrame,
|
|
50
|
+
{
|
|
51
|
+
tag: "button",
|
|
52
|
+
...triggerProps,
|
|
53
|
+
children: triggerProps.asChild ? (0, import_react.cloneElement)(children, { disabled: triggerProps.disabled }) : children,
|
|
54
|
+
ref: forwardedRef,
|
|
55
|
+
onPress: (0, import_core.composeEventHandlers)(props.onPress, context.onSubmit)
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
)
|
|
60
|
+
);
|
|
61
|
+
function FormComponent({
|
|
62
|
+
onSubmit,
|
|
63
|
+
...props
|
|
64
|
+
}) {
|
|
65
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormProvider, { scope: props.__scopeForm, onSubmit, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormFrame, { ...props, onSubmit: (e) => e.preventDefault() }) });
|
|
66
|
+
}
|
|
67
|
+
const Form = (0, import_core.withStaticProperties)(FormFrame.extractable(FormComponent), {
|
|
68
|
+
Trigger: FormTrigger
|
|
69
|
+
});
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {
|
|
72
|
+
Form,
|
|
73
|
+
FormFrame,
|
|
74
|
+
FormProvider,
|
|
75
|
+
FormTrigger,
|
|
76
|
+
useFormContext
|
|
77
|
+
});
|
|
78
|
+
//# sourceMappingURL=Form.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Form.tsx"],
|
|
4
|
+
"sourcesContent": ["import {\n GetProps,\n Stack,\n StackProps,\n TamaguiElement,\n composeEventHandlers,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { Scope, createContextScope } from '@tamagui/create-context'\nimport { PropsWithChildren, cloneElement, forwardRef } from 'react'\n\nconst FORM_NAME = 'Form'\n\nexport const FormFrame = styled(Stack, {\n name: FORM_NAME,\n tag: 'form',\n})\n\nexport type FormFrameProps = GetProps<typeof FormFrame> & {\n onSubmit: () => void\n}\n\n/* -------------------------------------------------------------------------------------------------\n * Context\n * -----------------------------------------------------------------------------------------------*/\n\ntype ScopedProps<P> = P & { __scopeForm?: Scope }\nconst [createFormContext] = createContextScope(FORM_NAME)\n\ntype FormContextValue = {\n onSubmit: () => unknown\n}\n\nexport const [FormProvider, useFormContext] =\n createFormContext<FormContextValue>(FORM_NAME)\n\nexport type FormProps = FormFrameProps\n\n/* -------------------------------------------------------------------------------------------------\n * FormTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'FormTrigger'\n\nconst FormTriggerFrame = styled(Stack, {\n name: TRIGGER_NAME,\n})\n\nexport interface FormTriggerProps extends StackProps {}\n\nexport const FormTrigger = FormTriggerFrame.extractable(\n forwardRef<TamaguiElement, FormTriggerProps>(\n (props: ScopedProps<FormTriggerProps>, forwardedRef) => {\n const { __scopeForm, children, ...triggerProps } = props\n const context = useFormContext(TRIGGER_NAME, __scopeForm)\n\n return (\n <FormTriggerFrame\n tag=\"button\"\n {...triggerProps}\n children={\n triggerProps.asChild\n ? cloneElement(children, { disabled: triggerProps.disabled })\n : children\n }\n ref={forwardedRef}\n onPress={composeEventHandlers(props.onPress as any, context.onSubmit)}\n />\n )\n }\n )\n)\n\n/* -------------------------------------------------------------------------------------------------\n * Form\n * -----------------------------------------------------------------------------------------------*/\n\nfunction FormComponent({\n onSubmit,\n ...props\n}: PropsWithChildren<ScopedProps<FormProps>>) {\n return (\n <FormProvider scope={props.__scopeForm} onSubmit={onSubmit}>\n <FormFrame {...props} onSubmit={((e: any) => e.preventDefault()) as any} />\n </FormProvider>\n )\n}\n\nexport const Form = withStaticProperties(FormFrame.extractable(FormComponent), {\n Trigger: FormTrigger,\n})\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0DQ;AA1DR,kBAQO;AACP,4BAA0C;AAC1C,mBAA4D;AAE5D,MAAM,YAAY;AAEX,MAAM,gBAAY,oBAAO,mBAAO;AAAA,EACrC,MAAM;AAAA,EACN,KAAK;AACP,CAAC;AAWD,MAAM,CAAC,iBAAiB,QAAI,0CAAmB,SAAS;AAMjD,MAAM,CAAC,cAAc,cAAc,IACxC,kBAAoC,SAAS;AAQ/C,MAAM,eAAe;AAErB,MAAM,uBAAmB,oBAAO,mBAAO;AAAA,EACrC,MAAM;AACR,CAAC;AAIM,MAAM,cAAc,iBAAiB;AAAA,MAC1C;AAAA,IACE,CAAC,OAAsC,iBAAiB;AACtD,YAAM,EAAE,aAAa,UAAU,GAAG,aAAa,IAAI;AACnD,YAAM,UAAU,eAAe,cAAc,WAAW;AAExD,aACE;AAAA,QAAC;AAAA;AAAA,UACC,KAAI;AAAA,UACH,GAAG;AAAA,UACJ,UACE,aAAa,cACT,2BAAa,UAAU,EAAE,UAAU,aAAa,SAAS,CAAC,IAC1D;AAAA,UAEN,KAAK;AAAA,UACL,aAAS,kCAAqB,MAAM,SAAgB,QAAQ,QAAQ;AAAA;AAAA,MACtE;AAAA,IAEJ;AAAA,EACF;AACF;AAMA,SAAS,cAAc;AAAA,EACrB;AAAA,EACA,GAAG;AACL,GAA8C;AAC5C,SACE,4CAAC,gBAAa,OAAO,MAAM,aAAa,UACtC,sDAAC,aAAW,GAAG,OAAO,UAAW,CAAC,MAAW,EAAE,eAAe,GAAW,GAC3E;AAEJ;AAEO,MAAM,WAAO,kCAAqB,UAAU,YAAY,aAAa,GAAG;AAAA,EAC7E,SAAS;AACX,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var src_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(src_exports);
|
|
18
|
+
__reExport(src_exports, require("./Form"), module.exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
package/dist/esm/Form.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
Stack,
|
|
4
|
+
composeEventHandlers,
|
|
5
|
+
styled,
|
|
6
|
+
withStaticProperties
|
|
7
|
+
} from "@tamagui/core";
|
|
8
|
+
import { createContextScope } from "@tamagui/create-context";
|
|
9
|
+
import { cloneElement, forwardRef } from "react";
|
|
10
|
+
const FORM_NAME = "Form";
|
|
11
|
+
const FormFrame = styled(Stack, {
|
|
12
|
+
name: FORM_NAME,
|
|
13
|
+
tag: "form"
|
|
14
|
+
});
|
|
15
|
+
const [createFormContext] = createContextScope(FORM_NAME);
|
|
16
|
+
const [FormProvider, useFormContext] = createFormContext(FORM_NAME);
|
|
17
|
+
const TRIGGER_NAME = "FormTrigger";
|
|
18
|
+
const FormTriggerFrame = styled(Stack, {
|
|
19
|
+
name: TRIGGER_NAME
|
|
20
|
+
});
|
|
21
|
+
const FormTrigger = FormTriggerFrame.extractable(
|
|
22
|
+
forwardRef(
|
|
23
|
+
(props, forwardedRef) => {
|
|
24
|
+
const { __scopeForm, children, ...triggerProps } = props;
|
|
25
|
+
const context = useFormContext(TRIGGER_NAME, __scopeForm);
|
|
26
|
+
return /* @__PURE__ */ jsx(
|
|
27
|
+
FormTriggerFrame,
|
|
28
|
+
{
|
|
29
|
+
tag: "button",
|
|
30
|
+
...triggerProps,
|
|
31
|
+
children: triggerProps.asChild ? cloneElement(children, { disabled: triggerProps.disabled }) : children,
|
|
32
|
+
ref: forwardedRef,
|
|
33
|
+
onPress: composeEventHandlers(props.onPress, context.onSubmit)
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
);
|
|
39
|
+
function FormComponent({
|
|
40
|
+
onSubmit,
|
|
41
|
+
...props
|
|
42
|
+
}) {
|
|
43
|
+
return /* @__PURE__ */ jsx(FormProvider, { scope: props.__scopeForm, onSubmit, children: /* @__PURE__ */ jsx(FormFrame, { ...props, onSubmit: (e) => e.preventDefault() }) });
|
|
44
|
+
}
|
|
45
|
+
const Form = withStaticProperties(FormFrame.extractable(FormComponent), {
|
|
46
|
+
Trigger: FormTrigger
|
|
47
|
+
});
|
|
48
|
+
export {
|
|
49
|
+
Form,
|
|
50
|
+
FormFrame,
|
|
51
|
+
FormProvider,
|
|
52
|
+
FormTrigger,
|
|
53
|
+
useFormContext
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=Form.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Form.tsx"],
|
|
4
|
+
"sourcesContent": ["import {\n GetProps,\n Stack,\n StackProps,\n TamaguiElement,\n composeEventHandlers,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { Scope, createContextScope } from '@tamagui/create-context'\nimport { PropsWithChildren, cloneElement, forwardRef } from 'react'\n\nconst FORM_NAME = 'Form'\n\nexport const FormFrame = styled(Stack, {\n name: FORM_NAME,\n tag: 'form',\n})\n\nexport type FormFrameProps = GetProps<typeof FormFrame> & {\n onSubmit: () => void\n}\n\n/* -------------------------------------------------------------------------------------------------\n * Context\n * -----------------------------------------------------------------------------------------------*/\n\ntype ScopedProps<P> = P & { __scopeForm?: Scope }\nconst [createFormContext] = createContextScope(FORM_NAME)\n\ntype FormContextValue = {\n onSubmit: () => unknown\n}\n\nexport const [FormProvider, useFormContext] =\n createFormContext<FormContextValue>(FORM_NAME)\n\nexport type FormProps = FormFrameProps\n\n/* -------------------------------------------------------------------------------------------------\n * FormTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'FormTrigger'\n\nconst FormTriggerFrame = styled(Stack, {\n name: TRIGGER_NAME,\n})\n\nexport interface FormTriggerProps extends StackProps {}\n\nexport const FormTrigger = FormTriggerFrame.extractable(\n forwardRef<TamaguiElement, FormTriggerProps>(\n (props: ScopedProps<FormTriggerProps>, forwardedRef) => {\n const { __scopeForm, children, ...triggerProps } = props\n const context = useFormContext(TRIGGER_NAME, __scopeForm)\n\n return (\n <FormTriggerFrame\n tag=\"button\"\n {...triggerProps}\n children={\n triggerProps.asChild\n ? cloneElement(children, { disabled: triggerProps.disabled })\n : children\n }\n ref={forwardedRef}\n onPress={composeEventHandlers(props.onPress as any, context.onSubmit)}\n />\n )\n }\n )\n)\n\n/* -------------------------------------------------------------------------------------------------\n * Form\n * -----------------------------------------------------------------------------------------------*/\n\nfunction FormComponent({\n onSubmit,\n ...props\n}: PropsWithChildren<ScopedProps<FormProps>>) {\n return (\n <FormProvider scope={props.__scopeForm} onSubmit={onSubmit}>\n <FormFrame {...props} onSubmit={((e: any) => e.preventDefault()) as any} />\n </FormProvider>\n )\n}\n\nexport const Form = withStaticProperties(FormFrame.extractable(FormComponent), {\n Trigger: FormTrigger,\n})\n"],
|
|
5
|
+
"mappings": "AA0DQ;AA1DR;AAAA,EAEE;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAgB,0BAA0B;AAC1C,SAA4B,cAAc,kBAAkB;AAE5D,MAAM,YAAY;AAEX,MAAM,YAAY,OAAO,OAAO;AAAA,EACrC,MAAM;AAAA,EACN,KAAK;AACP,CAAC;AAWD,MAAM,CAAC,iBAAiB,IAAI,mBAAmB,SAAS;AAMjD,MAAM,CAAC,cAAc,cAAc,IACxC,kBAAoC,SAAS;AAQ/C,MAAM,eAAe;AAErB,MAAM,mBAAmB,OAAO,OAAO;AAAA,EACrC,MAAM;AACR,CAAC;AAIM,MAAM,cAAc,iBAAiB;AAAA,EAC1C;AAAA,IACE,CAAC,OAAsC,iBAAiB;AACtD,YAAM,EAAE,aAAa,UAAU,GAAG,aAAa,IAAI;AACnD,YAAM,UAAU,eAAe,cAAc,WAAW;AAExD,aACE;AAAA,QAAC;AAAA;AAAA,UACC,KAAI;AAAA,UACH,GAAG;AAAA,UACJ,UACE,aAAa,UACT,aAAa,UAAU,EAAE,UAAU,aAAa,SAAS,CAAC,IAC1D;AAAA,UAEN,KAAK;AAAA,UACL,SAAS,qBAAqB,MAAM,SAAgB,QAAQ,QAAQ;AAAA;AAAA,MACtE;AAAA,IAEJ;AAAA,EACF;AACF;AAMA,SAAS,cAAc;AAAA,EACrB;AAAA,EACA,GAAG;AACL,GAA8C;AAC5C,SACE,oBAAC,gBAAa,OAAO,MAAM,aAAa,UACtC,8BAAC,aAAW,GAAG,OAAO,UAAW,CAAC,MAAW,EAAE,eAAe,GAAW,GAC3E;AAEJ;AAEO,MAAM,OAAO,qBAAqB,UAAU,YAAY,aAAa,GAAG;AAAA,EAC7E,SAAS;AACX,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
Stack,
|
|
4
|
+
composeEventHandlers,
|
|
5
|
+
styled,
|
|
6
|
+
withStaticProperties
|
|
7
|
+
} from "@tamagui/core";
|
|
8
|
+
import { createContextScope } from "@tamagui/create-context";
|
|
9
|
+
import { cloneElement, forwardRef } from "react";
|
|
10
|
+
const FORM_NAME = "Form";
|
|
11
|
+
const FormFrame = styled(Stack, {
|
|
12
|
+
name: FORM_NAME,
|
|
13
|
+
tag: "form"
|
|
14
|
+
});
|
|
15
|
+
const [createFormContext] = createContextScope(FORM_NAME);
|
|
16
|
+
const [FormProvider, useFormContext] = createFormContext(FORM_NAME);
|
|
17
|
+
const TRIGGER_NAME = "FormTrigger";
|
|
18
|
+
const FormTriggerFrame = styled(Stack, {
|
|
19
|
+
name: TRIGGER_NAME
|
|
20
|
+
});
|
|
21
|
+
const FormTrigger = FormTriggerFrame.extractable(
|
|
22
|
+
forwardRef(
|
|
23
|
+
(props, forwardedRef) => {
|
|
24
|
+
const { __scopeForm, children, ...triggerProps } = props;
|
|
25
|
+
const context = useFormContext(TRIGGER_NAME, __scopeForm);
|
|
26
|
+
return /* @__PURE__ */ jsx(
|
|
27
|
+
FormTriggerFrame,
|
|
28
|
+
{
|
|
29
|
+
tag: "button",
|
|
30
|
+
...triggerProps,
|
|
31
|
+
children: triggerProps.asChild ? cloneElement(children, { disabled: triggerProps.disabled }) : children,
|
|
32
|
+
ref: forwardedRef,
|
|
33
|
+
onPress: composeEventHandlers(props.onPress, context.onSubmit)
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
);
|
|
39
|
+
function FormComponent({
|
|
40
|
+
onSubmit,
|
|
41
|
+
...props
|
|
42
|
+
}) {
|
|
43
|
+
return /* @__PURE__ */ jsx(FormProvider, { scope: props.__scopeForm, onSubmit, children: /* @__PURE__ */ jsx(FormFrame, { ...props, onSubmit: (e) => e.preventDefault() }) });
|
|
44
|
+
}
|
|
45
|
+
const Form = withStaticProperties(FormFrame.extractable(FormComponent), {
|
|
46
|
+
Trigger: FormTrigger
|
|
47
|
+
});
|
|
48
|
+
export {
|
|
49
|
+
Form,
|
|
50
|
+
FormFrame,
|
|
51
|
+
FormProvider,
|
|
52
|
+
FormTrigger,
|
|
53
|
+
useFormContext
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=Form.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Form.tsx"],
|
|
4
|
+
"sourcesContent": ["import {\n GetProps,\n Stack,\n StackProps,\n TamaguiElement,\n composeEventHandlers,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { Scope, createContextScope } from '@tamagui/create-context'\nimport { PropsWithChildren, cloneElement, forwardRef } from 'react'\n\nconst FORM_NAME = 'Form'\n\nexport const FormFrame = styled(Stack, {\n name: FORM_NAME,\n tag: 'form',\n})\n\nexport type FormFrameProps = GetProps<typeof FormFrame> & {\n onSubmit: () => void\n}\n\n/* -------------------------------------------------------------------------------------------------\n * Context\n * -----------------------------------------------------------------------------------------------*/\n\ntype ScopedProps<P> = P & { __scopeForm?: Scope }\nconst [createFormContext] = createContextScope(FORM_NAME)\n\ntype FormContextValue = {\n onSubmit: () => unknown\n}\n\nexport const [FormProvider, useFormContext] =\n createFormContext<FormContextValue>(FORM_NAME)\n\nexport type FormProps = FormFrameProps\n\n/* -------------------------------------------------------------------------------------------------\n * FormTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'FormTrigger'\n\nconst FormTriggerFrame = styled(Stack, {\n name: TRIGGER_NAME,\n})\n\nexport interface FormTriggerProps extends StackProps {}\n\nexport const FormTrigger = FormTriggerFrame.extractable(\n forwardRef<TamaguiElement, FormTriggerProps>(\n (props: ScopedProps<FormTriggerProps>, forwardedRef) => {\n const { __scopeForm, children, ...triggerProps } = props\n const context = useFormContext(TRIGGER_NAME, __scopeForm)\n\n return (\n <FormTriggerFrame\n tag=\"button\"\n {...triggerProps}\n children={\n triggerProps.asChild\n ? cloneElement(children, { disabled: triggerProps.disabled })\n : children\n }\n ref={forwardedRef}\n onPress={composeEventHandlers(props.onPress as any, context.onSubmit)}\n />\n )\n }\n )\n)\n\n/* -------------------------------------------------------------------------------------------------\n * Form\n * -----------------------------------------------------------------------------------------------*/\n\nfunction FormComponent({\n onSubmit,\n ...props\n}: PropsWithChildren<ScopedProps<FormProps>>) {\n return (\n <FormProvider scope={props.__scopeForm} onSubmit={onSubmit}>\n <FormFrame {...props} onSubmit={((e: any) => e.preventDefault()) as any} />\n </FormProvider>\n )\n}\n\nexport const Form = withStaticProperties(FormFrame.extractable(FormComponent), {\n Trigger: FormTrigger,\n})\n"],
|
|
5
|
+
"mappings": "AA0DQ;AA1DR;AAAA,EAEE;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAgB,0BAA0B;AAC1C,SAA4B,cAAc,kBAAkB;AAE5D,MAAM,YAAY;AAEX,MAAM,YAAY,OAAO,OAAO;AAAA,EACrC,MAAM;AAAA,EACN,KAAK;AACP,CAAC;AAWD,MAAM,CAAC,iBAAiB,IAAI,mBAAmB,SAAS;AAMjD,MAAM,CAAC,cAAc,cAAc,IACxC,kBAAoC,SAAS;AAQ/C,MAAM,eAAe;AAErB,MAAM,mBAAmB,OAAO,OAAO;AAAA,EACrC,MAAM;AACR,CAAC;AAIM,MAAM,cAAc,iBAAiB;AAAA,EAC1C;AAAA,IACE,CAAC,OAAsC,iBAAiB;AACtD,YAAM,EAAE,aAAa,UAAU,GAAG,aAAa,IAAI;AACnD,YAAM,UAAU,eAAe,cAAc,WAAW;AAExD,aACE;AAAA,QAAC;AAAA;AAAA,UACC,KAAI;AAAA,UACH,GAAG;AAAA,UACJ,UACE,aAAa,UACT,aAAa,UAAU,EAAE,UAAU,aAAa,SAAS,CAAC,IAC1D;AAAA,UAEN,KAAK;AAAA,UACL,SAAS,qBAAqB,MAAM,SAAgB,QAAQ,QAAQ;AAAA;AAAA,MACtE;AAAA,IAEJ;AAAA,EACF;AACF;AAMA,SAAS,cAAc;AAAA,EACrB;AAAA,EACA,GAAG;AACL,GAA8C;AAC5C,SACE,oBAAC,gBAAa,OAAO,MAAM,aAAa,UACtC,8BAAC,aAAW,GAAG,OAAO,UAAW,CAAC,MAAW,EAAE,eAAe,GAAW,GAC3E;AAEJ;AAEO,MAAM,OAAO,qBAAqB,UAAU,YAAY,aAAa,GAAG;AAAA,EAC7E,SAAS;AACX,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/jsx/Form.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Stack,
|
|
3
|
+
composeEventHandlers,
|
|
4
|
+
styled,
|
|
5
|
+
withStaticProperties
|
|
6
|
+
} from "@tamagui/core";
|
|
7
|
+
import { createContextScope } from "@tamagui/create-context";
|
|
8
|
+
import { cloneElement, forwardRef } from "react";
|
|
9
|
+
const FORM_NAME = "Form";
|
|
10
|
+
const FormFrame = styled(Stack, {
|
|
11
|
+
name: FORM_NAME,
|
|
12
|
+
tag: "form"
|
|
13
|
+
});
|
|
14
|
+
const [createFormContext] = createContextScope(FORM_NAME);
|
|
15
|
+
const [FormProvider, useFormContext] = createFormContext(FORM_NAME);
|
|
16
|
+
const TRIGGER_NAME = "FormTrigger";
|
|
17
|
+
const FormTriggerFrame = styled(Stack, {
|
|
18
|
+
name: TRIGGER_NAME
|
|
19
|
+
});
|
|
20
|
+
const FormTrigger = FormTriggerFrame.extractable(
|
|
21
|
+
forwardRef(
|
|
22
|
+
(props, forwardedRef) => {
|
|
23
|
+
const { __scopeForm, children, ...triggerProps } = props;
|
|
24
|
+
const context = useFormContext(TRIGGER_NAME, __scopeForm);
|
|
25
|
+
return <FormTriggerFrame
|
|
26
|
+
tag="button"
|
|
27
|
+
{...triggerProps}
|
|
28
|
+
children={triggerProps.asChild ? cloneElement(children, { disabled: triggerProps.disabled }) : children}
|
|
29
|
+
ref={forwardedRef}
|
|
30
|
+
onPress={composeEventHandlers(props.onPress, context.onSubmit)}
|
|
31
|
+
/>;
|
|
32
|
+
}
|
|
33
|
+
)
|
|
34
|
+
);
|
|
35
|
+
function FormComponent({
|
|
36
|
+
onSubmit,
|
|
37
|
+
...props
|
|
38
|
+
}) {
|
|
39
|
+
return <FormProvider scope={props.__scopeForm} onSubmit={onSubmit}><FormFrame {...props} onSubmit={(e) => e.preventDefault()} /></FormProvider>;
|
|
40
|
+
}
|
|
41
|
+
const Form = withStaticProperties(FormFrame.extractable(FormComponent), {
|
|
42
|
+
Trigger: FormTrigger
|
|
43
|
+
});
|
|
44
|
+
export {
|
|
45
|
+
Form,
|
|
46
|
+
FormFrame,
|
|
47
|
+
FormProvider,
|
|
48
|
+
FormTrigger,
|
|
49
|
+
useFormContext
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=Form.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Form.tsx"],
|
|
4
|
+
"sourcesContent": ["import {\n GetProps,\n Stack,\n StackProps,\n TamaguiElement,\n composeEventHandlers,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { Scope, createContextScope } from '@tamagui/create-context'\nimport { PropsWithChildren, cloneElement, forwardRef } from 'react'\n\nconst FORM_NAME = 'Form'\n\nexport const FormFrame = styled(Stack, {\n name: FORM_NAME,\n tag: 'form',\n})\n\nexport type FormFrameProps = GetProps<typeof FormFrame> & {\n onSubmit: () => void\n}\n\n/* -------------------------------------------------------------------------------------------------\n * Context\n * -----------------------------------------------------------------------------------------------*/\n\ntype ScopedProps<P> = P & { __scopeForm?: Scope }\nconst [createFormContext] = createContextScope(FORM_NAME)\n\ntype FormContextValue = {\n onSubmit: () => unknown\n}\n\nexport const [FormProvider, useFormContext] =\n createFormContext<FormContextValue>(FORM_NAME)\n\nexport type FormProps = FormFrameProps\n\n/* -------------------------------------------------------------------------------------------------\n * FormTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'FormTrigger'\n\nconst FormTriggerFrame = styled(Stack, {\n name: TRIGGER_NAME,\n})\n\nexport interface FormTriggerProps extends StackProps {}\n\nexport const FormTrigger = FormTriggerFrame.extractable(\n forwardRef<TamaguiElement, FormTriggerProps>(\n (props: ScopedProps<FormTriggerProps>, forwardedRef) => {\n const { __scopeForm, children, ...triggerProps } = props\n const context = useFormContext(TRIGGER_NAME, __scopeForm)\n\n return (\n <FormTriggerFrame\n tag=\"button\"\n {...triggerProps}\n children={\n triggerProps.asChild\n ? cloneElement(children, { disabled: triggerProps.disabled })\n : children\n }\n ref={forwardedRef}\n onPress={composeEventHandlers(props.onPress as any, context.onSubmit)}\n />\n )\n }\n )\n)\n\n/* -------------------------------------------------------------------------------------------------\n * Form\n * -----------------------------------------------------------------------------------------------*/\n\nfunction FormComponent({\n onSubmit,\n ...props\n}: PropsWithChildren<ScopedProps<FormProps>>) {\n return (\n <FormProvider scope={props.__scopeForm} onSubmit={onSubmit}>\n <FormFrame {...props} onSubmit={((e: any) => e.preventDefault()) as any} />\n </FormProvider>\n )\n}\n\nexport const Form = withStaticProperties(FormFrame.extractable(FormComponent), {\n Trigger: FormTrigger,\n})\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EAEE;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAgB,0BAA0B;AAC1C,SAA4B,cAAc,kBAAkB;AAE5D,MAAM,YAAY;AAEX,MAAM,YAAY,OAAO,OAAO;AAAA,EACrC,MAAM;AAAA,EACN,KAAK;AACP,CAAC;AAWD,MAAM,CAAC,iBAAiB,IAAI,mBAAmB,SAAS;AAMjD,MAAM,CAAC,cAAc,cAAc,IACxC,kBAAoC,SAAS;AAQ/C,MAAM,eAAe;AAErB,MAAM,mBAAmB,OAAO,OAAO;AAAA,EACrC,MAAM;AACR,CAAC;AAIM,MAAM,cAAc,iBAAiB;AAAA,EAC1C;AAAA,IACE,CAAC,OAAsC,iBAAiB;AACtD,YAAM,EAAE,aAAa,UAAU,GAAG,aAAa,IAAI;AACnD,YAAM,UAAU,eAAe,cAAc,WAAW;AAExD,aACE,CAAC;AAAA,QACC,IAAI;AAAA,YACA;AAAA,QACJ,UACE,aAAa,UACT,aAAa,UAAU,EAAE,UAAU,aAAa,SAAS,CAAC,IAC1D;AAAA,QAEN,KAAK;AAAA,QACL,SAAS,qBAAqB,MAAM,SAAgB,QAAQ,QAAQ;AAAA,MACtE;AAAA,IAEJ;AAAA,EACF;AACF;AAMA,SAAS,cAAc;AAAA,EACrB;AAAA,EACA,GAAG;AACL,GAA8C;AAC5C,SACE,CAAC,aAAa,OAAO,MAAM,aAAa,UAAU,UAChD,CAAC,cAAc,OAAO,UAAW,CAAC,MAAW,EAAE,eAAe,GAAW,EAC3E,EAFC;AAIL;AAEO,MAAM,OAAO,qBAAqB,UAAU,YAAY,aAAa,GAAG;AAAA,EAC7E,SAAS;AACX,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Stack,
|
|
3
|
+
composeEventHandlers,
|
|
4
|
+
styled,
|
|
5
|
+
withStaticProperties
|
|
6
|
+
} from "@tamagui/core";
|
|
7
|
+
import { createContextScope } from "@tamagui/create-context";
|
|
8
|
+
import { cloneElement, forwardRef } from "react";
|
|
9
|
+
const FORM_NAME = "Form";
|
|
10
|
+
const FormFrame = styled(Stack, {
|
|
11
|
+
name: FORM_NAME,
|
|
12
|
+
tag: "form"
|
|
13
|
+
});
|
|
14
|
+
const [createFormContext] = createContextScope(FORM_NAME);
|
|
15
|
+
const [FormProvider, useFormContext] = createFormContext(FORM_NAME);
|
|
16
|
+
const TRIGGER_NAME = "FormTrigger";
|
|
17
|
+
const FormTriggerFrame = styled(Stack, {
|
|
18
|
+
name: TRIGGER_NAME
|
|
19
|
+
});
|
|
20
|
+
const FormTrigger = FormTriggerFrame.extractable(
|
|
21
|
+
forwardRef(
|
|
22
|
+
(props, forwardedRef) => {
|
|
23
|
+
const { __scopeForm, children, ...triggerProps } = props;
|
|
24
|
+
const context = useFormContext(TRIGGER_NAME, __scopeForm);
|
|
25
|
+
return <FormTriggerFrame
|
|
26
|
+
tag="button"
|
|
27
|
+
{...triggerProps}
|
|
28
|
+
children={triggerProps.asChild ? cloneElement(children, { disabled: triggerProps.disabled }) : children}
|
|
29
|
+
ref={forwardedRef}
|
|
30
|
+
onPress={composeEventHandlers(props.onPress, context.onSubmit)}
|
|
31
|
+
/>;
|
|
32
|
+
}
|
|
33
|
+
)
|
|
34
|
+
);
|
|
35
|
+
function FormComponent({
|
|
36
|
+
onSubmit,
|
|
37
|
+
...props
|
|
38
|
+
}) {
|
|
39
|
+
return <FormProvider scope={props.__scopeForm} onSubmit={onSubmit}><FormFrame {...props} onSubmit={(e) => e.preventDefault()} /></FormProvider>;
|
|
40
|
+
}
|
|
41
|
+
const Form = withStaticProperties(FormFrame.extractable(FormComponent), {
|
|
42
|
+
Trigger: FormTrigger
|
|
43
|
+
});
|
|
44
|
+
export {
|
|
45
|
+
Form,
|
|
46
|
+
FormFrame,
|
|
47
|
+
FormProvider,
|
|
48
|
+
FormTrigger,
|
|
49
|
+
useFormContext
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=Form.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Form.tsx"],
|
|
4
|
+
"sourcesContent": ["import {\n GetProps,\n Stack,\n StackProps,\n TamaguiElement,\n composeEventHandlers,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { Scope, createContextScope } from '@tamagui/create-context'\nimport { PropsWithChildren, cloneElement, forwardRef } from 'react'\n\nconst FORM_NAME = 'Form'\n\nexport const FormFrame = styled(Stack, {\n name: FORM_NAME,\n tag: 'form',\n})\n\nexport type FormFrameProps = GetProps<typeof FormFrame> & {\n onSubmit: () => void\n}\n\n/* -------------------------------------------------------------------------------------------------\n * Context\n * -----------------------------------------------------------------------------------------------*/\n\ntype ScopedProps<P> = P & { __scopeForm?: Scope }\nconst [createFormContext] = createContextScope(FORM_NAME)\n\ntype FormContextValue = {\n onSubmit: () => unknown\n}\n\nexport const [FormProvider, useFormContext] =\n createFormContext<FormContextValue>(FORM_NAME)\n\nexport type FormProps = FormFrameProps\n\n/* -------------------------------------------------------------------------------------------------\n * FormTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'FormTrigger'\n\nconst FormTriggerFrame = styled(Stack, {\n name: TRIGGER_NAME,\n})\n\nexport interface FormTriggerProps extends StackProps {}\n\nexport const FormTrigger = FormTriggerFrame.extractable(\n forwardRef<TamaguiElement, FormTriggerProps>(\n (props: ScopedProps<FormTriggerProps>, forwardedRef) => {\n const { __scopeForm, children, ...triggerProps } = props\n const context = useFormContext(TRIGGER_NAME, __scopeForm)\n\n return (\n <FormTriggerFrame\n tag=\"button\"\n {...triggerProps}\n children={\n triggerProps.asChild\n ? cloneElement(children, { disabled: triggerProps.disabled })\n : children\n }\n ref={forwardedRef}\n onPress={composeEventHandlers(props.onPress as any, context.onSubmit)}\n />\n )\n }\n )\n)\n\n/* -------------------------------------------------------------------------------------------------\n * Form\n * -----------------------------------------------------------------------------------------------*/\n\nfunction FormComponent({\n onSubmit,\n ...props\n}: PropsWithChildren<ScopedProps<FormProps>>) {\n return (\n <FormProvider scope={props.__scopeForm} onSubmit={onSubmit}>\n <FormFrame {...props} onSubmit={((e: any) => e.preventDefault()) as any} />\n </FormProvider>\n )\n}\n\nexport const Form = withStaticProperties(FormFrame.extractable(FormComponent), {\n Trigger: FormTrigger,\n})\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EAEE;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAgB,0BAA0B;AAC1C,SAA4B,cAAc,kBAAkB;AAE5D,MAAM,YAAY;AAEX,MAAM,YAAY,OAAO,OAAO;AAAA,EACrC,MAAM;AAAA,EACN,KAAK;AACP,CAAC;AAWD,MAAM,CAAC,iBAAiB,IAAI,mBAAmB,SAAS;AAMjD,MAAM,CAAC,cAAc,cAAc,IACxC,kBAAoC,SAAS;AAQ/C,MAAM,eAAe;AAErB,MAAM,mBAAmB,OAAO,OAAO;AAAA,EACrC,MAAM;AACR,CAAC;AAIM,MAAM,cAAc,iBAAiB;AAAA,EAC1C;AAAA,IACE,CAAC,OAAsC,iBAAiB;AACtD,YAAM,EAAE,aAAa,UAAU,GAAG,aAAa,IAAI;AACnD,YAAM,UAAU,eAAe,cAAc,WAAW;AAExD,aACE,CAAC;AAAA,QACC,IAAI;AAAA,YACA;AAAA,QACJ,UACE,aAAa,UACT,aAAa,UAAU,EAAE,UAAU,aAAa,SAAS,CAAC,IAC1D;AAAA,QAEN,KAAK;AAAA,QACL,SAAS,qBAAqB,MAAM,SAAgB,QAAQ,QAAQ;AAAA,MACtE;AAAA,IAEJ;AAAA,EACF;AACF;AAMA,SAAS,cAAc;AAAA,EACrB;AAAA,EACA,GAAG;AACL,GAA8C;AAC5C,SACE,CAAC,aAAa,OAAO,MAAM,aAAa,UAAU,UAChD,CAAC,cAAc,OAAO,UAAW,CAAC,MAAW,EAAE,eAAe,GAAW,EAC3E,EAFC;AAIL;AAEO,MAAM,OAAO,qBAAqB,UAAU,YAAY,aAAa,GAAG;AAAA,EAC7E,SAAS;AACX,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tamagui/form",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"sideEffects": [
|
|
5
|
+
"*.css"
|
|
6
|
+
],
|
|
7
|
+
"source": "src/index.ts",
|
|
8
|
+
"types": "./types/index.d.ts",
|
|
9
|
+
"main": "dist/cjs",
|
|
10
|
+
"module": "dist/esm",
|
|
11
|
+
"module:jsx": "dist/jsx",
|
|
12
|
+
"files": [
|
|
13
|
+
"src",
|
|
14
|
+
"types",
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tamagui-build",
|
|
19
|
+
"watch": "tamagui-build --watch",
|
|
20
|
+
"lint": "../../node_modules/.bin/rome check src",
|
|
21
|
+
"lint:fix": "../../node_modules/.bin/rome check --apply-suggested src",
|
|
22
|
+
"clean": "tamagui-build clean",
|
|
23
|
+
"clean:build": "tamagui-build clean:build"
|
|
24
|
+
},
|
|
25
|
+
"exports": {
|
|
26
|
+
"./package.json": "./package.json",
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./types/index.d.ts",
|
|
29
|
+
"import": "./dist/esm/index.js",
|
|
30
|
+
"require": "./dist/cjs/index.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@tamagui/compose-refs": "^1.3.0",
|
|
35
|
+
"@tamagui/core": "^1.3.0",
|
|
36
|
+
"@tamagui/create-context": "^1.3.0",
|
|
37
|
+
"@tamagui/focusable": "^1.3.0",
|
|
38
|
+
"@tamagui/get-button-sized": "^1.3.0",
|
|
39
|
+
"@tamagui/get-font-sized": "^1.3.0",
|
|
40
|
+
"@tamagui/text": "^1.3.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"react": "*",
|
|
44
|
+
"react-dom": "*",
|
|
45
|
+
"react-native": "*"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@tamagui/build": "^1.3.0",
|
|
49
|
+
"react": "^18.2.0",
|
|
50
|
+
"react-dom": "^18.2.0",
|
|
51
|
+
"react-native": "*"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
}
|
|
56
|
+
}
|
package/src/Form.tsx
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GetProps,
|
|
3
|
+
Stack,
|
|
4
|
+
StackProps,
|
|
5
|
+
TamaguiElement,
|
|
6
|
+
composeEventHandlers,
|
|
7
|
+
styled,
|
|
8
|
+
withStaticProperties,
|
|
9
|
+
} from '@tamagui/core'
|
|
10
|
+
import { Scope, createContextScope } from '@tamagui/create-context'
|
|
11
|
+
import { PropsWithChildren, cloneElement, forwardRef } from 'react'
|
|
12
|
+
|
|
13
|
+
const FORM_NAME = 'Form'
|
|
14
|
+
|
|
15
|
+
export const FormFrame = styled(Stack, {
|
|
16
|
+
name: FORM_NAME,
|
|
17
|
+
tag: 'form',
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
export type FormFrameProps = GetProps<typeof FormFrame> & {
|
|
21
|
+
onSubmit: () => void
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* -------------------------------------------------------------------------------------------------
|
|
25
|
+
* Context
|
|
26
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
27
|
+
|
|
28
|
+
type ScopedProps<P> = P & { __scopeForm?: Scope }
|
|
29
|
+
const [createFormContext] = createContextScope(FORM_NAME)
|
|
30
|
+
|
|
31
|
+
type FormContextValue = {
|
|
32
|
+
onSubmit: () => unknown
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const [FormProvider, useFormContext] =
|
|
36
|
+
createFormContext<FormContextValue>(FORM_NAME)
|
|
37
|
+
|
|
38
|
+
export type FormProps = FormFrameProps
|
|
39
|
+
|
|
40
|
+
/* -------------------------------------------------------------------------------------------------
|
|
41
|
+
* FormTrigger
|
|
42
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
43
|
+
|
|
44
|
+
const TRIGGER_NAME = 'FormTrigger'
|
|
45
|
+
|
|
46
|
+
const FormTriggerFrame = styled(Stack, {
|
|
47
|
+
name: TRIGGER_NAME,
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
export interface FormTriggerProps extends StackProps {}
|
|
51
|
+
|
|
52
|
+
export const FormTrigger = FormTriggerFrame.extractable(
|
|
53
|
+
forwardRef<TamaguiElement, FormTriggerProps>(
|
|
54
|
+
(props: ScopedProps<FormTriggerProps>, forwardedRef) => {
|
|
55
|
+
const { __scopeForm, children, ...triggerProps } = props
|
|
56
|
+
const context = useFormContext(TRIGGER_NAME, __scopeForm)
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<FormTriggerFrame
|
|
60
|
+
tag="button"
|
|
61
|
+
{...triggerProps}
|
|
62
|
+
children={
|
|
63
|
+
triggerProps.asChild
|
|
64
|
+
? cloneElement(children, { disabled: triggerProps.disabled })
|
|
65
|
+
: children
|
|
66
|
+
}
|
|
67
|
+
ref={forwardedRef}
|
|
68
|
+
onPress={composeEventHandlers(props.onPress as any, context.onSubmit)}
|
|
69
|
+
/>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
)
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
/* -------------------------------------------------------------------------------------------------
|
|
76
|
+
* Form
|
|
77
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
78
|
+
|
|
79
|
+
function FormComponent({
|
|
80
|
+
onSubmit,
|
|
81
|
+
...props
|
|
82
|
+
}: PropsWithChildren<ScopedProps<FormProps>>) {
|
|
83
|
+
return (
|
|
84
|
+
<FormProvider scope={props.__scopeForm} onSubmit={onSubmit}>
|
|
85
|
+
<FormFrame {...props} onSubmit={((e: any) => e.preventDefault()) as any} />
|
|
86
|
+
</FormProvider>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const Form = withStaticProperties(FormFrame.extractable(FormComponent), {
|
|
91
|
+
Trigger: FormTrigger,
|
|
92
|
+
})
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Form'
|
package/types/Form.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { GetProps, StackProps, TamaguiElement } from '@tamagui/core';
|
|
2
|
+
import { Scope } from '@tamagui/create-context';
|
|
3
|
+
import { PropsWithChildren } from 'react';
|
|
4
|
+
export declare const FormFrame: import("@tamagui/core").TamaguiComponent<(Omit<import("react-native").ViewProps, "display" | "children" | "onLayout" | keyof import("react-native").GestureResponderHandlers> & import("@tamagui/core").ExtendBaseStackProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase>> & import("@tamagui/core").PseudoProps<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase>>> & import("@tamagui/core").MediaProps<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase>> & import("@tamagui/core").PseudoProps<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase>>>> & import("@tamagui/core/types/reactNativeTypes").RNViewProps) | (Omit<import("react-native").ViewProps, "display" | "children" | "onLayout" | keyof import("react-native").GestureResponderHandlers> & import("@tamagui/core").ExtendBaseStackProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase>> & import("@tamagui/core/types/reactNativeTypes").RNViewProps & Omit<{}, string | number> & {
|
|
5
|
+
[x: string]: undefined;
|
|
6
|
+
} & import("@tamagui/core").MediaProps<Partial<Omit<import("react-native").ViewProps, "display" | "children" | "onLayout" | keyof import("react-native").GestureResponderHandlers> & import("@tamagui/core").ExtendBaseStackProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase>> & import("@tamagui/core/types/reactNativeTypes").RNViewProps & Omit<{}, string | number> & {
|
|
7
|
+
[x: string]: undefined;
|
|
8
|
+
}>> & import("@tamagui/core").PseudoProps<Partial<Omit<import("react-native").ViewProps, "display" | "children" | "onLayout" | keyof import("react-native").GestureResponderHandlers> & import("@tamagui/core").ExtendBaseStackProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase>> & import("@tamagui/core/types/reactNativeTypes").RNViewProps & Omit<{}, string | number> & {
|
|
9
|
+
[x: string]: undefined;
|
|
10
|
+
}>>), TamaguiElement, Omit<import("react-native").ViewProps, "display" | "children" | "onLayout" | keyof import("react-native").GestureResponderHandlers> & import("@tamagui/core").ExtendBaseStackProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase>> & import("@tamagui/core/types/reactNativeTypes").RNViewProps, {} | {
|
|
11
|
+
[x: string]: undefined;
|
|
12
|
+
}>;
|
|
13
|
+
export type FormFrameProps = GetProps<typeof FormFrame> & {
|
|
14
|
+
onSubmit: () => void;
|
|
15
|
+
};
|
|
16
|
+
type ScopedProps<P> = P & {
|
|
17
|
+
__scopeForm?: Scope;
|
|
18
|
+
};
|
|
19
|
+
type FormContextValue = {
|
|
20
|
+
onSubmit: () => unknown;
|
|
21
|
+
};
|
|
22
|
+
export declare const FormProvider: {
|
|
23
|
+
(props: FormContextValue & {
|
|
24
|
+
scope: Scope<FormContextValue>;
|
|
25
|
+
children: import("react").ReactNode;
|
|
26
|
+
}): JSX.Element;
|
|
27
|
+
displayName: string;
|
|
28
|
+
}, useFormContext: (consumerName: string, scope: Scope<FormContextValue | undefined>, options?: {
|
|
29
|
+
warn?: boolean | undefined;
|
|
30
|
+
fallback?: Partial<FormContextValue> | undefined;
|
|
31
|
+
} | undefined) => FormContextValue;
|
|
32
|
+
export type FormProps = FormFrameProps;
|
|
33
|
+
export interface FormTriggerProps extends StackProps {
|
|
34
|
+
}
|
|
35
|
+
export declare const FormTrigger: import("react").ForwardRefExoticComponent<FormTriggerProps & import("react").RefAttributes<TamaguiElement>>;
|
|
36
|
+
declare function FormComponent({ onSubmit, ...props }: PropsWithChildren<ScopedProps<FormProps>>): JSX.Element;
|
|
37
|
+
export declare const Form: typeof FormComponent & {
|
|
38
|
+
Trigger: import("react").ForwardRefExoticComponent<FormTriggerProps & import("react").RefAttributes<TamaguiElement>>;
|
|
39
|
+
};
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=Form.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../src/Form.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAER,UAAU,EACV,cAAc,EAIf,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,KAAK,EAAsB,MAAM,yBAAyB,CAAA;AACnE,OAAO,EAAE,iBAAiB,EAA4B,MAAM,OAAO,CAAA;AAInE,eAAO,MAAM,SAAS;;;;;;;;EAGpB,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,SAAS,CAAC,GAAG;IACxD,QAAQ,EAAE,MAAM,IAAI,CAAA;CACrB,CAAA;AAMD,KAAK,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG;IAAE,WAAW,CAAC,EAAE,KAAK,CAAA;CAAE,CAAA;AAGjD,KAAK,gBAAgB,GAAG;IACtB,QAAQ,EAAE,MAAM,OAAO,CAAA;CACxB,CAAA;AAED,eAAO,MAAO,YAAY;;;;;;GAAE,cAAc;;;kCACM,CAAA;AAEhD,MAAM,MAAM,SAAS,GAAG,cAAc,CAAA;AAYtC,MAAM,WAAW,gBAAiB,SAAQ,UAAU;CAAG;AAEvD,eAAO,MAAM,WAAW,6GAqBvB,CAAA;AAMD,iBAAS,aAAa,CAAC,EACrB,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,iBAAiB,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,eAM3C;AAED,eAAO,MAAM,IAAI;;CAEf,CAAA"}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA"}
|