@daisu-ui/ui 0.0.0-stage → 0.1.0-beta.4

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 (402) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/LICENSE +21 -0
  3. package/README.md +179 -2
  4. package/THIRD_PARTY_NOTICES.md +19 -0
  5. package/dist/ActionSheet.d.ts +45 -0
  6. package/dist/ActionSheet.jsx +37 -0
  7. package/dist/AnchoredBubble.d.ts +36 -0
  8. package/dist/AnchoredBubble.jsx +120 -0
  9. package/dist/Avatar.d.ts +35 -0
  10. package/dist/Avatar.jsx +29 -0
  11. package/dist/Backtop.d.ts +22 -0
  12. package/dist/Backtop.jsx +18 -0
  13. package/dist/Badge.d.ts +19 -0
  14. package/dist/Badge.jsx +11 -0
  15. package/dist/BarCode.d.ts +20 -0
  16. package/dist/BarCode.jsx +38 -0
  17. package/dist/Button.d.ts +21 -0
  18. package/dist/Button.jsx +19 -0
  19. package/dist/Calendar.d.ts +90 -0
  20. package/dist/Calendar.jsx +164 -0
  21. package/dist/CalendarView.d.ts +51 -0
  22. package/dist/CalendarView.jsx +136 -0
  23. package/dist/Card.d.ts +21 -0
  24. package/dist/Card.jsx +21 -0
  25. package/dist/Cascader.d.ts +75 -0
  26. package/dist/Cascader.jsx +212 -0
  27. package/dist/Cell.d.ts +34 -0
  28. package/dist/Cell.jsx +37 -0
  29. package/dist/Checkbox.d.ts +50 -0
  30. package/dist/Checkbox.jsx +74 -0
  31. package/dist/Circle.d.ts +19 -0
  32. package/dist/Circle.jsx +35 -0
  33. package/dist/Collapse.d.ts +31 -0
  34. package/dist/Collapse.jsx +61 -0
  35. package/dist/ConfigProvider.d.ts +15 -0
  36. package/dist/ConfigProvider.jsx +20 -0
  37. package/dist/CountDown.d.ts +20 -0
  38. package/dist/CountDown.jsx +15 -0
  39. package/dist/CountTo.d.ts +28 -0
  40. package/dist/CountTo.jsx +27 -0
  41. package/dist/Curtain.d.ts +29 -0
  42. package/dist/Curtain.jsx +51 -0
  43. package/dist/DatetimePicker.d.ts +46 -0
  44. package/dist/DatetimePicker.jsx +138 -0
  45. package/dist/DatetimePickerView.d.ts +38 -0
  46. package/dist/DatetimePickerView.jsx +36 -0
  47. package/dist/Dialog.d.ts +64 -0
  48. package/dist/Dialog.jsx +105 -0
  49. package/dist/Divider.d.ts +16 -0
  50. package/dist/Divider.jsx +9 -0
  51. package/dist/DropMenu.d.ts +55 -0
  52. package/dist/DropMenu.jsx +210 -0
  53. package/dist/Empty.d.ts +14 -0
  54. package/dist/Empty.jsx +14 -0
  55. package/dist/EmptyState.d.ts +6 -0
  56. package/dist/EmptyState.jsx +9 -0
  57. package/dist/Fab.d.ts +30 -0
  58. package/dist/Fab.jsx +127 -0
  59. package/dist/FloatingPanel.d.ts +21 -0
  60. package/dist/FloatingPanel.jsx +102 -0
  61. package/dist/Form.d.ts +63 -0
  62. package/dist/Form.jsx +108 -0
  63. package/dist/FormFieldRow.d.ts +56 -0
  64. package/dist/FormFieldRow.jsx +63 -0
  65. package/dist/Gap.d.ts +10 -0
  66. package/dist/Gap.jsx +14 -0
  67. package/dist/Grid.d.ts +47 -0
  68. package/dist/Grid.jsx +31 -0
  69. package/dist/Icon.d.ts +11 -0
  70. package/dist/Icon.jsx +12 -0
  71. package/dist/ImagePreview.d.ts +62 -0
  72. package/dist/ImagePreview.jsx +78 -0
  73. package/dist/Img.d.ts +28 -0
  74. package/dist/Img.jsx +59 -0
  75. package/dist/ImgCropper.d.ts +74 -0
  76. package/dist/ImgCropper.jsx +114 -0
  77. package/dist/IndexBar.d.ts +36 -0
  78. package/dist/IndexBar.jsx +149 -0
  79. package/dist/Input.d.ts +11 -0
  80. package/dist/Input.jsx +3 -0
  81. package/dist/InputNumber.d.ts +32 -0
  82. package/dist/InputNumber.jsx +165 -0
  83. package/dist/Keyboard.d.ts +37 -0
  84. package/dist/Keyboard.jsx +130 -0
  85. package/dist/Layout.d.ts +31 -0
  86. package/dist/Layout.jsx +14 -0
  87. package/dist/Loading.d.ts +18 -0
  88. package/dist/Loading.jsx +15 -0
  89. package/dist/Loadmore.d.ts +18 -0
  90. package/dist/Loadmore.jsx +16 -0
  91. package/dist/Navbar.d.ts +35 -0
  92. package/dist/Navbar.jsx +50 -0
  93. package/dist/NoticeBar.d.ts +30 -0
  94. package/dist/NoticeBar.jsx +86 -0
  95. package/dist/Notify.d.ts +34 -0
  96. package/dist/Notify.jsx +52 -0
  97. package/dist/NumberStepper.d.ts +11 -0
  98. package/dist/NumberStepper.jsx +41 -0
  99. package/dist/Overlay.d.ts +16 -0
  100. package/dist/Overlay.jsx +12 -0
  101. package/dist/PagedList.d.ts +13 -0
  102. package/dist/PagedList.jsx +36 -0
  103. package/dist/Pagination.d.ts +29 -0
  104. package/dist/Pagination.jsx +33 -0
  105. package/dist/PasswordInput.d.ts +16 -0
  106. package/dist/PasswordInput.jsx +20 -0
  107. package/dist/Picker.d.ts +61 -0
  108. package/dist/Picker.jsx +80 -0
  109. package/dist/PickerView.d.ts +43 -0
  110. package/dist/PickerView.jsx +142 -0
  111. package/dist/Popover.d.ts +23 -0
  112. package/dist/Popover.jsx +35 -0
  113. package/dist/Popup.d.ts +30 -0
  114. package/dist/Popup.jsx +32 -0
  115. package/dist/Progress.d.ts +17 -0
  116. package/dist/Progress.jsx +45 -0
  117. package/dist/QrCode.d.ts +46 -0
  118. package/dist/QrCode.jsx +67 -0
  119. package/dist/Radio.d.ts +21 -0
  120. package/dist/Radio.jsx +34 -0
  121. package/dist/Rate.d.ts +25 -0
  122. package/dist/Rate.jsx +39 -0
  123. package/dist/Resize.d.ts +17 -0
  124. package/dist/Resize.jsx +17 -0
  125. package/dist/RichText.d.ts +133 -0
  126. package/dist/RichText.jsx +288 -0
  127. package/dist/RootPortal.d.ts +11 -0
  128. package/dist/RootPortal.jsx +19 -0
  129. package/dist/Search.d.ts +39 -0
  130. package/dist/Search.jsx +94 -0
  131. package/dist/Segmented.d.ts +18 -0
  132. package/dist/Segmented.jsx +35 -0
  133. package/dist/SelectPicker.d.ts +54 -0
  134. package/dist/SelectPicker.jsx +136 -0
  135. package/dist/Sidebar.d.ts +34 -0
  136. package/dist/Sidebar.jsx +43 -0
  137. package/dist/Signature.d.ts +46 -0
  138. package/dist/Signature.jsx +203 -0
  139. package/dist/Skeleton.d.ts +27 -0
  140. package/dist/Skeleton.jsx +29 -0
  141. package/dist/SlideVerify.d.ts +27 -0
  142. package/dist/SlideVerify.jsx +138 -0
  143. package/dist/Slider.d.ts +21 -0
  144. package/dist/Slider.jsx +131 -0
  145. package/dist/SortButton.d.ts +16 -0
  146. package/dist/SortButton.jsx +19 -0
  147. package/dist/Steps.d.ts +23 -0
  148. package/dist/Steps.jsx +25 -0
  149. package/dist/Sticky.d.ts +17 -0
  150. package/dist/Sticky.jsx +69 -0
  151. package/dist/SwipeAction.d.ts +27 -0
  152. package/dist/SwipeAction.jsx +187 -0
  153. package/dist/Swiper.d.ts +54 -0
  154. package/dist/Swiper.jsx +94 -0
  155. package/dist/SwiperNav.d.ts +18 -0
  156. package/dist/SwiperNav.jsx +10 -0
  157. package/dist/Switch.d.ts +31 -0
  158. package/dist/Switch.jsx +46 -0
  159. package/dist/SyncedInput.d.ts +12 -0
  160. package/dist/SyncedInput.jsx +18 -0
  161. package/dist/SyncedTextarea.d.ts +11 -0
  162. package/dist/SyncedTextarea.jsx +18 -0
  163. package/dist/Tabbar.d.ts +37 -0
  164. package/dist/Tabbar.jsx +46 -0
  165. package/dist/Table.d.ts +51 -0
  166. package/dist/Table.jsx +125 -0
  167. package/dist/Tabs.d.ts +65 -0
  168. package/dist/Tabs.jsx +132 -0
  169. package/dist/Tag.d.ts +33 -0
  170. package/dist/Tag.jsx +63 -0
  171. package/dist/Text.d.ts +19 -0
  172. package/dist/Text.jsx +7 -0
  173. package/dist/TextField.d.ts +89 -0
  174. package/dist/TextField.jsx +149 -0
  175. package/dist/Textarea.d.ts +22 -0
  176. package/dist/Textarea.jsx +3 -0
  177. package/dist/Toast.d.ts +36 -0
  178. package/dist/Toast.jsx +30 -0
  179. package/dist/Tooltip.d.ts +8 -0
  180. package/dist/Tooltip.jsx +5 -0
  181. package/dist/Tour.d.ts +85 -0
  182. package/dist/Tour.jsx +150 -0
  183. package/dist/Transition.d.ts +32 -0
  184. package/dist/Transition.jsx +43 -0
  185. package/dist/Upload.d.ts +64 -0
  186. package/dist/Upload.jsx +163 -0
  187. package/dist/VideoPreview.d.ts +47 -0
  188. package/dist/VideoPreview.jsx +59 -0
  189. package/dist/Watermark.d.ts +36 -0
  190. package/dist/Watermark.jsx +18 -0
  191. package/dist/action-sheet.css +19 -0
  192. package/dist/avatar.css +23 -0
  193. package/dist/avatarModel.d.ts +8 -0
  194. package/dist/avatarModel.js +17 -0
  195. package/dist/backtop.css +6 -0
  196. package/dist/badge.css +15 -0
  197. package/dist/badgeModel.d.ts +2 -0
  198. package/dist/badgeModel.js +18 -0
  199. package/dist/bar-code.css +5 -0
  200. package/dist/barCodeModel.d.ts +80 -0
  201. package/dist/barCodeModel.js +99 -0
  202. package/dist/brand/logo.svg +8 -0
  203. package/dist/bubble.css +14 -0
  204. package/dist/bubblePosition.d.ts +19 -0
  205. package/dist/bubblePosition.js +41 -0
  206. package/dist/button.css +56 -0
  207. package/dist/calendar.css +56 -0
  208. package/dist/calendarModel.d.ts +62 -0
  209. package/dist/calendarModel.js +141 -0
  210. package/dist/card.css +8 -0
  211. package/dist/cascader.css +16 -0
  212. package/dist/cascaderModel.d.ts +21 -0
  213. package/dist/cascaderModel.js +32 -0
  214. package/dist/cell.css +41 -0
  215. package/dist/choice.css +27 -0
  216. package/dist/choice.d.ts +28 -0
  217. package/dist/choice.jsx +16 -0
  218. package/dist/circle.css +4 -0
  219. package/dist/circleModel.d.ts +15 -0
  220. package/dist/circleModel.js +31 -0
  221. package/dist/config-provider.css +2 -0
  222. package/dist/configContext.d.ts +23 -0
  223. package/dist/configContext.js +24 -0
  224. package/dist/configTheme.d.ts +3 -0
  225. package/dist/configTheme.js +22 -0
  226. package/dist/count-down.css +2 -0
  227. package/dist/count-to.css +8 -0
  228. package/dist/countDownModel.d.ts +11 -0
  229. package/dist/countDownModel.js +7 -0
  230. package/dist/countToModel.d.ts +3 -0
  231. package/dist/countToModel.js +3 -0
  232. package/dist/curtain.css +10 -0
  233. package/dist/datetime-picker.css +11 -0
  234. package/dist/datetimePickerModel.d.ts +47 -0
  235. package/dist/datetimePickerModel.js +128 -0
  236. package/dist/dialog.css +23 -0
  237. package/dist/divider.css +14 -0
  238. package/dist/drop-menu.css +28 -0
  239. package/dist/empty.css +7 -0
  240. package/dist/fab.css +23 -0
  241. package/dist/fabModel.d.ts +26 -0
  242. package/dist/fabModel.js +16 -0
  243. package/dist/floating-panel.css +6 -0
  244. package/dist/floatingPanelModel.d.ts +3 -0
  245. package/dist/floatingPanelModel.js +10 -0
  246. package/dist/form.css +10 -0
  247. package/dist/formContext.d.ts +7 -0
  248. package/dist/formContext.js +2 -0
  249. package/dist/formModel.d.ts +38 -0
  250. package/dist/formModel.js +16 -0
  251. package/dist/gap.css +1 -0
  252. package/dist/grid.css +17 -0
  253. package/dist/icon.css +8 -0
  254. package/dist/icons/LICENSE.tabler +21 -0
  255. package/dist/icons/paths.d.ts +309 -0
  256. package/dist/icons/paths.js +310 -0
  257. package/dist/icons/render.d.ts +2 -0
  258. package/dist/icons/render.js +5 -0
  259. package/dist/image-preview.css +8 -0
  260. package/dist/img-cropper.css +1 -0
  261. package/dist/img.css +5 -0
  262. package/dist/imgCropperModel.d.ts +55 -0
  263. package/dist/imgCropperModel.js +41 -0
  264. package/dist/imgModel.d.ts +13 -0
  265. package/dist/imgModel.js +22 -0
  266. package/dist/index-bar.css +12 -0
  267. package/dist/index.d.ts +200 -0
  268. package/dist/index.js +99 -0
  269. package/dist/indexBarModel.d.ts +19 -0
  270. package/dist/indexBarModel.js +37 -0
  271. package/dist/input-number.css +24 -0
  272. package/dist/inputNumberModel.d.ts +23 -0
  273. package/dist/inputNumberModel.js +40 -0
  274. package/dist/keyboard.css +26 -0
  275. package/dist/keyboardModel.d.ts +11 -0
  276. package/dist/keyboardModel.js +34 -0
  277. package/dist/layout.css +2 -0
  278. package/dist/legacy/RadioGroup.d.ts +13 -0
  279. package/dist/legacy/RadioGroup.jsx +13 -0
  280. package/dist/legacy-controls.css +87 -0
  281. package/dist/loading.css +31 -0
  282. package/dist/loadingModel.d.ts +2 -0
  283. package/dist/loadingModel.js +21 -0
  284. package/dist/loadmore.css +5 -0
  285. package/dist/navbar.css +16 -0
  286. package/dist/notice-bar.css +19 -0
  287. package/dist/notify.css +14 -0
  288. package/dist/overlay.css +2 -0
  289. package/dist/pagination.css +12 -0
  290. package/dist/paginationModel.d.ts +6 -0
  291. package/dist/paginationModel.js +7 -0
  292. package/dist/password-input.css +14 -0
  293. package/dist/passwordInputModel.d.ts +6 -0
  294. package/dist/passwordInputModel.js +11 -0
  295. package/dist/picker.css +42 -0
  296. package/dist/pickerModel.d.ts +32 -0
  297. package/dist/pickerModel.js +49 -0
  298. package/dist/popover.css +5 -0
  299. package/dist/popup.css +17 -0
  300. package/dist/progress.css +16 -0
  301. package/dist/progressModel.d.ts +12 -0
  302. package/dist/progressModel.js +19 -0
  303. package/dist/qr-code.css +4 -0
  304. package/dist/qrCodeModel.d.ts +36 -0
  305. package/dist/qrCodeModel.js +61 -0
  306. package/dist/rate.css +20 -0
  307. package/dist/rateModel.d.ts +4 -0
  308. package/dist/rateModel.js +38 -0
  309. package/dist/resize.css +2 -0
  310. package/dist/rich-text.css +19 -0
  311. package/dist/richTextMedia.d.ts +28 -0
  312. package/dist/richTextMedia.js +3 -0
  313. package/dist/richTextModel.d.ts +52 -0
  314. package/dist/richTextModel.js +195 -0
  315. package/dist/root-portal.css +1 -0
  316. package/dist/router/RouterView.d.ts +21 -0
  317. package/dist/router/RouterView.jsx +120 -0
  318. package/dist/router/core.d.ts +85 -0
  319. package/dist/router/core.js +255 -0
  320. package/dist/router/hooks.d.ts +17 -0
  321. package/dist/router/hooks.jsx +71 -0
  322. package/dist/router/index.d.ts +5 -0
  323. package/dist/router/index.js +3 -0
  324. package/dist/router/location.d.ts +8 -0
  325. package/dist/router/location.js +46 -0
  326. package/dist/router/router.css +7 -0
  327. package/dist/router/runtime.d.ts +1 -0
  328. package/dist/router/runtime.js +25 -0
  329. package/dist/search.css +23 -0
  330. package/dist/segmented.css +19 -0
  331. package/dist/segmentedModel.d.ts +10 -0
  332. package/dist/segmentedModel.js +8 -0
  333. package/dist/sidebar.css +18 -0
  334. package/dist/sidebarModel.d.ts +8 -0
  335. package/dist/sidebarModel.js +27 -0
  336. package/dist/signature.css +5 -0
  337. package/dist/signatureModel.d.ts +23 -0
  338. package/dist/signatureModel.js +80 -0
  339. package/dist/skeleton.css +16 -0
  340. package/dist/slide-verify.css +7 -0
  341. package/dist/slider.css +49 -0
  342. package/dist/sliderModel.d.ts +10 -0
  343. package/dist/sliderModel.js +27 -0
  344. package/dist/sort-button.css +12 -0
  345. package/dist/steps.css +35 -0
  346. package/dist/sticky.css +7 -0
  347. package/dist/styles.css +136 -0
  348. package/dist/styles.d.ts +1 -0
  349. package/dist/swipe-action.css +6 -0
  350. package/dist/swiper.css +27 -0
  351. package/dist/swiperAnimation.d.ts +3 -0
  352. package/dist/swiperAnimation.js +6 -0
  353. package/dist/swiperModel.d.ts +2 -0
  354. package/dist/swiperModel.js +3 -0
  355. package/dist/switch.css +12 -0
  356. package/dist/tabbar.css +17 -0
  357. package/dist/tabbarModel.d.ts +8 -0
  358. package/dist/tabbarModel.js +27 -0
  359. package/dist/table.css +21 -0
  360. package/dist/tableModel.d.ts +10 -0
  361. package/dist/tableModel.js +17 -0
  362. package/dist/tabs.css +31 -0
  363. package/dist/tabsModel.d.ts +7 -0
  364. package/dist/tabsModel.js +14 -0
  365. package/dist/tag.css +66 -0
  366. package/dist/text-field.css +15 -0
  367. package/dist/text.css +7 -0
  368. package/dist/textModel.d.ts +3 -0
  369. package/dist/textModel.js +24 -0
  370. package/dist/toast.css +13 -0
  371. package/dist/tokens.d.ts +34 -0
  372. package/dist/tokens.js +10 -0
  373. package/dist/tour.css +8 -0
  374. package/dist/transition.css +12 -0
  375. package/dist/upload.css +11 -0
  376. package/dist/useCountDown.d.ts +14 -0
  377. package/dist/useCountDown.js +73 -0
  378. package/dist/useDialog.d.ts +9 -0
  379. package/dist/useDialog.js +33 -0
  380. package/dist/useImagePreview.d.ts +7 -0
  381. package/dist/useImagePreview.js +17 -0
  382. package/dist/useNotify.d.ts +9 -0
  383. package/dist/useNotify.js +26 -0
  384. package/dist/usePressState.d.ts +6 -0
  385. package/dist/usePressState.js +17 -0
  386. package/dist/useToast.d.ts +11 -0
  387. package/dist/useToast.js +23 -0
  388. package/dist/useVideoPreview.d.ts +7 -0
  389. package/dist/useVideoPreview.js +17 -0
  390. package/dist/utils.d.ts +4 -0
  391. package/dist/utils.js +4 -0
  392. package/dist/video-preview.css +7 -0
  393. package/dist/watermark.css +6 -0
  394. package/dist/web/imgCropperElement.d.ts +2 -0
  395. package/dist/web/imgCropperElement.js +309 -0
  396. package/dist/web/index.d.ts +6 -0
  397. package/dist/web/index.js +6 -0
  398. package/dist/web/qrCodeExportElement.d.ts +4 -0
  399. package/dist/web/qrCodeExportElement.js +70 -0
  400. package/dist/web/richTextMediaElement.d.ts +2 -0
  401. package/dist/web/richTextMediaElement.js +276 -0
  402. package/package.json +98 -4
package/dist/Table.jsx ADDED
@@ -0,0 +1,125 @@
1
+ import { useMainThreadRef, useState } from '@lynx-js/react';
2
+ import { SortButton } from "./SortButton.jsx";
3
+ import { tableOffsets, tableRange, tableSpan } from './tableModel.js';
4
+ const length = (value) => typeof value === 'number' ? `${Math.max(0, value)}px` : value;
5
+ /** Bounded tables use native scroll-views; virtual mode mounts only a buffered row window. */
6
+ export function Table({ data, columns, border = true, stripe = true, height, rowHeight = 44, showHeader = true, ellipsis = false, index = false, fixedHeader = true, cellPadding, spanMethod, virtual = false, buffer = 5, rowKey, onSortMethod, onRowClick, className = '', style }) {
7
+ const padding = typeof cellPadding === 'number' ? [cellPadding, cellPadding] : cellPadding;
8
+ const paddingY = Number.isFinite(padding?.[0]) ? Math.max(0, padding[0]) : 12;
9
+ const paddingX = Number.isFinite(padding?.[1]) ? Math.max(0, padding[1]) : 16;
10
+ const paddingStyle = cellPadding === undefined ? {} : { padding: `${paddingY}px ${paddingX}px` };
11
+ const [widths, setWidths] = useState({}), [viewportHeight, setViewportHeight] = useState(400);
12
+ const [measurements, setMeasurements] = useState({}), [top, setTop] = useState(0);
13
+ const [sort, setSort] = useState({ prop: '', value: 0 });
14
+ const fixedHead = useMainThreadRef(null), fixedBody = useMainThreadRef(null);
15
+ const scrollOffset = useMainThreadRef(0);
16
+ const cols = index ? [{ prop: '__index', label: '序号', width: '13.333333vw', ...typeof index === 'object' ? index : {}, render: ({ index: i }) => i + 1 }, ...columns] : [...columns];
17
+ const sizes = cols.map((col, i) => widths[`${i}:${col.width ?? 100}`] ?? (typeof col.width === 'number' ? col.width : 100));
18
+ const x = tableOffsets(sizes), totalWidth = x[x.length - 1];
19
+ const minimum = Number.isFinite(rowHeight) && rowHeight > 0 ? rowHeight : 44;
20
+ const keyFor = (row, i) => typeof rowKey === 'function' ? rowKey(row, i) : rowKey ? String(row[rowKey]) : i;
21
+ const measureKey = (row, i, col, j) => `${keyFor(row, i)}:${j}:${col.prop}`;
22
+ const virtualized = virtual && height !== undefined;
23
+ // Span metadata is evaluated once per cell and used by layout and rendering.
24
+ const spans = !virtualized && spanMethod ? data.map((row, i) => cols.map((column, j) => tableSpan(spanMethod({ row, column, rowIndex: i, columnIndex: j }), i, j, data.length, cols.length))) : undefined;
25
+ const rowSizes = virtualized ? [] : data.map((row, i) => Math.max(minimum, ...cols.map((col, j) => {
26
+ const span = spans?.[i]?.[j];
27
+ const measured = measurements[measureKey(row, i, col, j)];
28
+ return span && (span.rowspan !== 1 || span.colspan === 0) ? minimum : measured === undefined ? minimum : measured + paddingY * 2;
29
+ })));
30
+ // A spanning cell can grow its covered rows without changing neighbouring alignment.
31
+ spans?.forEach((row, i) => row.forEach((span, j) => {
32
+ if (span.rowspan <= 1 || !span.colspan)
33
+ return;
34
+ const measured = measurements[measureKey(data[i], i, cols[j], j)];
35
+ const required = measured === undefined ? minimum : measured + paddingY * 2;
36
+ const available = rowSizes.slice(i, i + span.rowspan).reduce((sum, size) => sum + size, 0);
37
+ if (required > available)
38
+ rowSizes[i + span.rowspan - 1] += required - available;
39
+ }));
40
+ const y = tableOffsets(rowSizes), bodyHeight = virtualized ? data.length * minimum : y[y.length - 1];
41
+ const headerHeight = showHeader ? 44 : 0, fixed = showHeader && fixedHeader;
42
+ const contentHeight = bodyHeight + (fixed ? 0 : headerHeight);
43
+ const visibleHeight = height === undefined ? bodyHeight + headerHeight : Math.min(viewportHeight, bodyHeight + headerHeight);
44
+ const bodyViewport = Math.max(0, visibleHeight - (fixed ? headerHeight : 0));
45
+ const range = virtualized ? tableRange(data.length, top, bodyViewport, minimum, buffer) : { start: 0, end: data.length };
46
+ const lastFixed = cols.reduce((last, col, i) => col.fixed ? i : last, -1);
47
+ const onHorizontal = (event) => {
48
+ 'main thread';
49
+ const offset = Math.max(0, event.detail.scrollLeft);
50
+ scrollOffset.current = offset;
51
+ fixedHead.current?.setStyleProperty('transform', `translateX(${offset}px)`);
52
+ fixedBody.current?.setStyleProperty('transform', `translateX(${offset}px)`);
53
+ fixedHead.current?.setStyleProperty('box-shadow', offset > 0 ? '10px 0 12px -12px rgba(0,0,0,0.2)' : 'none');
54
+ fixedBody.current?.setStyleProperty('box-shadow', offset > 0 ? '10px 0 12px -12px rgba(0,0,0,0.2)' : 'none');
55
+ };
56
+ const restore = (event) => {
57
+ 'main thread';
58
+ event.currentTarget.setStyleProperty('transform', `translateX(${scrollOffset.current}px)`);
59
+ };
60
+ const text = (value) => typeof value === 'string' || typeof value === 'number' ? <text className="ui-table-value" text-maxline={ellipsis ? '2' : undefined}>{value}</text> : value;
61
+ const cellClass = (col, i, j, header = false) => `ui-table-cell ui-table-${col.align ?? 'left'} ${border ? 'ui-table-cell-border' : ''} ${stripe && (header || i % 2 === 1) ? 'ui-table-stripe' : ''} ${j === cols.length - 1 ? 'ui-table-last-column' : ''} ${!header && i === data.length - 1 ? 'ui-table-last-row' : ''}`;
62
+ const borders = border ? <view className="ui-table-borders"/> : null;
63
+ const headers = (pinned) => cols.map((col, j) => Boolean(col.fixed) === pinned ? <view key={col.prop} className={`${cellClass(col, 0, j, true)} ui-table-header-cell`} style={{ ...paddingStyle, left: `${x[j]}px`, width: `${sizes[j]}px`, height: '44px' }}>
64
+ {borders}{col.sortable ? <SortButton title={col.label} value={sort.prop === col.prop ? sort.value : 0} allowReset onChange={({ value }) => {
65
+ 'background only';
66
+ setSort({ prop: col.prop, value });
67
+ const { render: _render, ...column } = col;
68
+ onSortMethod?.({ width: 100, sortable: false, fixed: false, align: 'left', ...column, sortDirection: value });
69
+ }}/> : text(col.label ?? '')}
70
+ </view> : null);
71
+ const cells = (pinned) => data.slice(range.start, range.end).map((row, local) => {
72
+ const i = range.start + local;
73
+ return cols.map((col, j) => {
74
+ if (Boolean(col.fixed) !== pinned)
75
+ return null;
76
+ const span = spans?.[i]?.[j] ?? { rowspan: 1, colspan: 1 };
77
+ if (!span.rowspan || !span.colspan)
78
+ return null;
79
+ const cellHeight = virtualized ? minimum : y[i + span.rowspan] - y[i];
80
+ const key = measureKey(row, i, col, j);
81
+ return <view key={key} className={`${cellClass(col, i, j + span.colspan - 1)} ${i + span.rowspan === data.length ? 'ui-table-last-row' : ''}`} data-rowindex={i} data-column={col.prop} style={{ ...paddingStyle, left: `${x[j]}px`, top: `${(virtualized ? i * minimum : y[i]) + (!fixed ? headerHeight : 0)}px`, width: `${x[j + span.colspan] - x[j]}px`, height: `${cellHeight}px` }} bindtap={() => {
82
+ 'background only';
83
+ onRowClick?.({ rowIndex: i });
84
+ }}>
85
+ {borders}<view className="ui-table-content" bindlayoutchange={virtualized ? undefined : event => {
86
+ 'background only';
87
+ // The content wrapper is the only measurement boundary; descendants may bubble.
88
+ if (event.target.uid !== event.currentTarget.uid)
89
+ return;
90
+ const needed = Math.ceil(event.detail.height);
91
+ setMeasurements(previous => previous[key] === needed ? previous : { ...previous, [key]: needed });
92
+ }}>{text(col.render ? col.render({ row, index: i }) : String(row[col.prop] ?? ''))}</view>
93
+ </view>;
94
+ });
95
+ });
96
+ const fixedStyle = { width: `${lastFixed >= 0 ? x[lastFixed + 1] : 0}px`, height: '100%' };
97
+ const header = <view className="ui-table-header" style={{ height: `${headerHeight}px` }}>{headers(false)}<view className="ui-table-fixed" style={fixedStyle} main-thread:ref={fixedHead} main-thread:bindlayoutchange={restore}>{headers(true)}</view></view>;
98
+ return <view className={`ui-table ${border ? 'ui-table-border' : ''} ${className}`} style={style}>
99
+ <view className="ui-table-measures" style={{ height: '0px' }}>{cols.map((col, j) => <view key={`${j}:${col.width ?? 100}`} className="ui-table-measure" style={{ width: length(col.width ?? 100), height: '0px' }} bindlayoutchange={event => {
100
+ 'background only';
101
+ const width = event.detail.width, key = `${j}:${col.width ?? 100}`;
102
+ if (width > 0)
103
+ setWidths(previous => previous[key] === width ? previous : { ...previous, [key]: width });
104
+ }}/>)}</view>
105
+ {height !== undefined ? <view className="ui-table-measure" style={{ width: '0px', height: length(height) }} bindlayoutchange={event => {
106
+ 'background only';
107
+ setViewportHeight(Math.max(0, event.detail.height));
108
+ }}/> : null}
109
+ <scroll-view className="ui-table-horizontal" scroll-orientation="horizontal" bounces={false} main-thread:bindscroll={onHorizontal} style={{ height: `${visibleHeight}px`, width: '100%' }}>
110
+ <view style={{ width: `${totalWidth}px`, height: `${visibleHeight}px` }}>
111
+ {fixed ? header : null}
112
+ <scroll-view className="ui-table-vertical" scroll-orientation="vertical" enable-scroll={height !== undefined} enable-nested-scroll bounces={false} style={{ width: `${totalWidth}px`, height: `${bodyViewport}px` }} bindscroll={virtualized ? event => {
113
+ 'background only';
114
+ const next = Math.max(0, event.detail.scrollTop);
115
+ setTop(previous => Math.floor(previous / minimum) === Math.floor(next / minimum) ? previous : next);
116
+ } : undefined}>
117
+ <view className="ui-table-body" style={{ height: `${contentHeight}px`, width: `${totalWidth}px` }}>
118
+ {!fixed && showHeader ? header : null}{cells(false)}
119
+ <view className="ui-table-fixed" style={fixedStyle} main-thread:ref={fixedBody} main-thread:bindlayoutchange={restore}>{cells(true)}</view>
120
+ </view>
121
+ </scroll-view>
122
+ </view>
123
+ </scroll-view>
124
+ </view>;
125
+ }
package/dist/Tabs.d.ts ADDED
@@ -0,0 +1,65 @@
1
+ import type { ReactNode, Ref } from '@lynx-js/react';
2
+ import type { CSSProperties } from '@lynx-js/types';
3
+ import type { BadgeProps } from "./Badge.jsx";
4
+ import type { TabsValue } from './tabsModel.js';
5
+ export type TabOption = {
6
+ label: string;
7
+ value: string;
8
+ disabled?: boolean;
9
+ };
10
+ export type TabsItem = {
11
+ name?: TabsValue;
12
+ title: string;
13
+ disabled?: boolean;
14
+ lazy?: boolean;
15
+ badgeProps?: Omit<BadgeProps, 'children'>;
16
+ children?: ReactNode;
17
+ className?: string;
18
+ };
19
+ export type TabsEvent = {
20
+ index: number;
21
+ name: TabsValue;
22
+ };
23
+ export type TabsRef = {
24
+ setActive: (value: TabsValue) => void;
25
+ scrollIntoView: () => void;
26
+ updateLineStyle: () => void;
27
+ };
28
+ export type TabsLineTheme = 'normal' | 'text' | 'underline' | 'dot';
29
+ export type StandardTabsProps = {
30
+ items: readonly TabsItem[];
31
+ variant?: 'standard';
32
+ value?: TabsValue;
33
+ defaultValue?: TabsValue;
34
+ onChange?: (value: TabsValue, event: TabsEvent) => void;
35
+ onClick?: (event: TabsEvent) => void;
36
+ onDisabled?: (event: TabsEvent) => void;
37
+ slidable?: 'auto' | 'always';
38
+ slidableNum?: number;
39
+ mapNum?: number;
40
+ mapTitle?: string;
41
+ showScrollbar?: boolean;
42
+ sticky?: boolean;
43
+ offsetTop?: number;
44
+ swipeable?: boolean;
45
+ animated?: boolean;
46
+ duration?: number;
47
+ lineTheme?: TabsLineTheme;
48
+ lineWidth?: number | string;
49
+ lineHeight?: number | string;
50
+ color?: string;
51
+ inactiveColor?: string;
52
+ className?: string;
53
+ style?: CSSProperties;
54
+ ref?: Ref<TabsRef>;
55
+ };
56
+ export type LegacyTabsProps = {
57
+ options: readonly TabOption[];
58
+ value: string;
59
+ onChange: (value: string) => void;
60
+ className?: string;
61
+ };
62
+ export type TabsProps = StandardTabsProps | LegacyTabsProps;
63
+ /** Existing options API deliberately retains its production appearance. */
64
+ export declare function Tabs(props: LegacyTabsProps): ReactNode;
65
+ export declare function Tabs(props: StandardTabsProps): ReactNode;
package/dist/Tabs.jsx ADDED
@@ -0,0 +1,132 @@
1
+ import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from '@lynx-js/react';
2
+ import { Badge } from "./Badge.jsx";
3
+ import { Icon } from "./Icon.jsx";
4
+ import { Transition } from "./Transition.jsx";
5
+ import { nextTab, tabsIndex } from './tabsModel.js';
6
+ const unit = (n) => typeof n === 'number' ? `${n}px` : n;
7
+ export function Tabs(props) {
8
+ if ('items' in props)
9
+ return <StandardTabs {...props}/>;
10
+ return <view className={`ui-tabs ${props.className ?? ''}`}>{props.options.map(option => <view key={option.value} className={`ui-tab ${option.value === props.value ? 'ui-tab-active' : ''} ${option.disabled ? 'ui-tab-disabled' : ''}`} bindtap={() => {
11
+ 'background only';
12
+ if (!option.disabled)
13
+ props.onChange(option.value);
14
+ }}><text>{option.label}</text></view>)}</view>;
15
+ }
16
+ const StandardTabs = forwardRef(function StandardTabs({ items, value, defaultValue = 0, onChange, onClick, onDisabled, slidable = 'auto', slidableNum = 6, mapNum = 10, mapTitle = '', showScrollbar = false, sticky = false, offsetTop = 0, swipeable = false, animated = false, duration = 300, lineTheme = 'normal', lineWidth, lineHeight, color, inactiveColor, className = '', style }, ref) {
17
+ const [inner, setInner] = useState(defaultValue), [map, setMap] = useState(false);
18
+ const [widths, setWidths] = useState({}), [labels, setLabels] = useState({});
19
+ const [heights, setHeights] = useState({}), [viewport, setViewport] = useState(0), [drag, setDrag] = useState(0);
20
+ const selected = tabsIndex(items, value ?? inner);
21
+ const visited = useRef(new Set()); // Written in effects, never during render.
22
+ const [loaded, setLoaded] = useState([]);
23
+ const scroll = useRef(null);
24
+ const touch = useRef(null);
25
+ const scrolling = slidable === 'always' || items.length >= slidableNum;
26
+ const withMap = items.length >= mapNum;
27
+ const headerWidth = Math.max(0, viewport - (withMap ? 44 : 0));
28
+ const itemWidth = (i) => widths[i] ?? headerWidth / Math.max(items.length, 1);
29
+ const left = items.slice(0, Math.max(0, selected)).reduce((sum, _, i) => sum + itemWidth(i), 0);
30
+ const activeWidth = itemWidth(selected);
31
+ const totalWidth = items.reduce((sum, _, i) => sum + itemWidth(i), 0);
32
+ const scrollActive = () => {
33
+ 'background only';
34
+ if (scrolling && selected >= 0)
35
+ scroll.current?.invoke({ method: 'scrollTo', params: { index: 0, offset: Math.max(0, Math.min(totalWidth - headerWidth, left + activeWidth / 2 - headerWidth / 2)), smooth: true } }).exec();
36
+ };
37
+ useEffect(() => { if (selected >= 0 && !visited.current.has(selected)) {
38
+ visited.current.add(selected);
39
+ setLoaded([...visited.current]);
40
+ } }, [selected]);
41
+ useEffect(scrollActive, [selected, scrolling, headerWidth, left, activeWidth, totalWidth]);
42
+ const select = (index, click = false) => {
43
+ 'background only';
44
+ const item = items[index];
45
+ if (!item)
46
+ return;
47
+ const event = { index, name: item.name ?? index };
48
+ if (item.disabled) {
49
+ if (click)
50
+ onDisabled?.(event);
51
+ return;
52
+ }
53
+ setMap(false);
54
+ if (index !== selected) {
55
+ if (value === undefined)
56
+ setInner(event.name);
57
+ onChange?.(event.name, event);
58
+ }
59
+ if (click)
60
+ onClick?.(event);
61
+ };
62
+ useImperativeHandle(ref, () => ({ setActive: next => {
63
+ 'background only';
64
+ select(tabsIndex(items, next));
65
+ }, scrollIntoView: scrollActive, updateLineStyle: scrollActive }), [items, selected, scrolling, left, activeWidth, headerWidth, totalWidth, onChange]);
66
+ const size = (setter, index, n) => {
67
+ 'background only';
68
+ setter(previous => previous[index] === n ? previous : { ...previous, [index]: n });
69
+ };
70
+ const lineW = lineWidth ?? (lineTheme === 'text' ? labels[selected] ?? 24 : lineTheme === 'underline' ? activeWidth : lineTheme === 'dot' ? 6 : 24);
71
+ const lineH = lineHeight ?? (lineTheme === 'underline' ? 2 : lineTheme === 'dot' ? 6 : 4);
72
+ const milliseconds = Number.isFinite(duration) ? Math.max(0, duration) : 300;
73
+ const header = <view className={`ui-tabs-standard-header ${sticky ? 'ui-tabs-sticky' : ''}`} style={{ top: sticky ? `${offsetTop}px` : undefined }}>
74
+ <scroll-view ref={scroll} className="ui-tabs-nav-scroll" scroll-orientation="horizontal" scroll-x={scrolling} enable-scroll={scrolling} scroll-bar-enable={showScrollbar} style={{ marginRight: withMap ? '44px' : undefined }}>
75
+ <view className={`ui-tabs-nav-track ${scrolling ? 'ui-tabs-nav-slidable' : ''}`}>
76
+ {items.map((item, index) => <view key={`${typeof item.name}:${item.name ?? index}`} className={`ui-tabs-nav-item ${selected === index ? 'ui-tabs-nav-active' : ''} ${item.disabled ? 'ui-tabs-nav-disabled' : ''}`} style={{ color: item.disabled ? undefined : selected === index ? color : inactiveColor }} flatten={false} bindlayoutchange={e => size(setWidths, index, e.detail.width)} bindtap={() => select(index, true)} accessibility-element accessibility-traits="button" accessibility-label={`${item.title}${selected === index ? ',已选中' : ''}${item.disabled ? ',禁用' : ''}`}>
77
+ <Badge {...item.badgeProps}><text className="ui-tabs-nav-label" style={{ color: item.disabled ? undefined : selected === index ? color : inactiveColor }} bindlayoutchange={e => size(setLabels, index, e.detail.width)}>{item.title}</text></Badge>
78
+ </view>)}
79
+ {selected >= 0 ? <view className={`ui-tabs-line ui-tabs-line-${lineTheme}`} user-interaction-enabled={false} style={{ left: `${left + activeWidth / 2}px`, width: unit(lineW), height: unit(lineH), backgroundColor: color, transitionDuration: `${milliseconds}ms` }}/> : null}
80
+ </view>
81
+ </scroll-view>
82
+ {withMap ? <view className="ui-tabs-map-toggle" bindtap={() => {
83
+ 'background only';
84
+ setMap(!map);
85
+ }} accessibility-element accessibility-traits="button" accessibility-label="切换导航地图"><view style={{ transform: map ? 'rotate(180deg)' : undefined }}><Icon name="down" size={16}/></view></view> : null}
86
+ <Transition show={map} name="fade-down" duration={milliseconds} lazyRender className="ui-tabs-map">
87
+ {mapTitle ? <text className="ui-tabs-map-title">{mapTitle}</text> : null}
88
+ <view className="ui-tabs-map-items">{items.map((item, i) => <view key={i} className={`ui-tabs-map-item ${i === selected ? 'ui-tabs-map-active' : ''} ${item.disabled ? 'ui-tabs-map-disabled' : ''}`} bindtap={() => select(i, true)}><text>{item.title}</text></view>)}</view>
89
+ </Transition>
90
+ </view>;
91
+ const hasContent = items.some(item => item.children !== undefined);
92
+ return <view className={`ui-tabs-standard ${className}`} style={style} bindlayoutchange={e => {
93
+ 'background only';
94
+ setViewport(e.detail.width);
95
+ }}>
96
+ {header}
97
+ {hasContent ? <view className={`ui-tabs-content ${swipeable ? 'ui-tabs-swipeable' : ''}`} style={{ height: animated && heights[selected] !== undefined ? `${heights[selected]}px` : undefined }} consume-slide-event={swipeable ? [[-30, 30], [150, 180], [-180, -150]] : undefined} bindtouchstart={e => {
98
+ 'background only';
99
+ const t = e.touches[0];
100
+ touch.current = swipeable && t ? { x: t.clientX, y: t.clientY } : null;
101
+ }} bindtouchmove={e => {
102
+ 'background only';
103
+ const t = e.touches[0], start = touch.current;
104
+ if (!t || !start || e.touches.length !== 1)
105
+ return;
106
+ const dx = t.clientX - start.x, dy = t.clientY - start.y;
107
+ if (!start.axis && Math.max(Math.abs(dx), Math.abs(dy)) > 5)
108
+ start.axis = Math.abs(dx) > Math.abs(dy) ? 'x' : 'y';
109
+ if (start.axis === 'x' && animated)
110
+ setDrag(nextTab(items, selected, dx > 0 ? -1 : 1) === selected ? dx / 3 : dx);
111
+ }} bindtouchend={e => {
112
+ 'background only';
113
+ const start = touch.current, t = e.changedTouches[0];
114
+ touch.current = null;
115
+ setDrag(0);
116
+ if (t && start && Math.abs(t.clientX - start.x) > Math.max(40, viewport / 5) && Math.abs(t.clientX - start.x) > Math.abs(t.clientY - start.y))
117
+ select(nextTab(items, selected, t.clientX < start.x ? 1 : -1));
118
+ }} bindtouchcancel={() => {
119
+ 'background only';
120
+ touch.current = null;
121
+ setDrag(0);
122
+ }}>
123
+ <view className={`ui-tabs-panels ${animated ? 'ui-tabs-panels-animated' : ''}`} style={animated ? { transform: `translateX(${-Math.max(0, selected) * viewport + drag}px)`, transitionDuration: `${drag ? 0 : milliseconds}ms` } : undefined}>
124
+ {items.map((item, index) => <view key={`${typeof item.name}:${item.name ?? index}`} className={`ui-tabs-pane ${!animated && selected !== index ? 'ui-tabs-pane-hidden' : ''} ${item.className ?? ''}`} style={animated ? { width: `${viewport}px` } : undefined} user-interaction-enabled={selected === index} accessibility-elements-hidden={selected !== index} bindlayoutchange={e => size(setHeights, index, e.detail.height)}>{animated || item.lazy === false || selected === index || loaded.includes(index) ? item.children : null}</view>)}
125
+ </view>
126
+ </view> : null}
127
+ {map && hasContent ? <view className="ui-tabs-map-mask" bindtap={() => {
128
+ 'background only';
129
+ setMap(false);
130
+ }}/> : null}
131
+ </view>;
132
+ });
package/dist/Tag.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ import type { ReactNode } from '@lynx-js/react';
2
+ import type { CSSProperties } from '@lynx-js/types';
3
+ export type TagTone = 'primary' | 'success' | 'info' | 'warning' | 'danger' | 'neutral';
4
+ export type TagType = 'default' | 'primary' | 'success' | 'warning' | 'danger' | 'volcano' | 'lightblue' | 'cyan' | 'pink' | 'purple';
5
+ export type TagSize = 'small' | 'medium' | 'default' | 'large' | 'extra-large';
6
+ export type TagVariant = 'light' | 'dark' | 'plain' | 'dashed' | 'text';
7
+ export type TagProps = {
8
+ type?: TagType;
9
+ size?: TagSize;
10
+ variant?: TagVariant;
11
+ /** Compatibility aliases. Explicit type / variant take priority. */
12
+ tone?: TagTone;
13
+ plain?: boolean;
14
+ label?: string;
15
+ children?: ReactNode;
16
+ icon?: string;
17
+ iconSlot?: ReactNode;
18
+ add?: ReactNode;
19
+ color?: string;
20
+ bgColor?: string;
21
+ round?: boolean;
22
+ mark?: boolean;
23
+ closable?: boolean;
24
+ dynamic?: boolean;
25
+ onTap?: () => void;
26
+ onClose?: () => void;
27
+ onConfirm?: (detail: {
28
+ value: string;
29
+ }) => void;
30
+ className?: string;
31
+ style?: CSSProperties;
32
+ };
33
+ export declare function Tag({ type, tone, size: sizeProp, variant, plain, label, children, icon, iconSlot, add, color, bgColor, round: roundProp, mark, closable, dynamic, onTap, onClose, onConfirm, className, style }: TagProps): import("@lynx-js/react").JSX.Element;
package/dist/Tag.jsx ADDED
@@ -0,0 +1,63 @@
1
+ import { useEffect, useRef, useState } from '@lynx-js/react';
2
+ import { useConfigProvider } from './configContext.js';
3
+ import { Icon } from "./Icon.jsx";
4
+ const palette = { default: '#4e5369', primary: '#1c64fd', danger: '#f14646', warning: '#f57f00', success: '#12b886', volcano: '#fd5c1c', lightblue: '#1cb2fd', cyan: '#22b8cf', pink: '#ff357c', purple: '#8059f3' };
5
+ /** Editor mounts afresh for each addition; native focus and confirm work in Flutter. */
6
+ function TagEditor({ finish }) {
7
+ const input = useRef(null);
8
+ const completed = useRef(false);
9
+ useEffect(() => { input.current?.invoke({ method: 'focus' }).exec(); }, []);
10
+ const complete = (value) => {
11
+ 'background only';
12
+ if (completed.current)
13
+ return;
14
+ completed.current = true;
15
+ finish(value);
16
+ };
17
+ return <input ref={input} className="ui-tag-input" type="text" default-value="" placeholder="请输入标签" maxlength={-1} confirm-type="done" avoid-keyboard avoid-keyboard-spacing="12px" bindconfirm={event => {
18
+ 'background only';
19
+ complete(event.detail.value);
20
+ }} bindblur={() => {
21
+ 'background only';
22
+ complete();
23
+ }}/>;
24
+ }
25
+ export function Tag({ type, tone, size: sizeProp, variant, plain, label = '', children, icon = '', iconSlot, add, color, bgColor, round: roundProp, mark = false, closable = false, dynamic = false, onTap, onClose, onConfirm, className = '', style }) {
26
+ const config = useConfigProvider().tag;
27
+ const size = sizeProp ?? config.size ?? 'default', round = roundProp ?? config.round ?? false;
28
+ const [editing, setEditing] = useState(false);
29
+ const effectiveType = type ?? (tone === 'info' ? 'primary' : tone === 'neutral' ? 'default' : tone) ?? 'default';
30
+ const effectiveVariant = variant ?? (plain !== undefined ? plain ? 'plain' : 'dark' : config.variant ?? 'dark');
31
+ const content = children ?? label;
32
+ const glyphSize = size === 'small' ? 11 : size === 'large' || size === 'extra-large' ? 14 : 12;
33
+ const outlined = effectiveVariant === 'plain' || effectiveVariant === 'dashed';
34
+ const foreground = { color };
35
+ const rootStyle = { ...foreground, ...(bgColor && (effectiveVariant === 'dark' || effectiveVariant === 'light') ? { backgroundColor: bgColor } : {}), ...style };
36
+ const glyphColor = color || (effectiveVariant === 'dark' ? '#fff' : palette[effectiveType]);
37
+ const glyph = (name) => <view className="ui-tag-glyph"><Icon name={name} size={glyphSize} color={glyphColor} className="ui-tag-glyph-light"/>{!color && effectiveType === 'default' && effectiveVariant !== 'dark' ? <Icon name={name} size={glyphSize} color="#e5e6eb" className="ui-tag-glyph-dark"/> : null}</view>;
38
+ const tap = () => {
39
+ 'background only';
40
+ if (dynamic) {
41
+ setEditing(true);
42
+ return;
43
+ }
44
+ onTap?.();
45
+ };
46
+ const finish = (value) => {
47
+ 'background only';
48
+ setEditing(false);
49
+ if (value !== undefined)
50
+ onConfirm?.({ value });
51
+ };
52
+ return <view className={`ui-tag ui-tag-${effectiveType} ui-tag-${effectiveVariant} ui-tag-size-${size} ${round ? 'ui-tag-round' : ''} ${mark ? 'ui-tag-mark' : ''} ${dynamic ? 'ui-tag-dynamic' : ''} ${editing && dynamic ? 'ui-tag-editing' : ''} ${!color && effectiveType === 'default' && effectiveVariant !== 'dark' ? 'ui-tag-auto-glyph' : ''} ${className}`} style={rootStyle} bindtap={tap} accessibility-element={dynamic || !!onTap} accessibility-traits={dynamic || onTap ? 'button' : 'text'} accessibility-label={dynamic ? '新增标签' : typeof content === 'string' ? content : undefined}>
53
+ {outlined ? <view className="ui-tag-border" style={{ borderColor: bgColor }}/> : null}
54
+ {dynamic ? editing ? <TagEditor finish={finish}/> : add !== undefined ? <view className="ui-tag-content" style={foreground}>{add}</view> : <view className="ui-tag-content" style={foreground}>{glyph('plus')}<text className="ui-tag-label" style={foreground}>新增标签</text></view> : <>
55
+ {iconSlot !== undefined ? <view className="ui-tag-icon" style={foreground}>{iconSlot}</view> : icon ? glyph(icon) : null}
56
+ {typeof content === 'string' || typeof content === 'number' ? <text className="ui-tag-label" style={foreground}>{content}</text> : <view className="ui-tag-content" style={foreground}>{content}</view>}
57
+ {closable ? <view className="ui-tag-close" accessibility-element accessibility-traits="button" accessibility-label="关闭标签" catchtap={() => {
58
+ 'background only';
59
+ onClose?.();
60
+ }}>{glyph('close')}</view> : null}
61
+ </>}
62
+ </view>;
63
+ }
package/dist/Text.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import type { ReactNode } from '@lynx-js/react';
2
+ import type { TextMode } from './textModel.js';
3
+ export type TextProps = {
4
+ text: string | number;
5
+ type?: 'primary' | 'error' | 'warning' | 'success' | 'default';
6
+ mode?: TextMode;
7
+ format?: boolean;
8
+ color?: string;
9
+ size?: string | number;
10
+ bold?: boolean;
11
+ lines?: number;
12
+ lineHeight?: string | number;
13
+ decoration?: 'none' | 'underline' | 'line-through';
14
+ prefix?: ReactNode;
15
+ suffix?: ReactNode;
16
+ className?: string;
17
+ onTap?: () => void;
18
+ };
19
+ export declare function Text({ text, type, mode, format, color, size, bold, lines, lineHeight, decoration, prefix, suffix, className, onTap }: TextProps): import("@lynx-js/react").JSX.Element;
package/dist/Text.jsx ADDED
@@ -0,0 +1,7 @@
1
+ import { formatUiText } from './textModel.js';
2
+ export function Text({ text, type = 'default', mode = 'text', format = false, color, size, bold = false, lines, lineHeight, decoration, prefix, suffix, className = '', onTap }) {
3
+ const unit = (value) => typeof value === 'number' ? `${value}px` : value;
4
+ return <text className={`ui-text ui-text-${type} ${bold ? 'ui-text-bold' : ''} ${className}`} text-maxline={lines === undefined ? undefined : String(Math.max(1, Math.min(5, Math.floor(lines) || 1)))} style={{ color, fontSize: unit(size), lineHeight: unit(lineHeight), textDecoration: decoration }} bindtap={onTap}>
5
+ {prefix}{formatUiText(text, mode, format)}{suffix}
6
+ </text>;
7
+ }
@@ -0,0 +1,89 @@
1
+ import type { ReactNode } from '@lynx-js/react';
2
+ import type { CSSProperties } from '@lynx-js/types';
3
+ export type TextFieldEvent = {
4
+ value: string;
5
+ selectionStart?: number;
6
+ selectionEnd?: number;
7
+ isComposing?: boolean;
8
+ };
9
+ export type TextFieldRef = {
10
+ focus: () => void;
11
+ blur: () => void;
12
+ setSelectionRange: (start: number, end: number) => void;
13
+ };
14
+ export type TextFieldProps = {
15
+ value?: string | number;
16
+ defaultValue?: string | number;
17
+ onChange?: (value: string) => void;
18
+ onInput?: (event: TextFieldEvent) => void;
19
+ placeholder?: string;
20
+ maxlength?: number;
21
+ disabled?: boolean;
22
+ readonly?: boolean;
23
+ clearable?: boolean;
24
+ clearTrigger?: 'always' | 'focus';
25
+ focusWhenClear?: boolean;
26
+ error?: boolean;
27
+ compact?: boolean;
28
+ alignRight?: boolean;
29
+ prefixIcon?: string;
30
+ suffixIcon?: string;
31
+ prefix?: ReactNode;
32
+ suffix?: ReactNode;
33
+ showWordLimit?: boolean;
34
+ focus?: boolean;
35
+ confirmType?: 'done' | 'go' | 'next' | 'search' | 'send';
36
+ confirmHold?: boolean;
37
+ avoidKeyboard?: boolean;
38
+ cursorSpacing?: number;
39
+ softInputMode?: 'unspecified' | 'nothing' | 'pan' | 'resize';
40
+ holdKeyboard?: boolean;
41
+ selectionStart?: number;
42
+ selectionEnd?: number;
43
+ placeholderColor?: string;
44
+ inputFilter?: string;
45
+ showSoftInputOnFocus?: boolean;
46
+ ignoreCompositionEvent?: boolean;
47
+ onFocus?: (event: TextFieldEvent) => void;
48
+ onBlur?: (event: TextFieldEvent) => void;
49
+ onConfirm?: (event: TextFieldEvent) => void;
50
+ onClear?: () => void;
51
+ onClickPrefixIcon?: () => void;
52
+ onClickSuffixIcon?: () => void;
53
+ onTap?: () => void;
54
+ onKeyboardHeightChange?: (event: {
55
+ height: number;
56
+ }) => void;
57
+ className?: string;
58
+ inputClassName?: string;
59
+ style?: CSSProperties;
60
+ };
61
+ export type InternalTextFieldProps = TextFieldProps & {
62
+ multiline?: boolean;
63
+ type?: 'text' | 'number' | 'digit' | 'password' | 'tel' | 'email';
64
+ showPassword?: boolean;
65
+ textAlign?: 'left' | 'center' | 'right';
66
+ autoHeight?: boolean;
67
+ height?: number;
68
+ minHeight?: number;
69
+ maxHeight?: number;
70
+ maxlines?: number;
71
+ onLineChange?: (event: {
72
+ lineCount: number;
73
+ }) => void;
74
+ };
75
+ /** Shared native editing/synchronization; browser APIs belong only in the H5 host. */
76
+ export declare const TextField: (props: TextFieldProps & {
77
+ multiline?: boolean;
78
+ type?: "text" | "number" | "digit" | "password" | "tel" | "email";
79
+ showPassword?: boolean;
80
+ textAlign?: "left" | "center" | "right";
81
+ autoHeight?: boolean;
82
+ height?: number;
83
+ minHeight?: number;
84
+ maxHeight?: number;
85
+ maxlines?: number;
86
+ onLineChange?: (event: {
87
+ lineCount: number;
88
+ }) => void;
89
+ } & import("react").RefAttributes<TextFieldRef>) => React.ReactElement | null;