@octohirono/stitch-design-system 0.1.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.
Files changed (184) hide show
  1. package/README.md +7 -0
  2. package/dist/components/Accordion/Accordion.d.ts +45 -0
  3. package/dist/components/Accordion/Accordion.js +26 -0
  4. package/dist/components/Accordion/accordion.module.js +4 -0
  5. package/dist/components/Accordion/index.d.ts +2 -0
  6. package/dist/components/AlertDialog/AlertDialog.d.ts +45 -0
  7. package/dist/components/AlertDialog/AlertDialog.js +32 -0
  8. package/dist/components/AlertDialog/alert-dialog.module.js +4 -0
  9. package/dist/components/AlertDialog/index.d.ts +2 -0
  10. package/dist/components/AspectRatio/AspectRatio.d.ts +29 -0
  11. package/dist/components/AspectRatio/AspectRatio.js +15 -0
  12. package/dist/components/AspectRatio/aspect-ratio.module.js +4 -0
  13. package/dist/components/AspectRatio/index.d.ts +2 -0
  14. package/dist/components/Avatar/Avatar.d.ts +42 -0
  15. package/dist/components/Avatar/Avatar.js +21 -0
  16. package/dist/components/Avatar/avatar.module.js +13 -0
  17. package/dist/components/Avatar/index.d.ts +2 -0
  18. package/dist/components/Button/Button.d.ts +60 -0
  19. package/dist/components/Button/Button.js +22 -0
  20. package/dist/components/Button/button.module.js +19 -0
  21. package/dist/components/Button/index.d.ts +2 -0
  22. package/dist/components/Card/Card.d.ts +50 -0
  23. package/dist/components/Card/Card.js +21 -0
  24. package/dist/components/Card/card.module.js +22 -0
  25. package/dist/components/Card/index.d.ts +2 -0
  26. package/dist/components/Checkbox/Checkbox.d.ts +45 -0
  27. package/dist/components/Checkbox/Checkbox.js +56 -0
  28. package/dist/components/Checkbox/checkbox.module.js +17 -0
  29. package/dist/components/Checkbox/index.d.ts +2 -0
  30. package/dist/components/CodeBlock/CodeBlock.d.ts +10 -0
  31. package/dist/components/CodeBlock/CodeBlock.js +50 -0
  32. package/dist/components/CodeBlock/codeblock.module.js +17 -0
  33. package/dist/components/CodeBlock/index.d.ts +2 -0
  34. package/dist/components/Collapse/Collapse.d.ts +38 -0
  35. package/dist/components/Collapse/Collapse.js +50 -0
  36. package/dist/components/Collapse/collapse.module.js +13 -0
  37. package/dist/components/Collapse/index.d.ts +2 -0
  38. package/dist/components/ContextMenu/ContextMenu.d.ts +47 -0
  39. package/dist/components/ContextMenu/ContextMenu.js +50 -0
  40. package/dist/components/ContextMenu/context-menu.module.js +13 -0
  41. package/dist/components/ContextMenu/index.d.ts +2 -0
  42. package/dist/components/Divider/Divider.d.ts +50 -0
  43. package/dist/components/Divider/Divider.js +23 -0
  44. package/dist/components/Divider/divider.module.js +14 -0
  45. package/dist/components/Divider/index.d.ts +2 -0
  46. package/dist/components/Drawer/Drawer.d.ts +36 -0
  47. package/dist/components/Drawer/Drawer.js +76 -0
  48. package/dist/components/Drawer/drawer.module.js +21 -0
  49. package/dist/components/Drawer/index.d.ts +2 -0
  50. package/dist/components/DropdownMenu/DropdownMenu.d.ts +55 -0
  51. package/dist/components/DropdownMenu/DropdownMenu.js +54 -0
  52. package/dist/components/DropdownMenu/dropdown-menu.module.js +13 -0
  53. package/dist/components/DropdownMenu/index.d.ts +2 -0
  54. package/dist/components/Form/Form.d.ts +20 -0
  55. package/dist/components/Form/Form.js +105 -0
  56. package/dist/components/Form/FormItem.d.ts +3 -0
  57. package/dist/components/Form/FormItem.js +96 -0
  58. package/dist/components/Form/context.d.ts +22 -0
  59. package/dist/components/Form/context.js +5 -0
  60. package/dist/components/Form/form.module.js +25 -0
  61. package/dist/components/Form/index.d.ts +7 -0
  62. package/dist/components/Form/types.d.ts +164 -0
  63. package/dist/components/Form/types.js +6 -0
  64. package/dist/components/Form/useForm.d.ts +15 -0
  65. package/dist/components/Form/useForm.js +188 -0
  66. package/dist/components/Form/validators.d.ts +3 -0
  67. package/dist/components/Form/validators.js +73 -0
  68. package/dist/components/HoverCard/HoverCard.d.ts +47 -0
  69. package/dist/components/HoverCard/HoverCard.js +26 -0
  70. package/dist/components/HoverCard/hover-card.module.js +9 -0
  71. package/dist/components/HoverCard/index.d.ts +2 -0
  72. package/dist/components/Icon/Icon.d.ts +100 -0
  73. package/dist/components/Icon/Icon.js +150 -0
  74. package/dist/components/Icon/icon.module.js +7 -0
  75. package/dist/components/Icon/index.d.ts +2 -0
  76. package/dist/components/Image/Image.d.ts +50 -0
  77. package/dist/components/Image/Image.js +95 -0
  78. package/dist/components/Image/image.module.js +27 -0
  79. package/dist/components/Image/index.d.ts +2 -0
  80. package/dist/components/Input/Input.d.ts +41 -0
  81. package/dist/components/Input/Input.js +62 -0
  82. package/dist/components/Input/index.d.ts +2 -0
  83. package/dist/components/Input/input.module.js +17 -0
  84. package/dist/components/Label/Label.d.ts +28 -0
  85. package/dist/components/Label/Label.js +15 -0
  86. package/dist/components/Label/index.d.ts +2 -0
  87. package/dist/components/Label/label.module.js +4 -0
  88. package/dist/components/Loading/Loading.d.ts +22 -0
  89. package/dist/components/Loading/Loading.js +32 -0
  90. package/dist/components/Loading/index.d.ts +2 -0
  91. package/dist/components/Loading/loading.module.js +14 -0
  92. package/dist/components/Menubar/Menubar.d.ts +64 -0
  93. package/dist/components/Menubar/Menubar.js +70 -0
  94. package/dist/components/Menubar/index.d.ts +2 -0
  95. package/dist/components/Menubar/menubar.module.js +15 -0
  96. package/dist/components/Modal/Modal.d.ts +38 -0
  97. package/dist/components/Modal/Modal.js +68 -0
  98. package/dist/components/Modal/index.d.ts +2 -0
  99. package/dist/components/Modal/modal.module.js +13 -0
  100. package/dist/components/NavigationMenu/NavigationMenu.d.ts +47 -0
  101. package/dist/components/NavigationMenu/NavigationMenu.js +47 -0
  102. package/dist/components/NavigationMenu/index.d.ts +2 -0
  103. package/dist/components/NavigationMenu/navigation-menu.module.js +16 -0
  104. package/dist/components/Notification/Notification.d.ts +14 -0
  105. package/dist/components/Notification/Notification.js +87 -0
  106. package/dist/components/Notification/NotificationPortal.d.ts +29 -0
  107. package/dist/components/Notification/NotificationPortal.js +90 -0
  108. package/dist/components/Notification/index.d.ts +4 -0
  109. package/dist/components/Notification/notification.module.js +31 -0
  110. package/dist/components/Notification/types.d.ts +44 -0
  111. package/dist/components/OtpField/OtpField.d.ts +40 -0
  112. package/dist/components/OtpField/OtpField.js +20 -0
  113. package/dist/components/OtpField/index.d.ts +2 -0
  114. package/dist/components/OtpField/otp-field.module.js +7 -0
  115. package/dist/components/PasswordInput/PasswordInput.d.ts +36 -0
  116. package/dist/components/PasswordInput/PasswordInput.js +28 -0
  117. package/dist/components/PasswordInput/index.d.ts +2 -0
  118. package/dist/components/PasswordInput/password-input.module.js +4 -0
  119. package/dist/components/Popover/Popover.d.ts +42 -0
  120. package/dist/components/Popover/Popover.js +24 -0
  121. package/dist/components/Popover/index.d.ts +2 -0
  122. package/dist/components/Popover/popover.module.js +9 -0
  123. package/dist/components/Progress/Progress.d.ts +44 -0
  124. package/dist/components/Progress/Progress.js +55 -0
  125. package/dist/components/Progress/index.d.ts +2 -0
  126. package/dist/components/Progress/progress.module.js +21 -0
  127. package/dist/components/Radio/Radio.d.ts +47 -0
  128. package/dist/components/Radio/Radio.js +102 -0
  129. package/dist/components/Radio/index.d.ts +2 -0
  130. package/dist/components/Radio/radio.module.js +17 -0
  131. package/dist/components/ScrollArea/ScrollArea.d.ts +34 -0
  132. package/dist/components/ScrollArea/ScrollArea.js +34 -0
  133. package/dist/components/ScrollArea/index.d.ts +2 -0
  134. package/dist/components/ScrollArea/scroll-area.module.js +10 -0
  135. package/dist/components/Select/Select.d.ts +54 -0
  136. package/dist/components/Select/Select.js +118 -0
  137. package/dist/components/Select/index.d.ts +2 -0
  138. package/dist/components/Select/select.module.js +24 -0
  139. package/dist/components/Skeleton/Skeleton.d.ts +71 -0
  140. package/dist/components/Skeleton/Skeleton.js +147 -0
  141. package/dist/components/Skeleton/index.d.ts +2 -0
  142. package/dist/components/Skeleton/skeleton.module.js +16 -0
  143. package/dist/components/Slider/Slider.d.ts +58 -0
  144. package/dist/components/Slider/Slider.js +33 -0
  145. package/dist/components/Slider/index.d.ts +2 -0
  146. package/dist/components/Slider/slider.module.js +9 -0
  147. package/dist/components/Switch/Switch.d.ts +50 -0
  148. package/dist/components/Switch/Switch.js +43 -0
  149. package/dist/components/Switch/index.d.ts +2 -0
  150. package/dist/components/Switch/switch.module.js +15 -0
  151. package/dist/components/Table/Table.d.ts +65 -0
  152. package/dist/components/Table/Table.js +75 -0
  153. package/dist/components/Table/index.d.ts +2 -0
  154. package/dist/components/Table/table.module.js +21 -0
  155. package/dist/components/Tabs/Tabs.d.ts +37 -0
  156. package/dist/components/Tabs/Tabs.js +68 -0
  157. package/dist/components/Tabs/index.d.ts +2 -0
  158. package/dist/components/Tabs/tabs.module.js +13 -0
  159. package/dist/components/Tag/Tag.d.ts +67 -0
  160. package/dist/components/Tag/Tag.js +54 -0
  161. package/dist/components/Tag/index.d.ts +2 -0
  162. package/dist/components/Tag/tag.module.js +28 -0
  163. package/dist/components/Toggle/Toggle.d.ts +39 -0
  164. package/dist/components/Toggle/Toggle.js +29 -0
  165. package/dist/components/Toggle/index.d.ts +2 -0
  166. package/dist/components/Toggle/toggle.module.js +7 -0
  167. package/dist/components/ToggleGroup/ToggleGroup.d.ts +88 -0
  168. package/dist/components/ToggleGroup/ToggleGroup.js +42 -0
  169. package/dist/components/ToggleGroup/index.d.ts +2 -0
  170. package/dist/components/ToggleGroup/toggle-group.module.js +8 -0
  171. package/dist/components/Toolbar/Toolbar.d.ts +116 -0
  172. package/dist/components/Toolbar/Toolbar.js +72 -0
  173. package/dist/components/Toolbar/index.d.ts +2 -0
  174. package/dist/components/Toolbar/toolbar.module.js +14 -0
  175. package/dist/components/Tooltip/Tooltip.d.ts +41 -0
  176. package/dist/components/Tooltip/Tooltip.js +38 -0
  177. package/dist/components/Tooltip/index.d.ts +2 -0
  178. package/dist/components/Tooltip/tooltip.module.js +21 -0
  179. package/dist/components/_internal/useOverlay.d.ts +15 -0
  180. package/dist/components/_internal/useOverlay.js +55 -0
  181. package/dist/index.d.ts +82 -0
  182. package/dist/index.js +43 -0
  183. package/dist/style.css +3693 -0
  184. package/package.json +36 -0
@@ -0,0 +1,54 @@
1
+ import { Icon as e } from "../Icon/Icon.js";
2
+ import t from "./dropdown-menu.module.js";
3
+ import "react";
4
+ import n from "clsx";
5
+ import { Fragment as r, jsx as i, jsxs as a } from "react/jsx-runtime";
6
+ import { DropdownMenu as o } from "radix-ui";
7
+ //#region packages/react/src/components/DropdownMenu/DropdownMenu.tsx
8
+ function s(c, l = "") {
9
+ return c.map((c, u) => {
10
+ let d = `${l}${u}`, f = /* @__PURE__ */ a(r, { children: [c.icon && /* @__PURE__ */ i(e, {
11
+ name: c.icon,
12
+ size: "1em",
13
+ className: t.itemIcon
14
+ }), /* @__PURE__ */ i("span", {
15
+ className: t.itemLabel,
16
+ children: c.label
17
+ })] });
18
+ return c.children && c.children.length > 0 ? /* @__PURE__ */ a(o.Sub, { children: [/* @__PURE__ */ a(o.SubTrigger, {
19
+ className: n(t.item, c.danger && t.danger),
20
+ disabled: c.disabled,
21
+ children: [f, /* @__PURE__ */ i(e, {
22
+ name: "chevron-right",
23
+ size: "1em",
24
+ className: t.subArrow
25
+ })]
26
+ }), /* @__PURE__ */ i(o.Portal, { children: /* @__PURE__ */ i(o.SubContent, {
27
+ className: t.content,
28
+ sideOffset: 8,
29
+ children: s(c.children, `${d}-`)
30
+ }) })] }, d) : /* @__PURE__ */ i(o.Item, {
31
+ className: n(t.item, c.danger && t.danger),
32
+ disabled: c.disabled,
33
+ onSelect: c.onClick,
34
+ children: f
35
+ }, d);
36
+ });
37
+ }
38
+ var c = ({ trigger: e, items: r, open: c, defaultOpen: l, onOpenChange: u, sideOffset: d = 8, className: f, "aria-label": p }) => /* @__PURE__ */ a(o.Root, {
39
+ open: c,
40
+ defaultOpen: l,
41
+ onOpenChange: u,
42
+ children: [/* @__PURE__ */ i(o.Trigger, {
43
+ asChild: !0,
44
+ "aria-label": p,
45
+ children: e
46
+ }), /* @__PURE__ */ i(o.Portal, { children: /* @__PURE__ */ i(o.Content, {
47
+ className: n(t.content, f),
48
+ sideOffset: d,
49
+ children: s(r)
50
+ }) })]
51
+ });
52
+ c.displayName = "DropdownMenu";
53
+ //#endregion
54
+ export { c as DropdownMenu };
@@ -0,0 +1,13 @@
1
+ //#region packages/react/src/components/DropdownMenu/dropdown-menu.module.less
2
+ var e = "_content_5l6nu_1", t = "_item_5l6nu_21", n = "_danger_5l6nu_41", r = "_itemIcon_5l6nu_48", i = "_itemLabel_5l6nu_52", a = "_subArrow_5l6nu_55", o = {
3
+ content: e,
4
+ "stitch-dropdown-in": "_stitch-dropdown-in_5l6nu_1",
5
+ "stitch-dropdown-out": "_stitch-dropdown-out_5l6nu_1",
6
+ item: t,
7
+ danger: n,
8
+ itemIcon: r,
9
+ itemLabel: i,
10
+ subArrow: a
11
+ };
12
+ //#endregion
13
+ export { e as content, n as danger, o as default, t as item, r as itemIcon, i as itemLabel, a as subArrow };
@@ -0,0 +1,2 @@
1
+ export { DropdownMenu } from './DropdownMenu';
2
+ export type { DropdownMenuProps, DropdownMenuItem } from './DropdownMenu';
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import { useForm } from './useForm';
3
+ import { FormItem } from './FormItem';
4
+ import type { FormInstance, FormProps } from './types';
5
+ type FormComponent = ((props: FormProps<Record<string, unknown>> & {
6
+ ref?: React.Ref<HTMLFormElement>;
7
+ }) => React.ReactElement) & {
8
+ Item: typeof FormItem;
9
+ useForm: typeof useForm;
10
+ Provider: typeof FormProvider;
11
+ displayName?: string;
12
+ };
13
+ /** 透传 ref 渲染 <form> 的主组件 */
14
+ export declare const Form: FormComponent;
15
+ export interface FormProviderProps {
16
+ form: FormInstance;
17
+ children: React.ReactNode;
18
+ }
19
+ declare const FormProvider: React.FC<FormProviderProps>;
20
+ export default Form;
@@ -0,0 +1,105 @@
1
+ import e from "./form.module.js";
2
+ import { FormContext as t } from "./context.js";
3
+ import { useForm as n } from "./useForm.js";
4
+ import { FormItem as r } from "./FormItem.js";
5
+ import i, { useEffect as a, useMemo as o, useRef as s } from "react";
6
+ import c from "clsx";
7
+ import { jsx as l } from "react/jsx-runtime";
8
+ //#region packages/react/src/components/Form/Form.tsx
9
+ function u(r, i) {
10
+ let { form: u, initialValues: d, layout: f = "horizontal", labelAlign: p = f === "horizontal" ? "right" : "left", labelCol: m, wrapperCol: h, size: g = "middle", disabled: _ = !1, colon: v = !0, requiredMark: y = !1, onFinish: b, onFinishFailed: x, onValuesChange: S, onReset: C, className: w, children: T, ...E } = r, D = u !== void 0, [O] = n(), k = D ? u : O, A = s({
11
+ onFinish: b,
12
+ onFinishFailed: x,
13
+ onValuesChange: S
14
+ });
15
+ a(() => {
16
+ A.current = {
17
+ onFinish: b,
18
+ onFinishFailed: x,
19
+ onValuesChange: S
20
+ };
21
+ }, [
22
+ b,
23
+ x,
24
+ S
25
+ ]), a(() => {
26
+ let e = k;
27
+ typeof e.__bindCallbacks == "function" && e.__bindCallbacks(A.current);
28
+ }, [
29
+ k,
30
+ b,
31
+ x,
32
+ S
33
+ ]);
34
+ let j = s(void 0);
35
+ a(() => {
36
+ if (!d) return;
37
+ let e = JSON.stringify(d);
38
+ e !== j.current && (j.current = e, k.setFieldsValue(d));
39
+ }, [d, k]);
40
+ let M = o(() => ({
41
+ form: k,
42
+ layout: f,
43
+ labelAlign: p,
44
+ labelCol: m,
45
+ wrapperCol: h,
46
+ size: g,
47
+ disabled: _,
48
+ colon: v,
49
+ requiredMark: y
50
+ }), [
51
+ k,
52
+ f,
53
+ p,
54
+ m,
55
+ h,
56
+ g,
57
+ _,
58
+ v,
59
+ y
60
+ ]), N = (e) => {
61
+ e.preventDefault(), e.stopPropagation(), k.validateFields().then((e) => {
62
+ A.current.onFinish?.(e);
63
+ }, (e) => {
64
+ e && Array.isArray(e.errorFields) && A.current.onFinishFailed?.({
65
+ values: e.values ?? {},
66
+ errorFields: e.errorFields,
67
+ outOfDate: !1
68
+ });
69
+ });
70
+ }, P = (e) => {
71
+ e.preventDefault(), k.resetFields(), C?.(e);
72
+ }, F = c(e.form, e[f], e[g], { [e.disabled]: _ }, w);
73
+ return /* @__PURE__ */ l(t.Provider, {
74
+ value: M,
75
+ children: /* @__PURE__ */ l("form", {
76
+ ref: i,
77
+ className: F,
78
+ onSubmit: N,
79
+ onReset: P,
80
+ ...E,
81
+ children: T
82
+ })
83
+ });
84
+ }
85
+ var d = i.forwardRef(u);
86
+ d.displayName = "Form", d.useForm = n;
87
+ function f({ form: e, children: n }) {
88
+ let r = o(() => ({
89
+ form: e,
90
+ layout: "vertical",
91
+ labelAlign: "left",
92
+ size: "middle",
93
+ disabled: !1,
94
+ colon: !0,
95
+ requiredMark: !1
96
+ }), [e]);
97
+ return /* @__PURE__ */ l(t.Provider, {
98
+ value: r,
99
+ children: n
100
+ });
101
+ }
102
+ var p = f;
103
+ p.displayName = "FormProvider", d.Item = r, d.Provider = p;
104
+ //#endregion
105
+ export { d as Form, d as default };
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import type { FormItemProps } from './types';
3
+ export declare const FormItem: React.FC<FormItemProps>;
@@ -0,0 +1,96 @@
1
+ import { Icon as e } from "../Icon/Icon.js";
2
+ import t from "./form.module.js";
3
+ import { FormContext as n } from "./context.js";
4
+ import { stringifyNamePath as r } from "./types.js";
5
+ import i, { useCallback as a, useContext as o, useEffect as s, useMemo as ee, useState as c } from "react";
6
+ import l from "clsx";
7
+ import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
8
+ //#region packages/react/src/components/Form/FormItem.tsx
9
+ function p(e) {
10
+ if (typeof e != "object" || !e) return e;
11
+ let t = e.target;
12
+ if (t && typeof t == "object") {
13
+ if ((t.type === "checkbox" || t.type === "radio") && "checked" in t) return t.checked;
14
+ if ("value" in t && t.value !== void 0) return t.value;
15
+ }
16
+ return "value" in e ? e.value : e;
17
+ }
18
+ var m = (m) => {
19
+ let { name: h, label: g, rules: _ = [], required: v = !1, valuePropName: y = "value", trigger: b = "onChange", getValueFromEvent: x = p, normalize: S, hidden: te = !1, hasFeedback: ne = !1, validateStatus: re, help: ie, noStyle: ae = !1, labelCol: oe, wrapperCol: se, colon: ce, requiredMark: le, layout: ue, className: C, children: w } = m, T = o(n);
20
+ if (!T) throw Error("Form.Item must be used inside <Form> or <Form.Provider>");
21
+ let { form: E, layout: D, labelAlign: O, labelCol: k, wrapperCol: A, size: j, disabled: M, colon: N, requiredMark: P } = T, F = ee(() => h === void 0 ? null : r(h), [h]), [, I] = c(0), L = a(() => I((e) => e + 1), []);
22
+ if (s(() => {
23
+ if (!F) return;
24
+ let e = E.__store;
25
+ if (e) return e.registerField(h, _, void 0, L), () => e.unregisterField(F);
26
+ }, [
27
+ E,
28
+ F,
29
+ h,
30
+ L
31
+ ]), s(() => {
32
+ F && E.__store?.updateRules?.(F, _);
33
+ }, [
34
+ _,
35
+ F,
36
+ E
37
+ ]), te) return null;
38
+ let R = F ? E.getFieldValue(h) : void 0, z = F ? E.getFieldError(h) : void 0, B = F ? E.isFieldValidating(h) : !1, V = F ? E.isFieldTouched(h) : !1, H = re ?? (B ? "validating" : z?.[0] ? "error" : ""), U = (V && z?.[0] ? z[0] : void 0) ?? ie, de = le ?? P, W = (v || _.some((e) => typeof e == "object" && e.required)) && de !== !1, G = i.isValidElement(w), K = G ? { ...w.props } : {};
39
+ if (F && G) {
40
+ K[y] = R;
41
+ let e = K[b];
42
+ K[b] = (t) => {
43
+ typeof e == "function" && e(t);
44
+ let n = x(t), r = E.getFieldValue(h), i = S ? S(n, r, E.getFieldsValue(!0)) : n;
45
+ E.setFieldValue(h, i);
46
+ }, K.id === void 0 && (K.id = F);
47
+ }
48
+ let q = F ? `${F}_help` : void 0;
49
+ q && G && K["aria-errormessage"] === void 0 && (K["aria-errormessage"] = H === "error" ? q : void 0), M && K.disabled === void 0 && (K.disabled = !0), K.size === void 0 && (K.size = j), K.status === void 0 && (H === "error" || H === "warning") && (K.status = H);
50
+ let J = F && G ? i.cloneElement(w, K) : w, Y = ue ?? D, fe = Y === "inline" ? "vertical" : Y, X = oe ?? k, pe = se ?? A, me = ce ?? N, Z = (e, t = 1) => {
51
+ if (!e) return {};
52
+ let n = e.span ?? 24;
53
+ return { gridColumn: `${t + (e.offset ?? 0)} / span ${n}` };
54
+ }, he = (X?.span ?? 0) + (X?.offset ?? 0), ge = Z(X, 1), _e = Z(pe, he + 1), Q = l(t.item, t[`item-${fe}`], t[`item-${j}`], {
55
+ [t["item-has-error"]]: H === "error",
56
+ [t["item-has-warning"]]: H === "warning",
57
+ [t["item-has-success"]]: H === "success",
58
+ [t["item-is-validating"]]: H === "validating",
59
+ [t["item-required"]]: W
60
+ }, C), ve = g === void 0 ? null : /* @__PURE__ */ d("label", {
61
+ htmlFor: F ?? void 0,
62
+ className: l(t["item-label"], {
63
+ [t["item-label-required"]]: W,
64
+ [t["item-label-colon"]]: me && g !== ""
65
+ }),
66
+ style: {
67
+ ...ge,
68
+ textAlign: O
69
+ },
70
+ children: g
71
+ }), $ = U === void 0 ? null : /* @__PURE__ */ f("div", {
72
+ id: q,
73
+ role: H === "error" ? "alert" : void 0,
74
+ className: l(t["item-explain"], { [t["item-explain-error"]]: H === "error" }),
75
+ children: [ne && H === "error" ? /* @__PURE__ */ d(e, {
76
+ name: "close",
77
+ size: 14,
78
+ className: t["item-feedback-icon"]
79
+ }) : null, U]
80
+ });
81
+ return ae ? /* @__PURE__ */ f(u, { children: [J, $] }) : /* @__PURE__ */ f("div", {
82
+ className: Q,
83
+ "data-field-name": F ?? void 0,
84
+ children: [ve, /* @__PURE__ */ f("div", {
85
+ className: t["item-control"],
86
+ style: _e,
87
+ children: [/* @__PURE__ */ d("div", {
88
+ className: t["item-control-input"],
89
+ children: J
90
+ }), $]
91
+ })]
92
+ });
93
+ };
94
+ m.displayName = "FormItem";
95
+ //#endregion
96
+ export { m as FormItem };
@@ -0,0 +1,22 @@
1
+ import type { ColProps, FormInstance, FormLabelAlign, FormLayout, FormSize, RequiredMark } from './types';
2
+ export interface FormContextValue {
3
+ /** Form 实例(提供注册、校验、命令式 API) */
4
+ form: FormInstance;
5
+ /** 布局方向 */
6
+ layout: FormLayout;
7
+ /** label 对齐 */
8
+ labelAlign: FormLabelAlign;
9
+ /** label 网格 */
10
+ labelCol?: ColProps;
11
+ /** wrapper 网格 */
12
+ wrapperCol?: ColProps;
13
+ /** 全局尺寸 */
14
+ size: FormSize;
15
+ /** 全局禁用 */
16
+ disabled: boolean;
17
+ /** 是否显示冒号 */
18
+ colon: boolean;
19
+ /** 必填星号策略 */
20
+ requiredMark: RequiredMark;
21
+ }
22
+ export declare const FormContext: import("react").Context<FormContextValue | null>;
@@ -0,0 +1,5 @@
1
+ import { createContext as e } from "react";
2
+ //#region packages/react/src/components/Form/context.ts
3
+ var t = e(null);
4
+ //#endregion
5
+ export { t as FormContext };
@@ -0,0 +1,25 @@
1
+ //#region packages/react/src/components/Form/form.module.less
2
+ var e = "_form_lunb0_1", t = "_horizontal_lunb0_11", n = "_vertical_lunb0_16", r = "_inline_lunb0_21", i = "_item_lunb0_26", a = "_disabled_lunb0_29", o = {
3
+ form: e,
4
+ horizontal: t,
5
+ vertical: n,
6
+ inline: r,
7
+ item: i,
8
+ disabled: a,
9
+ "item-horizontal": "_item-horizontal_lunb0_39",
10
+ "item-vertical": "_item-vertical_lunb0_45",
11
+ "item-label": "_item-label_lunb0_48",
12
+ "item-label-required": "_item-label-required_lunb0_60",
13
+ "item-label-colon": "_item-label-colon_lunb0_65",
14
+ "item-control": "_item-control_lunb0_69",
15
+ "item-control-input": "_item-control-input_lunb0_72",
16
+ "item-explain": "_item-explain_lunb0_85",
17
+ "item-explain-error": "_item-explain-error_lunb0_92",
18
+ "item-feedback-icon": "_item-feedback-icon_lunb0_95",
19
+ "item-has-error": "_item-has-error_lunb0_101",
20
+ "item-has-warning": "_item-has-warning_lunb0_104",
21
+ "item-has-success": "_item-has-success_lunb0_107",
22
+ "item-is-validating": "_item-is-validating_lunb0_110"
23
+ };
24
+ //#endregion
25
+ export { o as default, a as disabled, e as form, t as horizontal, r as inline, i as item, n as vertical };
@@ -0,0 +1,7 @@
1
+ import Form from './Form';
2
+ export { Form } from './Form';
3
+ export { useForm } from './useForm';
4
+ export { FormItem } from './FormItem';
5
+ export type { FormProviderProps } from './Form';
6
+ export type { ColProps, FieldData, FormInstance, FormItemLayout, FormItemProps, FormLabelAlign, FormLayout, FormProps, FormSize, NamePath, RequiredMark, RuleObject, RuleRender, RuleType, Rules, ScrollOptions, StoreValue, ValidateError, ValidateInfo, ValidateStatus, } from './types';
7
+ export default Form;
@@ -0,0 +1,164 @@
1
+ import type React from 'react';
2
+ /** 字段名路径 —— 支持点号分隔的嵌套字段("user.name")或数组 */
3
+ export type NamePath = string | number | (string | number)[];
4
+ /** 字段值(任意类型) */
5
+ export type StoreValue = unknown;
6
+ /** 内部统一转为字符串 path,便于 Map 存储 */
7
+ export declare function stringifyNamePath(name: NamePath): string;
8
+ export type RuleType = 'string' | 'number' | 'boolean' | 'integer' | 'float' | 'array' | 'object' | 'email' | 'url' | 'date';
9
+ export interface RuleObject {
10
+ /** 必填 */
11
+ required?: boolean;
12
+ /** 提示文本(验证失败时显示) */
13
+ message?: string;
14
+ /** 字符串/数组最小长度/最小值 */
15
+ min?: number;
16
+ /** 字符串/数组最大长度/最大值 */
17
+ max?: number;
18
+ /** 字符串/数组精确长度 */
19
+ len?: number;
20
+ /** 正则 */
21
+ pattern?: RegExp;
22
+ /** 空白字符也算校验失败(搭配 required) */
23
+ whitespace?: boolean;
24
+ /** 值类型 */
25
+ type?: RuleType;
26
+ /** 自定义校验器,可返回 Promise(异步) */
27
+ validator?: (rule: RuleObject, value: unknown) => Promise<void | string> | void | string;
28
+ }
29
+ export type RuleRender = RuleObject | ((form: FormInstance) => RuleObject);
30
+ export type Rules = RuleRender[];
31
+ export interface ValidateError {
32
+ name: NamePath;
33
+ errors: string[];
34
+ }
35
+ export interface ValidateInfo {
36
+ values: Record<string, unknown>;
37
+ errorFields: ValidateError[];
38
+ outOfDate: boolean;
39
+ }
40
+ export interface FieldData {
41
+ name: NamePath;
42
+ value?: unknown;
43
+ errors?: string[];
44
+ touched?: boolean;
45
+ validating?: boolean;
46
+ }
47
+ export interface FormInstance<T = Record<string, unknown>> {
48
+ /** 取单个字段值 */
49
+ getFieldValue: (name: NamePath) => unknown;
50
+ /** 取所有/指定字段值 */
51
+ getFieldsValue: (nameList?: NamePath[] | true) => T;
52
+ /** 设置单个字段值(不触发校验) */
53
+ setFieldValue: (name: NamePath, value: unknown) => void;
54
+ /** 批量设置字段值 */
55
+ setFieldsValue: (values: Partial<T>) => void;
56
+ /** 重置字段(值回到 initialValues,错误清空) */
57
+ resetFields: (nameList?: NamePath[]) => void;
58
+ /** 校验指定字段(默认全部),reject 时为错误信息 */
59
+ validateFields: (nameList?: NamePath[]) => Promise<T>;
60
+ /** 提交(先校验,触发 onFinish 或 onFinishFailed) */
61
+ submit: () => void;
62
+ /** 批量更新字段状态(错误、值、touched、validating) */
63
+ setFields: (fields: FieldData[]) => void;
64
+ /** 是否被用户操作过 */
65
+ isFieldTouched: (name: NamePath) => boolean;
66
+ /** 是否正在校验中 */
67
+ isFieldValidating: (name: NamePath) => boolean;
68
+ /** 取字段错误 */
69
+ getFieldError: (name: NamePath) => string[] | undefined;
70
+ /** 滚动到字段(占位,scrollIntoBehavior 留给消费者) */
71
+ scrollToField: (name: NamePath, options?: ScrollOptions) => void;
72
+ }
73
+ export interface ScrollOptions {
74
+ behavior?: 'auto' | 'smooth';
75
+ block?: 'start' | 'center' | 'end' | 'nearest';
76
+ inline?: 'start' | 'center' | 'end' | 'nearest';
77
+ }
78
+ export type FormLayout = 'horizontal' | 'vertical' | 'inline';
79
+ export type FormLabelAlign = 'left' | 'right';
80
+ export type FormSize = 'small' | 'middle' | 'large';
81
+ export type RequiredMark = boolean | 'optional';
82
+ export interface ColProps {
83
+ span?: number;
84
+ offset?: number;
85
+ }
86
+ export interface FormProps<T = Record<string, unknown>> extends Omit<React.FormHTMLAttributes<HTMLFormElement>, 'onSubmit' | 'children'> {
87
+ /** 受控 form 实例(Form.useForm() 产出) */
88
+ form?: FormInstance<T>;
89
+ /** 初始值 */
90
+ initialValues?: Partial<T>;
91
+ /** 布局方向 */
92
+ layout?: FormLayout;
93
+ /** label 对齐 */
94
+ labelAlign?: FormLabelAlign;
95
+ /** label 网格 */
96
+ labelCol?: ColProps;
97
+ /** 输入控件网格 */
98
+ wrapperCol?: ColProps;
99
+ /** 全局尺寸 */
100
+ size?: FormSize;
101
+ /** 全局禁用 */
102
+ disabled?: boolean;
103
+ /** label 后是否显示冒号 */
104
+ colon?: boolean;
105
+ /** 必填星号显示策略 */
106
+ requiredMark?: RequiredMark;
107
+ /** 校验通过 */
108
+ onFinish?: (values: T) => void;
109
+ /** 校验失败 */
110
+ onFinishFailed?: (info: ValidateInfo) => void;
111
+ /** 任意字段值变化 */
112
+ onValuesChange?: (changedValues: Partial<T>, allValues: T) => void;
113
+ /** reset 回调 */
114
+ onReset?: (e: React.FormEvent<HTMLFormElement>) => void;
115
+ children?: React.ReactNode;
116
+ }
117
+ export type FormItemLayout = 'horizontal' | 'vertical';
118
+ export type ValidateStatus = 'success' | 'warning' | 'error' | 'validating' | '';
119
+ export interface FormItemProps {
120
+ /** 字段名,必传(无 name 的 FormItem 仅作展示) */
121
+ name?: NamePath;
122
+ /** label 文本 */
123
+ label?: React.ReactNode;
124
+ /** 校验规则 */
125
+ rules?: Rules;
126
+ /** 是否必填(仅显示星号,校验仍以 rules.required 为准) */
127
+ required?: boolean;
128
+ /** 关联字段:依赖字段值变化时重置本字段错误 */
129
+ dependencies?: NamePath[];
130
+ /** 子节点接收的 value prop 名,默认 'value' */
131
+ valuePropName?: string;
132
+ /** 子节点接收的 change 事件 prop 名,默认 'onChange' */
133
+ trigger?: string;
134
+ /** 自定义从事件对象取值 */
135
+ getValueFromEvent?: (event: unknown) => unknown;
136
+ /** 设置前的标准化处理 */
137
+ normalize?: (value: unknown, prevValue: unknown, prevAllValues: Record<string, unknown>) => unknown;
138
+ /** 隐藏字段(不渲染、不参与布局) */
139
+ hidden?: boolean;
140
+ /** 显示校验状态图标 */
141
+ hasFeedback?: boolean;
142
+ /** 手动指定校验状态(覆盖 rules 推断) */
143
+ validateStatus?: ValidateStatus;
144
+ /** 帮助文本(错误时显示错误,否则显示 help) */
145
+ help?: React.ReactNode;
146
+ /** 不渲染外层 label/wrapper,仅包 children */
147
+ noStyle?: boolean;
148
+ /** 覆盖父级 labelCol */
149
+ labelCol?: ColProps;
150
+ /** 覆盖父级 wrapperCol */
151
+ wrapperCol?: ColProps;
152
+ /** 覆盖父级 colon */
153
+ colon?: boolean;
154
+ /** 覆盖父级 requiredMark */
155
+ requiredMark?: RequiredMark;
156
+ /** 覆盖父级 layout */
157
+ layout?: FormItemLayout;
158
+ /** 字段初始值(仅在挂载时生效一次) */
159
+ initialValue?: StoreValue;
160
+ /** 额外 className */
161
+ className?: string;
162
+ /** 子节点:通常是受控控件;无 name 时允许传入纯文本 */
163
+ children?: React.ReactNode;
164
+ }
@@ -0,0 +1,6 @@
1
+ //#region packages/react/src/components/Form/types.ts
2
+ function e(e) {
3
+ return typeof e == "string" ? e : typeof e == "number" ? String(e) : e.map((e) => String(e)).join(".");
4
+ }
5
+ //#endregion
6
+ export { e as stringifyNamePath };
@@ -0,0 +1,15 @@
1
+ import type { FormInstance, ValidateError } from './types';
2
+ interface FormOptions {
3
+ initialValues?: Record<string, unknown>;
4
+ onValuesChange?: (changed: Record<string, unknown>, all: Record<string, unknown>) => void;
5
+ onFinish?: (values: Record<string, unknown>) => void;
6
+ onFinishFailed?: (info: {
7
+ values: Record<string, unknown>;
8
+ errorFields: ValidateError[];
9
+ outOfDate: boolean;
10
+ }) => void;
11
+ /** 提交回调:Form 触发 submit 时调用(先校验) */
12
+ submit: () => void;
13
+ }
14
+ export declare function useForm<T = Record<string, unknown>>(options?: Omit<FormOptions, 'submit'>): [FormInstance<T>];
15
+ export {};