@teamix-evo/ui 0.1.1

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 (270) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +336 -0
  3. package/_data.json +12 -0
  4. package/manifest.json +1688 -0
  5. package/package.json +90 -0
  6. package/src/components/accordion/accordion.meta.md +87 -0
  7. package/src/components/accordion/accordion.stories.tsx +67 -0
  8. package/src/components/accordion/accordion.tsx +58 -0
  9. package/src/components/affix/affix.meta.md +80 -0
  10. package/src/components/affix/affix.stories.tsx +57 -0
  11. package/src/components/affix/affix.tsx +97 -0
  12. package/src/components/alert/alert.meta.md +101 -0
  13. package/src/components/alert/alert.stories.tsx +93 -0
  14. package/src/components/alert/alert.tsx +132 -0
  15. package/src/components/alert-dialog/alert-dialog.meta.md +107 -0
  16. package/src/components/alert-dialog/alert-dialog.stories.tsx +81 -0
  17. package/src/components/alert-dialog/alert-dialog.tsx +136 -0
  18. package/src/components/anchor/anchor.meta.md +87 -0
  19. package/src/components/anchor/anchor.stories.tsx +74 -0
  20. package/src/components/anchor/anchor.tsx +130 -0
  21. package/src/components/app/app.meta.md +86 -0
  22. package/src/components/app/app.stories.tsx +62 -0
  23. package/src/components/app/app.tsx +58 -0
  24. package/src/components/aspect-ratio/aspect-ratio.meta.md +81 -0
  25. package/src/components/aspect-ratio/aspect-ratio.stories.tsx +59 -0
  26. package/src/components/aspect-ratio/aspect-ratio.tsx +22 -0
  27. package/src/components/auto-complete/auto-complete.meta.md +102 -0
  28. package/src/components/auto-complete/auto-complete.stories.tsx +93 -0
  29. package/src/components/auto-complete/auto-complete.tsx +205 -0
  30. package/src/components/avatar/avatar.meta.md +94 -0
  31. package/src/components/avatar/avatar.stories.tsx +80 -0
  32. package/src/components/avatar/avatar.tsx +126 -0
  33. package/src/components/badge/badge.meta.md +119 -0
  34. package/src/components/badge/badge.stories.tsx +153 -0
  35. package/src/components/badge/badge.tsx +210 -0
  36. package/src/components/breadcrumb/breadcrumb.meta.md +107 -0
  37. package/src/components/breadcrumb/breadcrumb.stories.tsx +84 -0
  38. package/src/components/breadcrumb/breadcrumb.tsx +122 -0
  39. package/src/components/button/button.meta.md +98 -0
  40. package/src/components/button/button.stories.tsx +235 -0
  41. package/src/components/button/button.tsx +160 -0
  42. package/src/components/button-group/button-group.meta.md +92 -0
  43. package/src/components/button-group/button-group.stories.tsx +90 -0
  44. package/src/components/button-group/button-group.tsx +75 -0
  45. package/src/components/calendar/calendar.meta.md +118 -0
  46. package/src/components/calendar/calendar.stories.tsx +68 -0
  47. package/src/components/calendar/calendar.tsx +107 -0
  48. package/src/components/card/card.meta.md +117 -0
  49. package/src/components/card/card.stories.tsx +112 -0
  50. package/src/components/card/card.tsx +222 -0
  51. package/src/components/carousel/carousel.meta.md +117 -0
  52. package/src/components/carousel/carousel.stories.tsx +84 -0
  53. package/src/components/carousel/carousel.tsx +224 -0
  54. package/src/components/cascader/cascader.meta.md +110 -0
  55. package/src/components/cascader/cascader.stories.tsx +108 -0
  56. package/src/components/cascader/cascader.tsx +198 -0
  57. package/src/components/checkbox/checkbox.meta.md +99 -0
  58. package/src/components/checkbox/checkbox.stories.tsx +130 -0
  59. package/src/components/checkbox/checkbox.tsx +125 -0
  60. package/src/components/collapsible/collapsible.meta.md +80 -0
  61. package/src/components/collapsible/collapsible.stories.tsx +35 -0
  62. package/src/components/collapsible/collapsible.tsx +18 -0
  63. package/src/components/color-picker/color-picker.meta.md +84 -0
  64. package/src/components/color-picker/color-picker.stories.tsx +80 -0
  65. package/src/components/color-picker/color-picker.tsx +160 -0
  66. package/src/components/combobox/combobox.meta.md +93 -0
  67. package/src/components/combobox/combobox.stories.tsx +55 -0
  68. package/src/components/combobox/combobox.tsx +130 -0
  69. package/src/components/command/command.meta.md +104 -0
  70. package/src/components/command/command.stories.tsx +59 -0
  71. package/src/components/command/command.tsx +147 -0
  72. package/src/components/context-menu/context-menu.meta.md +90 -0
  73. package/src/components/context-menu/context-menu.stories.tsx +46 -0
  74. package/src/components/context-menu/context-menu.tsx +191 -0
  75. package/src/components/data-table/data-table.meta.md +149 -0
  76. package/src/components/data-table/data-table.stories.tsx +125 -0
  77. package/src/components/data-table/data-table.tsx +185 -0
  78. package/src/components/date-picker/date-picker.meta.md +106 -0
  79. package/src/components/date-picker/date-picker.stories.tsx +58 -0
  80. package/src/components/date-picker/date-picker.tsx +156 -0
  81. package/src/components/descriptions/descriptions.meta.md +78 -0
  82. package/src/components/descriptions/descriptions.stories.tsx +60 -0
  83. package/src/components/descriptions/descriptions.tsx +129 -0
  84. package/src/components/dialog/dialog.meta.md +105 -0
  85. package/src/components/dialog/dialog.stories.tsx +93 -0
  86. package/src/components/dialog/dialog.tsx +128 -0
  87. package/src/components/drawer/drawer.meta.md +96 -0
  88. package/src/components/drawer/drawer.stories.tsx +54 -0
  89. package/src/components/drawer/drawer.tsx +114 -0
  90. package/src/components/dropdown-menu/dropdown-menu.meta.md +103 -0
  91. package/src/components/dropdown-menu/dropdown-menu.stories.tsx +112 -0
  92. package/src/components/dropdown-menu/dropdown-menu.tsx +195 -0
  93. package/src/components/empty/empty.meta.md +81 -0
  94. package/src/components/empty/empty.stories.tsx +46 -0
  95. package/src/components/empty/empty.tsx +47 -0
  96. package/src/components/field/field.meta.md +116 -0
  97. package/src/components/field/field.stories.tsx +117 -0
  98. package/src/components/field/field.tsx +164 -0
  99. package/src/components/flex/flex.meta.md +94 -0
  100. package/src/components/flex/flex.stories.tsx +112 -0
  101. package/src/components/flex/flex.tsx +122 -0
  102. package/src/components/float-button/float-button.meta.md +87 -0
  103. package/src/components/float-button/float-button.stories.tsx +78 -0
  104. package/src/components/float-button/float-button.tsx +143 -0
  105. package/src/components/form/form.meta.md +131 -0
  106. package/src/components/form/form.stories.tsx +122 -0
  107. package/src/components/form/form.tsx +194 -0
  108. package/src/components/grid/grid.meta.md +87 -0
  109. package/src/components/grid/grid.stories.tsx +99 -0
  110. package/src/components/grid/grid.tsx +130 -0
  111. package/src/components/hover-card/hover-card.meta.md +92 -0
  112. package/src/components/hover-card/hover-card.stories.tsx +68 -0
  113. package/src/components/hover-card/hover-card.tsx +29 -0
  114. package/src/components/image/image.meta.md +94 -0
  115. package/src/components/image/image.stories.tsx +55 -0
  116. package/src/components/image/image.tsx +138 -0
  117. package/src/components/input/input.meta.md +109 -0
  118. package/src/components/input/input.stories.tsx +117 -0
  119. package/src/components/input/input.tsx +213 -0
  120. package/src/components/input-group/input-group.meta.md +92 -0
  121. package/src/components/input-group/input-group.stories.tsx +88 -0
  122. package/src/components/input-group/input-group.tsx +107 -0
  123. package/src/components/input-number/input-number.meta.md +91 -0
  124. package/src/components/input-number/input-number.stories.tsx +87 -0
  125. package/src/components/input-number/input-number.tsx +210 -0
  126. package/src/components/input-otp/input-otp.meta.md +105 -0
  127. package/src/components/input-otp/input-otp.stories.tsx +65 -0
  128. package/src/components/input-otp/input-otp.tsx +97 -0
  129. package/src/components/item/item.meta.md +116 -0
  130. package/src/components/item/item.stories.tsx +113 -0
  131. package/src/components/item/item.tsx +171 -0
  132. package/src/components/kbd/kbd.meta.md +85 -0
  133. package/src/components/kbd/kbd.stories.tsx +70 -0
  134. package/src/components/kbd/kbd.tsx +81 -0
  135. package/src/components/label/label.meta.md +91 -0
  136. package/src/components/label/label.stories.tsx +87 -0
  137. package/src/components/label/label.tsx +66 -0
  138. package/src/components/masonry/masonry.meta.md +85 -0
  139. package/src/components/masonry/masonry.stories.tsx +66 -0
  140. package/src/components/masonry/masonry.tsx +59 -0
  141. package/src/components/mentions/mentions.meta.md +89 -0
  142. package/src/components/mentions/mentions.stories.tsx +75 -0
  143. package/src/components/mentions/mentions.tsx +237 -0
  144. package/src/components/menubar/menubar.meta.md +100 -0
  145. package/src/components/menubar/menubar.stories.tsx +81 -0
  146. package/src/components/menubar/menubar.tsx +232 -0
  147. package/src/components/native-select/native-select.meta.md +88 -0
  148. package/src/components/native-select/native-select.stories.tsx +80 -0
  149. package/src/components/native-select/native-select.tsx +54 -0
  150. package/src/components/navigation-menu/navigation-menu.meta.md +108 -0
  151. package/src/components/navigation-menu/navigation-menu.stories.tsx +112 -0
  152. package/src/components/navigation-menu/navigation-menu.tsx +125 -0
  153. package/src/components/notification/notification.meta.md +91 -0
  154. package/src/components/notification/notification.stories.tsx +96 -0
  155. package/src/components/notification/notification.tsx +84 -0
  156. package/src/components/pagination/pagination.meta.md +127 -0
  157. package/src/components/pagination/pagination.stories.tsx +62 -0
  158. package/src/components/pagination/pagination.tsx +285 -0
  159. package/src/components/popconfirm/popconfirm.meta.md +109 -0
  160. package/src/components/popconfirm/popconfirm.stories.tsx +76 -0
  161. package/src/components/popconfirm/popconfirm.tsx +134 -0
  162. package/src/components/popover/popover.meta.md +97 -0
  163. package/src/components/popover/popover.stories.tsx +82 -0
  164. package/src/components/popover/popover.tsx +55 -0
  165. package/src/components/progress/progress.meta.md +86 -0
  166. package/src/components/progress/progress.stories.tsx +75 -0
  167. package/src/components/progress/progress.tsx +195 -0
  168. package/src/components/radio-group/radio-group.meta.md +103 -0
  169. package/src/components/radio-group/radio-group.stories.tsx +77 -0
  170. package/src/components/radio-group/radio-group.tsx +78 -0
  171. package/src/components/rate/rate.meta.md +87 -0
  172. package/src/components/rate/rate.stories.tsx +81 -0
  173. package/src/components/rate/rate.tsx +153 -0
  174. package/src/components/resizable/resizable.meta.md +92 -0
  175. package/src/components/resizable/resizable.stories.tsx +104 -0
  176. package/src/components/resizable/resizable.tsx +56 -0
  177. package/src/components/result/result.meta.md +90 -0
  178. package/src/components/result/result.stories.tsx +71 -0
  179. package/src/components/result/result.tsx +91 -0
  180. package/src/components/scroll-area/scroll-area.meta.md +84 -0
  181. package/src/components/scroll-area/scroll-area.stories.tsx +41 -0
  182. package/src/components/scroll-area/scroll-area.tsx +51 -0
  183. package/src/components/segmented/segmented.meta.md +103 -0
  184. package/src/components/segmented/segmented.stories.tsx +101 -0
  185. package/src/components/segmented/segmented.tsx +138 -0
  186. package/src/components/select/select.meta.md +110 -0
  187. package/src/components/select/select.stories.tsx +100 -0
  188. package/src/components/select/select.tsx +188 -0
  189. package/src/components/separator/separator.meta.md +74 -0
  190. package/src/components/separator/separator.stories.tsx +71 -0
  191. package/src/components/separator/separator.tsx +104 -0
  192. package/src/components/sheet/sheet.meta.md +97 -0
  193. package/src/components/sheet/sheet.stories.tsx +82 -0
  194. package/src/components/sheet/sheet.tsx +139 -0
  195. package/src/components/sidebar/sidebar.meta.md +131 -0
  196. package/src/components/sidebar/sidebar.stories.tsx +82 -0
  197. package/src/components/sidebar/sidebar.tsx +351 -0
  198. package/src/components/skeleton/skeleton.meta.md +95 -0
  199. package/src/components/skeleton/skeleton.stories.tsx +79 -0
  200. package/src/components/skeleton/skeleton.tsx +144 -0
  201. package/src/components/slider/slider.meta.md +94 -0
  202. package/src/components/slider/slider.stories.tsx +69 -0
  203. package/src/components/slider/slider.tsx +86 -0
  204. package/src/components/sonner/sonner.meta.md +96 -0
  205. package/src/components/sonner/sonner.stories.tsx +91 -0
  206. package/src/components/sonner/sonner.tsx +40 -0
  207. package/src/components/space/space.meta.md +94 -0
  208. package/src/components/space/space.stories.tsx +94 -0
  209. package/src/components/space/space.tsx +106 -0
  210. package/src/components/spinner/spinner.meta.md +76 -0
  211. package/src/components/spinner/spinner.stories.tsx +71 -0
  212. package/src/components/spinner/spinner.tsx +64 -0
  213. package/src/components/statistic/statistic.meta.md +99 -0
  214. package/src/components/statistic/statistic.stories.tsx +71 -0
  215. package/src/components/statistic/statistic.tsx +197 -0
  216. package/src/components/steps/steps.meta.md +102 -0
  217. package/src/components/steps/steps.stories.tsx +75 -0
  218. package/src/components/steps/steps.tsx +170 -0
  219. package/src/components/switch/switch.meta.md +92 -0
  220. package/src/components/switch/switch.stories.tsx +75 -0
  221. package/src/components/switch/switch.tsx +101 -0
  222. package/src/components/table/table.meta.md +95 -0
  223. package/src/components/table/table.stories.tsx +75 -0
  224. package/src/components/table/table.tsx +122 -0
  225. package/src/components/tabs/tabs.meta.md +98 -0
  226. package/src/components/tabs/tabs.stories.tsx +70 -0
  227. package/src/components/tabs/tabs.tsx +119 -0
  228. package/src/components/tag/tag.meta.md +94 -0
  229. package/src/components/tag/tag.stories.tsx +77 -0
  230. package/src/components/tag/tag.tsx +185 -0
  231. package/src/components/textarea/textarea.meta.md +83 -0
  232. package/src/components/textarea/textarea.stories.tsx +63 -0
  233. package/src/components/textarea/textarea.tsx +113 -0
  234. package/src/components/time-picker/time-picker.meta.md +83 -0
  235. package/src/components/time-picker/time-picker.stories.tsx +59 -0
  236. package/src/components/time-picker/time-picker.tsx +94 -0
  237. package/src/components/timeline/timeline.meta.md +102 -0
  238. package/src/components/timeline/timeline.stories.tsx +104 -0
  239. package/src/components/timeline/timeline.tsx +147 -0
  240. package/src/components/toggle/toggle.meta.md +88 -0
  241. package/src/components/toggle/toggle.stories.tsx +66 -0
  242. package/src/components/toggle/toggle.tsx +53 -0
  243. package/src/components/toggle-group/toggle-group.meta.md +90 -0
  244. package/src/components/toggle-group/toggle-group.stories.tsx +83 -0
  245. package/src/components/toggle-group/toggle-group.tsx +78 -0
  246. package/src/components/tooltip/tooltip.meta.md +99 -0
  247. package/src/components/tooltip/tooltip.stories.tsx +71 -0
  248. package/src/components/tooltip/tooltip.tsx +93 -0
  249. package/src/components/tour/tour.meta.md +116 -0
  250. package/src/components/tour/tour.stories.tsx +66 -0
  251. package/src/components/tour/tour.tsx +242 -0
  252. package/src/components/transfer/transfer.meta.md +90 -0
  253. package/src/components/transfer/transfer.stories.tsx +68 -0
  254. package/src/components/transfer/transfer.tsx +251 -0
  255. package/src/components/tree/tree.meta.md +111 -0
  256. package/src/components/tree/tree.stories.tsx +109 -0
  257. package/src/components/tree/tree.tsx +367 -0
  258. package/src/components/tree-select/tree-select.meta.md +100 -0
  259. package/src/components/tree-select/tree-select.stories.tsx +80 -0
  260. package/src/components/tree-select/tree-select.tsx +171 -0
  261. package/src/components/typography/typography.meta.md +102 -0
  262. package/src/components/typography/typography.stories.tsx +115 -0
  263. package/src/components/typography/typography.tsx +245 -0
  264. package/src/components/upload/upload.meta.md +111 -0
  265. package/src/components/upload/upload.stories.tsx +75 -0
  266. package/src/components/upload/upload.tsx +265 -0
  267. package/src/components/watermark/watermark.meta.md +95 -0
  268. package/src/components/watermark/watermark.stories.tsx +78 -0
  269. package/src/components/watermark/watermark.tsx +165 -0
  270. package/src/utils/cn.ts +6 -0
@@ -0,0 +1,224 @@
1
+ import * as React from 'react';
2
+ import useEmblaCarousel, {
3
+ type UseEmblaCarouselType,
4
+ } from 'embla-carousel-react';
5
+ import { ArrowLeft, ArrowRight } from 'lucide-react';
6
+
7
+ import { cn } from '@/utils/cn';
8
+ import { Button } from '@/components/button/button';
9
+
10
+ type CarouselApi = UseEmblaCarouselType[1];
11
+ type UseCarouselParameters = Parameters<typeof useEmblaCarousel>;
12
+ type CarouselOptions = UseCarouselParameters[0];
13
+ type CarouselPlugin = UseCarouselParameters[1];
14
+
15
+ export interface CarouselProps extends React.HTMLAttributes<HTMLDivElement> {
16
+ /** embla 选项透传(`loop / align / startIndex / dragFree` 等)。 */
17
+ opts?: CarouselOptions;
18
+ /** embla 插件数组(`autoplay`、`fade` 等)。 */
19
+ plugins?: CarouselPlugin;
20
+ /**
21
+ * 滚动方向。
22
+ * @default "horizontal"
23
+ */
24
+ orientation?: 'horizontal' | 'vertical';
25
+ /** 提供 embla API 的回调,用于业务侧自行控制(scrollNext / scrollTo 等)。 */
26
+ setApi?: (api: CarouselApi) => void;
27
+ }
28
+
29
+ interface CarouselContextValue {
30
+ carouselRef: ReturnType<typeof useEmblaCarousel>[0];
31
+ api: CarouselApi;
32
+ orientation: 'horizontal' | 'vertical';
33
+ scrollPrev: () => void;
34
+ scrollNext: () => void;
35
+ canScrollPrev: boolean;
36
+ canScrollNext: boolean;
37
+ }
38
+
39
+ const CarouselContext = React.createContext<CarouselContextValue | null>(null);
40
+
41
+ function useCarousel() {
42
+ const ctx = React.useContext(CarouselContext);
43
+ if (!ctx)
44
+ throw new Error('useCarousel must be used within a <Carousel />');
45
+ return ctx;
46
+ }
47
+
48
+ const Carousel = React.forwardRef<HTMLDivElement, CarouselProps>(
49
+ (
50
+ {
51
+ orientation = 'horizontal',
52
+ opts,
53
+ plugins,
54
+ setApi,
55
+ className,
56
+ children,
57
+ ...props
58
+ },
59
+ ref,
60
+ ) => {
61
+ const [carouselRef, api] = useEmblaCarousel(
62
+ { ...opts, axis: orientation === 'horizontal' ? 'x' : 'y' },
63
+ plugins,
64
+ );
65
+ const [canScrollPrev, setCanScrollPrev] = React.useState(false);
66
+ const [canScrollNext, setCanScrollNext] = React.useState(false);
67
+
68
+ const onSelect = React.useCallback((a: CarouselApi) => {
69
+ if (!a) return;
70
+ setCanScrollPrev(a.canScrollPrev());
71
+ setCanScrollNext(a.canScrollNext());
72
+ }, []);
73
+
74
+ const scrollPrev = React.useCallback(() => api?.scrollPrev(), [api]);
75
+ const scrollNext = React.useCallback(() => api?.scrollNext(), [api]);
76
+
77
+ React.useEffect(() => {
78
+ if (!api || !setApi) return;
79
+ setApi(api);
80
+ }, [api, setApi]);
81
+
82
+ React.useEffect(() => {
83
+ if (!api) return;
84
+ onSelect(api);
85
+ api.on('reInit', onSelect);
86
+ api.on('select', onSelect);
87
+ return () => {
88
+ api.off('select', onSelect);
89
+ };
90
+ }, [api, onSelect]);
91
+
92
+ return (
93
+ <CarouselContext.Provider
94
+ value={{
95
+ carouselRef,
96
+ api,
97
+ orientation,
98
+ scrollPrev,
99
+ scrollNext,
100
+ canScrollPrev,
101
+ canScrollNext,
102
+ }}
103
+ >
104
+ <div
105
+ ref={ref}
106
+ className={cn('relative', className)}
107
+ role="region"
108
+ aria-roledescription="carousel"
109
+ {...props}
110
+ >
111
+ {children}
112
+ </div>
113
+ </CarouselContext.Provider>
114
+ );
115
+ },
116
+ );
117
+ Carousel.displayName = 'Carousel';
118
+
119
+ const CarouselContent = React.forwardRef<
120
+ HTMLDivElement,
121
+ React.HTMLAttributes<HTMLDivElement>
122
+ >(({ className, ...props }, ref) => {
123
+ const { carouselRef, orientation } = useCarousel();
124
+ return (
125
+ <div ref={carouselRef} className="overflow-hidden">
126
+ <div
127
+ ref={ref}
128
+ className={cn(
129
+ 'flex',
130
+ orientation === 'horizontal' ? '-ml-4' : '-mt-4 flex-col',
131
+ className,
132
+ )}
133
+ {...props}
134
+ />
135
+ </div>
136
+ );
137
+ });
138
+ CarouselContent.displayName = 'CarouselContent';
139
+
140
+ const CarouselItem = React.forwardRef<
141
+ HTMLDivElement,
142
+ React.HTMLAttributes<HTMLDivElement>
143
+ >(({ className, ...props }, ref) => {
144
+ const { orientation } = useCarousel();
145
+ return (
146
+ <div
147
+ ref={ref}
148
+ role="group"
149
+ aria-roledescription="slide"
150
+ className={cn(
151
+ 'min-w-0 shrink-0 grow-0 basis-full',
152
+ orientation === 'horizontal' ? 'pl-4' : 'pt-4',
153
+ className,
154
+ )}
155
+ {...props}
156
+ />
157
+ );
158
+ });
159
+ CarouselItem.displayName = 'CarouselItem';
160
+
161
+ const CarouselPrevious = React.forwardRef<
162
+ HTMLButtonElement,
163
+ React.ComponentPropsWithoutRef<typeof Button>
164
+ >(({ className, variant = 'outline', size = 'icon', ...props }, ref) => {
165
+ const { orientation, scrollPrev, canScrollPrev } = useCarousel();
166
+ return (
167
+ <Button
168
+ ref={ref}
169
+ variant={variant}
170
+ size={size}
171
+ className={cn(
172
+ 'absolute size-8 rounded-full',
173
+ orientation === 'horizontal'
174
+ ? '-left-12 top-1/2 -translate-y-1/2'
175
+ : '-top-12 left-1/2 -translate-x-1/2 rotate-90',
176
+ className,
177
+ )}
178
+ disabled={!canScrollPrev}
179
+ onClick={scrollPrev}
180
+ aria-label="上一张"
181
+ {...props}
182
+ >
183
+ <ArrowLeft />
184
+ </Button>
185
+ );
186
+ });
187
+ CarouselPrevious.displayName = 'CarouselPrevious';
188
+
189
+ const CarouselNext = React.forwardRef<
190
+ HTMLButtonElement,
191
+ React.ComponentPropsWithoutRef<typeof Button>
192
+ >(({ className, variant = 'outline', size = 'icon', ...props }, ref) => {
193
+ const { orientation, scrollNext, canScrollNext } = useCarousel();
194
+ return (
195
+ <Button
196
+ ref={ref}
197
+ variant={variant}
198
+ size={size}
199
+ className={cn(
200
+ 'absolute size-8 rounded-full',
201
+ orientation === 'horizontal'
202
+ ? '-right-12 top-1/2 -translate-y-1/2'
203
+ : '-bottom-12 left-1/2 -translate-x-1/2 rotate-90',
204
+ className,
205
+ )}
206
+ disabled={!canScrollNext}
207
+ onClick={scrollNext}
208
+ aria-label="下一张"
209
+ {...props}
210
+ >
211
+ <ArrowRight />
212
+ </Button>
213
+ );
214
+ });
215
+ CarouselNext.displayName = 'CarouselNext';
216
+
217
+ export {
218
+ Carousel,
219
+ CarouselContent,
220
+ CarouselItem,
221
+ CarouselPrevious,
222
+ CarouselNext,
223
+ type CarouselApi,
224
+ };
@@ -0,0 +1,110 @@
1
+ ---
2
+ id: cascader
3
+ name: Cascader
4
+ type: component
5
+ category: form
6
+ since: 0.1.0
7
+ package: "@teamix-evo/ui"
8
+ ---
9
+
10
+ # Cascader
11
+
12
+ 级联选择 — antd 独有补足。**等价 antd `Cascader`**。多级联动选择(地区 / 分类 / 组织架构 / 文件夹路径),选项树由 `options.children` 表达;点击触发器弹出多列面板,**叶子触发 onChange**(可改 `changeOnSelect` 为每级触发)。
13
+
14
+ ## When to use
15
+
16
+ - 地区 / 行政区划选择(国 - 省 - 市 - 区)
17
+ - 分类导航(电商类目、文件夹层级)
18
+ - 组织架构选择(公司 - 部门 - 团队 - 人)
19
+
20
+ ## When NOT to use
21
+
22
+ - 单层下拉 → `Select` / `Combobox`
23
+ - 树形多选 → `TreeSelect`(可勾选)
24
+ - 离散级别独立选择 → 多个 `Select` 并排(级联弱)
25
+
26
+ <!-- auto:props:begin -->
27
+ | 名称 | 类型 | 默认值 | 必填 | 说明 |
28
+ | --- | --- | --- | --- | --- |
29
+ | `options` | `CascaderOption[]` | – | ✓ | 级联选项树(antd `options` 并集)。 |
30
+ | `value` | `string[]` | – | – | 受控值(每层 value 数组)。 |
31
+ | `defaultValue` | `string[]` | – | – | uncontrolled 初值。 |
32
+ | `onChange` | `(value: string[], selectedOptions: CascaderOption[]) => void` | – | – | 值变化回调 — 触发条件:点选叶子节点或显式 changeOnSelect。 |
33
+ | `changeOnSelect` | `boolean` | `false` | – | 每选中一级即触发 onChange(antd `changeOnSelect` 并集) — 默认仅选叶子触发。 |
34
+ | `placeholder` | `string` | `"请选择"` | – | 占位文本。 |
35
+ | `separator` | `string` | `" / "` | – | 路径展示的分隔符。 |
36
+ | `disabled` | `boolean` | – | – | 整体禁用。 |
37
+ | `className` | `string` | – | – | 触发器 className(给外层 Button)。 |
38
+ | `size` | `'sm' \| 'default' \| 'lg'` | `"default"` | – | 触发器尺寸。 |
39
+ <!-- auto:props:end -->
40
+
41
+ <!-- auto:deps:begin -->
42
+ ### 同库依赖
43
+
44
+ > `teamix-evo ui add cascader` 时,以下 entry 会被自动连带安装(无需手动 add)。
45
+
46
+ | Entry | 类型 | 描述 |
47
+ | --- | --- | --- |
48
+ | `cn` | util | Tailwind className 合并工具(clsx + tailwind-merge) |
49
+ | `button` | component | 通用按钮 — shadcn 实现 + antd 功能扩展(loading / icon / shape / block / dashed variant) |
50
+ | `popover` | component | 可交互浮层 — Radix Popover + antd arrow 并集 |
51
+
52
+ ### npm 依赖
53
+
54
+ > 业务侧需要先 `pnpm add` / `npm install` 这些包。CLI 在 `ui add` 完成后会列出此提示。
55
+
56
+ ```bash
57
+ pnpm add lucide-react@^0.460.0
58
+ ```
59
+ <!-- auto:deps:end -->
60
+
61
+ ## AI 生成纪律
62
+
63
+ - **`value` 是 value 数组**(每层一个),`onChange` 第二参数给完整 `CascaderOption` 路径 — 用第二参数拿到 label / 业务字段
64
+ - **`changeOnSelect=true`** 允许"中途选择",适合"地区可只选到省" / "分类可选到任意级"
65
+ - **同级 `value` 必须唯一**(否则 findPath 出错)— 数据准备时务必检查
66
+ - **大量节点(> 300)**建议懒加载:数据先只展开第一层,在 onChange 中按需 fetch 子节点并更新 options
67
+ - **不要给 disabled 节点设可点击的子项** — 用户预期父级禁用即整支禁用
68
+
69
+ ## Examples
70
+
71
+ ```tsx
72
+ import { Cascader, type CascaderOption } from '@/components/ui/cascader';
73
+ import * as React from 'react';
74
+
75
+ const regions: CascaderOption[] = [
76
+ {
77
+ value: 'cn',
78
+ label: '中国',
79
+ children: [
80
+ {
81
+ value: 'zj',
82
+ label: '浙江',
83
+ children: [
84
+ { value: 'hz', label: '杭州' },
85
+ { value: 'nb', label: '宁波' },
86
+ ],
87
+ },
88
+ {
89
+ value: 'jx',
90
+ label: '江西',
91
+ children: [{ value: 'nc', label: '南昌' }],
92
+ },
93
+ ],
94
+ },
95
+ ];
96
+
97
+ // 基础
98
+ <Cascader options={regions} placeholder="选择地区" />
99
+
100
+ // 中途可选
101
+ <Cascader options={regions} changeOnSelect />
102
+
103
+ // 受控
104
+ const [v, setV] = React.useState<string[]>(['cn', 'zj', 'hz']);
105
+ <Cascader
106
+ options={regions}
107
+ value={v}
108
+ onChange={(vals, opts) => setV(vals)}
109
+ />
110
+ ```
@@ -0,0 +1,108 @@
1
+ import * as React from 'react';
2
+ import type { Meta, StoryObj } from '@storybook/react';
3
+ import { Cascader, type CascaderOption } from './cascader';
4
+
5
+ const meta: Meta<typeof Cascader> = {
6
+ title: '表单与输入 · Form/Cascader',
7
+ component: Cascader,
8
+ tags: ['autodocs'],
9
+ parameters: {
10
+ docs: {
11
+ description: {
12
+ component:
13
+ '级联选择 — 多级联动(地区 / 分类 / 文件夹路径),多列面板,叶子触发 onChange(可改 changeOnSelect 为每级触发)。等价 antd `Cascader`。视觉走 OpenTrek tokens,所有样式来自 `@teamix-evo/design`,无 mock。',
14
+ },
15
+ },
16
+ },
17
+ };
18
+
19
+ export default meta;
20
+ type Story = StoryObj<typeof Cascader>;
21
+
22
+ const regions: CascaderOption[] = [
23
+ {
24
+ value: 'cn',
25
+ label: '中国',
26
+ children: [
27
+ {
28
+ value: 'zj',
29
+ label: '浙江',
30
+ children: [
31
+ { value: 'hz', label: '杭州' },
32
+ { value: 'nb', label: '宁波' },
33
+ { value: 'wz', label: '温州' },
34
+ ],
35
+ },
36
+ {
37
+ value: 'js',
38
+ label: '江苏',
39
+ children: [
40
+ { value: 'nj', label: '南京' },
41
+ { value: 'sz', label: '苏州' },
42
+ ],
43
+ },
44
+ {
45
+ value: 'jx',
46
+ label: '江西',
47
+ disabled: true,
48
+ children: [{ value: 'nc', label: '南昌' }],
49
+ },
50
+ ],
51
+ },
52
+ {
53
+ value: 'us',
54
+ label: '美国',
55
+ children: [{ value: 'ca', label: '加州', children: [{ value: 'sf', label: '旧金山' }] }],
56
+ },
57
+ ];
58
+
59
+ export const Playground: Story = {
60
+ parameters: { controls: { disable: true } },
61
+ render: () => <Cascader options={regions} placeholder="选择地区" />,
62
+ };
63
+
64
+ export const ChangeOnSelect: Story = {
65
+ parameters: { controls: { disable: true } },
66
+ render: () => {
67
+ const [v, setV] = React.useState<string[]>([]);
68
+ return (
69
+ <div className="flex flex-col gap-2">
70
+ <Cascader
71
+ options={regions}
72
+ changeOnSelect
73
+ value={v}
74
+ onChange={setV}
75
+ />
76
+ <div className="text-xs text-muted-foreground">
77
+ value: {v.length ? v.join(' / ') : '(空)'}
78
+ </div>
79
+ </div>
80
+ );
81
+ },
82
+ };
83
+
84
+ export const Controlled: Story = {
85
+ parameters: { controls: { disable: true } },
86
+ render: () => {
87
+ const [v, setV] = React.useState<string[]>(['cn', 'zj', 'hz']);
88
+ return (
89
+ <div className="flex items-center gap-3">
90
+ <Cascader options={regions} value={v} onChange={setV} />
91
+ <button
92
+ type="button"
93
+ onClick={() => setV([])}
94
+ className="text-xs text-primary hover:underline"
95
+ >
96
+ 清空
97
+ </button>
98
+ </div>
99
+ );
100
+ },
101
+ };
102
+
103
+ export const Disabled: Story = {
104
+ parameters: { controls: { disable: true } },
105
+ render: () => (
106
+ <Cascader disabled options={regions} defaultValue={['cn', 'zj', 'hz']} />
107
+ ),
108
+ };
@@ -0,0 +1,198 @@
1
+ import * as React from 'react';
2
+ import { ChevronDown, ChevronRight } from 'lucide-react';
3
+
4
+ import { cn } from '@/utils/cn';
5
+ import { Button } from '@/components/button/button';
6
+ import {
7
+ Popover,
8
+ PopoverContent,
9
+ PopoverTrigger,
10
+ } from '@/components/popover/popover';
11
+
12
+ export interface CascaderOption {
13
+ /** 级联节点 value(同级 value 必须唯一)。 */
14
+ value: string;
15
+ /** 级联节点 label。 */
16
+ label: React.ReactNode;
17
+ /** 子选项 — 无 children 视为叶子。 */
18
+ children?: CascaderOption[];
19
+ /** 禁用此项。 */
20
+ disabled?: boolean;
21
+ }
22
+
23
+ export interface CascaderProps {
24
+ /** 级联选项树(antd `options` 并集)。 */
25
+ options: CascaderOption[];
26
+ /** 受控值(每层 value 数组)。 */
27
+ value?: string[];
28
+ /** uncontrolled 初值。 */
29
+ defaultValue?: string[];
30
+ /** 值变化回调 — 触发条件:点选叶子节点或显式 changeOnSelect。 */
31
+ onChange?: (value: string[], selectedOptions: CascaderOption[]) => void;
32
+ /**
33
+ * 每选中一级即触发 onChange(antd `changeOnSelect` 并集) — 默认仅选叶子触发。
34
+ * @default false
35
+ */
36
+ changeOnSelect?: boolean;
37
+ /**
38
+ * 占位文本。
39
+ * @default "请选择"
40
+ */
41
+ placeholder?: string;
42
+ /**
43
+ * 路径展示的分隔符。
44
+ * @default " / "
45
+ */
46
+ separator?: string;
47
+ /** 整体禁用。 */
48
+ disabled?: boolean;
49
+ /**
50
+ * 触发器 className(给外层 Button)。
51
+ */
52
+ className?: string;
53
+ /**
54
+ * 触发器尺寸。
55
+ * @default "default"
56
+ */
57
+ size?: 'sm' | 'default' | 'lg';
58
+ }
59
+
60
+ function findPath(
61
+ options: CascaderOption[],
62
+ value: string[],
63
+ ): CascaderOption[] {
64
+ const path: CascaderOption[] = [];
65
+ let cursor: CascaderOption[] | undefined = options;
66
+ for (const v of value) {
67
+ const found: CascaderOption | undefined = cursor?.find((o) => o.value === v);
68
+ if (!found) break;
69
+ path.push(found);
70
+ cursor = found.children;
71
+ }
72
+ return path;
73
+ }
74
+
75
+ /**
76
+ * 级联选择 — antd 独有补足。**等价 antd `Cascader`**。多级联动选择(地区 / 分类 / 组织架构),
77
+ * 选项树由 `options.children` 表达;点击触发器弹出多列面板,**叶子触发 onChange**(可改 `changeOnSelect` 为每级触发)。
78
+ */
79
+ const Cascader = React.forwardRef<HTMLButtonElement, CascaderProps>(
80
+ (
81
+ {
82
+ options,
83
+ value,
84
+ defaultValue,
85
+ onChange,
86
+ changeOnSelect = false,
87
+ placeholder = '请选择',
88
+ separator = ' / ',
89
+ disabled = false,
90
+ className,
91
+ size = 'default',
92
+ },
93
+ ref,
94
+ ) => {
95
+ const isControlled = value !== undefined;
96
+ const [internal, setInternal] = React.useState<string[]>(defaultValue ?? []);
97
+ const current = isControlled ? value! : internal;
98
+
99
+ const [open, setOpen] = React.useState(false);
100
+ const [activePath, setActivePath] = React.useState<string[]>(current);
101
+
102
+ React.useEffect(() => {
103
+ if (open) setActivePath(current);
104
+ }, [open, current]);
105
+
106
+ const selectedPath = findPath(options, current);
107
+
108
+ const handleSelect = (level: number, opt: CascaderOption) => {
109
+ if (opt.disabled) return;
110
+ const next = [...activePath.slice(0, level), opt.value];
111
+ setActivePath(next);
112
+ const hasChildren = !!opt.children && opt.children.length > 0;
113
+ if (!hasChildren || changeOnSelect) {
114
+ const path = findPath(options, next);
115
+ if (!isControlled) setInternal(next);
116
+ onChange?.(next, path);
117
+ if (!hasChildren) setOpen(false);
118
+ }
119
+ };
120
+
121
+ // Render columns based on activePath
122
+ const columns: CascaderOption[][] = [options];
123
+ let cursor: CascaderOption[] | undefined = options;
124
+ for (const v of activePath) {
125
+ const found: CascaderOption | undefined = cursor?.find((o) => o.value === v);
126
+ if (found?.children && found.children.length > 0) {
127
+ columns.push(found.children);
128
+ cursor = found.children;
129
+ } else break;
130
+ }
131
+
132
+ const display =
133
+ selectedPath.length > 0
134
+ ? selectedPath.map((o) => o.label).join(separator)
135
+ : '';
136
+
137
+ return (
138
+ <Popover open={open} onOpenChange={setOpen}>
139
+ <PopoverTrigger asChild>
140
+ <Button
141
+ ref={ref}
142
+ type="button"
143
+ variant="outline"
144
+ size={size}
145
+ disabled={disabled}
146
+ className={cn(
147
+ 'min-w-[200px] justify-between font-normal',
148
+ !display && 'text-muted-foreground',
149
+ className,
150
+ )}
151
+ >
152
+ <span className="truncate">{display || placeholder}</span>
153
+ <ChevronDown className="ml-2 size-4 shrink-0 opacity-50" />
154
+ </Button>
155
+ </PopoverTrigger>
156
+ <PopoverContent className="flex w-auto p-0" align="start">
157
+ {columns.map((col, level) => (
158
+ <ul
159
+ key={level}
160
+ role="listbox"
161
+ className={cn(
162
+ 'min-w-[160px] max-h-72 overflow-auto py-1 text-sm',
163
+ level > 0 && 'border-l',
164
+ )}
165
+ >
166
+ {col.map((opt) => {
167
+ const isActive = activePath[level] === opt.value;
168
+ const hasChildren = !!opt.children && opt.children.length > 0;
169
+ return (
170
+ <li
171
+ key={opt.value}
172
+ role="option"
173
+ aria-selected={isActive}
174
+ onClick={() => handleSelect(level, opt)}
175
+ className={cn(
176
+ 'flex cursor-pointer items-center justify-between gap-2 px-3 py-1.5',
177
+ !opt.disabled && 'hover:bg-accent',
178
+ isActive && !opt.disabled && 'bg-accent text-accent-foreground',
179
+ opt.disabled && 'cursor-not-allowed opacity-50',
180
+ )}
181
+ >
182
+ <span className="truncate">{opt.label}</span>
183
+ {hasChildren ? (
184
+ <ChevronRight className="size-3.5 shrink-0 opacity-60" />
185
+ ) : null}
186
+ </li>
187
+ );
188
+ })}
189
+ </ul>
190
+ ))}
191
+ </PopoverContent>
192
+ </Popover>
193
+ );
194
+ },
195
+ );
196
+ Cascader.displayName = 'Cascader';
197
+
198
+ export { Cascader };