@expcat/tigercat-react 0.0.65 → 0.0.67

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/styles/index.css +4 -0
  2. package/dist/styles/index.d.mts +2 -0
  3. package/package.json +12 -9
  4. package/dist/chunk-2DOPHSZP.js +0 -32
  5. package/dist/chunk-2TS6X5RA.js +0 -73
  6. package/dist/chunk-2Y327ZU4.js +0 -493
  7. package/dist/chunk-3OF7XPIQ.js +0 -90
  8. package/dist/chunk-3WPKVV4N.js +0 -140
  9. package/dist/chunk-5FRENLDC.js +0 -194
  10. package/dist/chunk-5QKMQRCW.js +0 -89
  11. package/dist/chunk-5ZVSFIZD.js +0 -50
  12. package/dist/chunk-6MGEGOYJ.js +0 -108
  13. package/dist/chunk-6PUSRC6S.js +0 -68
  14. package/dist/chunk-72ZRDBXN.js +0 -25
  15. package/dist/chunk-77D7VQMG.js +0 -43
  16. package/dist/chunk-7P6PHSFM.js +0 -548
  17. package/dist/chunk-AG6GVQ5O.js +0 -271
  18. package/dist/chunk-AQ6DHCP6.js +0 -53
  19. package/dist/chunk-AQQRWISY.js +0 -184
  20. package/dist/chunk-C5EFBJBR.js +0 -540
  21. package/dist/chunk-D3I2SY7X.js +0 -301
  22. package/dist/chunk-DZJUFU55.js +0 -300
  23. package/dist/chunk-EI2GHMQS.js +0 -37
  24. package/dist/chunk-ENR3RIMM.js +0 -205
  25. package/dist/chunk-EQWQXURG.js +0 -18
  26. package/dist/chunk-EUHWE7MN.js +0 -267
  27. package/dist/chunk-FAKTU64M.js +0 -67
  28. package/dist/chunk-FQ6UHRAO.js +0 -499
  29. package/dist/chunk-GX74TC62.js +0 -54
  30. package/dist/chunk-HDDBBZQH.js +0 -321
  31. package/dist/chunk-IFY46RWU.js +0 -25
  32. package/dist/chunk-IQINYCU6.js +0 -99
  33. package/dist/chunk-IY4LEJYF.js +0 -78
  34. package/dist/chunk-JW64IJP2.js +0 -210
  35. package/dist/chunk-KUCFT2OA.js +0 -43
  36. package/dist/chunk-LNKI6HQ3.js +0 -152
  37. package/dist/chunk-LXA2YBAO.js +0 -38
  38. package/dist/chunk-MKWXJZ3T.js +0 -74
  39. package/dist/chunk-NEULKOYJ.js +0 -48
  40. package/dist/chunk-NI2WNZRT.js +0 -38
  41. package/dist/chunk-OFCKGWTS.js +0 -12
  42. package/dist/chunk-OTRGVENC.js +0 -305
  43. package/dist/chunk-P273E6XE.js +0 -219
  44. package/dist/chunk-Q3DPJHNM.js +0 -407
  45. package/dist/chunk-QFVE7GKD.js +0 -109
  46. package/dist/chunk-QL6OBKEN.js +0 -84
  47. package/dist/chunk-QL6UEG3U.js +0 -27
  48. package/dist/chunk-QORSSZX4.js +0 -144
  49. package/dist/chunk-R4JSBXGG.js +0 -12
  50. package/dist/chunk-R5BQHZWB.js +0 -698
  51. package/dist/chunk-R7MS42PL.js +0 -90
  52. package/dist/chunk-TB2UHDOZ.js +0 -19
  53. package/dist/chunk-TBIEWDY5.js +0 -175
  54. package/dist/chunk-TJFS44SH.js +0 -48
  55. package/dist/chunk-TZ26HQAW.js +0 -85
  56. package/dist/chunk-U4ZVEPYD.js +0 -71
  57. package/dist/chunk-UFAXJVMD.js +0 -120
  58. package/dist/chunk-VJJ76I7U.js +0 -19
  59. package/dist/chunk-VO4WDK4K.js +0 -37
  60. package/dist/chunk-VSF4DF7N.js +0 -84
  61. package/dist/chunk-VVO4V4IK.js +0 -56
  62. package/dist/chunk-WK5HN4OH.js +0 -113
  63. package/dist/chunk-XZDJ5FRB.js +0 -333
  64. package/dist/chunk-YE2M2HNM.js +0 -168
  65. package/dist/chunk-YYGTJKP5.js +0 -39
  66. package/dist/chunk-ZREFCRX3.js +0 -52
  67. package/dist/components/Alert.d.ts +0 -24
  68. package/dist/components/Alert.js +0 -10
  69. package/dist/components/Avatar.d.ts +0 -12
  70. package/dist/components/Avatar.js +0 -10
  71. package/dist/components/Badge.d.ts +0 -12
  72. package/dist/components/Badge.js +0 -10
  73. package/dist/components/Breadcrumb.d.ts +0 -13
  74. package/dist/components/Breadcrumb.js +0 -14
  75. package/dist/components/BreadcrumbItem.d.ts +0 -21
  76. package/dist/components/BreadcrumbItem.js +0 -11
  77. package/dist/components/Button.d.ts +0 -8
  78. package/dist/components/Button.js +0 -10
  79. package/dist/components/Card.d.ts +0 -33
  80. package/dist/components/Card.js +0 -10
  81. package/dist/components/Checkbox.d.ts +0 -48
  82. package/dist/components/Checkbox.js +0 -11
  83. package/dist/components/CheckboxGroup.d.ts +0 -39
  84. package/dist/components/CheckboxGroup.js +0 -14
  85. package/dist/components/Code.d.ts +0 -9
  86. package/dist/components/Code.js +0 -16
  87. package/dist/components/Col.d.ts +0 -7
  88. package/dist/components/Col.js +0 -11
  89. package/dist/components/ConfigProvider.d.ts +0 -14
  90. package/dist/components/ConfigProvider.js +0 -14
  91. package/dist/components/Container.d.ts +0 -13
  92. package/dist/components/Container.js +0 -10
  93. package/dist/components/Content.d.ts +0 -9
  94. package/dist/components/Content.js +0 -10
  95. package/dist/components/DatePicker.d.ts +0 -24
  96. package/dist/components/DatePicker.js +0 -10
  97. package/dist/components/Descriptions.d.ts +0 -53
  98. package/dist/components/Descriptions.js +0 -16
  99. package/dist/components/Divider.d.ts +0 -12
  100. package/dist/components/Divider.js +0 -10
  101. package/dist/components/Drawer.d.ts +0 -19
  102. package/dist/components/Drawer.js +0 -11
  103. package/dist/components/Dropdown.d.ts +0 -22
  104. package/dist/components/Dropdown.js +0 -16
  105. package/dist/components/DropdownItem.d.ts +0 -17
  106. package/dist/components/DropdownItem.js +0 -13
  107. package/dist/components/DropdownMenu.d.ts +0 -13
  108. package/dist/components/DropdownMenu.js +0 -10
  109. package/dist/components/Footer.d.ts +0 -9
  110. package/dist/components/Footer.js +0 -10
  111. package/dist/components/Form.d.ts +0 -56
  112. package/dist/components/Form.js +0 -14
  113. package/dist/components/FormItem.d.ts +0 -16
  114. package/dist/components/FormItem.js +0 -11
  115. package/dist/components/Header.d.ts +0 -9
  116. package/dist/components/Header.js +0 -10
  117. package/dist/components/Icon.d.ts +0 -9
  118. package/dist/components/Icon.js +0 -10
  119. package/dist/components/Input.d.ts +0 -28
  120. package/dist/components/Input.js +0 -10
  121. package/dist/components/Layout.d.ts +0 -9
  122. package/dist/components/Layout.js +0 -10
  123. package/dist/components/Link.d.ts +0 -10
  124. package/dist/components/Link.js +0 -10
  125. package/dist/components/List.d.ts +0 -94
  126. package/dist/components/List.js +0 -12
  127. package/dist/components/Loading.d.ts +0 -8
  128. package/dist/components/Loading.js +0 -10
  129. package/dist/components/Menu.d.ts +0 -35
  130. package/dist/components/Menu.js +0 -14
  131. package/dist/components/MenuItem.d.ts +0 -20
  132. package/dist/components/MenuItem.js +0 -11
  133. package/dist/components/MenuItemGroup.d.ts +0 -16
  134. package/dist/components/MenuItemGroup.js +0 -12
  135. package/dist/components/Message.d.ts +0 -44
  136. package/dist/components/Message.js +0 -20
  137. package/dist/components/Modal.d.ts +0 -41
  138. package/dist/components/Modal.js +0 -11
  139. package/dist/components/Notification.d.ts +0 -40
  140. package/dist/components/Notification.js +0 -20
  141. package/dist/components/Pagination.d.ts +0 -11
  142. package/dist/components/Pagination.js +0 -16
  143. package/dist/components/Popconfirm.d.ts +0 -34
  144. package/dist/components/Popconfirm.js +0 -10
  145. package/dist/components/Popover.d.ts +0 -14
  146. package/dist/components/Popover.js +0 -10
  147. package/dist/components/Progress.d.ts +0 -8
  148. package/dist/components/Progress.js +0 -10
  149. package/dist/components/Radio.d.ts +0 -20
  150. package/dist/components/Radio.js +0 -11
  151. package/dist/components/RadioGroup.d.ts +0 -28
  152. package/dist/components/RadioGroup.js +0 -14
  153. package/dist/components/Row.d.ts +0 -11
  154. package/dist/components/Row.js +0 -14
  155. package/dist/components/Select.d.ts +0 -23
  156. package/dist/components/Select.js +0 -10
  157. package/dist/components/Sidebar.d.ts +0 -9
  158. package/dist/components/Sidebar.js +0 -10
  159. package/dist/components/Skeleton.d.ts +0 -7
  160. package/dist/components/Skeleton.js +0 -10
  161. package/dist/components/Slider.d.ts +0 -12
  162. package/dist/components/Slider.js +0 -10
  163. package/dist/components/Space.d.ts +0 -11
  164. package/dist/components/Space.js +0 -10
  165. package/dist/components/Steps.d.ts +0 -31
  166. package/dist/components/Steps.js +0 -14
  167. package/dist/components/StepsItem.d.ts +0 -36
  168. package/dist/components/StepsItem.js +0 -10
  169. package/dist/components/SubMenu.d.ts +0 -20
  170. package/dist/components/SubMenu.js +0 -13
  171. package/dist/components/Switch.d.ts +0 -12
  172. package/dist/components/Switch.js +0 -10
  173. package/dist/components/TabPane.d.ts +0 -42
  174. package/dist/components/TabPane.js +0 -10
  175. package/dist/components/Table.d.ts +0 -46
  176. package/dist/components/Table.js +0 -10
  177. package/dist/components/Tabs.d.ts +0 -43
  178. package/dist/components/Tabs.js +0 -14
  179. package/dist/components/Tag.d.ts +0 -16
  180. package/dist/components/Tag.js +0 -10
  181. package/dist/components/Text.d.ts +0 -9
  182. package/dist/components/Text.js +0 -10
  183. package/dist/components/Textarea.d.ts +0 -13
  184. package/dist/components/Textarea.js +0 -10
  185. package/dist/components/TimePicker.d.ts +0 -28
  186. package/dist/components/TimePicker.js +0 -10
  187. package/dist/components/Timeline.d.ts +0 -47
  188. package/dist/components/Timeline.js +0 -10
  189. package/dist/components/Tooltip.d.ts +0 -15
  190. package/dist/components/Tooltip.js +0 -10
  191. package/dist/components/Tree.d.ts +0 -154
  192. package/dist/components/Tree.js +0 -16
  193. package/dist/components/Upload.d.ts +0 -16
  194. package/dist/components/Upload.js +0 -11
  195. package/dist/index.d.ts +0 -77
  196. package/dist/index.js +0 -364
@@ -1,305 +0,0 @@
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;
@@ -1,219 +0,0 @@
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;