x-ui-design 1.0.31-gamma.1 → 1.0.33

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 (218) hide show
  1. package/.github/workflows/x-ui-design.yml +14 -0
  2. package/README.md +22 -1
  3. package/compile.sh +15 -0
  4. package/dist/{components → esm/types/components}/DatePicker/DatePicker.d.ts +2 -1
  5. package/dist/{components → esm/types/components}/DatePicker/RangePicker/RangePicker.d.ts +2 -1
  6. package/dist/{components → esm/types/components}/Dropdown/Dropdown.d.ts +2 -1
  7. package/dist/{components → esm/types/components}/Empty/Empty.d.ts +2 -1
  8. package/dist/{components → esm/types/components}/Form/Item/Item.d.ts +2 -1
  9. package/dist/esm/types/components/Icons/Icons.d.ts +19 -0
  10. package/dist/{components → esm/types/components}/Input/Input.d.ts +2 -1
  11. package/dist/{components → esm/types/components}/Input/Textarea/Textarea.d.ts +2 -1
  12. package/dist/{components → esm/types/components}/Popover/Popover.d.ts +2 -1
  13. package/dist/{components → esm/types/components}/Radio/Button/Button.d.ts +2 -1
  14. package/dist/{components → esm/types/components}/Radio/Group/Group.d.ts +2 -1
  15. package/dist/{components → esm/types/components}/Radio/Radio.d.ts +2 -1
  16. package/dist/{components → esm/types/components}/Result/Result.d.ts +2 -1
  17. package/dist/{components → esm/types/components}/Switch/Switch.d.ts +2 -1
  18. package/dist/{components → esm/types/components}/Upload/Upload.d.ts +2 -1
  19. package/dist/esm/types/index.d.ts +50 -0
  20. package/dist/{types → esm/types/types}/input.d.ts +2 -2
  21. package/dist/index.d.ts +144 -1
  22. package/dist/index.esm.js +4233 -3792
  23. package/dist/index.esm.js.map +1 -1
  24. package/dist/index.js +4338 -3897
  25. package/dist/index.js.map +1 -1
  26. package/eslint.config.mjs +16 -0
  27. package/lib/components/Button/Button.tsx +136 -0
  28. package/lib/components/Button/index.ts +1 -0
  29. package/lib/components/Button/style.css +197 -0
  30. package/lib/components/Checkbox/Checkbox.tsx +131 -0
  31. package/lib/components/Checkbox/index.ts +1 -0
  32. package/lib/components/Checkbox/style.css +95 -0
  33. package/lib/components/ConditionalWrapper/index.tsx +12 -0
  34. package/lib/components/DatePicker/DatePicker.tsx +526 -0
  35. package/lib/components/DatePicker/RangePicker/RangePicker.tsx +500 -0
  36. package/lib/components/DatePicker/RangePicker/index.ts +1 -0
  37. package/lib/components/DatePicker/RangePicker/style.css +434 -0
  38. package/lib/components/DatePicker/TimePicker/TimePicker.tsx +497 -0
  39. package/lib/components/DatePicker/TimePicker/index.ts +1 -0
  40. package/lib/components/DatePicker/TimePicker/style.css +197 -0
  41. package/lib/components/DatePicker/index.ts +1 -0
  42. package/lib/components/DatePicker/style.css +318 -0
  43. package/lib/components/Dropdown/Dropdown.tsx +234 -0
  44. package/lib/components/Dropdown/index.ts +1 -0
  45. package/lib/components/Dropdown/style.css +124 -0
  46. package/lib/components/Empty/Empty.tsx +45 -0
  47. package/lib/components/Empty/index.ts +1 -0
  48. package/lib/components/Empty/style.css +13 -0
  49. package/lib/components/Form/Form.tsx +130 -0
  50. package/lib/components/Form/Item/Item.tsx +294 -0
  51. package/lib/components/Form/Item/index.ts +1 -0
  52. package/lib/components/Form/Item/style.css +61 -0
  53. package/lib/components/Form/index.ts +1 -0
  54. package/lib/components/Icons/Icons.tsx +433 -0
  55. package/lib/components/Icons/index.ts +15 -0
  56. package/lib/components/Input/Input.tsx +218 -0
  57. package/lib/components/Input/Textarea/Textarea.tsx +110 -0
  58. package/lib/components/Input/Textarea/index.ts +1 -0
  59. package/lib/components/Input/Textarea/style.css +104 -0
  60. package/lib/components/Input/index.ts +1 -0
  61. package/lib/components/Input/style.css +137 -0
  62. package/lib/components/Menu/Item/Item.tsx +65 -0
  63. package/lib/components/Menu/Menu.tsx +261 -0
  64. package/lib/components/Menu/SubMenu/SubMenu.tsx +68 -0
  65. package/lib/components/Menu/index.css +145 -0
  66. package/lib/components/Menu/index.ts +1 -0
  67. package/lib/components/Popover/Popover.tsx +135 -0
  68. package/lib/components/Popover/index.ts +1 -0
  69. package/lib/components/Popover/style.css +82 -0
  70. package/lib/components/Radio/Button/Button.tsx +42 -0
  71. package/lib/components/Radio/Button/index.ts +1 -0
  72. package/lib/components/Radio/Button/style.css +43 -0
  73. package/lib/components/Radio/Group/Group.tsx +105 -0
  74. package/lib/components/Radio/Group/index.ts +1 -0
  75. package/lib/components/Radio/Group/style.css +53 -0
  76. package/lib/components/Radio/Radio.tsx +83 -0
  77. package/lib/components/Radio/index.ts +1 -0
  78. package/lib/components/Radio/style.css +73 -0
  79. package/lib/components/Result/Result.tsx +39 -0
  80. package/lib/components/Result/index.ts +1 -0
  81. package/lib/components/Result/style.css +173 -0
  82. package/lib/components/Select/Option/Option.tsx +49 -0
  83. package/lib/components/Select/Option/index.ts +1 -0
  84. package/lib/components/Select/Option/style.css +50 -0
  85. package/lib/components/Select/Select.tsx +935 -0
  86. package/lib/components/Select/Tag/Tag.tsx +43 -0
  87. package/lib/components/Select/Tag/index.ts +1 -0
  88. package/lib/components/Select/Tag/style.css +87 -0
  89. package/lib/components/Select/index.ts +1 -0
  90. package/lib/components/Select/style.css +186 -0
  91. package/lib/components/Skeleton/Avatar/Avatar.tsx +61 -0
  92. package/lib/components/Skeleton/Avatar/index.ts +1 -0
  93. package/lib/components/Skeleton/Avatar/style.css +27 -0
  94. package/lib/components/Skeleton/Button/Button.tsx +44 -0
  95. package/lib/components/Skeleton/Button/index.ts +1 -0
  96. package/lib/components/Skeleton/Button/style.css +50 -0
  97. package/lib/components/Skeleton/Image/Image.tsx +45 -0
  98. package/lib/components/Skeleton/Image/index.ts +1 -0
  99. package/lib/components/Skeleton/Image/style.css +23 -0
  100. package/lib/components/Skeleton/Input/Input.tsx +42 -0
  101. package/lib/components/Skeleton/Input/index.ts +1 -0
  102. package/lib/components/Skeleton/Input/style.css +56 -0
  103. package/lib/components/Skeleton/Skeleton.tsx +97 -0
  104. package/lib/components/Skeleton/index.ts +1 -0
  105. package/lib/components/Skeleton/style.css +84 -0
  106. package/lib/components/Switch/Switch.tsx +68 -0
  107. package/lib/components/Switch/index.css +50 -0
  108. package/lib/components/Switch/index.ts +1 -0
  109. package/lib/components/Upload/Upload.tsx +291 -0
  110. package/lib/components/Upload/index.ts +1 -0
  111. package/lib/components/Upload/style.css +151 -0
  112. package/lib/global.d.ts +1 -0
  113. package/lib/helpers/flatten.ts +26 -0
  114. package/lib/helpers/index.ts +52 -0
  115. package/lib/helpers/mask.ts +52 -0
  116. package/lib/hooks/useForm.ts +548 -0
  117. package/lib/hooks/usePosition.ts +206 -0
  118. package/lib/hooks/useWatch.ts +41 -0
  119. package/lib/hooks/useWatchError.ts +20 -0
  120. package/lib/index.ts +184 -0
  121. package/lib/styles/global.css +57 -0
  122. package/lib/types/button.ts +83 -0
  123. package/lib/types/checkbox.ts +32 -0
  124. package/lib/types/datepicker.ts +165 -0
  125. package/lib/types/dropdown.ts +41 -0
  126. package/lib/types/empty.ts +8 -0
  127. package/lib/types/form.ts +179 -0
  128. package/lib/types/index.ts +38 -0
  129. package/lib/types/input.ts +72 -0
  130. package/lib/types/menu.ts +55 -0
  131. package/lib/types/popover.ts +16 -0
  132. package/lib/types/radio.ts +69 -0
  133. package/lib/types/result.ts +22 -0
  134. package/lib/types/select.ts +126 -0
  135. package/lib/types/skeleton.ts +62 -0
  136. package/lib/types/switch.ts +22 -0
  137. package/lib/types/upload.ts +67 -0
  138. package/lib/utils/index.ts +37 -0
  139. package/lib/utils/lazy.ts +17 -0
  140. package/next.config.ts +7 -0
  141. package/package.json +18 -20
  142. package/rollup.config.js +71 -0
  143. package/src/app/favicon.ico +0 -0
  144. package/src/app/globals.css +48 -0
  145. package/src/app/layout.d.ts +5 -0
  146. package/src/app/layout.tsx +16 -0
  147. package/src/app/page.d.ts +1 -0
  148. package/src/app/page.tsx +22 -0
  149. package/tsconfig.json +46 -0
  150. package/dist/components/Icons/Icons.d.ts +0 -18
  151. /package/dist/{components → esm/types/components}/Button/Button.d.ts +0 -0
  152. /package/dist/{components → esm/types/components}/Button/index.d.ts +0 -0
  153. /package/dist/{components → esm/types/components}/Checkbox/Checkbox.d.ts +0 -0
  154. /package/dist/{components → esm/types/components}/Checkbox/index.d.ts +0 -0
  155. /package/dist/{components → esm/types/components}/ConditionalWrapper/index.d.ts +0 -0
  156. /package/dist/{components → esm/types/components}/DatePicker/RangePicker/index.d.ts +0 -0
  157. /package/dist/{components → esm/types/components}/DatePicker/TimePicker/TimePicker.d.ts +0 -0
  158. /package/dist/{components → esm/types/components}/DatePicker/TimePicker/index.d.ts +0 -0
  159. /package/dist/{components → esm/types/components}/DatePicker/index.d.ts +0 -0
  160. /package/dist/{components → esm/types/components}/Dropdown/index.d.ts +0 -0
  161. /package/dist/{components → esm/types/components}/Empty/index.d.ts +0 -0
  162. /package/dist/{components → esm/types/components}/Form/Form.d.ts +0 -0
  163. /package/dist/{components → esm/types/components}/Form/Item/index.d.ts +0 -0
  164. /package/dist/{components → esm/types/components}/Form/index.d.ts +0 -0
  165. /package/dist/{components → esm/types/components}/Icons/index.d.ts +0 -0
  166. /package/dist/{components → esm/types/components}/Input/Textarea/index.d.ts +0 -0
  167. /package/dist/{components → esm/types/components}/Input/index.d.ts +0 -0
  168. /package/dist/{components → esm/types/components}/Menu/Item/Item.d.ts +0 -0
  169. /package/dist/{components → esm/types/components}/Menu/Menu.d.ts +0 -0
  170. /package/dist/{components → esm/types/components}/Menu/SubMenu/SubMenu.d.ts +0 -0
  171. /package/dist/{components → esm/types/components}/Menu/index.d.ts +0 -0
  172. /package/dist/{components → esm/types/components}/Popover/index.d.ts +0 -0
  173. /package/dist/{components → esm/types/components}/Radio/Button/index.d.ts +0 -0
  174. /package/dist/{components → esm/types/components}/Radio/Group/index.d.ts +0 -0
  175. /package/dist/{components → esm/types/components}/Radio/index.d.ts +0 -0
  176. /package/dist/{components → esm/types/components}/Result/index.d.ts +0 -0
  177. /package/dist/{components → esm/types/components}/Select/Option/Option.d.ts +0 -0
  178. /package/dist/{components → esm/types/components}/Select/Option/index.d.ts +0 -0
  179. /package/dist/{components → esm/types/components}/Select/Select.d.ts +0 -0
  180. /package/dist/{components → esm/types/components}/Select/Tag/Tag.d.ts +0 -0
  181. /package/dist/{components → esm/types/components}/Select/Tag/index.d.ts +0 -0
  182. /package/dist/{components → esm/types/components}/Select/index.d.ts +0 -0
  183. /package/dist/{components → esm/types/components}/Skeleton/Avatar/Avatar.d.ts +0 -0
  184. /package/dist/{components → esm/types/components}/Skeleton/Avatar/index.d.ts +0 -0
  185. /package/dist/{components → esm/types/components}/Skeleton/Button/Button.d.ts +0 -0
  186. /package/dist/{components → esm/types/components}/Skeleton/Button/index.d.ts +0 -0
  187. /package/dist/{components → esm/types/components}/Skeleton/Image/Image.d.ts +0 -0
  188. /package/dist/{components → esm/types/components}/Skeleton/Image/index.d.ts +0 -0
  189. /package/dist/{components → esm/types/components}/Skeleton/Input/Input.d.ts +0 -0
  190. /package/dist/{components → esm/types/components}/Skeleton/Input/index.d.ts +0 -0
  191. /package/dist/{components → esm/types/components}/Skeleton/Skeleton.d.ts +0 -0
  192. /package/dist/{components → esm/types/components}/Skeleton/index.d.ts +0 -0
  193. /package/dist/{components → esm/types/components}/Switch/index.d.ts +0 -0
  194. /package/dist/{components → esm/types/components}/Upload/index.d.ts +0 -0
  195. /package/dist/{helpers → esm/types/helpers}/flatten.d.ts +0 -0
  196. /package/dist/{helpers → esm/types/helpers}/index.d.ts +0 -0
  197. /package/dist/{helpers → esm/types/helpers}/mask.d.ts +0 -0
  198. /package/dist/{hooks → esm/types/hooks}/useForm.d.ts +0 -0
  199. /package/dist/{hooks → esm/types/hooks}/usePosition.d.ts +0 -0
  200. /package/dist/{hooks → esm/types/hooks}/useWatch.d.ts +0 -0
  201. /package/dist/{hooks → esm/types/hooks}/useWatchError.d.ts +0 -0
  202. /package/dist/{types → esm/types/types}/button.d.ts +0 -0
  203. /package/dist/{types → esm/types/types}/checkbox.d.ts +0 -0
  204. /package/dist/{types → esm/types/types}/datepicker.d.ts +0 -0
  205. /package/dist/{types → esm/types/types}/dropdown.d.ts +0 -0
  206. /package/dist/{types → esm/types/types}/empty.d.ts +0 -0
  207. /package/dist/{types → esm/types/types}/form.d.ts +0 -0
  208. /package/dist/{types → esm/types/types}/index.d.ts +0 -0
  209. /package/dist/{types → esm/types/types}/menu.d.ts +0 -0
  210. /package/dist/{types → esm/types/types}/popover.d.ts +0 -0
  211. /package/dist/{types → esm/types/types}/radio.d.ts +0 -0
  212. /package/dist/{types → esm/types/types}/result.d.ts +0 -0
  213. /package/dist/{types → esm/types/types}/select.d.ts +0 -0
  214. /package/dist/{types → esm/types/types}/skeleton.d.ts +0 -0
  215. /package/dist/{types → esm/types/types}/switch.d.ts +0 -0
  216. /package/dist/{types → esm/types/types}/upload.d.ts +0 -0
  217. /package/dist/{utils → esm/types/utils}/index.d.ts +0 -0
  218. /package/dist/{utils → esm/types/utils}/lazy.d.ts +0 -0
@@ -0,0 +1,206 @@
1
+ import { Placement } from "../types";
2
+ import {
3
+ CSSProperties,
4
+ RefObject,
5
+ useCallback,
6
+ useEffect,
7
+ useState
8
+ } from "react";
9
+
10
+ type TPosition = {
11
+ isOpen: boolean;
12
+ popupRef: RefObject<HTMLDivElement | null>;
13
+ triggerRef: RefObject<HTMLDivElement | null>;
14
+ getPopupContainer?: HTMLElement;
15
+ placement?: Placement;
16
+ offset?: number;
17
+ };
18
+
19
+ function getScrollParent(
20
+ el: HTMLElement | null,
21
+ includeSelf = false
22
+ ): HTMLElement | null {
23
+ if (!el) return null;
24
+
25
+ let current: HTMLElement | null = includeSelf ? el : el.parentElement;
26
+
27
+ while (current) {
28
+ const style = getComputedStyle(current);
29
+
30
+ const overflowY = style.overflowY;
31
+ const overflowX = style.overflowX;
32
+
33
+ const canScroll =
34
+ overflowY === 'auto' ||
35
+ overflowY === 'scroll' ||
36
+ overflowX === 'auto' ||
37
+ overflowX === 'scroll';
38
+
39
+ if (canScroll) {
40
+ return current;
41
+ }
42
+
43
+ current = current.parentElement;
44
+ }
45
+
46
+ return document.scrollingElement as HTMLElement;
47
+ }
48
+
49
+ const clampWithinContainer = (
50
+ left: number,
51
+ popupWidth: number,
52
+ containerRect: DOMRect
53
+ ) => {
54
+ const minLeft = containerRect.left + document.documentElement.scrollLeft;
55
+ const maxLeft = containerRect.right + document.documentElement.scrollLeft - popupWidth;
56
+
57
+ return {
58
+ minLeft,
59
+ maxLeft,
60
+ leftPosition: Math.min(Math.max(left, minLeft), maxLeft)
61
+ };
62
+ };
63
+
64
+ export const usePosition = ({
65
+ isOpen,
66
+ offset = 4,
67
+ popupRef,
68
+ placement,
69
+ triggerRef,
70
+ getPopupContainer
71
+ }: TPosition): {
72
+ showPlacement: string;
73
+ dropdownPosition: CSSProperties
74
+ } => {
75
+ const [showPlacement, setShowPlacement] = useState('');
76
+ const [_dropdownPosition, setDropdownPosition] = useState<CSSProperties>({});
77
+
78
+ const dropdownPosition = useCallback(() => {
79
+ if (!triggerRef.current) {
80
+ return {};
81
+ }
82
+
83
+ const inputRect = triggerRef.current?.getBoundingClientRect();
84
+ const dropdownHeight = popupRef.current?.offsetHeight || (popupRef.current?.offsetHeight || 0);
85
+ const containerRect = (getPopupContainer || getScrollParent(triggerRef.current, true) || document.body).getBoundingClientRect();
86
+
87
+ const spaceAbove = inputRect.top - containerRect.top;
88
+ const spaceBelow = containerRect.bottom - inputRect.bottom;
89
+
90
+ const _shouldShowAbove = spaceBelow < dropdownHeight && spaceAbove > dropdownHeight;
91
+ const hasRight = placement?.includes('Right');
92
+
93
+ if (getPopupContainer) {
94
+ const { minLeft, maxLeft, leftPosition } = clampWithinContainer(
95
+ hasRight
96
+ ? (inputRect.left || 0) + (triggerRef.current?.offsetWidth || 0) - (popupRef.current?.offsetWidth || 0)
97
+ : (inputRect.left || 0) + document.documentElement.scrollLeft,
98
+ popupRef.current?.offsetWidth || 0,
99
+ containerRect
100
+ );
101
+
102
+ const _center = (minLeft + maxLeft) < (popupRef.current?.offsetWidth || 0) ? 'center' : ''
103
+ setShowPlacement(_shouldShowAbove ? `bottom ${_center}` : `${_center}`);
104
+
105
+ const _top = (inputRect.top || 0) + document.documentElement.scrollTop;
106
+
107
+ if (_shouldShowAbove) {
108
+ setDropdownPosition({
109
+ top: _top - (popupRef.current?.offsetHeight || 0) + 4 - (offset !== 4 ? offset * 2 : 0),
110
+ left: leftPosition
111
+ })
112
+ } else {
113
+ setDropdownPosition({
114
+ top: _top + (triggerRef.current?.offsetHeight || 0) + offset,
115
+ left: leftPosition
116
+ })
117
+ }
118
+ } else {
119
+ setDropdownPosition({
120
+ top:
121
+ (_shouldShowAbove
122
+ ? triggerRef.current.offsetTop -
123
+ (popupRef.current?.offsetHeight || dropdownHeight) - offset * 2
124
+ : triggerRef.current.offsetTop + triggerRef.current?.offsetHeight) + offset,
125
+ ...(hasRight ? {
126
+ left: (() => {
127
+ const { minLeft, maxLeft, leftPosition } = clampWithinContainer(
128
+ triggerRef.current.offsetLeft +
129
+ (triggerRef.current?.offsetWidth || 0) -
130
+ (popupRef.current?.offsetWidth || dropdownHeight),
131
+ popupRef.current?.offsetWidth || dropdownHeight,
132
+ containerRect
133
+ )
134
+
135
+ const _center = (minLeft + maxLeft) < (popupRef.current?.offsetWidth || 0) ? 'center' : ''
136
+ setShowPlacement(_shouldShowAbove ? `bottom ${_center}` : `${_center}`);
137
+
138
+ return leftPosition
139
+ })()
140
+ } : {
141
+ left: (() => {
142
+ const { minLeft, maxLeft, leftPosition } = clampWithinContainer(
143
+ triggerRef.current.offsetLeft,
144
+ popupRef.current?.offsetWidth || dropdownHeight,
145
+ containerRect
146
+ );
147
+
148
+ const _center = (minLeft + maxLeft) < (popupRef.current?.offsetWidth || 0) ? 'center' : ''
149
+ setShowPlacement(_shouldShowAbove ? `bottom ${_center}` : `${_center}`);
150
+
151
+ return leftPosition
152
+ })()
153
+ })
154
+ });
155
+ }
156
+ }, [
157
+ offset,
158
+ popupRef,
159
+ placement,
160
+ triggerRef,
161
+ getPopupContainer
162
+ ]);
163
+
164
+ useEffect(() => {
165
+ if (!isOpen) return;
166
+
167
+ const _dropdownPosition = () => dropdownPosition();
168
+
169
+ _dropdownPosition();
170
+
171
+ const controller = new AbortController();
172
+
173
+ const scrollableParents = getScrollParent(triggerRef.current, true);
174
+
175
+ scrollableParents?.addEventListener('scroll', _dropdownPosition, {
176
+ passive: true,
177
+ signal: controller.signal
178
+ });
179
+
180
+ window.addEventListener('scroll', _dropdownPosition, {
181
+ passive: true,
182
+ signal: controller.signal
183
+ });
184
+
185
+ window.addEventListener('resize', _dropdownPosition, {
186
+ signal: controller.signal
187
+ });
188
+
189
+ return () => {
190
+ controller.abort();
191
+ };
192
+ }, [
193
+ isOpen,
194
+ triggerRef,
195
+ getPopupContainer,
196
+ dropdownPosition
197
+ ]);
198
+
199
+ return {
200
+ showPlacement,
201
+ dropdownPosition: {
202
+ ..._dropdownPosition,
203
+ opacity: Object.keys(_dropdownPosition).length ? 1 : 0
204
+ }
205
+ }
206
+ }
@@ -0,0 +1,41 @@
1
+ import { useContext, useEffect, useState } from 'react';
2
+ import { FormContext } from '../components/Form/Form';
3
+ import { RuleType } from '../types';
4
+ import { FormInstance } from '../types/form';
5
+
6
+ type UseWatchProps = {
7
+ name?: string;
8
+ defaultValue?: RuleType;
9
+ form?: FormInstance;
10
+ };
11
+
12
+ export const useWatch = ({ name, defaultValue, form }: UseWatchProps) => {
13
+ const formContext = useContext(FormContext);
14
+ const formInstance = form || formContext;
15
+
16
+ if (!formInstance) {
17
+ throw new Error(
18
+ 'useWatch must be used within a Form or with a form instance.'
19
+ );
20
+ }
21
+
22
+ const [value, setValue] = useState(() => {
23
+ return name
24
+ ? formInstance.getFieldValue(name) ?? defaultValue
25
+ : formInstance.getFieldsValue() ?? defaultValue;
26
+ });
27
+
28
+ useEffect(() => {
29
+ if (!name) {
30
+ const unsubscribe = formInstance.subscribeToForm(setValue);
31
+
32
+ return () => unsubscribe();
33
+ }
34
+
35
+ const unsubscribe = formInstance.subscribeToField(name, setValue);
36
+
37
+ return () => unsubscribe();
38
+ }, [name, formInstance]);
39
+
40
+ return value;
41
+ };
@@ -0,0 +1,20 @@
1
+ import { useEffect, useState } from 'react';
2
+ import type { FormInstance } from '../types/form';
3
+
4
+ export function useWatchError(form: FormInstance, name: string): string[] | undefined {
5
+ const [errors, setErrors] = useState<string[] | undefined>(form.getFieldError(name));
6
+
7
+ useEffect(() => {
8
+ // Subscribe directly to error changes
9
+ const unsubscribe = form.subscribeToError?.(name, (newErrors: string[] | undefined) => {
10
+ setErrors(newErrors);
11
+ });
12
+
13
+ // Initialize on mount
14
+ setErrors(form.getFieldError(name));
15
+
16
+ return unsubscribe;
17
+ }, [form, name]);
18
+
19
+ return errors;
20
+ }
package/lib/index.ts ADDED
@@ -0,0 +1,184 @@
1
+ // Styles
2
+ import dynamic from 'next/dynamic';
3
+ import './styles/global.css';
4
+
5
+ const Button = dynamic(() => import('@/components/Button/Button'), { ssr: false });
6
+ const Checkbox = dynamic(() => import('@/components/Checkbox/Checkbox'), { ssr: false });
7
+ const Switch = dynamic(() => import('@/components/Switch/Switch'), { ssr: false });
8
+ const Empty = dynamic(() => import('@/components/Empty/Empty'), { ssr: false });
9
+ const Upload = dynamic(() => import('@/components/Upload/Upload'), { ssr: false });
10
+
11
+ const DatePicker = dynamic(() => import('@/components/DatePicker/DatePicker'), { ssr: false });
12
+ const RangePicker = dynamic(() => import('@/components/DatePicker/RangePicker/RangePicker'), { ssr: false });
13
+ const TimePicker = dynamic(() => import('@/components/DatePicker/TimePicker/TimePicker'), { ssr: false });
14
+
15
+ const Form = dynamic(() => import('@/components/Form/Form'), { ssr: false });
16
+ const FormItem = dynamic(() => import('@/components/Form/Item/Item'), { ssr: false });
17
+
18
+ const Input = dynamic(() => import('@/components/Input/Input'), { ssr: false });
19
+ const Textarea = dynamic(() => import('@/components/Input/Textarea/Textarea'), { ssr: false });
20
+
21
+ const Radio = dynamic(() => import('@/components/Radio/Radio'), { ssr: false });
22
+ const RadioButton = dynamic(() => import('@/components/Radio/Button/Button'), { ssr: false });
23
+ const RadioGroup = dynamic(() => import('@/components/Radio/Group/Group'), { ssr: false });
24
+
25
+ const Select = dynamic(() => import('@/components/Select/Select'), { ssr: false });
26
+ const Option = dynamic(() => import('@/components/Select/Option/Option'), { ssr: false });
27
+ const Tag = dynamic(() => import('@/components/Select/Tag/Tag'), { ssr: false });
28
+
29
+ const Skeleton = dynamic(() => import('@/components/Skeleton/Skeleton'), { ssr: false });
30
+ const SkeletonAvatar = dynamic(() => import('@/components/Skeleton/Avatar/Avatar'), { ssr: false });
31
+ const SkeletonButton = dynamic(() => import('@/components/Skeleton/Button/Button'), { ssr: false });
32
+ const SkeletonImage = dynamic(() => import('@/components/Skeleton/Image/Image'), { ssr: false });
33
+ const SkeletonInput = dynamic(() => import('@/components/Skeleton/Input/Input'), { ssr: false });
34
+
35
+ const Menu = dynamic(() => import('@/components/Menu/Menu'), { ssr: false });
36
+ const MenuItem = dynamic(() => import('@/components/Menu/Item/Item'), { ssr: false });
37
+ const MenuSubMenu = dynamic(() => import('@/components/Menu/SubMenu/SubMenu'), { ssr: false });
38
+
39
+ const Dropdown = dynamic(() => import('@/components/Dropdown/Dropdown'), { ssr: false });
40
+
41
+ const Popover = dynamic(() => import('@/components/Popover/Popover'), { ssr: false });
42
+
43
+ const Result = dynamic(() => import('@/components/Result/Result'), { ssr: false });
44
+
45
+ export {
46
+ Button,
47
+ Checkbox,
48
+ Empty,
49
+ DatePicker,
50
+ RangePicker,
51
+ TimePicker,
52
+ Form,
53
+ FormItem,
54
+ Input,
55
+ Textarea,
56
+ Radio,
57
+ RadioButton,
58
+ RadioGroup,
59
+ Select,
60
+ Option,
61
+ Tag,
62
+ Skeleton,
63
+ SkeletonAvatar,
64
+ SkeletonButton,
65
+ SkeletonImage,
66
+ SkeletonInput,
67
+ Upload,
68
+ Switch,
69
+ Menu,
70
+ MenuItem,
71
+ MenuSubMenu,
72
+ Dropdown,
73
+ Popover,
74
+ Result
75
+ };
76
+
77
+ export {
78
+ ClearIcon,
79
+ ArrowIcon,
80
+ LoadingIcon,
81
+ CheckIcon,
82
+ SearchIcon,
83
+ CalendarIcon,
84
+ SuccessIcon,
85
+ ErrorIcon,
86
+ DateDistanceIcon,
87
+ TimeIcon,
88
+ StampleIcon,
89
+ TrashIcon,
90
+ SpinerIcon,
91
+ } from '@/components/Icons';
92
+
93
+ // Hooks
94
+ export { useForm } from '@/hooks/useForm';
95
+ export { useWatch } from '@/hooks/useWatch';
96
+
97
+ export type {
98
+ FormInstance,
99
+ RuleObject,
100
+ RuleRender,
101
+ FieldData,
102
+ FieldInstancesInputRef,
103
+ FieldError,
104
+ FormProps,
105
+ FormItemChildComponentProps
106
+ } from '@/types/form';
107
+
108
+ export type {
109
+ DefaultProps,
110
+ TargetProps,
111
+ RuleTypes,
112
+ RuleType,
113
+ MouseEventHandlerSelect,
114
+ SyntheticBaseEvent,
115
+ Placement
116
+ } from '@/types';
117
+
118
+ export type {
119
+ CheckboxProps
120
+ } from '@/types/checkbox';
121
+
122
+ export type {
123
+ InputProps,
124
+ TextareaProps
125
+ } from '@/types/input';
126
+
127
+ export type {
128
+ PopoverProps
129
+ } from '@/types/popover';
130
+
131
+ export type {
132
+ ButtonType,
133
+ ButtonProps,
134
+ BaseButtonProps
135
+ } from '@/types/button';
136
+
137
+ export type {
138
+ ItemType,
139
+ MenuProps,
140
+ SubMenuItem
141
+ } from '@/types/menu';
142
+
143
+ export type {
144
+ DropdownProps,
145
+ DropdownItemType,
146
+ } from '@/types/dropdown';
147
+
148
+ export type {
149
+ ResultProps,
150
+ ResultStatusType
151
+ } from '@/types/result';
152
+
153
+ export type {
154
+ RadioProps,
155
+ RadioGroupProps,
156
+ RadioButtonProps
157
+ } from '@/types/radio';
158
+
159
+ export type {
160
+ TDatePickerProps,
161
+ TRangePickerProps,
162
+ TimePickerProps
163
+ } from '@/types/datepicker';
164
+
165
+ export type {
166
+ SelectProps,
167
+ OptionType,
168
+ OptionProps,
169
+ CustomTagProps,
170
+ TagProps,
171
+ DisplayValueType
172
+ } from '@/types/select';
173
+
174
+ export type {
175
+ RcFile,
176
+ UploadFile,
177
+ UploadProps,
178
+ UploadChangeParam
179
+ } from '@/types/upload';
180
+
181
+ export { FormContext } from '@/components/Form/Form';
182
+
183
+ export { clsx, createArray, parseValue } from '@/helpers'
184
+ export { flattenChildren } from '@/helpers/flatten';
@@ -0,0 +1,57 @@
1
+ :root {
2
+ /* MAIN */
3
+ --xui-color-hover: #f5f5f5;
4
+ --xui-color-disabled: #e6e6e6;
5
+
6
+ --xui-primary-color: #1677ff;
7
+ --xui-primary-color-light: #40a9ff;
8
+
9
+ --xui-text-color: rgba(0, 0, 0, 0.88);
10
+ --xui-text-color-light: rgba(0, 0, 0, 0.5);
11
+
12
+ --xui-error-color: #ff4d4f;
13
+ --xui-error-color-light: #ff6668;
14
+ --xui-success-color: #52c41a;
15
+
16
+ --xui-background-color: #ffffff;
17
+
18
+ /* FONTS */
19
+ --xui-font-size-xs: 12px;
20
+ --xui-font-size-sm: 14px;
21
+ --xui-font-size-md: 14px;
22
+ --xui-font-size-lg: 16px;
23
+
24
+ /* BORDERS */
25
+ --xui-border-radius-sm: 4px;
26
+ --xui-border-radius-md: 4px;
27
+ --xui-border-radius-lg: 6px;
28
+
29
+ --xui-border-color: #d9d9d9;
30
+
31
+ /* SELECT */
32
+ --xui-select-primary-color: var(--xui-primary-color);
33
+ --xui-select-background-color: var(--xui-background-color);
34
+
35
+ /* MENU */
36
+ --xui-menu-inline-bg: rgba(0, 0, 0, 0.02);
37
+
38
+ /* RESULT */
39
+ --xui-result-bg: #fff;
40
+ --xui-result-color: rgba(0, 0, 0, 0.85);
41
+ --xui-subtle-color: rgba(0, 0, 0, 0.45);
42
+ --xui-padding: 24px;
43
+ --xui-gap: 16px;
44
+ --xui-icon-size: 72px;
45
+ --xui-max-width: 560px;
46
+ --xui-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial;
47
+ }
48
+
49
+ html {
50
+ font-family: sans-serif;
51
+ }
52
+
53
+ .globalEllipsis {
54
+ text-overflow: ellipsis;
55
+ overflow: hidden;
56
+ white-space: nowrap;
57
+ }
@@ -0,0 +1,83 @@
1
+ import { ButtonHTMLAttributes, CSSProperties, ReactNode } from 'react';
2
+
3
+ export const ButtonTypes = [
4
+ 'default',
5
+ 'primary',
6
+ 'dashed',
7
+ 'link',
8
+ 'text',
9
+ 'ghost'
10
+ ] as const;
11
+ export const ButtonShapes = ['default', 'circle', 'round'] as const;
12
+ export const ButtonVariantTypes = [
13
+ 'outlined',
14
+ 'dashed',
15
+ 'solid',
16
+ 'filled',
17
+ 'text',
18
+ 'link'
19
+ ] as const;
20
+ export const ButtonColorTypes = [
21
+ 'default',
22
+ 'primary',
23
+ 'danger',
24
+ 'blue',
25
+ 'purple',
26
+ 'cyan',
27
+ 'green',
28
+ 'magenta',
29
+ 'pink',
30
+ 'red',
31
+ 'orange',
32
+ 'yellow',
33
+ 'volcano',
34
+ 'geekblue',
35
+ 'lime',
36
+ 'gold'
37
+ ] as const;
38
+
39
+ export type ButtonType = (typeof ButtonTypes)[number];
40
+ export type ButtonShape = (typeof ButtonShapes)[number];
41
+ export type ButtonVariantType = (typeof ButtonVariantTypes)[number];
42
+ export type ButtonColorType = (typeof ButtonColorTypes)[number];
43
+ export type SizeType = 'small' | 'middle' | 'large' | undefined;
44
+ export type ButtonHTMLType = 'button' | 'submit' | 'reset';
45
+
46
+ export interface BaseButtonProps {
47
+ type?: ButtonType;
48
+ color?: ButtonColorType;
49
+ variant?: ButtonVariantType;
50
+ icon?: ReactNode;
51
+ iconPosition?: 'start' | 'end';
52
+ shape?: ButtonShape;
53
+ size?: SizeType;
54
+ disabled?: boolean;
55
+ loading?:
56
+ | boolean
57
+ | {
58
+ delay?: number;
59
+ icon?: ReactNode;
60
+ };
61
+ prefixCls?: string;
62
+ prefixClsV3?: string;
63
+ className?: string;
64
+ rootClassName?: string;
65
+ ghost?: boolean;
66
+ danger?: boolean;
67
+ block?: boolean;
68
+ children?: ReactNode;
69
+ classNames?: {
70
+ icon?: string;
71
+ };
72
+ styles?: {
73
+ icon?: CSSProperties;
74
+ };
75
+ child?: ReactNode
76
+ }
77
+
78
+ export interface ButtonProps
79
+ extends BaseButtonProps,
80
+ Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'color' | 'type'> {
81
+ href?: string;
82
+ htmlType?: ButtonHTMLType;
83
+ }
@@ -0,0 +1,32 @@
1
+ import {
2
+ ForwardedRef,
3
+ KeyboardEventHandler,
4
+ MouseEvent,
5
+ MouseEventHandler,
6
+ ReactNode
7
+ } from 'react';
8
+ import { DefaultProps, TargetProps } from '.';
9
+
10
+ export type CheckboxProps = DefaultProps & {
11
+ disabled?: boolean;
12
+ onChange?: (e: MouseEvent<HTMLInputElement> & TargetProps) => void;
13
+ onClick?: MouseEventHandler<HTMLElement>;
14
+ onMouseEnter?: MouseEventHandler<HTMLElement>;
15
+ onMouseLeave?: MouseEventHandler<HTMLElement>;
16
+ onKeyPress?: KeyboardEventHandler<HTMLElement>;
17
+ onKeyDown?: KeyboardEventHandler<HTMLElement>;
18
+ value?: boolean;
19
+ tabIndex?: number;
20
+ name?: string;
21
+ children?: ReactNode;
22
+ id?: string;
23
+ autoFocus?: boolean;
24
+ type?: string;
25
+ skipGroup?: boolean;
26
+ required?: boolean;
27
+ defaultChecked?: boolean;
28
+ checked?: boolean;
29
+ titleClick?: boolean;
30
+ ref?: ForwardedRef<HTMLDivElement>;
31
+ controlled?: boolean;
32
+ };