@expcat/tigercat-react 0.0.67 → 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 (196) hide show
  1. package/dist/chunk-2DOPHSZP.js +32 -0
  2. package/dist/chunk-2TS6X5RA.js +73 -0
  3. package/dist/chunk-2Y327ZU4.js +493 -0
  4. package/dist/chunk-3OF7XPIQ.js +90 -0
  5. package/dist/chunk-3WPKVV4N.js +140 -0
  6. package/dist/chunk-5FRENLDC.js +194 -0
  7. package/dist/chunk-5QKMQRCW.js +89 -0
  8. package/dist/chunk-5ZVSFIZD.js +50 -0
  9. package/dist/chunk-6MGEGOYJ.js +108 -0
  10. package/dist/chunk-6PUSRC6S.js +68 -0
  11. package/dist/chunk-72ZRDBXN.js +25 -0
  12. package/dist/chunk-77D7VQMG.js +43 -0
  13. package/dist/chunk-7P6PHSFM.js +548 -0
  14. package/dist/chunk-AG6GVQ5O.js +271 -0
  15. package/dist/chunk-AQ6DHCP6.js +53 -0
  16. package/dist/chunk-AQQRWISY.js +184 -0
  17. package/dist/chunk-C5EFBJBR.js +540 -0
  18. package/dist/chunk-D3I2SY7X.js +301 -0
  19. package/dist/chunk-DZJUFU55.js +300 -0
  20. package/dist/chunk-EI2GHMQS.js +37 -0
  21. package/dist/chunk-ENR3RIMM.js +205 -0
  22. package/dist/chunk-EQWQXURG.js +18 -0
  23. package/dist/chunk-EUHWE7MN.js +267 -0
  24. package/dist/chunk-FAKTU64M.js +67 -0
  25. package/dist/chunk-FQ6UHRAO.js +499 -0
  26. package/dist/chunk-GX74TC62.js +54 -0
  27. package/dist/chunk-HDDBBZQH.js +321 -0
  28. package/dist/chunk-IFY46RWU.js +25 -0
  29. package/dist/chunk-IQINYCU6.js +99 -0
  30. package/dist/chunk-IY4LEJYF.js +78 -0
  31. package/dist/chunk-JW64IJP2.js +210 -0
  32. package/dist/chunk-KUCFT2OA.js +43 -0
  33. package/dist/chunk-LNKI6HQ3.js +152 -0
  34. package/dist/chunk-LXA2YBAO.js +38 -0
  35. package/dist/chunk-MKWXJZ3T.js +74 -0
  36. package/dist/chunk-NEULKOYJ.js +48 -0
  37. package/dist/chunk-NI2WNZRT.js +38 -0
  38. package/dist/chunk-OFCKGWTS.js +12 -0
  39. package/dist/chunk-OTRGVENC.js +305 -0
  40. package/dist/chunk-P273E6XE.js +219 -0
  41. package/dist/chunk-Q3DPJHNM.js +407 -0
  42. package/dist/chunk-QFVE7GKD.js +109 -0
  43. package/dist/chunk-QL6OBKEN.js +84 -0
  44. package/dist/chunk-QL6UEG3U.js +27 -0
  45. package/dist/chunk-QORSSZX4.js +144 -0
  46. package/dist/chunk-R4JSBXGG.js +12 -0
  47. package/dist/chunk-R5BQHZWB.js +698 -0
  48. package/dist/chunk-R7MS42PL.js +90 -0
  49. package/dist/chunk-TB2UHDOZ.js +19 -0
  50. package/dist/chunk-TBIEWDY5.js +175 -0
  51. package/dist/chunk-TJFS44SH.js +48 -0
  52. package/dist/chunk-TZ26HQAW.js +85 -0
  53. package/dist/chunk-U4ZVEPYD.js +71 -0
  54. package/dist/chunk-UFAXJVMD.js +120 -0
  55. package/dist/chunk-VJJ76I7U.js +19 -0
  56. package/dist/chunk-VO4WDK4K.js +37 -0
  57. package/dist/chunk-VSF4DF7N.js +84 -0
  58. package/dist/chunk-VVO4V4IK.js +56 -0
  59. package/dist/chunk-WK5HN4OH.js +113 -0
  60. package/dist/chunk-XZDJ5FRB.js +333 -0
  61. package/dist/chunk-YE2M2HNM.js +168 -0
  62. package/dist/chunk-YYGTJKP5.js +39 -0
  63. package/dist/chunk-ZREFCRX3.js +52 -0
  64. package/dist/components/Alert.d.ts +24 -0
  65. package/dist/components/Alert.js +10 -0
  66. package/dist/components/Avatar.d.ts +12 -0
  67. package/dist/components/Avatar.js +10 -0
  68. package/dist/components/Badge.d.ts +12 -0
  69. package/dist/components/Badge.js +10 -0
  70. package/dist/components/Breadcrumb.d.ts +13 -0
  71. package/dist/components/Breadcrumb.js +14 -0
  72. package/dist/components/BreadcrumbItem.d.ts +21 -0
  73. package/dist/components/BreadcrumbItem.js +11 -0
  74. package/dist/components/Button.d.ts +8 -0
  75. package/dist/components/Button.js +10 -0
  76. package/dist/components/Card.d.ts +33 -0
  77. package/dist/components/Card.js +10 -0
  78. package/dist/components/Checkbox.d.ts +48 -0
  79. package/dist/components/Checkbox.js +11 -0
  80. package/dist/components/CheckboxGroup.d.ts +39 -0
  81. package/dist/components/CheckboxGroup.js +14 -0
  82. package/dist/components/Code.d.ts +9 -0
  83. package/dist/components/Code.js +16 -0
  84. package/dist/components/Col.d.ts +7 -0
  85. package/dist/components/Col.js +11 -0
  86. package/dist/components/ConfigProvider.d.ts +14 -0
  87. package/dist/components/ConfigProvider.js +14 -0
  88. package/dist/components/Container.d.ts +13 -0
  89. package/dist/components/Container.js +10 -0
  90. package/dist/components/Content.d.ts +9 -0
  91. package/dist/components/Content.js +10 -0
  92. package/dist/components/DatePicker.d.ts +24 -0
  93. package/dist/components/DatePicker.js +10 -0
  94. package/dist/components/Descriptions.d.ts +53 -0
  95. package/dist/components/Descriptions.js +16 -0
  96. package/dist/components/Divider.d.ts +12 -0
  97. package/dist/components/Divider.js +10 -0
  98. package/dist/components/Drawer.d.ts +19 -0
  99. package/dist/components/Drawer.js +11 -0
  100. package/dist/components/Dropdown.d.ts +22 -0
  101. package/dist/components/Dropdown.js +16 -0
  102. package/dist/components/DropdownItem.d.ts +17 -0
  103. package/dist/components/DropdownItem.js +13 -0
  104. package/dist/components/DropdownMenu.d.ts +13 -0
  105. package/dist/components/DropdownMenu.js +10 -0
  106. package/dist/components/Footer.d.ts +9 -0
  107. package/dist/components/Footer.js +10 -0
  108. package/dist/components/Form.d.ts +56 -0
  109. package/dist/components/Form.js +14 -0
  110. package/dist/components/FormItem.d.ts +16 -0
  111. package/dist/components/FormItem.js +11 -0
  112. package/dist/components/Header.d.ts +9 -0
  113. package/dist/components/Header.js +10 -0
  114. package/dist/components/Icon.d.ts +9 -0
  115. package/dist/components/Icon.js +10 -0
  116. package/dist/components/Input.d.ts +28 -0
  117. package/dist/components/Input.js +10 -0
  118. package/dist/components/Layout.d.ts +9 -0
  119. package/dist/components/Layout.js +10 -0
  120. package/dist/components/Link.d.ts +10 -0
  121. package/dist/components/Link.js +10 -0
  122. package/dist/components/List.d.ts +94 -0
  123. package/dist/components/List.js +12 -0
  124. package/dist/components/Loading.d.ts +8 -0
  125. package/dist/components/Loading.js +10 -0
  126. package/dist/components/Menu.d.ts +35 -0
  127. package/dist/components/Menu.js +14 -0
  128. package/dist/components/MenuItem.d.ts +20 -0
  129. package/dist/components/MenuItem.js +11 -0
  130. package/dist/components/MenuItemGroup.d.ts +16 -0
  131. package/dist/components/MenuItemGroup.js +12 -0
  132. package/dist/components/Message.d.ts +44 -0
  133. package/dist/components/Message.js +20 -0
  134. package/dist/components/Modal.d.ts +41 -0
  135. package/dist/components/Modal.js +11 -0
  136. package/dist/components/Notification.d.ts +40 -0
  137. package/dist/components/Notification.js +20 -0
  138. package/dist/components/Pagination.d.ts +11 -0
  139. package/dist/components/Pagination.js +16 -0
  140. package/dist/components/Popconfirm.d.ts +34 -0
  141. package/dist/components/Popconfirm.js +10 -0
  142. package/dist/components/Popover.d.ts +14 -0
  143. package/dist/components/Popover.js +10 -0
  144. package/dist/components/Progress.d.ts +8 -0
  145. package/dist/components/Progress.js +10 -0
  146. package/dist/components/Radio.d.ts +20 -0
  147. package/dist/components/Radio.js +11 -0
  148. package/dist/components/RadioGroup.d.ts +28 -0
  149. package/dist/components/RadioGroup.js +14 -0
  150. package/dist/components/Row.d.ts +11 -0
  151. package/dist/components/Row.js +14 -0
  152. package/dist/components/Select.d.ts +23 -0
  153. package/dist/components/Select.js +10 -0
  154. package/dist/components/Sidebar.d.ts +9 -0
  155. package/dist/components/Sidebar.js +10 -0
  156. package/dist/components/Skeleton.d.ts +7 -0
  157. package/dist/components/Skeleton.js +10 -0
  158. package/dist/components/Slider.d.ts +12 -0
  159. package/dist/components/Slider.js +10 -0
  160. package/dist/components/Space.d.ts +11 -0
  161. package/dist/components/Space.js +10 -0
  162. package/dist/components/Steps.d.ts +31 -0
  163. package/dist/components/Steps.js +14 -0
  164. package/dist/components/StepsItem.d.ts +36 -0
  165. package/dist/components/StepsItem.js +10 -0
  166. package/dist/components/SubMenu.d.ts +20 -0
  167. package/dist/components/SubMenu.js +13 -0
  168. package/dist/components/Switch.d.ts +12 -0
  169. package/dist/components/Switch.js +10 -0
  170. package/dist/components/TabPane.d.ts +42 -0
  171. package/dist/components/TabPane.js +10 -0
  172. package/dist/components/Table.d.ts +46 -0
  173. package/dist/components/Table.js +10 -0
  174. package/dist/components/Tabs.d.ts +43 -0
  175. package/dist/components/Tabs.js +14 -0
  176. package/dist/components/Tag.d.ts +16 -0
  177. package/dist/components/Tag.js +10 -0
  178. package/dist/components/Text.d.ts +9 -0
  179. package/dist/components/Text.js +10 -0
  180. package/dist/components/Textarea.d.ts +13 -0
  181. package/dist/components/Textarea.js +10 -0
  182. package/dist/components/TimePicker.d.ts +28 -0
  183. package/dist/components/TimePicker.js +10 -0
  184. package/dist/components/Timeline.d.ts +47 -0
  185. package/dist/components/Timeline.js +10 -0
  186. package/dist/components/Tooltip.d.ts +15 -0
  187. package/dist/components/Tooltip.js +10 -0
  188. package/dist/components/Tree.d.ts +154 -0
  189. package/dist/components/Tree.js +16 -0
  190. package/dist/components/Upload.d.ts +16 -0
  191. package/dist/components/Upload.js +11 -0
  192. package/dist/index.d.ts +77 -0
  193. package/dist/index.js +364 -0
  194. package/package.json +3 -6
  195. package/dist/styles/index.css +0 -4
  196. package/dist/styles/index.d.mts +0 -2
@@ -0,0 +1,305 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var client = require('react-dom/client');
5
+ var tigercatCore = require('@expcat/tigercat-core');
6
+ var jsxRuntime = require('react/jsx-runtime');
7
+
8
+ // src/components/Notification.tsx
9
+ var NOTIFICATION_CONTAINER_ID_PREFIX = "tiger-notification-container";
10
+ var notificationInstancesByPosition = {
11
+ "top-left": [],
12
+ "top-right": [],
13
+ "bottom-left": [],
14
+ "bottom-right": []
15
+ };
16
+ var instanceIdCounter = 0;
17
+ var containerRoots = {
18
+ "top-left": null,
19
+ "top-right": null,
20
+ "bottom-left": null,
21
+ "bottom-right": null
22
+ };
23
+ var updateCallbacks = {
24
+ "top-left": null,
25
+ "top-right": null,
26
+ "bottom-left": null,
27
+ "bottom-right": null
28
+ };
29
+ function getNextInstanceId() {
30
+ return ++instanceIdCounter;
31
+ }
32
+ var Icon = ({ path, className }) => {
33
+ return /* @__PURE__ */ jsxRuntime.jsx(
34
+ "svg",
35
+ {
36
+ className,
37
+ xmlns: "http://www.w3.org/2000/svg",
38
+ fill: "none",
39
+ viewBox: tigercatCore.icon24ViewBox,
40
+ stroke: "currentColor",
41
+ strokeWidth: tigercatCore.icon24StrokeWidth,
42
+ "aria-hidden": "true",
43
+ focusable: "false",
44
+ children: /* @__PURE__ */ jsxRuntime.jsx(
45
+ "path",
46
+ {
47
+ strokeLinecap: tigercatCore.icon24PathStrokeLinecap,
48
+ strokeLinejoin: tigercatCore.icon24PathStrokeLinejoin,
49
+ d: path
50
+ }
51
+ )
52
+ }
53
+ );
54
+ };
55
+ var NotificationItem = ({ notification: notification2, onClose }) => {
56
+ const [isVisible, setIsVisible] = react.useState(false);
57
+ react.useEffect(() => {
58
+ setTimeout(() => setIsVisible(true), 10);
59
+ }, []);
60
+ const colorScheme = tigercatCore.getNotificationTypeClasses(notification2.type, tigercatCore.defaultNotificationThemeColors);
61
+ const notificationClasses = tigercatCore.classNames(
62
+ tigercatCore.notificationBaseClasses,
63
+ colorScheme.bg,
64
+ colorScheme.border,
65
+ notification2.className,
66
+ isVisible ? "opacity-100 translate-x-0" : "opacity-0 translate-x-full"
67
+ );
68
+ const iconPath = notification2.icon || tigercatCore.getNotificationIconPath(notification2.type);
69
+ const iconClass = tigercatCore.classNames(tigercatCore.notificationIconClasses, colorScheme.icon);
70
+ const handleClose = () => {
71
+ setIsVisible(false);
72
+ setTimeout(() => onClose(notification2.id), 300);
73
+ };
74
+ const a11yRole = notification2.type === "error" ? "alert" : "status";
75
+ const ariaLive = notification2.type === "error" ? "assertive" : "polite";
76
+ return /* @__PURE__ */ jsxRuntime.jsxs(
77
+ "div",
78
+ {
79
+ className: notificationClasses,
80
+ role: a11yRole,
81
+ "aria-live": ariaLive,
82
+ "aria-atomic": "true",
83
+ onClick: notification2.onClick,
84
+ onKeyDown: (e) => {
85
+ if (!notification2.onClick) return;
86
+ if (e.key === "Enter" || e.key === " ") {
87
+ e.preventDefault();
88
+ notification2.onClick();
89
+ }
90
+ },
91
+ tabIndex: notification2.onClick ? 0 : void 0,
92
+ style: notification2.onClick ? { cursor: "pointer" } : void 0,
93
+ "data-tiger-notification": "",
94
+ "data-tiger-notification-type": notification2.type,
95
+ "data-tiger-notification-id": String(notification2.id),
96
+ children: [
97
+ /* @__PURE__ */ jsxRuntime.jsx(Icon, { path: iconPath, className: iconClass }),
98
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: tigercatCore.notificationContentClasses, children: [
99
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: tigercatCore.classNames(tigercatCore.notificationTitleClasses, colorScheme.titleText), children: notification2.title }),
100
+ notification2.description && /* @__PURE__ */ jsxRuntime.jsx("div", { className: tigercatCore.classNames(tigercatCore.notificationDescriptionClasses, colorScheme.descriptionText), children: notification2.description })
101
+ ] }),
102
+ notification2.closable && /* @__PURE__ */ jsxRuntime.jsx(
103
+ "button",
104
+ {
105
+ className: tigercatCore.notificationCloseButtonClasses,
106
+ onClick: (e) => {
107
+ e.stopPropagation();
108
+ handleClose();
109
+ },
110
+ "aria-label": "Close notification",
111
+ type: "button",
112
+ children: /* @__PURE__ */ jsxRuntime.jsx(Icon, { path: tigercatCore.notificationCloseIconPath, className: tigercatCore.notificationCloseIconClasses })
113
+ }
114
+ )
115
+ ]
116
+ }
117
+ );
118
+ };
119
+ var NotificationContainer = ({
120
+ position = "top-right"
121
+ }) => {
122
+ const [notifications, setNotifications] = react.useState([]);
123
+ react.useEffect(() => {
124
+ updateCallbacks[position] = () => {
125
+ setNotifications([...notificationInstancesByPosition[position]]);
126
+ };
127
+ updateCallbacks[position]();
128
+ return () => {
129
+ updateCallbacks[position] = null;
130
+ };
131
+ }, [position]);
132
+ const containerClasses = tigercatCore.classNames(
133
+ tigercatCore.notificationContainerBaseClasses,
134
+ tigercatCore.notificationPositionClasses[position]
135
+ );
136
+ const handleRemove = (id) => {
137
+ const instances = notificationInstancesByPosition[position];
138
+ const index = instances.findIndex((notif) => notif.id === id);
139
+ if (index !== -1) {
140
+ const instance = instances[index];
141
+ instances.splice(index, 1);
142
+ if (instance.onClose) {
143
+ instance.onClose();
144
+ }
145
+ updateCallbacks[position]?.();
146
+ }
147
+ };
148
+ return /* @__PURE__ */ jsxRuntime.jsx(
149
+ "div",
150
+ {
151
+ className: containerClasses,
152
+ id: `${NOTIFICATION_CONTAINER_ID_PREFIX}-${position}`,
153
+ "aria-live": "polite",
154
+ "aria-relevant": "additions",
155
+ "data-tiger-notification-container": "",
156
+ "data-tiger-notification-position": position,
157
+ children: notifications.map((notification2) => /* @__PURE__ */ jsxRuntime.jsx(
158
+ NotificationItem,
159
+ {
160
+ notification: notification2,
161
+ onClose: handleRemove
162
+ },
163
+ notification2.id
164
+ ))
165
+ }
166
+ );
167
+ };
168
+ function ensureContainer(position) {
169
+ if (!tigercatCore.isBrowser()) {
170
+ return;
171
+ }
172
+ const containerId = `${NOTIFICATION_CONTAINER_ID_PREFIX}-${position}`;
173
+ const rootId = `${containerId}-root`;
174
+ const existingRootEl = document.getElementById(rootId);
175
+ if (containerRoots[position] && !existingRootEl) {
176
+ containerRoots[position] = null;
177
+ updateCallbacks[position] = null;
178
+ }
179
+ if (containerRoots[position]) {
180
+ return;
181
+ }
182
+ let rootEl = existingRootEl;
183
+ if (!rootEl) {
184
+ rootEl = document.createElement("div");
185
+ rootEl.id = rootId;
186
+ document.body.appendChild(rootEl);
187
+ }
188
+ containerRoots[position] = client.createRoot(rootEl);
189
+ containerRoots[position].render(/* @__PURE__ */ jsxRuntime.jsx(NotificationContainer, { position }));
190
+ }
191
+ function addNotification(config) {
192
+ const position = config.position || "top-right";
193
+ ensureContainer(position);
194
+ const id = getNextInstanceId();
195
+ const instance = {
196
+ id,
197
+ type: config.type || "info",
198
+ title: config.title,
199
+ description: config.description,
200
+ duration: config.duration !== void 0 ? config.duration : 4500,
201
+ closable: config.closable !== void 0 ? config.closable : true,
202
+ onClose: config.onClose,
203
+ onClick: config.onClick,
204
+ icon: config.icon,
205
+ className: config.className,
206
+ position
207
+ };
208
+ notificationInstancesByPosition[position].push(instance);
209
+ if (updateCallbacks[position]) {
210
+ updateCallbacks[position]();
211
+ }
212
+ if (instance.duration > 0) {
213
+ setTimeout(() => {
214
+ removeNotification(id, position);
215
+ }, instance.duration);
216
+ }
217
+ return () => removeNotification(id, position);
218
+ }
219
+ function removeNotification(id, position) {
220
+ const instances = notificationInstancesByPosition[position];
221
+ const index = instances.findIndex((notif) => notif.id === id);
222
+ if (index !== -1) {
223
+ const instance = instances[index];
224
+ instances.splice(index, 1);
225
+ if (instance.onClose) {
226
+ instance.onClose();
227
+ }
228
+ if (updateCallbacks[position]) {
229
+ updateCallbacks[position]();
230
+ }
231
+ }
232
+ }
233
+ function clearAll(position) {
234
+ if (position) {
235
+ notificationInstancesByPosition[position].forEach((instance) => {
236
+ if (instance.onClose) {
237
+ instance.onClose();
238
+ }
239
+ });
240
+ notificationInstancesByPosition[position] = [];
241
+ if (updateCallbacks[position]) {
242
+ updateCallbacks[position]();
243
+ }
244
+ } else {
245
+ Object.keys(notificationInstancesByPosition).forEach((pos) => {
246
+ const p = pos;
247
+ notificationInstancesByPosition[p].forEach((instance) => {
248
+ if (instance.onClose) {
249
+ instance.onClose();
250
+ }
251
+ });
252
+ notificationInstancesByPosition[p] = [];
253
+ if (updateCallbacks[p]) {
254
+ updateCallbacks[p]();
255
+ }
256
+ });
257
+ }
258
+ }
259
+ function normalizeOptions(options) {
260
+ if (typeof options === "string") {
261
+ return { title: options };
262
+ }
263
+ return options;
264
+ }
265
+ var notification = {
266
+ /**
267
+ * Show an info notification
268
+ */
269
+ info(options) {
270
+ const config = normalizeOptions(options);
271
+ return addNotification({ ...config, type: "info" });
272
+ },
273
+ /**
274
+ * Show a success notification
275
+ */
276
+ success(options) {
277
+ const config = normalizeOptions(options);
278
+ return addNotification({ ...config, type: "success" });
279
+ },
280
+ /**
281
+ * Show a warning notification
282
+ */
283
+ warning(options) {
284
+ const config = normalizeOptions(options);
285
+ return addNotification({ ...config, type: "warning" });
286
+ },
287
+ /**
288
+ * Show an error notification
289
+ */
290
+ error(options) {
291
+ const config = normalizeOptions(options);
292
+ return addNotification({ ...config, type: "error" });
293
+ },
294
+ /**
295
+ * Clear all notifications
296
+ */
297
+ clear(position) {
298
+ clearAll(position);
299
+ }
300
+ };
301
+ var Notification_default = notification;
302
+
303
+ exports.NotificationContainer = NotificationContainer;
304
+ exports.Notification_default = Notification_default;
305
+ exports.notification = notification;
@@ -0,0 +1,219 @@
1
+ 'use strict';
2
+
3
+ var chunkJW64IJP2_js = require('./chunk-JW64IJP2.js');
4
+ var React = require('react');
5
+ var tigercatCore = require('@expcat/tigercat-core');
6
+ var jsxRuntime = require('react/jsx-runtime');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var React__default = /*#__PURE__*/_interopDefault(React);
11
+
12
+ var FormItem = ({
13
+ name,
14
+ label,
15
+ labelWidth,
16
+ required,
17
+ rules,
18
+ error: controlledError,
19
+ showMessage = true,
20
+ size,
21
+ children,
22
+ className
23
+ }) => {
24
+ const formContext = chunkJW64IJP2_js.useFormContext();
25
+ const [errorMessage, setErrorMessage] = React.useState("");
26
+ const reactId = React.useId();
27
+ const baseId = React.useMemo(() => `tiger-form-item-${reactId}`, [reactId]);
28
+ const labelId = `${baseId}-label`;
29
+ const fieldId = `${baseId}-field`;
30
+ const errorId = `${baseId}-error`;
31
+ const mergeAriaDescribedBy = React.useCallback(
32
+ (existing, next) => {
33
+ if (!existing) {
34
+ return next;
35
+ }
36
+ if (!next) {
37
+ return existing;
38
+ }
39
+ const parts = new Set(
40
+ `${existing} ${next}`.split(" ").map((s) => s.trim()).filter(Boolean)
41
+ );
42
+ return Array.from(parts).join(" ");
43
+ },
44
+ []
45
+ );
46
+ const actualSize = size || formContext?.size || "md";
47
+ const labelPosition = formContext?.labelPosition || "right";
48
+ const labelAlign = formContext?.labelAlign || "right";
49
+ const actualLabelWidth = React.useMemo(() => {
50
+ const width = labelWidth || formContext?.labelWidth;
51
+ if (typeof width === "number") {
52
+ return `${width}px`;
53
+ }
54
+ return width;
55
+ }, [labelWidth, formContext?.labelWidth]);
56
+ const showRequiredAsterisk = React.useMemo(() => {
57
+ if (required !== void 0) {
58
+ return required;
59
+ }
60
+ if (rules) {
61
+ const ruleArray = Array.isArray(rules) ? rules : [rules];
62
+ return ruleArray.some((rule) => rule.required);
63
+ }
64
+ if (name && formContext?.rules) {
65
+ const fieldRules = formContext.rules[name];
66
+ if (fieldRules) {
67
+ const ruleArray = Array.isArray(fieldRules) ? fieldRules : [fieldRules];
68
+ return ruleArray.some((rule) => rule.required);
69
+ }
70
+ }
71
+ return false;
72
+ }, [required, rules, name, formContext?.rules]);
73
+ const isRequired = React.useMemo(
74
+ () => showRequiredAsterisk && (formContext?.showRequiredAsterisk ?? true),
75
+ [showRequiredAsterisk, formContext?.showRequiredAsterisk]
76
+ );
77
+ React.useEffect(() => {
78
+ if (name && formContext?.errors) {
79
+ const error = tigercatCore.getFieldError(name, formContext.errors);
80
+ setErrorMessage(error || "");
81
+ }
82
+ }, [name, formContext?.errors]);
83
+ React.useEffect(() => {
84
+ if (controlledError !== void 0) {
85
+ setErrorMessage(controlledError);
86
+ }
87
+ }, [controlledError]);
88
+ React.useEffect(() => {
89
+ if (!name || !formContext) {
90
+ return;
91
+ }
92
+ if (rules) {
93
+ formContext.registerFieldRules(name, rules);
94
+ }
95
+ return () => {
96
+ formContext.registerFieldRules(name, void 0);
97
+ };
98
+ }, [name, rules, formContext]);
99
+ const handleBlur = React.useCallback(() => {
100
+ if (name && formContext) {
101
+ formContext.validateField(name, rules, "blur");
102
+ }
103
+ }, [name, formContext, rules]);
104
+ const handleChange = React.useCallback(() => {
105
+ if (name && formContext) {
106
+ formContext.validateField(name, rules, "change");
107
+ }
108
+ }, [name, formContext, rules]);
109
+ const hasError = React.useMemo(() => !!errorMessage, [errorMessage]);
110
+ const describedById = React.useMemo(
111
+ () => showMessage && hasError ? errorId : void 0,
112
+ [showMessage, hasError, errorId]
113
+ );
114
+ const onlyChild = React.useMemo(() => {
115
+ const count = React__default.default.Children.count(children);
116
+ if (count !== 1) {
117
+ return null;
118
+ }
119
+ return React__default.default.Children.toArray(children)[0] ?? null;
120
+ }, [children]);
121
+ const isClonableChild = React__default.default.isValidElement(onlyChild);
122
+ const childId = isClonableChild ? onlyChild.props.id : void 0;
123
+ const effectiveFieldId = childId ?? fieldId;
124
+ const enhancedChild = React.useMemo(() => {
125
+ if (!isClonableChild) {
126
+ return children;
127
+ }
128
+ const nextProps = {
129
+ id: effectiveFieldId,
130
+ "aria-invalid": hasError ? true : onlyChild.props["aria-invalid"],
131
+ "aria-required": isRequired ? true : onlyChild.props["aria-required"],
132
+ "aria-describedby": mergeAriaDescribedBy(onlyChild.props["aria-describedby"], describedById),
133
+ onBlur: (event) => {
134
+ onlyChild.props.onBlur?.(event);
135
+ handleBlur();
136
+ },
137
+ onChange: (event) => {
138
+ onlyChild.props.onChange?.(event);
139
+ handleChange();
140
+ }
141
+ };
142
+ return React__default.default.cloneElement(onlyChild, nextProps);
143
+ }, [
144
+ isClonableChild,
145
+ children,
146
+ onlyChild,
147
+ effectiveFieldId,
148
+ hasError,
149
+ isRequired,
150
+ mergeAriaDescribedBy,
151
+ describedById,
152
+ handleBlur,
153
+ handleChange
154
+ ]);
155
+ const formItemClasses = React.useMemo(
156
+ () => tigercatCore.classNames(
157
+ "tiger-form-item",
158
+ `tiger-form-item--${actualSize}`,
159
+ `tiger-form-item--label-${labelPosition}`,
160
+ hasError && "tiger-form-item--error",
161
+ formContext?.disabled && "tiger-form-item--disabled",
162
+ className
163
+ ),
164
+ [actualSize, labelPosition, hasError, formContext?.disabled, className]
165
+ );
166
+ const labelClasses = React.useMemo(
167
+ () => tigercatCore.classNames(
168
+ "tiger-form-item__label",
169
+ `tiger-form-item__label--${labelAlign}`,
170
+ isRequired && "tiger-form-item__label--required"
171
+ ),
172
+ [labelAlign, isRequired]
173
+ );
174
+ const labelStyles = React.useMemo(() => {
175
+ if (labelPosition === "top") {
176
+ return {};
177
+ }
178
+ return actualLabelWidth ? { width: actualLabelWidth } : {};
179
+ }, [labelPosition, actualLabelWidth]);
180
+ const errorClasses = React.useMemo(
181
+ () => tigercatCore.classNames("tiger-form-item__error", hasError && "tiger-form-item__error--show"),
182
+ [hasError]
183
+ );
184
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: formItemClasses, children: [
185
+ label && /* @__PURE__ */ jsxRuntime.jsxs(
186
+ "label",
187
+ {
188
+ id: labelId,
189
+ className: labelClasses,
190
+ style: labelStyles,
191
+ htmlFor: isClonableChild ? effectiveFieldId : void 0,
192
+ children: [
193
+ isRequired && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tiger-form-item__asterisk", children: "*" }),
194
+ label
195
+ ]
196
+ }
197
+ ),
198
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tiger-form-item__content", children: [
199
+ /* @__PURE__ */ jsxRuntime.jsx(
200
+ "div",
201
+ {
202
+ className: "tiger-form-item__field",
203
+ role: "group",
204
+ "aria-labelledby": label ? labelId : void 0,
205
+ "aria-describedby": describedById,
206
+ "aria-invalid": hasError ? true : void 0,
207
+ "aria-required": isRequired ? true : void 0,
208
+ onBlur: isClonableChild ? void 0 : handleBlur,
209
+ onChange: isClonableChild ? void 0 : handleChange,
210
+ children: enhancedChild
211
+ }
212
+ ),
213
+ showMessage && hasError && /* @__PURE__ */ jsxRuntime.jsx("div", { id: errorId, role: "alert", className: errorClasses, children: errorMessage })
214
+ ] })
215
+ ] });
216
+ };
217
+ FormItem.displayName = "TigerFormItem";
218
+
219
+ exports.FormItem = FormItem;