@vx-oss/heroui-v2-form 2.1.28-alpha.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/LICENSE ADDED
@@ -0,0 +1,32 @@
1
+ SPDX-License-Identifier: MIT
2
+
3
+ The MIT License (MIT)
4
+
5
+ Parameters
6
+
7
+ Creator / Maintainer : Vezham Technologies Private Limited
8
+ Original Author : NextUI Inc
9
+ Licensor : Vezham Technologies Private Limited
10
+
11
+ Copyright © 2025, Vezham Technologies Private Limited. All rights reserved.
12
+ Copyright (c) 2020, NextUI Inc.
13
+
14
+ ---
15
+
16
+ Permission is hereby granted, free of charge, to any person obtaining a copy
17
+ of this software and associated documentation files (the "Software"), to deal
18
+ in the Software without restriction, including without limitation the rights
19
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
+ copies of the Software, and to permit persons to whom the Software is
21
+ furnished to do so, subject to the following conditions:
22
+
23
+ The above copyright notice and this permission notice shall be included in all
24
+ copies or substantial portions of the Software.
25
+
26
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # @vx-oss/heroui-v2-form
2
+
3
+ A form is a group of inputs that allows users submit data to a server and supports field validation errors.
4
+
5
+ Please refer to the [documentation](https://heroui.com/docs/components/form) for more information.
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ yarn add @vx-oss/heroui-v2-form
11
+ # or
12
+ npm i @vx-oss/heroui-v2-form
13
+ ```
14
+
15
+ ## Contribution
16
+
17
+ Yes please! See the
18
+ [contributing guidelines](https://github.com/heroui-inc/heroui/blob/master/CONTRIBUTING.md)
19
+ for details.
20
+
21
+ ## License
22
+
23
+ This project is licensed under the terms of the
24
+ [MIT license](https://github.com/heroui-inc/heroui/blob/master/LICENSE).
@@ -0,0 +1,22 @@
1
+ import { FormProps as FormProps$1 } from '@react-types/form';
2
+ import { DOMProps, ContextValue } from './utils.mjs';
3
+ import React__default from 'react';
4
+ import '@react-types/shared';
5
+
6
+ interface FormProps extends FormProps$1, DOMProps {
7
+ /**
8
+ * Whether to use native HTML form validation to prevent form submission
9
+ * when a field value is missing or invalid, or mark fields as required
10
+ * or invalid via ARIA.
11
+ * @default 'native'
12
+ */
13
+ validationBehavior?: "aria" | "native";
14
+ }
15
+ declare const FormContext: React__default.Context<ContextValue<FormProps, HTMLFormElement>>;
16
+ /**
17
+ * A form is a group of inputs that allows users to submit data to a server,
18
+ * with support for providing field validation errors.
19
+ */
20
+ declare const Form: React__default.ForwardRefExoticComponent<FormProps & React__default.RefAttributes<HTMLFormElement>>;
21
+
22
+ export { Form, FormContext, type FormProps };
@@ -0,0 +1,22 @@
1
+ import { FormProps as FormProps$1 } from '@react-types/form';
2
+ import { DOMProps, ContextValue } from './utils.js';
3
+ import React__default from 'react';
4
+ import '@react-types/shared';
5
+
6
+ interface FormProps extends FormProps$1, DOMProps {
7
+ /**
8
+ * Whether to use native HTML form validation to prevent form submission
9
+ * when a field value is missing or invalid, or mark fields as required
10
+ * or invalid via ARIA.
11
+ * @default 'native'
12
+ */
13
+ validationBehavior?: "aria" | "native";
14
+ }
15
+ declare const FormContext: React__default.Context<ContextValue<FormProps, HTMLFormElement>>;
16
+ /**
17
+ * A form is a group of inputs that allows users to submit data to a server,
18
+ * with support for providing field validation errors.
19
+ */
20
+ declare const Form: React__default.ForwardRefExoticComponent<FormProps & React__default.RefAttributes<HTMLFormElement>>;
21
+
22
+ export { Form, FormContext, type FormProps };
@@ -0,0 +1,130 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/base-form.tsx
22
+ var base_form_exports = {};
23
+ __export(base_form_exports, {
24
+ Form: () => Form,
25
+ FormContext: () => FormContext
26
+ });
27
+ module.exports = __toCommonJS(base_form_exports);
28
+ var import_form = require("@react-stately/form");
29
+ var import_react2 = require("react");
30
+ var import_heroui_v2_theme = require("@vx-oss/heroui-v2-theme");
31
+
32
+ // src/utils.ts
33
+ var import_react = require("react");
34
+ var import_heroui_v2_shared_utils = require("@vx-oss/heroui-v2-shared-utils");
35
+ var DEFAULT_SLOT = Symbol("default");
36
+ function useObjectRef(ref) {
37
+ const objRef = (0, import_react.useRef)(null);
38
+ const cleanupRef = (0, import_react.useRef)(void 0);
39
+ const refEffect = (0, import_react.useCallback)(
40
+ (instance) => {
41
+ if (typeof ref === "function") {
42
+ const refCallback = ref;
43
+ const refCleanup = refCallback(instance);
44
+ return () => {
45
+ if (typeof refCleanup === "function") {
46
+ refCleanup();
47
+ } else {
48
+ refCallback(null);
49
+ }
50
+ };
51
+ } else if (ref) {
52
+ ref.current = instance;
53
+ return () => {
54
+ ref.current = null;
55
+ };
56
+ }
57
+ },
58
+ [ref]
59
+ );
60
+ return (0, import_react.useMemo)(
61
+ () => ({
62
+ get current() {
63
+ return objRef.current;
64
+ },
65
+ set current(value) {
66
+ objRef.current = value;
67
+ if (cleanupRef.current) {
68
+ cleanupRef.current();
69
+ cleanupRef.current = void 0;
70
+ }
71
+ if (value != null) {
72
+ cleanupRef.current = refEffect(value);
73
+ }
74
+ }
75
+ }),
76
+ [refEffect]
77
+ );
78
+ }
79
+ function useSlottedContext(context, slot) {
80
+ let ctx = (0, import_react.useContext)(context);
81
+ if (slot === null) {
82
+ return null;
83
+ }
84
+ if (ctx && typeof ctx === "object" && "slots" in ctx && ctx.slots) {
85
+ let availableSlots = new Intl.ListFormat().format(Object.keys(ctx.slots).map((p) => `"${p}"`));
86
+ if (!slot && !ctx.slots[DEFAULT_SLOT]) {
87
+ throw new Error(`A slot prop is required. Valid slot names are ${availableSlots}.`);
88
+ }
89
+ let slotKey = slot || DEFAULT_SLOT;
90
+ if (!ctx.slots[slotKey]) {
91
+ throw new Error(`Invalid slot "${slot}". Valid slot names are ${availableSlots}.`);
92
+ }
93
+ return ctx.slots[slotKey];
94
+ }
95
+ return ctx;
96
+ }
97
+ function useContextProps(props, ref, context) {
98
+ let ctx = useSlottedContext(context, props.slot) || {};
99
+ let { ref: contextRef, ...contextProps } = ctx;
100
+ let mergedRef = useObjectRef((0, import_react.useMemo)(() => (0, import_heroui_v2_shared_utils.mergeRefs)(ref, contextRef), [ref, contextRef]));
101
+ let mergedProps = (0, import_heroui_v2_shared_utils.mergeProps)(contextProps, props);
102
+ if ("style" in contextProps && contextProps.style && "style" in props && props.style) {
103
+ if (typeof contextProps.style === "function" || typeof props.style === "function") {
104
+ mergedProps.style = (renderProps) => {
105
+ let contextStyle = typeof contextProps.style === "function" ? contextProps.style(renderProps) : contextProps.style;
106
+ let defaultStyle = { ...renderProps.defaultStyle, ...contextStyle };
107
+ let style = typeof props.style === "function" ? props.style({ ...renderProps, defaultStyle }) : props.style;
108
+ return { ...defaultStyle, ...style };
109
+ };
110
+ } else {
111
+ mergedProps.style = { ...contextProps.style, ...props.style };
112
+ }
113
+ }
114
+ return [mergedProps, mergedRef];
115
+ }
116
+
117
+ // src/base-form.tsx
118
+ var import_jsx_runtime = require("react/jsx-runtime");
119
+ var FormContext = (0, import_react2.createContext)(null);
120
+ var Form = (0, import_react2.forwardRef)(function Form2(props, ref) {
121
+ [props, ref] = useContextProps(props, ref, FormContext);
122
+ let { validationErrors, validationBehavior = "native", children, className, ...domProps } = props;
123
+ const styles = (0, import_react2.useMemo)(() => (0, import_heroui_v2_theme.form)({ className }), [className]);
124
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("form", { noValidate: validationBehavior !== "native", ...domProps, ref, className: styles, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormContext.Provider, { value: { ...props, validationBehavior }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_form.FormValidationContext.Provider, { value: validationErrors != null ? validationErrors : {}, children }) }) });
125
+ });
126
+ // Annotate the CommonJS export names for ESM import in node:
127
+ 0 && (module.exports = {
128
+ Form,
129
+ FormContext
130
+ });
@@ -0,0 +1,10 @@
1
+ "use client";
2
+ import {
3
+ Form,
4
+ FormContext
5
+ } from "./chunk-TTDMASG4.mjs";
6
+ import "./chunk-G2FFP3K6.mjs";
7
+ export {
8
+ Form,
9
+ FormContext
10
+ };
@@ -0,0 +1,19 @@
1
+ "use client";
2
+ import {
3
+ Form
4
+ } from "./chunk-TTDMASG4.mjs";
5
+
6
+ // src/form.tsx
7
+ import { useProviderContext } from "@vx-oss/heroui-v2-system";
8
+ import { forwardRef } from "react";
9
+ import { jsx } from "react/jsx-runtime";
10
+ var Form2 = forwardRef(function Form3(props, ref) {
11
+ var _a, _b;
12
+ const globalContext = useProviderContext();
13
+ const validationBehavior = (_b = (_a = props.validationBehavior) != null ? _a : globalContext == null ? void 0 : globalContext.validationBehavior) != null ? _b : "native";
14
+ return /* @__PURE__ */ jsx(Form, { ...props, ref, validationBehavior });
15
+ });
16
+
17
+ export {
18
+ Form2 as Form
19
+ };
@@ -0,0 +1,93 @@
1
+ "use client";
2
+
3
+ // src/utils.ts
4
+ import { useContext, useMemo, useRef, useCallback } from "react";
5
+ import { mergeProps, mergeRefs } from "@vx-oss/heroui-v2-shared-utils";
6
+ var DEFAULT_SLOT = Symbol("default");
7
+ function useObjectRef(ref) {
8
+ const objRef = useRef(null);
9
+ const cleanupRef = useRef(void 0);
10
+ const refEffect = useCallback(
11
+ (instance) => {
12
+ if (typeof ref === "function") {
13
+ const refCallback = ref;
14
+ const refCleanup = refCallback(instance);
15
+ return () => {
16
+ if (typeof refCleanup === "function") {
17
+ refCleanup();
18
+ } else {
19
+ refCallback(null);
20
+ }
21
+ };
22
+ } else if (ref) {
23
+ ref.current = instance;
24
+ return () => {
25
+ ref.current = null;
26
+ };
27
+ }
28
+ },
29
+ [ref]
30
+ );
31
+ return useMemo(
32
+ () => ({
33
+ get current() {
34
+ return objRef.current;
35
+ },
36
+ set current(value) {
37
+ objRef.current = value;
38
+ if (cleanupRef.current) {
39
+ cleanupRef.current();
40
+ cleanupRef.current = void 0;
41
+ }
42
+ if (value != null) {
43
+ cleanupRef.current = refEffect(value);
44
+ }
45
+ }
46
+ }),
47
+ [refEffect]
48
+ );
49
+ }
50
+ function useSlottedContext(context, slot) {
51
+ let ctx = useContext(context);
52
+ if (slot === null) {
53
+ return null;
54
+ }
55
+ if (ctx && typeof ctx === "object" && "slots" in ctx && ctx.slots) {
56
+ let availableSlots = new Intl.ListFormat().format(Object.keys(ctx.slots).map((p) => `"${p}"`));
57
+ if (!slot && !ctx.slots[DEFAULT_SLOT]) {
58
+ throw new Error(`A slot prop is required. Valid slot names are ${availableSlots}.`);
59
+ }
60
+ let slotKey = slot || DEFAULT_SLOT;
61
+ if (!ctx.slots[slotKey]) {
62
+ throw new Error(`Invalid slot "${slot}". Valid slot names are ${availableSlots}.`);
63
+ }
64
+ return ctx.slots[slotKey];
65
+ }
66
+ return ctx;
67
+ }
68
+ function useContextProps(props, ref, context) {
69
+ let ctx = useSlottedContext(context, props.slot) || {};
70
+ let { ref: contextRef, ...contextProps } = ctx;
71
+ let mergedRef = useObjectRef(useMemo(() => mergeRefs(ref, contextRef), [ref, contextRef]));
72
+ let mergedProps = mergeProps(contextProps, props);
73
+ if ("style" in contextProps && contextProps.style && "style" in props && props.style) {
74
+ if (typeof contextProps.style === "function" || typeof props.style === "function") {
75
+ mergedProps.style = (renderProps) => {
76
+ let contextStyle = typeof contextProps.style === "function" ? contextProps.style(renderProps) : contextProps.style;
77
+ let defaultStyle = { ...renderProps.defaultStyle, ...contextStyle };
78
+ let style = typeof props.style === "function" ? props.style({ ...renderProps, defaultStyle }) : props.style;
79
+ return { ...defaultStyle, ...style };
80
+ };
81
+ } else {
82
+ mergedProps.style = { ...contextProps.style, ...props.style };
83
+ }
84
+ }
85
+ return [mergedProps, mergedRef];
86
+ }
87
+
88
+ export {
89
+ DEFAULT_SLOT,
90
+ useObjectRef,
91
+ useSlottedContext,
92
+ useContextProps
93
+ };
@@ -0,0 +1,22 @@
1
+ "use client";
2
+ import {
3
+ useContextProps
4
+ } from "./chunk-G2FFP3K6.mjs";
5
+
6
+ // src/base-form.tsx
7
+ import { FormValidationContext } from "@react-stately/form";
8
+ import { createContext, forwardRef, useMemo } from "react";
9
+ import { form } from "@vx-oss/heroui-v2-theme";
10
+ import { jsx } from "react/jsx-runtime";
11
+ var FormContext = createContext(null);
12
+ var Form = forwardRef(function Form2(props, ref) {
13
+ [props, ref] = useContextProps(props, ref, FormContext);
14
+ let { validationErrors, validationBehavior = "native", children, className, ...domProps } = props;
15
+ const styles = useMemo(() => form({ className }), [className]);
16
+ return /* @__PURE__ */ jsx("form", { noValidate: validationBehavior !== "native", ...domProps, ref, className: styles, children: /* @__PURE__ */ jsx(FormContext.Provider, { value: { ...props, validationBehavior }, children: /* @__PURE__ */ jsx(FormValidationContext.Provider, { value: validationErrors != null ? validationErrors : {}, children }) }) });
17
+ });
18
+
19
+ export {
20
+ FormContext,
21
+ Form
22
+ };
@@ -0,0 +1,9 @@
1
+ import { FormProps } from './base-form.mjs';
2
+ import './utils.mjs';
3
+ import * as React from 'react';
4
+ import '@react-types/form';
5
+ import '@react-types/shared';
6
+
7
+ declare const Form: React.ForwardRefExoticComponent<FormProps & React.RefAttributes<HTMLFormElement>>;
8
+
9
+ export { Form };
package/dist/form.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { FormProps } from './base-form.js';
2
+ import './utils.js';
3
+ import * as React from 'react';
4
+ import '@react-types/form';
5
+ import '@react-types/shared';
6
+
7
+ declare const Form: React.ForwardRefExoticComponent<FormProps & React.RefAttributes<HTMLFormElement>>;
8
+
9
+ export { Form };
package/dist/form.js ADDED
@@ -0,0 +1,141 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/form.tsx
22
+ var form_exports = {};
23
+ __export(form_exports, {
24
+ Form: () => Form3
25
+ });
26
+ module.exports = __toCommonJS(form_exports);
27
+ var import_heroui_v2_system = require("@vx-oss/heroui-v2-system");
28
+ var import_react3 = require("react");
29
+
30
+ // src/base-form.tsx
31
+ var import_form = require("@react-stately/form");
32
+ var import_react2 = require("react");
33
+ var import_heroui_v2_theme = require("@vx-oss/heroui-v2-theme");
34
+
35
+ // src/utils.ts
36
+ var import_react = require("react");
37
+ var import_heroui_v2_shared_utils = require("@vx-oss/heroui-v2-shared-utils");
38
+ var DEFAULT_SLOT = Symbol("default");
39
+ function useObjectRef(ref) {
40
+ const objRef = (0, import_react.useRef)(null);
41
+ const cleanupRef = (0, import_react.useRef)(void 0);
42
+ const refEffect = (0, import_react.useCallback)(
43
+ (instance) => {
44
+ if (typeof ref === "function") {
45
+ const refCallback = ref;
46
+ const refCleanup = refCallback(instance);
47
+ return () => {
48
+ if (typeof refCleanup === "function") {
49
+ refCleanup();
50
+ } else {
51
+ refCallback(null);
52
+ }
53
+ };
54
+ } else if (ref) {
55
+ ref.current = instance;
56
+ return () => {
57
+ ref.current = null;
58
+ };
59
+ }
60
+ },
61
+ [ref]
62
+ );
63
+ return (0, import_react.useMemo)(
64
+ () => ({
65
+ get current() {
66
+ return objRef.current;
67
+ },
68
+ set current(value) {
69
+ objRef.current = value;
70
+ if (cleanupRef.current) {
71
+ cleanupRef.current();
72
+ cleanupRef.current = void 0;
73
+ }
74
+ if (value != null) {
75
+ cleanupRef.current = refEffect(value);
76
+ }
77
+ }
78
+ }),
79
+ [refEffect]
80
+ );
81
+ }
82
+ function useSlottedContext(context, slot) {
83
+ let ctx = (0, import_react.useContext)(context);
84
+ if (slot === null) {
85
+ return null;
86
+ }
87
+ if (ctx && typeof ctx === "object" && "slots" in ctx && ctx.slots) {
88
+ let availableSlots = new Intl.ListFormat().format(Object.keys(ctx.slots).map((p) => `"${p}"`));
89
+ if (!slot && !ctx.slots[DEFAULT_SLOT]) {
90
+ throw new Error(`A slot prop is required. Valid slot names are ${availableSlots}.`);
91
+ }
92
+ let slotKey = slot || DEFAULT_SLOT;
93
+ if (!ctx.slots[slotKey]) {
94
+ throw new Error(`Invalid slot "${slot}". Valid slot names are ${availableSlots}.`);
95
+ }
96
+ return ctx.slots[slotKey];
97
+ }
98
+ return ctx;
99
+ }
100
+ function useContextProps(props, ref, context) {
101
+ let ctx = useSlottedContext(context, props.slot) || {};
102
+ let { ref: contextRef, ...contextProps } = ctx;
103
+ let mergedRef = useObjectRef((0, import_react.useMemo)(() => (0, import_heroui_v2_shared_utils.mergeRefs)(ref, contextRef), [ref, contextRef]));
104
+ let mergedProps = (0, import_heroui_v2_shared_utils.mergeProps)(contextProps, props);
105
+ if ("style" in contextProps && contextProps.style && "style" in props && props.style) {
106
+ if (typeof contextProps.style === "function" || typeof props.style === "function") {
107
+ mergedProps.style = (renderProps) => {
108
+ let contextStyle = typeof contextProps.style === "function" ? contextProps.style(renderProps) : contextProps.style;
109
+ let defaultStyle = { ...renderProps.defaultStyle, ...contextStyle };
110
+ let style = typeof props.style === "function" ? props.style({ ...renderProps, defaultStyle }) : props.style;
111
+ return { ...defaultStyle, ...style };
112
+ };
113
+ } else {
114
+ mergedProps.style = { ...contextProps.style, ...props.style };
115
+ }
116
+ }
117
+ return [mergedProps, mergedRef];
118
+ }
119
+
120
+ // src/base-form.tsx
121
+ var import_jsx_runtime = require("react/jsx-runtime");
122
+ var FormContext = (0, import_react2.createContext)(null);
123
+ var Form = (0, import_react2.forwardRef)(function Form2(props, ref) {
124
+ [props, ref] = useContextProps(props, ref, FormContext);
125
+ let { validationErrors, validationBehavior = "native", children, className, ...domProps } = props;
126
+ const styles = (0, import_react2.useMemo)(() => (0, import_heroui_v2_theme.form)({ className }), [className]);
127
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("form", { noValidate: validationBehavior !== "native", ...domProps, ref, className: styles, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormContext.Provider, { value: { ...props, validationBehavior }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_form.FormValidationContext.Provider, { value: validationErrors != null ? validationErrors : {}, children }) }) });
128
+ });
129
+
130
+ // src/form.tsx
131
+ var import_jsx_runtime2 = require("react/jsx-runtime");
132
+ var Form3 = (0, import_react3.forwardRef)(function Form4(props, ref) {
133
+ var _a, _b;
134
+ const globalContext = (0, import_heroui_v2_system.useProviderContext)();
135
+ const validationBehavior = (_b = (_a = props.validationBehavior) != null ? _a : globalContext == null ? void 0 : globalContext.validationBehavior) != null ? _b : "native";
136
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Form, { ...props, ref, validationBehavior });
137
+ });
138
+ // Annotate the CommonJS export names for ESM import in node:
139
+ 0 && (module.exports = {
140
+ Form
141
+ });
package/dist/form.mjs ADDED
@@ -0,0 +1,9 @@
1
+ "use client";
2
+ import {
3
+ Form
4
+ } from "./chunk-6ZVVJ3SO.mjs";
5
+ import "./chunk-TTDMASG4.mjs";
6
+ import "./chunk-G2FFP3K6.mjs";
7
+ export {
8
+ Form
9
+ };
@@ -0,0 +1,6 @@
1
+ export { FormContext, FormProps } from './base-form.mjs';
2
+ export { useSlottedContext } from './utils.mjs';
3
+ export { Form } from './form.mjs';
4
+ import '@react-types/form';
5
+ import 'react';
6
+ import '@react-types/shared';
@@ -0,0 +1,6 @@
1
+ export { FormContext, FormProps } from './base-form.js';
2
+ export { useSlottedContext } from './utils.js';
3
+ export { Form } from './form.js';
4
+ import '@react-types/form';
5
+ import 'react';
6
+ import '@react-types/shared';
package/dist/index.js ADDED
@@ -0,0 +1,143 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ Form: () => Form3,
25
+ FormContext: () => FormContext,
26
+ useSlottedContext: () => useSlottedContext
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+
30
+ // src/utils.ts
31
+ var import_react = require("react");
32
+ var import_heroui_v2_shared_utils = require("@vx-oss/heroui-v2-shared-utils");
33
+ var DEFAULT_SLOT = Symbol("default");
34
+ function useObjectRef(ref) {
35
+ const objRef = (0, import_react.useRef)(null);
36
+ const cleanupRef = (0, import_react.useRef)(void 0);
37
+ const refEffect = (0, import_react.useCallback)(
38
+ (instance) => {
39
+ if (typeof ref === "function") {
40
+ const refCallback = ref;
41
+ const refCleanup = refCallback(instance);
42
+ return () => {
43
+ if (typeof refCleanup === "function") {
44
+ refCleanup();
45
+ } else {
46
+ refCallback(null);
47
+ }
48
+ };
49
+ } else if (ref) {
50
+ ref.current = instance;
51
+ return () => {
52
+ ref.current = null;
53
+ };
54
+ }
55
+ },
56
+ [ref]
57
+ );
58
+ return (0, import_react.useMemo)(
59
+ () => ({
60
+ get current() {
61
+ return objRef.current;
62
+ },
63
+ set current(value) {
64
+ objRef.current = value;
65
+ if (cleanupRef.current) {
66
+ cleanupRef.current();
67
+ cleanupRef.current = void 0;
68
+ }
69
+ if (value != null) {
70
+ cleanupRef.current = refEffect(value);
71
+ }
72
+ }
73
+ }),
74
+ [refEffect]
75
+ );
76
+ }
77
+ function useSlottedContext(context, slot) {
78
+ let ctx = (0, import_react.useContext)(context);
79
+ if (slot === null) {
80
+ return null;
81
+ }
82
+ if (ctx && typeof ctx === "object" && "slots" in ctx && ctx.slots) {
83
+ let availableSlots = new Intl.ListFormat().format(Object.keys(ctx.slots).map((p) => `"${p}"`));
84
+ if (!slot && !ctx.slots[DEFAULT_SLOT]) {
85
+ throw new Error(`A slot prop is required. Valid slot names are ${availableSlots}.`);
86
+ }
87
+ let slotKey = slot || DEFAULT_SLOT;
88
+ if (!ctx.slots[slotKey]) {
89
+ throw new Error(`Invalid slot "${slot}". Valid slot names are ${availableSlots}.`);
90
+ }
91
+ return ctx.slots[slotKey];
92
+ }
93
+ return ctx;
94
+ }
95
+ function useContextProps(props, ref, context) {
96
+ let ctx = useSlottedContext(context, props.slot) || {};
97
+ let { ref: contextRef, ...contextProps } = ctx;
98
+ let mergedRef = useObjectRef((0, import_react.useMemo)(() => (0, import_heroui_v2_shared_utils.mergeRefs)(ref, contextRef), [ref, contextRef]));
99
+ let mergedProps = (0, import_heroui_v2_shared_utils.mergeProps)(contextProps, props);
100
+ if ("style" in contextProps && contextProps.style && "style" in props && props.style) {
101
+ if (typeof contextProps.style === "function" || typeof props.style === "function") {
102
+ mergedProps.style = (renderProps) => {
103
+ let contextStyle = typeof contextProps.style === "function" ? contextProps.style(renderProps) : contextProps.style;
104
+ let defaultStyle = { ...renderProps.defaultStyle, ...contextStyle };
105
+ let style = typeof props.style === "function" ? props.style({ ...renderProps, defaultStyle }) : props.style;
106
+ return { ...defaultStyle, ...style };
107
+ };
108
+ } else {
109
+ mergedProps.style = { ...contextProps.style, ...props.style };
110
+ }
111
+ }
112
+ return [mergedProps, mergedRef];
113
+ }
114
+
115
+ // src/base-form.tsx
116
+ var import_form = require("@react-stately/form");
117
+ var import_react2 = require("react");
118
+ var import_heroui_v2_theme = require("@vx-oss/heroui-v2-theme");
119
+ var import_jsx_runtime = require("react/jsx-runtime");
120
+ var FormContext = (0, import_react2.createContext)(null);
121
+ var Form = (0, import_react2.forwardRef)(function Form2(props, ref) {
122
+ [props, ref] = useContextProps(props, ref, FormContext);
123
+ let { validationErrors, validationBehavior = "native", children, className, ...domProps } = props;
124
+ const styles = (0, import_react2.useMemo)(() => (0, import_heroui_v2_theme.form)({ className }), [className]);
125
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("form", { noValidate: validationBehavior !== "native", ...domProps, ref, className: styles, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormContext.Provider, { value: { ...props, validationBehavior }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_form.FormValidationContext.Provider, { value: validationErrors != null ? validationErrors : {}, children }) }) });
126
+ });
127
+
128
+ // src/form.tsx
129
+ var import_heroui_v2_system = require("@vx-oss/heroui-v2-system");
130
+ var import_react3 = require("react");
131
+ var import_jsx_runtime2 = require("react/jsx-runtime");
132
+ var Form3 = (0, import_react3.forwardRef)(function Form4(props, ref) {
133
+ var _a, _b;
134
+ const globalContext = (0, import_heroui_v2_system.useProviderContext)();
135
+ const validationBehavior = (_b = (_a = props.validationBehavior) != null ? _a : globalContext == null ? void 0 : globalContext.validationBehavior) != null ? _b : "native";
136
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Form, { ...props, ref, validationBehavior });
137
+ });
138
+ // Annotate the CommonJS export names for ESM import in node:
139
+ 0 && (module.exports = {
140
+ Form,
141
+ FormContext,
142
+ useSlottedContext
143
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,15 @@
1
+ "use client";
2
+ import {
3
+ Form
4
+ } from "./chunk-6ZVVJ3SO.mjs";
5
+ import {
6
+ FormContext
7
+ } from "./chunk-TTDMASG4.mjs";
8
+ import {
9
+ useSlottedContext
10
+ } from "./chunk-G2FFP3K6.mjs";
11
+ export {
12
+ Form,
13
+ FormContext,
14
+ useSlottedContext
15
+ };
@@ -0,0 +1,43 @@
1
+ import { CSSProperties, ReactNode, ForwardedRef, Context, MutableRefObject } from 'react';
2
+ import { DOMProps as DOMProps$1, RefObject } from '@react-types/shared';
3
+
4
+ declare const DEFAULT_SLOT: unique symbol;
5
+ interface SlottedValue<T> {
6
+ slots?: Record<string | symbol, T>;
7
+ }
8
+ type WithRef<T, E> = T & {
9
+ ref?: ForwardedRef<E>;
10
+ };
11
+ type SlottedContextValue<T> = SlottedValue<T> | T | null | undefined;
12
+ type ContextValue<T, E> = SlottedContextValue<WithRef<T, E>>;
13
+ interface StyleProps {
14
+ /** The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. */
15
+ className?: string;
16
+ /** The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element. */
17
+ style?: CSSProperties;
18
+ }
19
+ interface DOMProps extends StyleProps, DOMProps$1 {
20
+ /** The children of the component. */
21
+ children?: ReactNode;
22
+ }
23
+ interface SlotProps {
24
+ /**
25
+ * A slot name for the component. Slots allow the component to receive props from a parent component.
26
+ * An explicit `null` value indicates that the local props completely override all props received from a parent.
27
+ */
28
+ slot?: string | null;
29
+ }
30
+ /**
31
+ * Offers an object ref for a given callback ref or an object ref. Especially
32
+ * helfpul when passing forwarded refs (created using `React.forwardRef`) to
33
+ * React Aria hooks.
34
+ *
35
+ * @param ref The original ref intended to be used.
36
+ * @returns An object ref that updates the given ref.
37
+ * @see https://react.dev/reference/react/forwardRef
38
+ */
39
+ declare function useObjectRef<T>(ref?: ((instance: T | null) => (() => void) | void) | MutableRefObject<T | null> | null): MutableRefObject<T | null>;
40
+ declare function useSlottedContext<T>(context: Context<SlottedContextValue<T>>, slot?: string | null): T | null | undefined;
41
+ declare function useContextProps<T, U extends SlotProps, E extends Element>(props: T & SlotProps, ref: ForwardedRef<E>, context: Context<ContextValue<U, E>>): [T, RefObject<E | null>];
42
+
43
+ export { type ContextValue, DEFAULT_SLOT, type DOMProps, type SlotProps, type SlottedContextValue, type StyleProps, type WithRef, useContextProps, useObjectRef, useSlottedContext };
@@ -0,0 +1,43 @@
1
+ import { CSSProperties, ReactNode, ForwardedRef, Context, MutableRefObject } from 'react';
2
+ import { DOMProps as DOMProps$1, RefObject } from '@react-types/shared';
3
+
4
+ declare const DEFAULT_SLOT: unique symbol;
5
+ interface SlottedValue<T> {
6
+ slots?: Record<string | symbol, T>;
7
+ }
8
+ type WithRef<T, E> = T & {
9
+ ref?: ForwardedRef<E>;
10
+ };
11
+ type SlottedContextValue<T> = SlottedValue<T> | T | null | undefined;
12
+ type ContextValue<T, E> = SlottedContextValue<WithRef<T, E>>;
13
+ interface StyleProps {
14
+ /** The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. */
15
+ className?: string;
16
+ /** The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element. */
17
+ style?: CSSProperties;
18
+ }
19
+ interface DOMProps extends StyleProps, DOMProps$1 {
20
+ /** The children of the component. */
21
+ children?: ReactNode;
22
+ }
23
+ interface SlotProps {
24
+ /**
25
+ * A slot name for the component. Slots allow the component to receive props from a parent component.
26
+ * An explicit `null` value indicates that the local props completely override all props received from a parent.
27
+ */
28
+ slot?: string | null;
29
+ }
30
+ /**
31
+ * Offers an object ref for a given callback ref or an object ref. Especially
32
+ * helfpul when passing forwarded refs (created using `React.forwardRef`) to
33
+ * React Aria hooks.
34
+ *
35
+ * @param ref The original ref intended to be used.
36
+ * @returns An object ref that updates the given ref.
37
+ * @see https://react.dev/reference/react/forwardRef
38
+ */
39
+ declare function useObjectRef<T>(ref?: ((instance: T | null) => (() => void) | void) | MutableRefObject<T | null> | null): MutableRefObject<T | null>;
40
+ declare function useSlottedContext<T>(context: Context<SlottedContextValue<T>>, slot?: string | null): T | null | undefined;
41
+ declare function useContextProps<T, U extends SlotProps, E extends Element>(props: T & SlotProps, ref: ForwardedRef<E>, context: Context<ContextValue<U, E>>): [T, RefObject<E | null>];
42
+
43
+ export { type ContextValue, DEFAULT_SLOT, type DOMProps, type SlotProps, type SlottedContextValue, type StyleProps, type WithRef, useContextProps, useObjectRef, useSlottedContext };
package/dist/utils.js ADDED
@@ -0,0 +1,119 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/utils.ts
22
+ var utils_exports = {};
23
+ __export(utils_exports, {
24
+ DEFAULT_SLOT: () => DEFAULT_SLOT,
25
+ useContextProps: () => useContextProps,
26
+ useObjectRef: () => useObjectRef,
27
+ useSlottedContext: () => useSlottedContext
28
+ });
29
+ module.exports = __toCommonJS(utils_exports);
30
+ var import_react = require("react");
31
+ var import_heroui_v2_shared_utils = require("@vx-oss/heroui-v2-shared-utils");
32
+ var DEFAULT_SLOT = Symbol("default");
33
+ function useObjectRef(ref) {
34
+ const objRef = (0, import_react.useRef)(null);
35
+ const cleanupRef = (0, import_react.useRef)(void 0);
36
+ const refEffect = (0, import_react.useCallback)(
37
+ (instance) => {
38
+ if (typeof ref === "function") {
39
+ const refCallback = ref;
40
+ const refCleanup = refCallback(instance);
41
+ return () => {
42
+ if (typeof refCleanup === "function") {
43
+ refCleanup();
44
+ } else {
45
+ refCallback(null);
46
+ }
47
+ };
48
+ } else if (ref) {
49
+ ref.current = instance;
50
+ return () => {
51
+ ref.current = null;
52
+ };
53
+ }
54
+ },
55
+ [ref]
56
+ );
57
+ return (0, import_react.useMemo)(
58
+ () => ({
59
+ get current() {
60
+ return objRef.current;
61
+ },
62
+ set current(value) {
63
+ objRef.current = value;
64
+ if (cleanupRef.current) {
65
+ cleanupRef.current();
66
+ cleanupRef.current = void 0;
67
+ }
68
+ if (value != null) {
69
+ cleanupRef.current = refEffect(value);
70
+ }
71
+ }
72
+ }),
73
+ [refEffect]
74
+ );
75
+ }
76
+ function useSlottedContext(context, slot) {
77
+ let ctx = (0, import_react.useContext)(context);
78
+ if (slot === null) {
79
+ return null;
80
+ }
81
+ if (ctx && typeof ctx === "object" && "slots" in ctx && ctx.slots) {
82
+ let availableSlots = new Intl.ListFormat().format(Object.keys(ctx.slots).map((p) => `"${p}"`));
83
+ if (!slot && !ctx.slots[DEFAULT_SLOT]) {
84
+ throw new Error(`A slot prop is required. Valid slot names are ${availableSlots}.`);
85
+ }
86
+ let slotKey = slot || DEFAULT_SLOT;
87
+ if (!ctx.slots[slotKey]) {
88
+ throw new Error(`Invalid slot "${slot}". Valid slot names are ${availableSlots}.`);
89
+ }
90
+ return ctx.slots[slotKey];
91
+ }
92
+ return ctx;
93
+ }
94
+ function useContextProps(props, ref, context) {
95
+ let ctx = useSlottedContext(context, props.slot) || {};
96
+ let { ref: contextRef, ...contextProps } = ctx;
97
+ let mergedRef = useObjectRef((0, import_react.useMemo)(() => (0, import_heroui_v2_shared_utils.mergeRefs)(ref, contextRef), [ref, contextRef]));
98
+ let mergedProps = (0, import_heroui_v2_shared_utils.mergeProps)(contextProps, props);
99
+ if ("style" in contextProps && contextProps.style && "style" in props && props.style) {
100
+ if (typeof contextProps.style === "function" || typeof props.style === "function") {
101
+ mergedProps.style = (renderProps) => {
102
+ let contextStyle = typeof contextProps.style === "function" ? contextProps.style(renderProps) : contextProps.style;
103
+ let defaultStyle = { ...renderProps.defaultStyle, ...contextStyle };
104
+ let style = typeof props.style === "function" ? props.style({ ...renderProps, defaultStyle }) : props.style;
105
+ return { ...defaultStyle, ...style };
106
+ };
107
+ } else {
108
+ mergedProps.style = { ...contextProps.style, ...props.style };
109
+ }
110
+ }
111
+ return [mergedProps, mergedRef];
112
+ }
113
+ // Annotate the CommonJS export names for ESM import in node:
114
+ 0 && (module.exports = {
115
+ DEFAULT_SLOT,
116
+ useContextProps,
117
+ useObjectRef,
118
+ useSlottedContext
119
+ });
package/dist/utils.mjs ADDED
@@ -0,0 +1,13 @@
1
+ "use client";
2
+ import {
3
+ DEFAULT_SLOT,
4
+ useContextProps,
5
+ useObjectRef,
6
+ useSlottedContext
7
+ } from "./chunk-G2FFP3K6.mjs";
8
+ export {
9
+ DEFAULT_SLOT,
10
+ useContextProps,
11
+ useObjectRef,
12
+ useSlottedContext
13
+ };
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@vx-oss/heroui-v2-form",
3
+ "version": "2.1.28-alpha.0",
4
+ "description": "A form is a group of inputs that allows users submit data to a server and supports field validation errors.",
5
+ "keywords": [
6
+ "form"
7
+ ],
8
+ "author": "Vx OSS Devs <oss-developers@vezham.com>",
9
+ "homepage": "https://vezham.com",
10
+ "license": "MIT",
11
+ "main": "dist/index.js",
12
+ "sideEffects": false,
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/vezham/heroui-v2.git",
22
+ "directory": "packages/components/form"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/vezham/heroui-v2/issues"
26
+ },
27
+ "peerDependencies": {
28
+ "@vx-oss/heroui-v2-system": ">=2.4.24-alpha.0",
29
+ "@vx-oss/heroui-v2-theme": ">=2.4.24-alpha.0",
30
+ "react": ">=18",
31
+ "react-dom": ">=18"
32
+ },
33
+ "dependencies": {
34
+ "@react-types/shared": "3.32.1",
35
+ "@react-stately/form": "3.2.2",
36
+ "@react-types/form": "3.7.16",
37
+ "@vx-oss/heroui-v2-system": "2.4.24-alpha.0",
38
+ "@vx-oss/heroui-v2-theme": "2.4.24-alpha.0",
39
+ "@vx-oss/heroui-v2-shared-utils": "2.1.13-alpha.0"
40
+ },
41
+ "clean-package": "../../../clean-package.config.json",
42
+ "module": "dist/index.mjs",
43
+ "types": "dist/index.d.ts",
44
+ "exports": {
45
+ ".": {
46
+ "types": "./dist/index.d.ts",
47
+ "import": "./dist/index.mjs",
48
+ "require": "./dist/index.js"
49
+ },
50
+ "./package.json": "./package.json"
51
+ },
52
+ "scripts": {
53
+ "build": "tsup src --dts",
54
+ "build:fast": "tsup src",
55
+ "dev": "pnpm build:fast --watch",
56
+ "clean": "rimraf dist .turbo",
57
+ "typecheck": "tsc --noEmit"
58
+ }
59
+ }