@lark-apaas/coding-template-nestjs-react-fullstack 0.1.36-alpha.20260903095202 → 0.1.36-alpha.20260903185731

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 (112) hide show
  1. package/package.json +1 -1
  2. package/template/client/src/components/ui/markdown.tsx +43 -0
  3. package/template/client/src/index.css +0 -1
  4. package/template/package-lock.json +5783 -13022
  5. package/template/package.json +5 -68
  6. package/template/client/src/components/business-ui/README.md +0 -519
  7. package/template/client/src/components/business-ui/api/chats/queries.ts +0 -39
  8. package/template/client/src/components/business-ui/api/chats/service.ts +0 -29
  9. package/template/client/src/components/business-ui/api/departments/queries.ts +0 -42
  10. package/template/client/src/components/business-ui/api/departments/service.ts +0 -18
  11. package/template/client/src/components/business-ui/api/files/service.ts +0 -28
  12. package/template/client/src/components/business-ui/api/user-profiles/queries.ts +0 -42
  13. package/template/client/src/components/business-ui/api/user-profiles/service.ts +0 -23
  14. package/template/client/src/components/business-ui/api/users/queries.ts +0 -34
  15. package/template/client/src/components/business-ui/api/users/service.ts +0 -40
  16. package/template/client/src/components/business-ui/chat-select/README.md +0 -128
  17. package/template/client/src/components/business-ui/chat-select/chat-item.tsx +0 -85
  18. package/template/client/src/components/business-ui/chat-select/chat-select-tag.tsx +0 -83
  19. package/template/client/src/components/business-ui/chat-select/chat-select.tsx +0 -197
  20. package/template/client/src/components/business-ui/chat-select/index.tsx +0 -12
  21. package/template/client/src/components/business-ui/chat-select/types.ts +0 -102
  22. package/template/client/src/components/business-ui/chat-select/use-chat-value.ts +0 -180
  23. package/template/client/src/components/business-ui/chat-select/utils.ts +0 -81
  24. package/template/client/src/components/business-ui/department-select/department-item.tsx +0 -55
  25. package/template/client/src/components/business-ui/department-select/department-select-field.tsx +0 -86
  26. package/template/client/src/components/business-ui/department-select/department-select-tag.tsx +0 -56
  27. package/template/client/src/components/business-ui/department-select/department-select.tsx +0 -168
  28. package/template/client/src/components/business-ui/department-select/icon-department.tsx +0 -22
  29. package/template/client/src/components/business-ui/department-select/index.tsx +0 -7
  30. package/template/client/src/components/business-ui/department-select/types.ts +0 -15
  31. package/template/client/src/components/business-ui/department-select/utils.ts +0 -17
  32. package/template/client/src/components/business-ui/entity-combobox/base-combobox-content.tsx +0 -35
  33. package/template/client/src/components/business-ui/entity-combobox/base-combobox-empty.tsx +0 -28
  34. package/template/client/src/components/business-ui/entity-combobox/base-combobox-error.tsx +0 -35
  35. package/template/client/src/components/business-ui/entity-combobox/base-combobox-item.tsx +0 -55
  36. package/template/client/src/components/business-ui/entity-combobox/base-combobox-list.tsx +0 -174
  37. package/template/client/src/components/business-ui/entity-combobox/base-combobox-loading.tsx +0 -19
  38. package/template/client/src/components/business-ui/entity-combobox/base-combobox-search.tsx +0 -31
  39. package/template/client/src/components/business-ui/entity-combobox/base-combobox-trigger.tsx +0 -281
  40. package/template/client/src/components/business-ui/entity-combobox/base-combobox.tsx +0 -132
  41. package/template/client/src/components/business-ui/entity-combobox/context.tsx +0 -19
  42. package/template/client/src/components/business-ui/entity-combobox/entity-combobox.tsx +0 -145
  43. package/template/client/src/components/business-ui/entity-combobox/highlight-text.tsx +0 -52
  44. package/template/client/src/components/business-ui/entity-combobox/hooks.tsx +0 -21
  45. package/template/client/src/components/business-ui/entity-combobox/index.tsx +0 -31
  46. package/template/client/src/components/business-ui/entity-combobox/item-pill.tsx +0 -179
  47. package/template/client/src/components/business-ui/entity-combobox/popover-wrapper.tsx +0 -149
  48. package/template/client/src/components/business-ui/entity-combobox/search-trigger.tsx +0 -262
  49. package/template/client/src/components/business-ui/entity-combobox/shared-types.ts +0 -296
  50. package/template/client/src/components/business-ui/entity-combobox/size-variants.tsx +0 -322
  51. package/template/client/src/components/business-ui/entity-combobox/types.ts +0 -246
  52. package/template/client/src/components/business-ui/entity-combobox/use-fetch-data.tsx +0 -81
  53. package/template/client/src/components/business-ui/entity-combobox/use-infinite-scroll.tsx +0 -99
  54. package/template/client/src/components/business-ui/entity-combobox/use-popover-outside-click.tsx +0 -32
  55. package/template/client/src/components/business-ui/form/checkbox-field.tsx +0 -83
  56. package/template/client/src/components/business-ui/form/context.tsx +0 -38
  57. package/template/client/src/components/business-ui/form/field-layout.tsx +0 -91
  58. package/template/client/src/components/business-ui/form/form.tsx +0 -54
  59. package/template/client/src/components/business-ui/form/hooks/form-context.tsx +0 -4
  60. package/template/client/src/components/business-ui/form/hooks/form-utils.ts +0 -23
  61. package/template/client/src/components/business-ui/form/hooks/form.tsx +0 -40
  62. package/template/client/src/components/business-ui/form/index.tsx +0 -4
  63. package/template/client/src/components/business-ui/form/input-field.tsx +0 -74
  64. package/template/client/src/components/business-ui/form/radio-group-field.tsx +0 -138
  65. package/template/client/src/components/business-ui/form/select-field.tsx +0 -155
  66. package/template/client/src/components/business-ui/form/switch-field.tsx +0 -66
  67. package/template/client/src/components/business-ui/form/textarea-field.tsx +0 -72
  68. package/template/client/src/components/business-ui/form/types.ts +0 -32
  69. package/template/client/src/components/business-ui/tiptap-editor/README.md +0 -324
  70. package/template/client/src/components/business-ui/tiptap-editor/components/attachment-toolbar-button.tsx +0 -74
  71. package/template/client/src/components/business-ui/tiptap-editor/components/blockquote-toolbar-button.tsx +0 -41
  72. package/template/client/src/components/business-ui/tiptap-editor/components/code-block-toolbar-button.tsx +0 -41
  73. package/template/client/src/components/business-ui/tiptap-editor/components/color-highlight-toolbar-button.tsx +0 -141
  74. package/template/client/src/components/business-ui/tiptap-editor/components/heading-toolbar-button.tsx +0 -99
  75. package/template/client/src/components/business-ui/tiptap-editor/components/horizontal-rule-toolbar-button.tsx +0 -39
  76. package/template/client/src/components/business-ui/tiptap-editor/components/image-upload-toolbar-button.tsx +0 -65
  77. package/template/client/src/components/business-ui/tiptap-editor/components/link-edit-form.tsx +0 -127
  78. package/template/client/src/components/business-ui/tiptap-editor/components/link-hover-toolbar.tsx +0 -380
  79. package/template/client/src/components/business-ui/tiptap-editor/components/link-toolbar-button.tsx +0 -96
  80. package/template/client/src/components/business-ui/tiptap-editor/components/list-toolbar-button.tsx +0 -75
  81. package/template/client/src/components/business-ui/tiptap-editor/components/mark-toolbar-button.tsx +0 -118
  82. package/template/client/src/components/business-ui/tiptap-editor/components/text-align-toolbar-button.tsx +0 -84
  83. package/template/client/src/components/business-ui/tiptap-editor/components/undo-redo-toolbar-button.tsx +0 -54
  84. package/template/client/src/components/business-ui/tiptap-editor/extensions/attachment.tsx +0 -539
  85. package/template/client/src/components/business-ui/tiptap-editor/extensions/code-block-shiki.tsx +0 -236
  86. package/template/client/src/components/business-ui/tiptap-editor/extensions/complete-kit.ts +0 -260
  87. package/template/client/src/components/business-ui/tiptap-editor/extensions/image.tsx +0 -456
  88. package/template/client/src/components/business-ui/tiptap-editor/hooks/use-tiptap-editor.ts +0 -47
  89. package/template/client/src/components/business-ui/tiptap-editor/index.ts +0 -38
  90. package/template/client/src/components/business-ui/tiptap-editor/tiptap-editor-complete.tsx +0 -112
  91. package/template/client/src/components/business-ui/tiptap-editor/tiptap-editor.tsx +0 -169
  92. package/template/client/src/components/business-ui/types/user.ts +0 -74
  93. package/template/client/src/components/business-ui/user-display/index.tsx +0 -2
  94. package/template/client/src/components/business-ui/user-display/overflow-tooltip-text.tsx +0 -90
  95. package/template/client/src/components/business-ui/user-display/type.ts +0 -27
  96. package/template/client/src/components/business-ui/user-display/user-display.tsx +0 -99
  97. package/template/client/src/components/business-ui/user-display/user-with-avatar.tsx +0 -158
  98. package/template/client/src/components/business-ui/user-display/utils.ts +0 -37
  99. package/template/client/src/components/business-ui/user-profile/error-image.tsx +0 -302
  100. package/template/client/src/components/business-ui/user-profile/user-external-script.ts +0 -73
  101. package/template/client/src/components/business-ui/user-profile/user-profile.tsx +0 -370
  102. package/template/client/src/components/business-ui/user-select/index.tsx +0 -28
  103. package/template/client/src/components/business-ui/user-select/types.ts +0 -109
  104. package/template/client/src/components/business-ui/user-select/use-user-value.ts +0 -160
  105. package/template/client/src/components/business-ui/user-select/user-item.tsx +0 -98
  106. package/template/client/src/components/business-ui/user-select/user-pill.tsx +0 -140
  107. package/template/client/src/components/business-ui/user-select/user-select-tag.tsx +0 -82
  108. package/template/client/src/components/business-ui/user-select/user-select.tsx +0 -359
  109. package/template/client/src/components/business-ui/user-select/utils.tsx +0 -188
  110. package/template/client/src/components/business-ui/utils/user.ts +0 -72
  111. package/template/client/src/components/ui/streamdown.tsx +0 -186
  112. package/template/client/src/lib/shiki.ts +0 -92
@@ -1,246 +0,0 @@
1
- import type { ReactNode } from 'react';
2
-
3
- import type {
4
- ClassNamesConfig,
5
- ComboboxSize,
6
- ItemValue,
7
- PopoverSlotProps,
8
- TriggerRenderProps,
9
- TriggerType,
10
- } from '@client/src/components/business-ui/entity-combobox/shared-types';
11
-
12
- // 重新导出共享类型
13
- export type {
14
- ItemValue,
15
- TriggerType,
16
- TriggerRenderProps,
17
- ClassNamesConfig,
18
- PopoverSlotProps,
19
- ComboboxSize,
20
- };
21
-
22
- /**
23
- * EntityCombobox 组件的 Props
24
- */
25
- export type EntityComboboxProps<
26
- T = unknown,
27
- TRaw = unknown,
28
- TValue extends ItemValue<TRaw> = ItemValue<TRaw>,
29
- > = {
30
- // 尺寸
31
- size?: ComboboxSize;
32
-
33
- // 数据获取
34
- fetchFn: (search: string) => Promise<{ items: T[] }>;
35
-
36
- // 受控/非受控
37
- multiple?: boolean;
38
- value?: TValue | TValue[] | null;
39
- defaultValue?: TValue | TValue[] | null;
40
- onChange?: (value: TValue | TValue[] | null) => void;
41
-
42
- // 弹层控制
43
- open?: boolean;
44
- defaultOpen?: boolean;
45
- onOpenChange?: (open: boolean) => void;
46
-
47
- // 配置
48
- pageSize?: number;
49
- debounce?: number;
50
- disabled?: boolean;
51
-
52
- // 回调
53
- onSelect?: (value: TValue) => void;
54
- onDeselect?: (value: TValue) => void;
55
- onSearch?: (value: string) => void;
56
- onClear?: () => void;
57
-
58
- children: ReactNode;
59
-
60
- // 转换函数
61
- getItemValue: (item: T) => TValue;
62
- };
63
-
64
- /**
65
- * EntityCombobox Context 值
66
- */
67
- export type EntityComboboxContextValue<
68
- T = unknown,
69
- TRaw = unknown,
70
- TValue extends ItemValue<TRaw> = ItemValue<TRaw>,
71
- > = {
72
- // 状态
73
- open: boolean;
74
- setOpen: (open: boolean) => void;
75
- searchValue: string;
76
- setSearchValue: (value: string) => void;
77
- selectedValue: TValue | TValue[] | null;
78
- debouncedSearch: string;
79
-
80
- // 方法
81
- handleSelect: (value: TValue) => void;
82
- handleDeselect: (value: TValue) => void;
83
- handleClear: () => void;
84
-
85
- // 数据
86
- data: T[];
87
- isFetching: boolean;
88
- isPending: boolean;
89
- isError: boolean;
90
- refetch: () => void;
91
-
92
- // 配置
93
- multiple: boolean;
94
- disabled: boolean;
95
- size: ComboboxSize;
96
- isSuccess?: boolean;
97
- fetchStatus?: string;
98
- isPlaceholderData?: boolean;
99
-
100
- // 转换函数
101
- getItemValue: (item: T) => TValue;
102
- };
103
-
104
- /**
105
- * BaseCombobox 组件的 Props
106
- */
107
- export type BaseComboboxProps<
108
- T = unknown,
109
- TRaw = unknown,
110
- TValue extends ItemValue<TRaw> = ItemValue<TRaw>,
111
- > = {
112
- // 尺寸
113
- size?: ComboboxSize;
114
-
115
- // 数据获取
116
- fetchFn: (search: string) => Promise<{ items: T[] }>;
117
-
118
- // 触发器
119
- triggerType?: TriggerType;
120
- renderTrigger?: (props: TriggerRenderProps<TRaw>) => ReactNode;
121
-
122
- // 受控/非受控
123
- multiple?: boolean;
124
- value?: TValue | TValue[] | null;
125
- defaultValue?: TValue | TValue[] | null;
126
- onChange?: (value: TValue | TValue[] | null) => void;
127
-
128
- // 弹层控制
129
- open?: boolean;
130
- defaultOpen?: boolean;
131
- onOpenChange?: (open: boolean) => void;
132
-
133
- // 配置
134
- debounce?: number;
135
- disabled?: boolean;
136
- showSearch?: boolean;
137
- autoFocus?: boolean;
138
- required?: boolean;
139
- name?: string;
140
-
141
- // 渲染函数
142
- renderItem: (
143
- item: T,
144
- isSelected: boolean,
145
- className?: string,
146
- disabled?: boolean,
147
- ) => ReactNode;
148
- renderTag?: (
149
- value: TValue,
150
- onClose: (value: TValue, e: React.MouseEvent) => void,
151
- disabled?: boolean,
152
- ) => ReactNode;
153
- /**
154
- * 判断选项是否禁用
155
- * @param value 选项值
156
- * @returns 如果返回 true,该选项将被禁用
157
- */
158
- getOptionDisabled?: (value: TValue) => boolean;
159
- getItemLabel?: (item: T) => string;
160
-
161
- // Placeholder
162
- placeholder?: string;
163
- searchPlaceholder?: string;
164
- emptyText?: string;
165
- loadingText?: string;
166
-
167
- // 样式
168
- className?: string;
169
- classNames?: ClassNamesConfig;
170
-
171
- // 标签(多选)
172
- tagClosable?: boolean;
173
- maxTagCount?: number | 'responsive';
174
- maxTagTextLength?: number;
175
-
176
- // Popover 配置
177
- placement?: 'top' | 'bottom' | 'left' | 'right';
178
- align?: 'start' | 'center' | 'end';
179
- sideOffset?: number;
180
-
181
- // 回调
182
- onSelect?: (value: TValue) => void;
183
- onDeselect?: (value: TValue) => void;
184
- onSearch?: (value: string) => void;
185
- onClear?: () => void;
186
- onFocus?: (event: React.FocusEvent<HTMLElement>) => void;
187
- onBlur?: (event: React.FocusEvent<HTMLElement>) => void;
188
-
189
- // 转换函数
190
- getItemValue?: (item: T) => TValue;
191
-
192
- slotProps?: PopoverSlotProps;
193
- children?: ReactNode;
194
- };
195
-
196
- /**
197
- * PopoverWrapper 组件的 Props
198
- */
199
- export type PopoverWrapperProps<
200
- T = unknown,
201
- TRaw = unknown,
202
- TValue extends ItemValue<TRaw> = ItemValue<TRaw>,
203
- > = {
204
- size?: ComboboxSize;
205
- triggerType?: TriggerType;
206
- renderTrigger?: (props: TriggerRenderProps<TRaw>) => ReactNode;
207
- placeholder?: string;
208
- maxTagCount?: number | 'responsive';
209
- maxTagTextLength?: number;
210
- tagClosable?: boolean;
211
- className?: string;
212
- classNames?: ClassNamesConfig;
213
- placement?: 'top' | 'bottom' | 'left' | 'right';
214
- align?: 'start' | 'center' | 'end';
215
- sideOffset?: number;
216
- showSearch?: boolean;
217
- searchPlaceholder?: string;
218
- renderItem: (
219
- item: T,
220
- isSelected: boolean,
221
- className?: string,
222
- disabled?: boolean,
223
- ) => ReactNode;
224
- renderTag?: (
225
- value: TValue,
226
- onClose: (value: TValue, e: React.MouseEvent) => void,
227
- disabled?: boolean,
228
- ) => ReactNode;
229
- getItemValue: (item: T) => TValue;
230
- getOptionDisabled?: (value: TValue) => boolean;
231
- emptyText?: string;
232
- loadingText?: string;
233
- onFocus?: (event: React.FocusEvent<HTMLElement>) => void;
234
- onBlur?: (event: React.FocusEvent<HTMLElement>) => void;
235
- slotProps?: PopoverSlotProps;
236
- children?: ReactNode;
237
- };
238
-
239
- /**
240
- * 国际化文本类型
241
- */
242
- export type I18nText = {
243
- zh_cn: string;
244
- en_us?: string;
245
- ja_jp?: string;
246
- };
@@ -1,81 +0,0 @@
1
- 'use client';
2
-
3
- import { logger } from '@lark-apaas/client-toolkit/logger';
4
- import { useCallback, useEffect, useState } from 'react';
5
-
6
- export type UseFetchDataOptions<T> = {
7
- fetchFn: (search: string) => Promise<{ items: T[] }>;
8
- enabled: boolean;
9
- search: string;
10
- onSearch?: (search: string) => void;
11
- };
12
-
13
- export type UseFetchDataResult<T> = {
14
- data: T[] | undefined;
15
- isFetching: boolean;
16
- isError: boolean;
17
- isSuccess: boolean;
18
- fetchStatus: 'fetching' | 'idle';
19
- refetch: () => Promise<void>;
20
- };
21
-
22
- export function useFetchData<T>({
23
- fetchFn,
24
- enabled,
25
- search,
26
- onSearch,
27
- }: UseFetchDataOptions<T>): UseFetchDataResult<T> {
28
- const [data, setData] = useState<T[] | undefined>();
29
- const [isFetching, setIsFetching] = useState(false);
30
- const [isError, setIsError] = useState(false);
31
- const [isSuccess, setIsSuccess] = useState(false);
32
-
33
- const fetchData = useCallback(async () => {
34
- if (!enabled || search.trim() === '') {
35
- setData([]);
36
- setIsSuccess(true);
37
- return;
38
- }
39
-
40
- try {
41
- setIsFetching(true);
42
- setIsError(false);
43
-
44
- const result = await fetchFn(search);
45
-
46
- setData(result?.items || []);
47
- setIsSuccess(true);
48
- setIsError(false);
49
- } catch (error) {
50
- logger.error('Failed to fetch data:', error);
51
- setIsError(true);
52
- setIsSuccess(false);
53
- setData([]);
54
- } finally {
55
- setIsFetching(false);
56
- }
57
- }, [enabled, search, fetchFn]);
58
-
59
- useEffect(() => {
60
- if (enabled && search.trim() !== '') {
61
- fetchData();
62
- } else {
63
- setData(undefined);
64
- setIsSuccess(true);
65
- }
66
- }, [search, enabled, fetchData]);
67
-
68
- // 单独处理 onSearch 回调
69
- useEffect(() => {
70
- onSearch?.(search);
71
- }, [search, onSearch]);
72
-
73
- return {
74
- data,
75
- isFetching,
76
- isError,
77
- isSuccess,
78
- fetchStatus: isFetching ? 'fetching' : 'idle',
79
- refetch: fetchData,
80
- };
81
- }
@@ -1,99 +0,0 @@
1
- 'use client';
2
-
3
- import { useCallback, useEffect, useRef } from 'react';
4
-
5
- export type UseInfiniteScrollOptions = {
6
- /**
7
- * 加载更多数据的回调函数
8
- */
9
- onLoadMore: () => void;
10
- /**
11
- * 是否还有更多数据
12
- */
13
- hasMore: boolean;
14
- /**
15
- * 是否正在加载中
16
- */
17
- isLoading: boolean;
18
- /**
19
- * 是否启用无限滚动
20
- * @default true
21
- */
22
- enabled?: boolean;
23
- /**
24
- * IntersectionObserver 的 threshold
25
- * @default 0.1
26
- */
27
- threshold?: number;
28
- /**
29
- * IntersectionObserver 的 rootMargin,用于提前触发加载
30
- * @default '50px'
31
- */
32
- rootMargin?: string;
33
- };
34
-
35
- export type UseInfiniteScrollResult = {
36
- /**
37
- * 绑定到触发元素的 ref
38
- */
39
- triggerRef: React.RefObject<HTMLDivElement | null>;
40
- };
41
-
42
- /**
43
- * 无限滚动加载 hook
44
- * 使用 IntersectionObserver 检测滚动触底,自动触发加载更多
45
- *
46
- * @example
47
- * ```tsx
48
- * const { triggerRef } = useInfiniteScroll({
49
- * onLoadMore: fetchMore,
50
- * hasMore,
51
- * isLoading: isFetchingMore,
52
- * })
53
- *
54
- * return (
55
- * <ScrollArea>
56
- * {items.map(item => <Item key={item.id} />)}
57
- * <div ref={triggerRef} />
58
- * </ScrollArea>
59
- * )
60
- * ```
61
- */
62
- export function useInfiniteScroll({
63
- onLoadMore,
64
- hasMore,
65
- isLoading,
66
- enabled = true,
67
- threshold = 0.1,
68
- rootMargin = '50px',
69
- }: UseInfiniteScrollOptions): UseInfiniteScrollResult {
70
- const triggerRef = useRef<HTMLDivElement>(null);
71
-
72
- const handleIntersect = useCallback(
73
- (entries: IntersectionObserverEntry[]) => {
74
- const [entry] = entries;
75
- if (entry?.isIntersecting && hasMore && !isLoading && enabled) {
76
- onLoadMore();
77
- }
78
- },
79
- [hasMore, isLoading, enabled, onLoadMore],
80
- );
81
-
82
- useEffect(() => {
83
- const element = triggerRef.current;
84
- if (!element || !enabled) return;
85
-
86
- const observer = new IntersectionObserver(handleIntersect, {
87
- threshold,
88
- rootMargin,
89
- });
90
-
91
- observer.observe(element);
92
-
93
- return () => {
94
- observer.disconnect();
95
- };
96
- }, [handleIntersect, threshold, rootMargin, enabled]);
97
-
98
- return { triggerRef };
99
- }
@@ -1,32 +0,0 @@
1
- import { useEffect } from 'react';
2
-
3
- /**
4
- * 处理点击外部关闭浮层的 Hook
5
- * 仅在 search 模式下使用
6
- */
7
- export function usePopoverOutsideClick(
8
- open: boolean,
9
- enabled: boolean,
10
- popoverRef: React.RefObject<HTMLElement | null>,
11
- triggerRef: React.RefObject<HTMLElement | null>,
12
- onClose: () => void,
13
- ) {
14
- useEffect(() => {
15
- if (!open || !enabled) return;
16
-
17
- const handleClickOutside = (event: MouseEvent) => {
18
- const target = event.target as Node;
19
- if (
20
- popoverRef.current &&
21
- triggerRef.current &&
22
- !popoverRef.current.contains(target) &&
23
- !triggerRef.current.contains(target)
24
- ) {
25
- onClose();
26
- }
27
- };
28
-
29
- document.addEventListener('mousedown', handleClickOutside);
30
- return () => document.removeEventListener('mousedown', handleClickOutside);
31
- }, [open, enabled, popoverRef, triggerRef, onClose]);
32
- }
@@ -1,83 +0,0 @@
1
- import { useFormGlobalProps } from '@client/src/components/business-ui/form/context';
2
- import { FieldLayout } from '@client/src/components/business-ui/form/field-layout';
3
- import { useFieldContext } from '@client/src/components/business-ui/form/hooks/form-context';
4
- import {
5
- useFieldName,
6
- useFieldValidation,
7
- } from '@client/src/components/business-ui/form/hooks/form-utils';
8
- import type {
9
- CommonFieldProps,
10
- FieldLayoutClassNames,
11
- FieldLayoutStyles,
12
- } from '@client/src/components/business-ui/form/types';
13
- import { Checkbox } from '@client/src/components/ui/checkbox';
14
- import { Field, FieldLabel } from '@client/src/components/ui/field';
15
-
16
- type CheckboxFieldProps = CommonFieldProps &
17
- React.ComponentProps<typeof Checkbox> & {
18
- options?: {
19
- label: string;
20
- value: boolean | 'indeterminate';
21
- }[];
22
- classNames?: Partial<FieldLayoutClassNames & Record<'checkbox', string>>;
23
- styles?: Partial<
24
- FieldLayoutStyles & Record<'checkbox', React.CSSProperties>
25
- >;
26
- };
27
-
28
- export function CheckboxField({
29
- label,
30
- description,
31
- disabled,
32
- required,
33
- layout,
34
- classNames,
35
- styles,
36
- ...rest
37
- }: CheckboxFieldProps) {
38
- const field = useFieldContext<boolean | 'indeterminate'>();
39
- const { layout: formLayout } = useFormGlobalProps();
40
- const { isInvalid, errorMessage } = useFieldValidation();
41
- const name = useFieldName();
42
-
43
- const { checkbox: checkboxClassName, ...fieldLayoutClassNames } =
44
- classNames ?? {};
45
- const { checkbox: checkboxStyle, ...fieldLayoutStyles } = styles ?? {};
46
-
47
- return (
48
- <FieldLayout
49
- description={description}
50
- isInvalid={isInvalid}
51
- layout={layout ?? formLayout ?? 'vertical'}
52
- required={required ?? false}
53
- classNames={fieldLayoutClassNames ?? {}}
54
- styles={fieldLayoutStyles ?? {}}
55
- errorMessage={errorMessage}
56
- name={name}
57
- >
58
- <Field orientation="horizontal">
59
- <Checkbox
60
- {...rest}
61
- id={name}
62
- name={name}
63
- className={checkboxClassName ?? ''}
64
- style={checkboxStyle ?? {}}
65
- required={required ?? false}
66
- aria-invalid={isInvalid}
67
- checked={field.state.value}
68
- disabled={disabled}
69
- onCheckedChange={(checked) => {
70
- field.handleChange(checked);
71
- }}
72
- />
73
- <FieldLabel
74
- style={styles?.label}
75
- className={classNames?.['label']}
76
- htmlFor={name}
77
- >
78
- {label}
79
- </FieldLabel>
80
- </Field>
81
- </FieldLayout>
82
- );
83
- }
@@ -1,38 +0,0 @@
1
- 'use client';
2
-
3
- import React from 'react';
4
-
5
- export interface FormGlobalProps {
6
- layout: 'vertical' | 'responsive' | 'horizontal';
7
- }
8
-
9
- export type FormContextType = FormGlobalProps | null;
10
-
11
- export const FormContext = React.createContext<FormContextType>(null);
12
-
13
- export const useFormContext = () => {
14
- const context = React.useContext(FormContext);
15
- if (!context) {
16
- throw new Error('useFormContext must be used within a FormProvider');
17
- }
18
- return context as FormGlobalProps;
19
- };
20
-
21
- export const FormProvider: React.FC<{
22
- layout: 'vertical' | 'responsive' | 'horizontal';
23
- children: React.ReactNode;
24
- }> = ({ layout, children }) => {
25
- const value = React.useMemo(
26
- () => ({
27
- layout: layout,
28
- }),
29
- [layout],
30
- );
31
-
32
- return <FormContext.Provider value={value}>{children}</FormContext.Provider>;
33
- };
34
-
35
- export const useFormGlobalProps = () => {
36
- const context = useFormContext();
37
- return context;
38
- };
@@ -1,91 +0,0 @@
1
- import { Asterisk } from 'lucide-react';
2
-
3
- import type { FieldLayoutProps } from '@client/src/components/business-ui/form/types';
4
- import { cn } from '@/lib/utils';
5
- import {
6
- Field,
7
- FieldContent,
8
- FieldDescription,
9
- FieldError,
10
- FieldLabel,
11
- } from '@client/src/components/ui/field';
12
-
13
- export function FieldLayout({
14
- label,
15
- children,
16
- description,
17
- layout = 'vertical',
18
- isInvalid,
19
- errorMessage,
20
- name,
21
- required,
22
- classNames,
23
- styles,
24
- }: React.PropsWithChildren<FieldLayoutProps>) {
25
- const descriptionComponent = description && (
26
- <FieldDescription
27
- className={classNames?.['description']}
28
- style={styles?.['description']}
29
- >
30
- {description}
31
- </FieldDescription>
32
- );
33
-
34
- const labelComponent = label && (
35
- <FieldLabel
36
- className={cn('gap-0.5', classNames?.['label'])}
37
- htmlFor={name}
38
- style={styles?.['label']}
39
- >
40
- {label}
41
- {required && (
42
- <span className="text-red-500">
43
- <Asterisk size={12} />
44
- </span>
45
- )}
46
- </FieldLabel>
47
- );
48
-
49
- const errorComponent = isInvalid && (
50
- <FieldError className={classNames?.['error']} style={styles?.['error']}>
51
- {errorMessage}
52
- </FieldError>
53
- );
54
-
55
- if (layout !== 'vertical') {
56
- return (
57
- <Field
58
- orientation={layout}
59
- className={cn(classNames?.['root'])}
60
- style={styles?.['root']}
61
- >
62
- {descriptionComponent ? (
63
- <FieldContent>
64
- {labelComponent}
65
- {descriptionComponent}
66
- </FieldContent>
67
- ) : (
68
- labelComponent
69
- )}
70
- <FieldContent className={'has-[>[role=switch]]:flex-initial'}>
71
- {children}
72
- {errorComponent}
73
- </FieldContent>
74
- </Field>
75
- );
76
- }
77
- return (
78
- <Field
79
- orientation={layout}
80
- className={classNames?.['root']}
81
- style={styles?.['root']}
82
- >
83
- {labelComponent}
84
- <FieldContent className={'has-[>[role=switch]]:flex-initial'}>
85
- {children}
86
- {errorComponent}
87
- </FieldContent>
88
- {descriptionComponent}
89
- </Field>
90
- );
91
- }