@robert-stackflow/oneui 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (380) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +72 -2
  3. package/assets/LUCIDE-LICENSE.txt +43 -0
  4. package/assets/character-metadata.json +1 -0
  5. package/assets/emoji.json +1 -0
  6. package/assets/icon-catalog.json +1 -0
  7. package/assets/symbols.json +1 -0
  8. package/components/Accessibility.module.css +8 -0
  9. package/components/Accordion.d.ts +7 -0
  10. package/components/Accordion.js +41 -0
  11. package/components/Accordion.module.css +38 -0
  12. package/components/Alert.d.ts +9 -0
  13. package/components/Alert.js +42 -0
  14. package/components/Alert.module.css +56 -0
  15. package/components/AppShell.d.ts +30 -0
  16. package/components/AppShell.js +152 -0
  17. package/components/AppShell.module.css +239 -0
  18. package/components/AppearanceSettings.d.ts +7 -0
  19. package/components/AppearanceSettings.js +201 -0
  20. package/components/AppearanceSettings.module.css +32 -0
  21. package/components/Avatar.d.ts +14 -0
  22. package/components/Avatar.js +69 -0
  23. package/components/Avatar.module.css +70 -0
  24. package/components/AvatarGroup.d.ts +15 -0
  25. package/components/AvatarGroup.js +115 -0
  26. package/components/AvatarGroup.module.css +54 -0
  27. package/components/Badge.d.ts +5 -0
  28. package/components/Badge.js +11 -0
  29. package/components/Badge.module.css +30 -0
  30. package/components/BlockedTab.d.ts +4 -0
  31. package/components/BlockedTab.js +10 -0
  32. package/components/Breadcrumb.d.ts +16 -0
  33. package/components/Breadcrumb.js +157 -0
  34. package/components/Breadcrumb.module.css +97 -0
  35. package/components/Button.d.ts +13 -0
  36. package/components/Button.js +52 -0
  37. package/components/Button.module.css +88 -0
  38. package/components/Calendar.d.ts +10 -0
  39. package/components/Calendar.js +260 -0
  40. package/components/Calendar.module.css +106 -0
  41. package/components/Card.d.ts +8 -0
  42. package/components/Card.js +29 -0
  43. package/components/Card.module.css +47 -0
  44. package/components/Cascader.d.ts +14 -0
  45. package/components/Cascader.js +296 -0
  46. package/components/CatalogIcon.d.ts +3 -0
  47. package/components/CatalogIcon.js +11 -0
  48. package/components/CharacterPicker.d.ts +15 -0
  49. package/components/CharacterPicker.js +200 -0
  50. package/components/Checkbox.d.ts +12 -0
  51. package/components/Checkbox.js +82 -0
  52. package/components/Checkbox.module.css +95 -0
  53. package/components/ColorField.d.ts +6 -0
  54. package/components/ColorField.js +61 -0
  55. package/components/ColorField.module.css +15 -0
  56. package/components/ColorPicker.d.ts +5 -0
  57. package/components/ColorPicker.js +188 -0
  58. package/components/ColorPicker.module.css +90 -0
  59. package/components/Combobox.d.ts +13 -0
  60. package/components/Combobox.js +338 -0
  61. package/components/Combobox.module.css +24 -0
  62. package/components/CommandPalette.d.ts +25 -0
  63. package/components/CommandPalette.js +269 -0
  64. package/components/CommandPalette.module.css +49 -0
  65. package/components/ContextMenu.d.ts +9 -0
  66. package/components/ContextMenu.js +363 -0
  67. package/components/ContextMenu.module.css +42 -0
  68. package/components/ContextMenuPanel.d.ts +22 -0
  69. package/components/ContextMenuPanel.js +155 -0
  70. package/components/ContributionCalendar.d.ts +18 -0
  71. package/components/ContributionCalendar.js +201 -0
  72. package/components/ContributionCalendar.module.css +114 -0
  73. package/components/ContributionCell.d.ts +11 -0
  74. package/components/ContributionCell.js +41 -0
  75. package/components/Control.module.css +86 -0
  76. package/components/DataTable.d.ts +49 -0
  77. package/components/DataTable.js +220 -0
  78. package/components/DataTable.module.css +112 -0
  79. package/components/DatePicker.d.ts +15 -0
  80. package/components/DatePicker.js +186 -0
  81. package/components/DatePicker.module.css +85 -0
  82. package/components/DateRangePicker.d.ts +9 -0
  83. package/components/DateRangePicker.js +168 -0
  84. package/components/Descriptions.d.ts +21 -0
  85. package/components/Descriptions.js +162 -0
  86. package/components/Descriptions.module.css +117 -0
  87. package/components/Dialog.d.ts +14 -0
  88. package/components/Dialog.js +125 -0
  89. package/components/Dialog.module.css +88 -0
  90. package/components/DialogVariants.d.ts +27 -0
  91. package/components/DialogVariants.js +161 -0
  92. package/components/DialogVariants.module.css +29 -0
  93. package/components/DisclosureChevron.d.ts +3 -0
  94. package/components/DisclosureChevron.js +17 -0
  95. package/components/DisclosureChevron.module.css +17 -0
  96. package/components/Divider.d.ts +5 -0
  97. package/components/Divider.js +24 -0
  98. package/components/Divider.module.css +19 -0
  99. package/components/Drawer.d.ts +18 -0
  100. package/components/Drawer.js +145 -0
  101. package/components/Drawer.module.css +109 -0
  102. package/components/EmojiPicker.d.ts +6 -0
  103. package/components/EmojiPicker.js +19 -0
  104. package/components/EmptyState.d.ts +8 -0
  105. package/components/EmptyState.js +20 -0
  106. package/components/EmptyState.module.css +30 -0
  107. package/components/FieldLabel.d.ts +8 -0
  108. package/components/FieldLabel.js +20 -0
  109. package/components/FieldMessages.d.ts +5 -0
  110. package/components/FieldMessages.js +15 -0
  111. package/components/FileDropOverlay.d.ts +5 -0
  112. package/components/FileDropOverlay.js +26 -0
  113. package/components/FileDropOverlay.module.css +55 -0
  114. package/components/FileDropZone.d.ts +15 -0
  115. package/components/FileDropZone.js +113 -0
  116. package/components/FileDropZone.module.css +6 -0
  117. package/components/FilePicker.d.ts +10 -0
  118. package/components/FilePicker.js +59 -0
  119. package/components/FileSelectionFeedback.d.ts +5 -0
  120. package/components/FileSelectionFeedback.js +23 -0
  121. package/components/FileSelectionFeedback.module.css +14 -0
  122. package/components/FileTree.d.ts +13 -0
  123. package/components/FileTree.js +125 -0
  124. package/components/FileTree.module.css +66 -0
  125. package/components/Form.d.ts +7 -0
  126. package/components/Form.js +26 -0
  127. package/components/Form.module.css +7 -0
  128. package/components/FormErrorSummary.d.ts +6 -0
  129. package/components/FormErrorSummary.js +27 -0
  130. package/components/FormErrorSummary.module.css +27 -0
  131. package/components/FormField.d.ts +9 -0
  132. package/components/FormField.js +59 -0
  133. package/components/FormField.module.css +85 -0
  134. package/components/FormGroup.d.ts +9 -0
  135. package/components/FormGroup.js +32 -0
  136. package/components/HierarchyPicker.module.css +181 -0
  137. package/components/IconButton.d.ts +7 -0
  138. package/components/IconButton.js +30 -0
  139. package/components/IconButton.module.css +42 -0
  140. package/components/IconPicker.d.ts +6 -0
  141. package/components/IconPicker.js +111 -0
  142. package/components/Indicator.d.ts +18 -0
  143. package/components/Indicator.js +97 -0
  144. package/components/Indicator.module.css +83 -0
  145. package/components/Input.d.ts +8 -0
  146. package/components/Input.js +37 -0
  147. package/components/Input.module.css +40 -0
  148. package/components/LoadingOverlay.d.ts +6 -0
  149. package/components/LoadingOverlay.js +16 -0
  150. package/components/LoadingOverlay.module.css +22 -0
  151. package/components/LoadingState.d.ts +7 -0
  152. package/components/LoadingState.js +40 -0
  153. package/components/LoadingState.module.css +17 -0
  154. package/components/Menu.d.ts +11 -0
  155. package/components/Menu.js +82 -0
  156. package/components/MenuItem.d.ts +15 -0
  157. package/components/MenuItem.js +51 -0
  158. package/components/MenuItem.module.css +172 -0
  159. package/components/MenuItemContent.d.ts +8 -0
  160. package/components/MenuItemContent.js +19 -0
  161. package/components/MultiSelect.d.ts +13 -0
  162. package/components/MultiSelect.js +225 -0
  163. package/components/MultiSelect.module.css +99 -0
  164. package/components/NumberInput.d.ts +12 -0
  165. package/components/NumberInput.js +114 -0
  166. package/components/NumberInput.module.css +33 -0
  167. package/components/OptionList.module.css +12 -0
  168. package/components/Page.d.ts +7 -0
  169. package/components/Page.js +22 -0
  170. package/components/Page.module.css +44 -0
  171. package/components/Pagination.d.ts +11 -0
  172. package/components/Pagination.js +160 -0
  173. package/components/Pagination.module.css +70 -0
  174. package/components/PasswordField.d.ts +9 -0
  175. package/components/PasswordField.js +102 -0
  176. package/components/PasswordField.module.css +64 -0
  177. package/components/Picker.module.css +52 -0
  178. package/components/PinInput.d.ts +13 -0
  179. package/components/PinInput.js +173 -0
  180. package/components/PinInput.module.css +72 -0
  181. package/components/Placeholder.d.ts +31 -0
  182. package/components/Placeholder.js +36 -0
  183. package/components/Popconfirm.d.ts +17 -0
  184. package/components/Popconfirm.js +159 -0
  185. package/components/Popconfirm.module.css +49 -0
  186. package/components/Popover.d.ts +16 -0
  187. package/components/Popover.js +156 -0
  188. package/components/Popover.module.css +19 -0
  189. package/components/Progress.d.ts +5 -0
  190. package/components/Progress.js +31 -0
  191. package/components/Progress.module.css +33 -0
  192. package/components/RadioGroup.d.ts +15 -0
  193. package/components/RadioGroup.js +73 -0
  194. package/components/RadioGroup.module.css +87 -0
  195. package/components/RangeSlider.d.ts +22 -0
  196. package/components/RangeSlider.js +278 -0
  197. package/components/RangeSlider.module.css +141 -0
  198. package/components/ResizablePanel.d.ts +21 -0
  199. package/components/ResizablePanel.js +219 -0
  200. package/components/ResizablePanel.module.css +101 -0
  201. package/components/SearchField.d.ts +11 -0
  202. package/components/SearchField.js +67 -0
  203. package/components/SearchField.module.css +37 -0
  204. package/components/Section.d.ts +6 -0
  205. package/components/Section.js +18 -0
  206. package/components/Section.module.css +14 -0
  207. package/components/Segmented.d.ts +11 -0
  208. package/components/Segmented.js +77 -0
  209. package/components/Segmented.module.css +82 -0
  210. package/components/Select.d.ts +11 -0
  211. package/components/Select.js +172 -0
  212. package/components/Select.module.css +24 -0
  213. package/components/SelectOptionContent.d.ts +5 -0
  214. package/components/SelectOptionContent.js +20 -0
  215. package/components/SelectOptionContent.module.css +7 -0
  216. package/components/SelectTrigger.d.ts +5 -0
  217. package/components/SelectTrigger.js +32 -0
  218. package/components/SelectTrigger.module.css +24 -0
  219. package/components/SelectionTag.d.ts +8 -0
  220. package/components/SelectionTag.js +39 -0
  221. package/components/SettingRow.d.ts +7 -0
  222. package/components/SettingRow.js +19 -0
  223. package/components/SettingRow.module.css +44 -0
  224. package/components/SettingsLayout.d.ts +11 -0
  225. package/components/SettingsLayout.js +61 -0
  226. package/components/SettingsLayout.module.css +68 -0
  227. package/components/ShortcutInput.d.ts +8 -0
  228. package/components/ShortcutInput.js +131 -0
  229. package/components/ShortcutInput.module.css +39 -0
  230. package/components/Skeleton.d.ts +5 -0
  231. package/components/Skeleton.js +19 -0
  232. package/components/Skeleton.module.css +27 -0
  233. package/components/SkeletonRows.d.ts +4 -0
  234. package/components/SkeletonRows.js +19 -0
  235. package/components/SkeletonRows.module.css +19 -0
  236. package/components/SkinTonePicker.d.ts +4 -0
  237. package/components/SkinTonePicker.js +43 -0
  238. package/components/SkinTonePicker.module.css +50 -0
  239. package/components/Slider.d.ts +10 -0
  240. package/components/Slider.js +40 -0
  241. package/components/Slider.module.css +19 -0
  242. package/components/Spinner.d.ts +6 -0
  243. package/components/Spinner.js +31 -0
  244. package/components/Spinner.module.css +57 -0
  245. package/components/SplitButton.d.ts +17 -0
  246. package/components/SplitButton.js +102 -0
  247. package/components/SplitButton.module.css +56 -0
  248. package/components/Statistic.d.ts +22 -0
  249. package/components/Statistic.js +102 -0
  250. package/components/Statistic.module.css +55 -0
  251. package/components/Steps.d.ts +19 -0
  252. package/components/Steps.js +102 -0
  253. package/components/Steps.module.css +176 -0
  254. package/components/Switch.d.ts +6 -0
  255. package/components/Switch.js +25 -0
  256. package/components/Switch.module.css +59 -0
  257. package/components/SymbolPicker.d.ts +6 -0
  258. package/components/SymbolPicker.js +18 -0
  259. package/components/Tab.module.css +145 -0
  260. package/components/TabList.d.ts +11 -0
  261. package/components/TabList.js +51 -0
  262. package/components/Table.d.ts +16 -0
  263. package/components/Table.js +30 -0
  264. package/components/Table.module.css +48 -0
  265. package/components/TableColumnFilter.d.ts +6 -0
  266. package/components/TableColumnFilter.js +76 -0
  267. package/components/TableColumnVisibility.d.ts +11 -0
  268. package/components/TableColumnVisibility.js +76 -0
  269. package/components/Tabs.d.ts +13 -0
  270. package/components/Tabs.js +49 -0
  271. package/components/Tabs.module.css +3 -0
  272. package/components/TagInput.d.ts +11 -0
  273. package/components/TagInput.js +142 -0
  274. package/components/TagInput.module.css +64 -0
  275. package/components/Textarea.d.ts +6 -0
  276. package/components/Textarea.js +24 -0
  277. package/components/Textarea.module.css +9 -0
  278. package/components/ThemePicker.d.ts +6 -0
  279. package/components/ThemePicker.js +78 -0
  280. package/components/ThemePicker.module.css +178 -0
  281. package/components/ThemeProvider.d.ts +11 -0
  282. package/components/ThemeProvider.js +94 -0
  283. package/components/ThemeStylePicker.d.ts +5 -0
  284. package/components/ThemeStylePicker.js +22 -0
  285. package/components/TimeColumns.d.ts +6 -0
  286. package/components/TimeColumns.js +55 -0
  287. package/components/TimeColumns.module.css +47 -0
  288. package/components/Timeline.d.ts +26 -0
  289. package/components/Timeline.js +131 -0
  290. package/components/Timeline.module.css +202 -0
  291. package/components/Toast.d.ts +6 -0
  292. package/components/Toast.js +181 -0
  293. package/components/Toast.module.css +175 -0
  294. package/components/ToastProvider.d.ts +35 -0
  295. package/components/ToastProvider.js +47 -0
  296. package/components/Tooltip.d.ts +10 -0
  297. package/components/Tooltip.js +169 -0
  298. package/components/Tooltip.module.css +53 -0
  299. package/components/TreeGuides.d.ts +9 -0
  300. package/components/TreeGuides.js +39 -0
  301. package/components/TreeGuides.module.css +45 -0
  302. package/components/TreeSelect.d.ts +26 -0
  303. package/components/TreeSelect.js +337 -0
  304. package/components/TreeTable.d.ts +15 -0
  305. package/components/TreeTable.js +151 -0
  306. package/components/TreeTable.module.css +53 -0
  307. package/components/UIProvider.d.ts +10 -0
  308. package/components/UIProvider.js +20 -0
  309. package/components/UnderlinedTab.d.ts +2 -0
  310. package/components/UnderlinedTab.js +8 -0
  311. package/components/Upload.d.ts +22 -0
  312. package/components/Upload.js +165 -0
  313. package/components/Upload.module.css +36 -0
  314. package/components/UploadList.d.ts +9 -0
  315. package/components/UploadList.js +14 -0
  316. package/components/UploadList.module.css +130 -0
  317. package/components/UploadListItem.d.ts +13 -0
  318. package/components/UploadListItem.js +122 -0
  319. package/components/VirtualPickerList.d.ts +25 -0
  320. package/components/VirtualPickerList.js +269 -0
  321. package/components/VirtualPickerList.module.css +93 -0
  322. package/components/appearance.d.ts +20 -0
  323. package/components/appearance.js +69 -0
  324. package/components/characterCatalog.d.ts +9 -0
  325. package/components/characterCatalog.js +55 -0
  326. package/components/color.d.ts +7 -0
  327. package/components/color.js +18 -0
  328. package/components/contribution.d.ts +57 -0
  329. package/components/contribution.js +86 -0
  330. package/components/dateConstraints.d.ts +13 -0
  331. package/components/dateConstraints.js +44 -0
  332. package/components/field.d.ts +58 -0
  333. package/components/field.js +57 -0
  334. package/components/fileSelection.d.ts +21 -0
  335. package/components/fileSelection.js +43 -0
  336. package/components/hierarchy.d.ts +23 -0
  337. package/components/hierarchy.js +33 -0
  338. package/components/iconCatalog.d.ts +13 -0
  339. package/components/iconCatalog.js +80 -0
  340. package/components/index.d.ts +152 -0
  341. package/components/index.js +225 -0
  342. package/components/menuFocus.d.ts +7 -0
  343. package/components/menuFocus.js +21 -0
  344. package/components/menuPointer.d.ts +6 -0
  345. package/components/menuPointer.js +13 -0
  346. package/components/menuTypes.d.ts +24 -0
  347. package/components/menuTypes.js +0 -0
  348. package/components/motion.d.ts +9 -0
  349. package/components/motion.js +82 -0
  350. package/components/rangeMath.d.ts +12 -0
  351. package/components/rangeMath.js +30 -0
  352. package/components/surfacePortal.d.ts +13 -0
  353. package/components/surfacePortal.js +22 -0
  354. package/components/tooltipState.d.ts +5 -0
  355. package/components/tooltipState.js +48 -0
  356. package/components/types.d.ts +9 -0
  357. package/components/types.js +0 -0
  358. package/components/uploadTypes.d.ts +21 -0
  359. package/components/uploadTypes.js +0 -0
  360. package/components/useFormState.d.ts +51 -0
  361. package/components/useFormState.js +218 -0
  362. package/components/useHierarchy.d.ts +8 -0
  363. package/components/useHierarchy.js +80 -0
  364. package/components/useMenuLayers.d.ts +17 -0
  365. package/components/useMenuLayers.js +23 -0
  366. package/components/useModalScrollLock.d.ts +1 -0
  367. package/components/useModalScrollLock.js +18 -0
  368. package/components/usePopover.d.ts +8 -0
  369. package/components/usePopover.js +22 -0
  370. package/components/useTabIndicator.d.ts +12 -0
  371. package/components/useTabIndicator.js +63 -0
  372. package/components/useUploadQueue.d.ts +20 -0
  373. package/components/useUploadQueue.js +175 -0
  374. package/package.json +810 -3
  375. package/styles/base.css +206 -0
  376. package/styles/blue.css +268 -0
  377. package/styles/desktop.css +2 -0
  378. package/styles/minimal.css +337 -0
  379. package/styles/themes.css +2 -0
  380. package/styles/web.css +2 -0
@@ -0,0 +1,49 @@
1
+ import { type ReactNode } from "react";
2
+ export interface TableColumn<T> {
3
+ key: string;
4
+ label: string;
5
+ value(row: T): string | number;
6
+ render?(row: T): ReactNode;
7
+ sortable?: boolean;
8
+ filterOptions?: string[];
9
+ hideable?: boolean;
10
+ }
11
+ export type TableSort = {
12
+ key: string;
13
+ direction: "asc" | "desc";
14
+ } | null;
15
+ export type TableFilters = Record<string, string[]>;
16
+ export type TablePagination = {
17
+ page: number;
18
+ pageSize: number;
19
+ };
20
+ export type DataTableProps<T, K extends string | number> = {
21
+ rows: T[];
22
+ columns: TableColumn<T>[];
23
+ rowKey(row: T): K;
24
+ label?: string;
25
+ selected?: K[];
26
+ onSelectionChange?(ids: K[]): void;
27
+ selectionLabel?(row: T): string;
28
+ initialPageSize?: number;
29
+ loading?: boolean;
30
+ sort?: TableSort;
31
+ defaultSort?: TableSort;
32
+ onSortChange?(sort: TableSort): void;
33
+ filters?: TableFilters;
34
+ defaultFilters?: TableFilters;
35
+ onFiltersChange?(filters: TableFilters): void;
36
+ pagination?: TablePagination;
37
+ defaultPagination?: Partial<TablePagination>;
38
+ onPaginationChange?(pagination: TablePagination): void;
39
+ pageSizes?: number[];
40
+ visibleColumns?: string[];
41
+ defaultVisibleColumns?: string[];
42
+ onVisibleColumnsChange?(keys: string[]): void;
43
+ showColumnSelector?: boolean;
44
+ manualFiltering?: boolean;
45
+ manualSorting?: boolean;
46
+ manualPagination?: boolean;
47
+ total?: number;
48
+ };
49
+ export declare function DataTable<T, K extends string | number>({ rows, columns, rowKey, label, selected, onSelectionChange, selectionLabel, initialPageSize, loading, sort: controlledSort, defaultSort, onSortChange, filters: controlledFilters, defaultFilters, onFiltersChange, pagination, defaultPagination, onPaginationChange, pageSizes, visibleColumns, defaultVisibleColumns, onVisibleColumnsChange, showColumnSelector, manualFiltering, manualSorting, manualPagination, total, }: DataTableProps<T, K>): import("react").JSX.Element;
@@ -0,0 +1,220 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useMemo, useState } from "react";
3
+ import { ArrowDown, ArrowUp, ArrowUpDown } from "lucide-react";
4
+ import { Checkbox } from "./Checkbox.js";
5
+ import { Pagination } from "./Pagination.js";
6
+ import { TableColumnFilter } from "./TableColumnFilter.js";
7
+ import { TableColumnVisibility } from "./TableColumnVisibility.js";
8
+ import { Button } from "./Button.js";
9
+ import { Placeholder } from "./Placeholder.js";
10
+ import { LoadingOverlay } from "./LoadingOverlay.js";
11
+ import s from "./DataTable.module.css";
12
+ const positive = (value, fallback) => typeof value === "number" && Number.isFinite(value) ? Math.max(1, Math.floor(value)) : fallback;
13
+ function DataTable({
14
+ rows,
15
+ columns,
16
+ rowKey,
17
+ label = "\u6570\u636E\u8868\u683C",
18
+ selected,
19
+ onSelectionChange,
20
+ selectionLabel,
21
+ initialPageSize = 5,
22
+ loading = false,
23
+ sort: controlledSort,
24
+ defaultSort = null,
25
+ onSortChange,
26
+ filters: controlledFilters,
27
+ defaultFilters = {},
28
+ onFiltersChange,
29
+ pagination,
30
+ defaultPagination,
31
+ onPaginationChange,
32
+ pageSizes,
33
+ visibleColumns,
34
+ defaultVisibleColumns,
35
+ onVisibleColumnsChange,
36
+ showColumnSelector = true,
37
+ manualFiltering = false,
38
+ manualSorting = false,
39
+ manualPagination = false,
40
+ total
41
+ }) {
42
+ const [localSort, setLocalSort] = useState(defaultSort), [localFilters, setLocalFilters] = useState(defaultFilters), [localPage, setLocalPage] = useState({
43
+ page: positive(defaultPagination?.page, 1),
44
+ pageSize: positive(
45
+ defaultPagination?.pageSize,
46
+ positive(initialPageSize, 5)
47
+ )
48
+ }), [hidden, setHidden] = useState(
49
+ () => defaultVisibleColumns ? columns.filter((column) => !defaultVisibleColumns.includes(column.key)).map((column) => column.key) : []
50
+ );
51
+ const sort = controlledSort === void 0 ? localSort : controlledSort, filters = controlledFilters ?? localFilters;
52
+ const pageSize = positive(pagination?.pageSize, localPage.pageSize), page = positive(pagination?.page, localPage.page);
53
+ const filtered = useMemo(() => {
54
+ const result = manualFiltering ? [...rows] : rows.filter(
55
+ (row) => columns.every(
56
+ (column2) => !filters[column2.key]?.length || filters[column2.key].includes(String(column2.value(row)))
57
+ )
58
+ );
59
+ const column = columns.find((item) => item.key === sort?.key);
60
+ if (column && sort && !manualSorting)
61
+ result.sort((a, b) => {
62
+ const x = column.value(a), y = column.value(b);
63
+ return (typeof x === "number" && typeof y === "number" ? x - y : String(x).localeCompare(String(y), "zh-CN", { numeric: true })) * (sort.direction === "asc" ? 1 : -1);
64
+ });
65
+ return result;
66
+ }, [rows, columns, filters, sort, manualFiltering, manualSorting]);
67
+ const count = manualPagination ? typeof total === "number" && Number.isFinite(total) ? Math.max(0, Math.floor(total)) : rows.length : filtered.length;
68
+ const current = Math.min(page, Math.max(1, Math.ceil(count / pageSize))), visible = manualPagination ? filtered : filtered.slice((current - 1) * pageSize, current * pageSize), ids = visible.map(rowKey), selection = selected || [], selectedCount = ids.filter((key) => selection.includes(key)).length;
69
+ const normalizeColumns = (keys) => {
70
+ const next = columns.filter(
71
+ (column) => column.hideable === false || keys.includes(column.key)
72
+ ).map((column) => column.key);
73
+ if (!next.length && columns[0]) next.push(columns[0].key);
74
+ return next;
75
+ };
76
+ const visibleKeys = normalizeColumns(
77
+ visibleColumns ?? columns.filter((column) => !hidden.includes(column.key)).map((column) => column.key)
78
+ ), displayColumns = columns.filter(
79
+ (column) => visibleKeys.includes(column.key)
80
+ );
81
+ const changePage = (next) => {
82
+ if (pagination === void 0) setLocalPage(next);
83
+ if (next.page !== current || next.pageSize !== pageSize)
84
+ onPaginationChange?.(next);
85
+ };
86
+ const changeSort = (next) => {
87
+ if (controlledSort === void 0) setLocalSort(next);
88
+ onSortChange?.(next);
89
+ changePage({ page: 1, pageSize });
90
+ };
91
+ const changeFilters = (next) => {
92
+ if (controlledFilters === void 0) setLocalFilters(next);
93
+ onFiltersChange?.(next);
94
+ changePage({ page: 1, pageSize });
95
+ };
96
+ const active = !!sort || columns.some((column) => filters[column.key]?.length);
97
+ return /* @__PURE__ */ jsxs("div", { className: s.container, role: "region", "aria-label": `${label}\u533A\u57DF`, children: [
98
+ (showColumnSelector || active) && /* @__PURE__ */ jsxs("div", { className: s.toolbar, children: [
99
+ active && /* @__PURE__ */ jsx(
100
+ Button,
101
+ {
102
+ variant: "ghost",
103
+ onClick: () => {
104
+ if (controlledSort === void 0) setLocalSort(null);
105
+ if (controlledFilters === void 0) setLocalFilters({});
106
+ onSortChange?.(null);
107
+ onFiltersChange?.({});
108
+ changePage({ page: 1, pageSize });
109
+ },
110
+ children: "\u6E05\u9664\u7B5B\u9009\u4E0E\u6392\u5E8F"
111
+ }
112
+ ),
113
+ showColumnSelector && /* @__PURE__ */ jsx(
114
+ TableColumnVisibility,
115
+ {
116
+ columns,
117
+ value: visibleKeys,
118
+ label: `${label}\u663E\u793A\u5217`,
119
+ onChange: (keys) => {
120
+ const next = normalizeColumns(keys);
121
+ if (visibleColumns === void 0)
122
+ setHidden(
123
+ columns.filter((column) => !next.includes(column.key)).map((column) => column.key)
124
+ );
125
+ onVisibleColumnsChange?.(next);
126
+ }
127
+ }
128
+ )
129
+ ] }),
130
+ /* @__PURE__ */ jsx(LoadingOverlay, { active: loading, children: /* @__PURE__ */ jsxs("div", { className: s.scroll, children: [
131
+ /* @__PURE__ */ jsxs("table", { className: s.table, "aria-label": label, children: [
132
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
133
+ onSelectionChange && /* @__PURE__ */ jsx("th", { className: s.selection, children: /* @__PURE__ */ jsx(
134
+ Checkbox,
135
+ {
136
+ label: "\u9009\u62E9\u5F53\u524D\u9875",
137
+ checked: ids.length > 0 && selectedCount === ids.length,
138
+ indeterminate: selectedCount > 0 && selectedCount < ids.length,
139
+ disabled: !ids.length,
140
+ onChange: (checked) => onSelectionChange(
141
+ checked ? [.../* @__PURE__ */ new Set([...selection, ...ids])] : selection.filter((key) => !ids.includes(key))
142
+ )
143
+ }
144
+ ) }),
145
+ displayColumns.map((column) => /* @__PURE__ */ jsx(
146
+ "th",
147
+ {
148
+ scope: "col",
149
+ "aria-sort": sort?.key === column.key ? sort.direction === "asc" ? "ascending" : "descending" : "none",
150
+ children: /* @__PURE__ */ jsxs("div", { className: s.heading, children: [
151
+ column.sortable ? /* @__PURE__ */ jsxs(
152
+ "button",
153
+ {
154
+ type: "button",
155
+ className: s.sort,
156
+ "aria-label": `\u6392\u5E8F${column.label}`,
157
+ onClick: () => changeSort(
158
+ sort?.key !== column.key ? { key: column.key, direction: "asc" } : sort.direction === "asc" ? { key: column.key, direction: "desc" } : null
159
+ ),
160
+ children: [
161
+ column.label,
162
+ sort?.key === column.key ? sort.direction === "asc" ? /* @__PURE__ */ jsx(ArrowUp, {}) : /* @__PURE__ */ jsx(ArrowDown, {}) : /* @__PURE__ */ jsx(ArrowUpDown, {})
163
+ ]
164
+ }
165
+ ) : column.label,
166
+ column.filterOptions && /* @__PURE__ */ jsx(
167
+ TableColumnFilter,
168
+ {
169
+ label: column.label,
170
+ options: column.filterOptions,
171
+ value: filters[column.key] || [],
172
+ onChange: (values) => changeFilters({ ...filters, [column.key]: values })
173
+ }
174
+ )
175
+ ] })
176
+ },
177
+ column.key
178
+ ))
179
+ ] }) }),
180
+ /* @__PURE__ */ jsx("tbody", { children: visible.map((row) => /* @__PURE__ */ jsxs(
181
+ "tr",
182
+ {
183
+ "data-selected": selection.includes(rowKey(row)),
184
+ children: [
185
+ onSelectionChange && /* @__PURE__ */ jsx("td", { className: s.selection, children: /* @__PURE__ */ jsx(
186
+ Checkbox,
187
+ {
188
+ label: selectionLabel?.(row) || `\u9009\u62E9${rowKey(row)}`,
189
+ checked: selection.includes(rowKey(row)),
190
+ onChange: (checked) => onSelectionChange(
191
+ checked ? [.../* @__PURE__ */ new Set([...selection, rowKey(row)])] : selection.filter((key) => key !== rowKey(row))
192
+ )
193
+ }
194
+ ) }),
195
+ displayColumns.map((column) => /* @__PURE__ */ jsx("td", { children: column.render ? column.render(row) : column.value(row) }, column.key))
196
+ ]
197
+ },
198
+ rowKey(row)
199
+ )) })
200
+ ] }),
201
+ !filtered.length && /* @__PURE__ */ jsx(Placeholder, { variant: rows.length ? "search" : "empty" })
202
+ ] }) }),
203
+ /* @__PURE__ */ jsx(
204
+ Pagination,
205
+ {
206
+ summary: selection.length ? ` \xB7 \u5DF2\u9009\u62E9 ${selection.length} \u9879` : void 0,
207
+ page: current,
208
+ pageSize,
209
+ total: count,
210
+ pageSizes,
211
+ resetPageOnSizeChange: false,
212
+ onPageChange: (next) => changePage({ page: next, pageSize }),
213
+ onPageSizeChange: (next) => changePage({ page: 1, pageSize: next })
214
+ }
215
+ )
216
+ ] });
217
+ }
218
+ export {
219
+ DataTable
220
+ };
@@ -0,0 +1,112 @@
1
+ .container {
2
+ min-width: 0;
3
+ }
4
+ .toolbar {
5
+ display: flex;
6
+ justify-content: flex-end;
7
+ align-items: center;
8
+ gap: 8px;
9
+ flex-wrap: wrap;
10
+ margin-bottom: 12px;
11
+ }
12
+ .columnMenu {
13
+ display: flex;
14
+ flex-direction: column;
15
+ }
16
+ .scroll {
17
+ overflow: auto;
18
+ border: 1px solid var(--line);
19
+ border-radius: var(--radius);
20
+ }
21
+ .table {
22
+ width: 100%;
23
+ border-collapse: collapse;
24
+ text-align: left;
25
+ white-space: nowrap;
26
+ }
27
+ .table th {
28
+ background: var(--soft);
29
+ font-size: 12px;
30
+ font-weight: 500;
31
+ color: var(--muted);
32
+ }
33
+ .table td,
34
+ .table th {
35
+ padding: 12px 16px;
36
+ border-bottom: var(--separator-width) var(--separator-style)
37
+ var(--separator-color);
38
+ height: 48px;
39
+ }
40
+ .table tbody tr:last-child td {
41
+ border-bottom: 0;
42
+ }
43
+ .table tbody tr:hover {
44
+ background: var(--hover);
45
+ }
46
+ .table tr[data-selected="true"] {
47
+ background: var(--selected);
48
+ }
49
+ .heading {
50
+ display: flex;
51
+ align-items: center;
52
+ justify-content: space-between;
53
+ gap: 8px;
54
+ }
55
+ .sort,
56
+ .filter {
57
+ display: inline-flex;
58
+ align-items: center;
59
+ gap: 7px;
60
+ border: 0;
61
+ background: transparent;
62
+ padding: 4px;
63
+ border-radius: 5px;
64
+ color: inherit;
65
+ }
66
+ .sort:hover,
67
+ .filter:hover {
68
+ background: var(--hover);
69
+ color: var(--fg);
70
+ }
71
+ .sort svg,
72
+ .filter svg {
73
+ width: 14px;
74
+ height: 14px;
75
+ }
76
+ .filter[data-active="true"] {
77
+ color: var(--accent);
78
+ background: var(--selected);
79
+ }
80
+ .filterPanel {
81
+ max-height: 300px;
82
+ overflow: auto;
83
+ }
84
+ .selection {
85
+ width: 44px;
86
+ }
87
+ .selection label > span:last-child {
88
+ position: absolute;
89
+ width: 1px;
90
+ height: 1px;
91
+ overflow: hidden;
92
+ clip-path: inset(50%);
93
+ }
94
+ .table td > button {
95
+ display: flex;
96
+ gap: 9px;
97
+ align-items: center;
98
+ border: 0;
99
+ background: transparent;
100
+ border-radius: 5px;
101
+ padding: 4px;
102
+ color: inherit;
103
+ }
104
+
105
+ .filterReset {
106
+ display: flex;
107
+ justify-content: flex-end;
108
+ margin-top: 6px;
109
+ padding-top: 6px;
110
+ border-top: var(--separator-width) var(--separator-style)
111
+ var(--separator-color);
112
+ }
@@ -0,0 +1,15 @@
1
+ import { type FieldOptions } from "./field";
2
+ import { type DateConstraints } from "./dateConstraints";
3
+ import { type DateRangePickerProps } from "./DateRangePicker";
4
+ export type DatePickerMode = "date" | "time" | "datetime" | "range";
5
+ export type SingleDatePickerProps = FieldOptions & DateConstraints & {
6
+ value: string;
7
+ onChange(value: string): void;
8
+ label: string;
9
+ mode?: Exclude<DatePickerMode, "range">;
10
+ seconds?: boolean;
11
+ };
12
+ export type DatePickerProps = SingleDatePickerProps | (DateRangePickerProps & {
13
+ mode: "range";
14
+ });
15
+ export declare function DatePicker(props: DatePickerProps): import("react").JSX.Element;
@@ -0,0 +1,186 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { createElement } from "react";
3
+ import { fieldTriggerProps, useFieldControl } from "./field.js";
4
+ import { useId, useState } from "react";
5
+ import { CalendarDays, Clock3 } from "lucide-react";
6
+ import { Popover } from "./Popover.js";
7
+ import { usePopover } from "./usePopover.js";
8
+ import { Calendar, dateKey } from "./Calendar.js";
9
+ import { TimeColumns } from "./TimeColumns.js";
10
+ import { Button } from "./Button.js";
11
+ import s from "./DatePicker.module.css";
12
+ import {
13
+ boundedDate,
14
+ isDateAllowed
15
+ } from "./dateConstraints.js";
16
+ import { DateRangePicker } from "./DateRangePicker.js";
17
+ function DatePicker(props) {
18
+ return props.mode === "range" ? /* @__PURE__ */ jsx(DateRangePicker, { ...props }) : /* @__PURE__ */ jsx(SingleDatePicker, { ...props });
19
+ }
20
+ function SingleDatePicker({
21
+ value,
22
+ onChange,
23
+ label,
24
+ mode = "date",
25
+ seconds = false,
26
+ disabled,
27
+ readOnly,
28
+ name,
29
+ id: controlId,
30
+ required,
31
+ error,
32
+ hint,
33
+ minDate,
34
+ maxDate,
35
+ disabledDate,
36
+ ...aria
37
+ }) {
38
+ const constraints = { minDate, maxDate, disabledDate };
39
+ const field = useFieldControl({
40
+ id: controlId,
41
+ name,
42
+ label,
43
+ disabled,
44
+ readOnly,
45
+ required,
46
+ error,
47
+ hint,
48
+ ...aria
49
+ });
50
+ const pop = usePopover(field.disabled || field.readOnly), id = useId(), [date, setDate] = useState(value.slice(0, 10) || dateKey(/* @__PURE__ */ new Date())), [time, setTime] = useState("00:00");
51
+ const close = pop.closeAndFocus;
52
+ const show = () => {
53
+ if (field.disabled || field.readOnly) return;
54
+ if (pop.open) {
55
+ pop.close();
56
+ return;
57
+ }
58
+ setDate(
59
+ mode === "time" ? dateKey(/* @__PURE__ */ new Date()) : boundedDate(value.slice(0, 10), constraints)
60
+ );
61
+ setTime(
62
+ (mode === "time" ? value : value.split(/[T ]/)[1]) || (seconds ? "00:00:00" : "00:00")
63
+ );
64
+ pop.show();
65
+ };
66
+ const commit = () => {
67
+ if (mode !== "time" && !isDateAllowed(date, constraints)) return;
68
+ onChange(
69
+ mode === "date" ? date : mode === "time" ? time : date + "T" + time
70
+ );
71
+ close();
72
+ };
73
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
74
+ /* @__PURE__ */ jsxs(
75
+ "button",
76
+ {
77
+ ...fieldTriggerProps(field),
78
+ role: "combobox",
79
+ ref: pop.anchor,
80
+ type: "button",
81
+ className: s.trigger,
82
+ "aria-expanded": pop.open,
83
+ "aria-haspopup": "dialog",
84
+ "aria-controls": id,
85
+ onClick: show,
86
+ onKeyDown: (e) => {
87
+ if (e.key === "ArrowDown" && !pop.open) {
88
+ e.preventDefault();
89
+ show();
90
+ }
91
+ },
92
+ children: [
93
+ /* @__PURE__ */ jsx("span", { children: value.replace("T", " ") || "\u8BF7\u9009\u62E9" }),
94
+ mode === "time" ? /* @__PURE__ */ jsx(Clock3, {}) : /* @__PURE__ */ jsx(CalendarDays, {})
95
+ ]
96
+ }
97
+ ),
98
+ field.name && /* @__PURE__ */ jsx(
99
+ "input",
100
+ {
101
+ type: "hidden",
102
+ name: field.name,
103
+ value,
104
+ disabled: field.disabled
105
+ }
106
+ ),
107
+ /* @__PURE__ */ jsxs(
108
+ Popover,
109
+ {
110
+ anchor: pop.anchor,
111
+ open: pop.open,
112
+ onClose: pop.close,
113
+ label,
114
+ id,
115
+ width: mode === "datetime" ? seconds ? 530 : 470 : mode === "time" ? seconds ? 260 : 210 : 288,
116
+ children: [
117
+ /* @__PURE__ */ jsxs("div", { className: s.body, "data-mode": mode, children: [
118
+ mode !== "time" && /* @__PURE__ */ createElement(
119
+ Calendar,
120
+ {
121
+ ...constraints,
122
+ key: pop.open ? "open" : "closed",
123
+ value: date,
124
+ onChange: (next) => {
125
+ if (!isDateAllowed(next, constraints)) return;
126
+ setDate(next);
127
+ if (mode === "date") {
128
+ onChange(next);
129
+ close();
130
+ }
131
+ }
132
+ }
133
+ ),
134
+ mode !== "date" && /* @__PURE__ */ jsx(
135
+ TimeColumns,
136
+ {
137
+ value: time,
138
+ onChange: setTime,
139
+ seconds,
140
+ active: pop.open
141
+ }
142
+ )
143
+ ] }),
144
+ /* @__PURE__ */ jsxs("footer", { className: s.footer, children: [
145
+ /* @__PURE__ */ jsx(
146
+ "button",
147
+ {
148
+ type: "button",
149
+ disabled: mode !== "time" && !isDateAllowed(dateKey(/* @__PURE__ */ new Date()), constraints),
150
+ onClick: () => {
151
+ const now = /* @__PURE__ */ new Date(), nextDate = dateKey(now), nextTime = [
152
+ now.getHours(),
153
+ now.getMinutes(),
154
+ ...seconds ? [now.getSeconds()] : []
155
+ ].map((v) => String(v).padStart(2, "0")).join(":");
156
+ if (mode !== "time" && !isDateAllowed(nextDate, constraints))
157
+ return;
158
+ setDate(nextDate);
159
+ setTime(nextTime);
160
+ if (mode === "date") {
161
+ onChange(nextDate);
162
+ close();
163
+ }
164
+ },
165
+ children: mode === "date" ? "\u4ECA\u5929" : "\u6B64\u523B"
166
+ }
167
+ ),
168
+ mode !== "date" && /* @__PURE__ */ jsx(
169
+ Button,
170
+ {
171
+ variant: "primary",
172
+ size: "small",
173
+ onClick: commit,
174
+ disabled: mode !== "time" && !isDateAllowed(date, constraints),
175
+ children: "\u786E\u5B9A"
176
+ }
177
+ )
178
+ ] })
179
+ ]
180
+ }
181
+ )
182
+ ] });
183
+ }
184
+ export {
185
+ DatePicker
186
+ };
@@ -0,0 +1,85 @@
1
+ .trigger {
2
+ composes: surface from "./Control.module.css";
3
+ display: flex;
4
+ align-items: center;
5
+ justify-content: space-between;
6
+ gap: 18px;
7
+ padding: 5px 10px;
8
+ min-width: 168px;
9
+ }
10
+ .trigger svg {
11
+ width: 15px;
12
+ height: 15px;
13
+ color: var(--muted);
14
+ }
15
+ .body {
16
+ display: flex;
17
+ }
18
+ .body[data-mode="datetime"] > :first-child {
19
+ flex: 1;
20
+ }
21
+ .body[data-mode="datetime"] > :last-child {
22
+ width: 170px;
23
+ border-left: var(--separator-width) var(--separator-style)
24
+ var(--separator-color);
25
+ margin-left: 8px;
26
+ }
27
+ .body[data-mode="time"] > div {
28
+ width: 100%;
29
+ }
30
+ .footer {
31
+ display: flex;
32
+ align-items: center;
33
+ justify-content: space-between;
34
+ padding: 9px 4px 4px;
35
+ margin-top: 6px;
36
+ border-top: var(--separator-width) var(--separator-style)
37
+ var(--separator-color);
38
+ min-height: 38px;
39
+ }
40
+ .footer > button:first-child {
41
+ border: 0;
42
+ background: transparent;
43
+ border-radius: 5px;
44
+ padding: 5px 10px;
45
+ font-size: 12px;
46
+ }
47
+ .footer > button:first-child:hover {
48
+ background: var(--hover);
49
+ }
50
+ .footer > button:first-child:disabled {
51
+ cursor: not-allowed;
52
+ opacity: 0.42;
53
+ }
54
+ .footer > button:first-child:disabled:hover {
55
+ background: transparent;
56
+ }
57
+ .rangeSummary {
58
+ display: flex;
59
+ align-items: center;
60
+ justify-content: space-between;
61
+ gap: 8px;
62
+ padding: 9px 8px;
63
+ font-size: 12px;
64
+ border-bottom: var(--separator-width) var(--separator-style)
65
+ var(--separator-color);
66
+ }
67
+ .rangeSummary > svg {
68
+ width: 14px;
69
+ height: 14px;
70
+ color: var(--muted);
71
+ }
72
+ .rangeError {
73
+ min-height: 20px;
74
+ color: var(--danger);
75
+ font-size: 11px;
76
+ padding: 2px 6px;
77
+ }
78
+ .rangeActions {
79
+ display: flex;
80
+ align-items: center;
81
+ gap: 6px;
82
+ }
83
+ .footer > button:only-child {
84
+ width: 100%;
85
+ }
@@ -0,0 +1,9 @@
1
+ import { type FieldOptions } from "./field";
2
+ import { type DateConstraints, type DateRange } from "./dateConstraints";
3
+ export type DateRangePickerProps = FieldOptions & DateConstraints & {
4
+ value: DateRange;
5
+ onChange(value: DateRange): void;
6
+ label: string;
7
+ clearable?: boolean;
8
+ };
9
+ export declare function DateRangePicker({ value, onChange, label, clearable, minDate, maxDate, disabledDate, ...options }: DateRangePickerProps): import("react").JSX.Element;