@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
@@ -0,0 +1,20 @@
1
+ import { useContext, useMemo } from '@lynx-js/react';
2
+ import { ConfigContext, configThemeVars } from './configContext.js';
3
+ import { configThemeAppearance, configThemeTokens } from './configTheme.js';
4
+ export { useConfigProvider } from './configContext.js';
5
+ export function ConfigProvider({ theme, themeVars, button, tag, children, className = '', style }) {
6
+ const parent = useContext(ConfigContext);
7
+ const { config, scope } = useMemo(() => {
8
+ const own = { ...configThemeVars(themeVars), ...Object.fromEntries(Object.entries(style ?? {}).filter(([key, value]) => key.startsWith('--cso-ui-') && value !== undefined).map(([key, value]) => [key, String(value)])) };
9
+ const variables = { ...parent?.themeVars, ...own };
10
+ const scope = theme === undefined ? { ...configThemeAppearance(parent?.theme ?? 'light'), ...variables } : { ...configThemeTokens(theme), ...variables };
11
+ const config = {
12
+ theme: theme ?? parent?.theme ?? 'light', themeVars: variables,
13
+ button: { ...parent?.button, ...Object.fromEntries(Object.entries(button ?? {}).filter(([, value]) => value !== undefined)) },
14
+ tag: { ...parent?.tag, ...Object.fromEntries(Object.entries(tag ?? {}).filter(([, value]) => value !== undefined)) },
15
+ tokens: { ...parent?.tokens, ...scope },
16
+ };
17
+ return { config, scope };
18
+ }, [parent, theme, themeVars, button, tag, style]);
19
+ return <ConfigContext.Provider value={config}><view className={`ui-config-provider ${className}`} style={{ ...scope, ...style }}>{children}</view></ConfigContext.Provider>;
20
+ }
@@ -0,0 +1,20 @@
1
+ import type { ReactNode } from '@lynx-js/react';
2
+ import type { CSSProperties } from '@lynx-js/types';
3
+ import type { TimeData } from './countDownModel.js';
4
+ export type CountDownRef = {
5
+ start: () => void;
6
+ pause: () => void;
7
+ reset: () => void;
8
+ };
9
+ export type CountDownProps = {
10
+ time?: number;
11
+ millisecond?: boolean;
12
+ autoStart?: boolean;
13
+ format?: string;
14
+ onChange?: (current: TimeData) => void;
15
+ onFinish?: () => void;
16
+ children?: ReactNode | ((current: TimeData) => ReactNode);
17
+ className?: string;
18
+ style?: CSSProperties;
19
+ };
20
+ export declare const CountDown: (props: CountDownProps & import("react").RefAttributes<CountDownRef>) => React.ReactElement | null;
@@ -0,0 +1,15 @@
1
+ import { forwardRef, useEffect, useImperativeHandle } from '@lynx-js/react';
2
+ import { useCountDown } from './useCountDown.js';
3
+ import { formatCountDown } from './countDownModel.js';
4
+ export const CountDown = forwardRef(function CountDown({ time = 0, millisecond = false, autoStart = true, format = 'HH:mm:ss', onChange, onFinish, children, className = '', style }, ref) {
5
+ const timer = useCountDown({ time, millisecond, onChange, onFinish });
6
+ const reset = () => {
7
+ 'background only';
8
+ timer.reset(time);
9
+ if (autoStart)
10
+ timer.start();
11
+ };
12
+ useImperativeHandle(ref, () => ({ start: timer.start, pause: timer.pause, reset }));
13
+ useEffect(reset, [time, autoStart]);
14
+ return <view className={`ui-count-down ${className}`} style={style}>{typeof children === 'function' ? children(timer.current) : children ?? <text className="ui-count-down-text">{formatCountDown(format, timer.current)}</text>}</view>;
15
+ });
@@ -0,0 +1,28 @@
1
+ import type { ReactNode } from '@lynx-js/react';
2
+ import type { CSSProperties } from '@lynx-js/types';
3
+ export type CountToRef = {
4
+ start: () => void;
5
+ pause: () => void;
6
+ reset: () => void;
7
+ };
8
+ export type CountToProps = {
9
+ startVal?: number;
10
+ endVal?: number;
11
+ duration?: number;
12
+ autoStart?: boolean;
13
+ decimals?: number;
14
+ decimal?: string;
15
+ separator?: string;
16
+ prefix?: ReactNode;
17
+ suffix?: ReactNode;
18
+ useEasing?: boolean;
19
+ fontSize?: number;
20
+ color?: string;
21
+ type?: 'default' | 'primary' | 'error' | 'warning' | 'success' | 'info';
22
+ onMounted?: () => void;
23
+ onFinish?: () => void;
24
+ children?: ReactNode | ((value: number, formatted: string) => ReactNode);
25
+ className?: string;
26
+ style?: CSSProperties;
27
+ };
28
+ export declare const CountTo: (props: CountToProps & import("react").RefAttributes<CountToRef>) => React.ReactElement | null;
@@ -0,0 +1,27 @@
1
+ import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from '@lynx-js/react';
2
+ import { useCountDown } from './useCountDown.js';
3
+ import { countDownTime } from './countDownModel.js';
4
+ import { countToNumber, countToValue, formatCountTo } from './countToModel.js';
5
+ export const CountTo = forwardRef(function CountTo({ startVal = 0, endVal = 2024, duration = 3000, autoStart = true, decimals = 0, decimal = '.', separator = ',', prefix, suffix, useEasing = true, fontSize, color, type = 'default', onMounted, onFinish, children, className = '', style }, ref) {
6
+ const callbacks = useRef({ onMounted, onFinish });
7
+ callbacks.current = { onMounted, onFinish };
8
+ const [done, setDone] = useState(false), milliseconds = countDownTime(duration);
9
+ const timer = useCountDown({ time: milliseconds, millisecond: true, onFinish: () => {
10
+ 'background only';
11
+ setDone(true);
12
+ callbacks.current.onFinish?.();
13
+ } });
14
+ const reset = () => {
15
+ 'background only';
16
+ setDone(false);
17
+ timer.reset(milliseconds);
18
+ if (autoStart)
19
+ timer.start();
20
+ };
21
+ useImperativeHandle(ref, () => ({ start: timer.start, pause: timer.pause, reset }));
22
+ useEffect(reset, [startVal, endVal, duration, autoStart]);
23
+ useEffect(() => { callbacks.current.onMounted?.(); }, []);
24
+ const progress = milliseconds ? 1 - timer.current.total / milliseconds : done ? 1 : 0, value = countToValue(countToNumber(startVal), countToNumber(endVal), progress, useEasing), formatted = formatCountTo(value, decimals, decimal, separator);
25
+ const slot = (node) => typeof node === 'string' || typeof node === 'number' ? <text className="ui-count-to-affix">{node}</text> : node;
26
+ return <view className={`ui-count-to ui-count-to-${type} ${className}`} style={{ color, ...(fontSize !== undefined ? { '--cso-ui-count-to-font-size': `${Number.isFinite(fontSize) ? Math.max(0, fontSize) : 18}px`, '--cso-ui-count-to-line-height': `${Number.isFinite(fontSize) ? Math.max(0, fontSize) + 8 : 26}px` } : {}), ...style }}>{slot(prefix)}{typeof children === 'function' ? children(value, formatted) : children ?? <text className="ui-count-to-value">{formatted}</text>}{slot(suffix)}</view>;
27
+ });
@@ -0,0 +1,29 @@
1
+ import type { ReactNode } from '@lynx-js/react';
2
+ import type { BaseEvent, CSSProperties, ImageErrorEvent, ImageLoadEvent } from '@lynx-js/types';
3
+ import type { LayerLifecycle } from "./Overlay.jsx";
4
+ export type CurtainClosePosition = 'inset' | 'top' | 'bottom' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
5
+ export type CurtainProps = LayerLifecycle & {
6
+ value: boolean;
7
+ onChange?: (value: boolean) => void;
8
+ src: string;
9
+ width?: number;
10
+ to?: string;
11
+ closePosition?: CurtainClosePosition;
12
+ closeOnClickModal?: boolean;
13
+ closeOnClick?: boolean;
14
+ zIndex?: number;
15
+ rootPortal?: boolean;
16
+ onNavigate?: (url: string) => void;
17
+ onClick?: () => void;
18
+ onClose?: (reason: 'close' | 'modal' | 'image') => void;
19
+ onClickModal?: () => void;
20
+ onClosed?: () => void;
21
+ onLoad?: (event: BaseEvent<'load', ImageLoadEvent>) => void;
22
+ onError?: (event: BaseEvent<'error', ImageErrorEvent>) => void;
23
+ renderClose?: (close: () => void) => ReactNode;
24
+ customCloseClass?: string;
25
+ customCloseStyle?: CSSProperties;
26
+ className?: string;
27
+ style?: CSSProperties;
28
+ };
29
+ export declare function Curtain(props: CurtainProps): import("@lynx-js/react").JSX.Element;
@@ -0,0 +1,51 @@
1
+ import { useState } from '@lynx-js/react';
2
+ import { Icon } from "./Icon.jsx";
3
+ import { Popup } from "./Popup.jsx";
4
+ export function Curtain(props) { return <CurtainSource key={props.src} {...props}/>; }
5
+ function CurtainSource({ value, onChange, src, width, closePosition = 'inset', closeOnClickModal = false, closeOnClick = true, zIndex = 10, rootPortal = false, to, onNavigate, onClick, onClose, onClickModal, onClosed, onLoad, onError, renderClose, customCloseClass = '', customCloseStyle, className = '', style, onAfterLeave, ...lifecycle }) {
6
+ const [natural, setNatural] = useState({ width: 300, height: 300 }), [failed, setFailed] = useState(false);
7
+ const actualWidth = width === undefined ? natural.width : Number.isFinite(width) ? Math.max(1, width) : 300;
8
+ const close = (reason) => {
9
+ 'background only';
10
+ if (!value || failed)
11
+ return;
12
+ onChange?.(false);
13
+ onClose?.(reason);
14
+ };
15
+ return <Popup {...lifecycle} show={value && !failed} onChange={() => {
16
+ 'background only';
17
+ close('modal');
18
+ }} onClickModal={onClickModal} onAfterLeave={() => {
19
+ 'background only';
20
+ onAfterLeave?.();
21
+ onClosed?.();
22
+ }} rootPortal={rootPortal} zIndex={zIndex} transition="zoom-in" closeOnClickModal={closeOnClickModal} className={`ui-curtain ${className}`} style={{ width: `${actualWidth}px`, ...style }}>
23
+ <view className="ui-curtain-content">
24
+ <image className="ui-curtain-image" src={src} mode="scaleToFill" style={{ width: `${actualWidth}px`, height: `${actualWidth * natural.height / natural.width}px` }} bindload={event => {
25
+ 'background only';
26
+ const { width: w, height: h } = event.detail;
27
+ if (w > 0 && h > 0)
28
+ setNatural({ width: w, height: h });
29
+ setFailed(false);
30
+ onLoad?.(event);
31
+ }} binderror={event => {
32
+ 'background only';
33
+ setFailed(true);
34
+ onError?.(event);
35
+ }} bindtap={() => {
36
+ 'background only';
37
+ if (!value || failed)
38
+ return;
39
+ if (to)
40
+ onNavigate?.(to);
41
+ onClick?.();
42
+ if (closeOnClick)
43
+ close('image');
44
+ }}/>
45
+ {renderClose ? renderClose(() => {
46
+ 'background only';
47
+ close('close');
48
+ }) : <view className={`ui-curtain-close ui-curtain-close-${closePosition} ${customCloseClass}`} style={customCloseStyle} catchtap={() => close('close')} accessibility-element accessibility-traits="button" accessibility-label="关闭幕帘"><Icon name="close-circle" size={32} color={typeof customCloseStyle?.color === 'string' ? customCloseStyle.color : '#fff'}/></view>}
49
+ </view>
50
+ </Popup>;
51
+ }
@@ -0,0 +1,46 @@
1
+ import type { ReactNode, Ref } from '@lynx-js/react';
2
+ import type { DatetimePickerViewProps } from "./DatetimePickerView.jsx";
3
+ import type { DatetimeModelProps, DatetimePickerValue } from './datetimePickerModel.js';
4
+ import type { PickerOption } from './pickerModel.js';
5
+ export { DatetimePickerView } from "./DatetimePickerView.jsx";
6
+ export type { DatetimePickerViewProps, DatetimePickerViewRef, DatetimePickerChange } from "./DatetimePickerView.jsx";
7
+ export type { DatetimePickerType, DatetimePickerValue, DatetimeColumn, DatetimeColumnType, DatetimeFilterParams } from './datetimePickerModel.js';
8
+ export type DatetimePickerModelValue = DatetimePickerValue | readonly DatetimePickerValue[];
9
+ type Result<V> = V extends readonly DatetimePickerValue[] ? DatetimePickerValue[] : DatetimePickerValue;
10
+ export type DatetimePickerRef = {
11
+ open: () => void;
12
+ close: () => void;
13
+ };
14
+ export type DatetimePickerProps<V extends DatetimePickerModelValue = DatetimePickerValue> = Omit<DatetimePickerViewProps, 'value' | 'onChange'> & {
15
+ value?: V;
16
+ visible?: boolean;
17
+ onVisibleChange?: (visible: boolean) => void;
18
+ title?: string;
19
+ cancelButtonText?: string;
20
+ confirmButtonText?: string;
21
+ beforeConfirm?: (value: Result<V>) => boolean | Promise<boolean>;
22
+ onConfirm?: (event: {
23
+ value: Result<V>;
24
+ }) => void;
25
+ onChange?: (event: {
26
+ value: Result<V>;
27
+ }) => void;
28
+ onPickChange?: (event: {
29
+ value: Result<V>;
30
+ }) => void;
31
+ onToggle?: (value: DatetimePickerValue) => void;
32
+ onCancel?: () => void;
33
+ onClose?: () => void;
34
+ onOpen?: () => void;
35
+ displayFormatTabLabel?: (items: PickerOption[]) => string;
36
+ closeOnClickModal?: boolean;
37
+ rootPortal?: boolean;
38
+ safeAreaInsetBottom?: boolean;
39
+ safeAreaBottom?: number;
40
+ zIndex?: number;
41
+ viewClassName?: string;
42
+ };
43
+ export declare function datetimeDraft(value: DatetimePickerModelValue | undefined, props: DatetimeModelProps): DatetimePickerValue | DatetimePickerValue[];
44
+ export declare const DatetimePicker: <V extends DatetimePickerModelValue = DatetimePickerValue>(props: DatetimePickerProps<V> & {
45
+ ref?: Ref<DatetimePickerRef>;
46
+ }) => ReactNode;
@@ -0,0 +1,138 @@
1
+ import { forwardRef, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState } from '@lynx-js/react';
2
+ import { Popup } from "./Popup.jsx";
3
+ import { Loading } from "./Loading.jsx";
4
+ import { FormFieldContext } from './formContext.js';
5
+ import { DatetimePickerView } from "./DatetimePickerView.jsx";
6
+ import { datetimeDefaults, datetimeLabel, datetimeModel } from './datetimePickerModel.js';
7
+ export { DatetimePickerView } from "./DatetimePickerView.jsx";
8
+ function boundary(value, type) {
9
+ if (type !== 'time')
10
+ return Number(value);
11
+ const [hour = 0, minute = 0, second = 0] = String(value).split(':').map(Number);
12
+ return new Date(2000, 0, 1, hour, minute, second).getTime();
13
+ }
14
+ export function datetimeDraft(value, props) {
15
+ if (!Array.isArray(value))
16
+ return datetimeModel({ ...props, value: value }).value;
17
+ const first = datetimeModel({ ...props, value: value[0] }).value;
18
+ const last = value[1] === '' || value[1] === undefined ? props.type === 'time' ? `${String(props.maxHour ?? 23).padStart(2, '0')}:${String(props.maxMinute ?? 59).padStart(2, '0')}${props.useSecond ? `:${String(props.maxSecond ?? 59).padStart(2, '0')}` : ''}` : props.maxDate ?? datetimeDefaults.maxDate : value[1];
19
+ const second = datetimeModel({ ...props, value: last }).value;
20
+ return [first, first !== '' && second !== '' && boundary(first, props.type) > boundary(second, props.type) ? first : second];
21
+ }
22
+ const DatetimePickerImpl = forwardRef(function DatetimePicker({ value, visible, onVisibleChange, title = '', cancelButtonText = '取消', confirmButtonText = '完成', beforeConfirm, onConfirm, onChange, onPickChange, onToggle, onCancel, onClose, onOpen, displayFormatTabLabel, closeOnClickModal = true, rootPortal = false, safeAreaInsetBottom = true, safeAreaBottom = 0, zIndex = 100, viewClassName = '', className = '', style, disabled: disabledProp, ...props }, ref) {
23
+ const field = useContext(FormFieldContext), disabled = disabledProp ?? field?.disabled ?? false;
24
+ const [innerVisible, setInnerVisible] = useState(false), [innerValue, setInnerValue] = useState(), show = visible ?? innerVisible;
25
+ const sourceValue = value ?? innerValue;
26
+ const { type, minDate, maxDate, minHour, maxHour, minMinute, maxMinute, minSecond, maxSecond, useSecond, filter, formatter, columnFormatter, boundaryMinDate, boundaryMaxDate } = props;
27
+ const modelProps = useMemo(() => ({ type, minDate, maxDate, minHour, maxHour, minMinute, maxMinute, minSecond, maxSecond, useSecond, filter, formatter, columnFormatter, boundaryMinDate, boundaryMaxDate }), [type, minDate, maxDate, minHour, maxHour, minMinute, maxMinute, minSecond, maxSecond, useSecond, filter, formatter, columnFormatter, boundaryMinDate, boundaryMaxDate]);
28
+ const snapshot = useMemo(() => ({ sourceValue, modelProps, show, disabled, loading: props.loading }), [sourceValue, modelProps, show, disabled, props.loading]);
29
+ const latestSource = useRef(snapshot);
30
+ latestSource.current = snapshot;
31
+ const [ready, setReady] = useState();
32
+ const [draft, setDraft] = useState(''), [tab, setTab] = useState(0), [busy, setBusy] = useState(false);
33
+ const current = useRef(draft), active = useRef(0), view = useRef(null), generation = useRef(0), pending = useRef(false), openCallback = useRef(onOpen);
34
+ openCallback.current = onOpen;
35
+ useEffect(() => { generation.current++; pending.current = false; setBusy(false); if (show) {
36
+ setReady(snapshot);
37
+ const next = datetimeDraft(sourceValue, modelProps);
38
+ current.current = next;
39
+ setDraft(next);
40
+ active.current = 0;
41
+ setTab(0);
42
+ } }, [snapshot]);
43
+ useEffect(() => { if (show)
44
+ openCallback.current?.(); }, [show]);
45
+ useEffect(() => () => { generation.current++; }, []);
46
+ const changeVisible = (next) => {
47
+ 'background only';
48
+ if (visible === undefined)
49
+ setInnerVisible(next);
50
+ onVisibleChange?.(next);
51
+ };
52
+ const close = () => {
53
+ 'background only';
54
+ generation.current++;
55
+ pending.current = false;
56
+ setBusy(false);
57
+ if (show) {
58
+ changeVisible(false);
59
+ onClose?.();
60
+ }
61
+ };
62
+ const cancel = () => {
63
+ 'background only';
64
+ if (show) {
65
+ onCancel?.();
66
+ close();
67
+ }
68
+ };
69
+ useImperativeHandle(ref, () => ({ open: () => {
70
+ 'background only';
71
+ if (!show && !disabled)
72
+ changeVisible(true);
73
+ }, close: cancel }), [show, disabled, visible, onVisibleChange, onClose, onCancel]);
74
+ const range = Array.isArray(draft), values = range ? draft : [draft], selected = values[tab] ?? '';
75
+ const limit = range && values[1 - tab] !== '' ? boundary(values[1 - tab], type) : undefined;
76
+ const viewProps = { ...modelProps, boundaryMinDate: range && tab === 1 ? limit : boundaryMinDate, boundaryMaxDate: range && tab === 0 ? limit : boundaryMaxDate };
77
+ const update = (next, emit = true) => {
78
+ 'background only';
79
+ if (!show || disabled || props.loading || busy)
80
+ return;
81
+ const value = Array.isArray(current.current) ? current.current.map((value, index) => index === active.current ? next : value) : next;
82
+ current.current = value;
83
+ setDraft(value);
84
+ if (emit)
85
+ onPickChange?.({ value });
86
+ };
87
+ const capture = () => {
88
+ 'background only';
89
+ const next = view.current?.getSelected().value ?? (Array.isArray(current.current) ? current.current[active.current] ?? '' : current.current);
90
+ update(next, false);
91
+ return current.current;
92
+ };
93
+ const confirm = async () => {
94
+ 'background only';
95
+ if (!show || disabled || props.loading || pending.current)
96
+ return;
97
+ const next = capture();
98
+ if (next === '' || Array.isArray(next) && next.some(value => value === ''))
99
+ return;
100
+ pending.current = true;
101
+ setBusy(true);
102
+ const ticket = ++generation.current, source = latestSource.current;
103
+ try {
104
+ if (!await (beforeConfirm?.(next) ?? true) || ticket !== generation.current || source !== latestSource.current)
105
+ return;
106
+ if (value === undefined)
107
+ setInnerValue(next);
108
+ onChange?.({ value: next });
109
+ onConfirm?.({ value: next });
110
+ close();
111
+ }
112
+ catch { /* Rejection keeps the current draft available. */ }
113
+ finally {
114
+ if (ticket === generation.current) {
115
+ pending.current = false;
116
+ setBusy(false);
117
+ }
118
+ }
119
+ };
120
+ return <Popup show={show} onClose={cancel} position="bottom" round duration={200} lockScroll={false} closeOnClickModal={closeOnClickModal} rootPortal={rootPortal} safeAreaInsetBottom={safeAreaInsetBottom} safeAreaBottom={safeAreaBottom} zIndex={zIndex} className={`ui-datetime-picker ${className}`} style={style}>
121
+ <view className="ui-datetime-picker-toolbar"><text className="ui-datetime-picker-cancel" bindtap={cancel}>{cancelButtonText}</text>{title ? <text className="ui-datetime-picker-title">{title}</text> : <view />}<view className="ui-datetime-picker-confirm" bindtap={() => {
122
+ 'background only';
123
+ void confirm();
124
+ }} accessibility-element accessibility-traits="button" accessibility-label={confirmButtonText}>{busy ? <Loading size={20}/> : <text>{confirmButtonText}</text>}</view></view>
125
+ {range ? <view className="ui-datetime-picker-range">{values.map((value, index) => <view key={index} className={`ui-datetime-picker-range-item ${tab === index ? 'ui-datetime-picker-range-active' : ''}`} bindtap={() => {
126
+ 'background only';
127
+ if (busy || disabled || props.loading || index === tab)
128
+ return;
129
+ const next = capture();
130
+ active.current = index;
131
+ setTab(index);
132
+ if (Array.isArray(next))
133
+ onToggle?.(next[index]);
134
+ }}><text>{displayFormatTabLabel ? displayFormatTabLabel(datetimeModel({ ...modelProps, value }).selectedOptions) : datetimeLabel(value, type, useSecond)}</text><view className="ui-datetime-picker-range-line"/></view>).flatMap((item, index) => index ? [<view key="separator" className="ui-datetime-picker-range-separator"/>, item] : [item])}</view> : null}
135
+ {ready && (!show || ready === snapshot) ? <DatetimePickerView key={tab} {...props} {...viewProps} ref={view} value={selected} disabled={disabled || busy || !show} className={viewClassName} onChange={({ value }) => update(value)}/> : null}
136
+ </Popup>;
137
+ });
138
+ export const DatetimePicker = DatetimePickerImpl;
@@ -0,0 +1,38 @@
1
+ import type { CSSProperties } from '@lynx-js/types';
2
+ import type { PickerOption } from './pickerModel.js';
3
+ import type { DatetimeColumn, DatetimeModelProps, DatetimePickerValue } from './datetimePickerModel.js';
4
+ export type DatetimePickerChange = {
5
+ value: DatetimePickerValue;
6
+ columns: DatetimeColumn[];
7
+ selectedOptions: PickerOption[];
8
+ };
9
+ export type DatetimePickerViewProps = DatetimeModelProps & {
10
+ disabled?: boolean;
11
+ loading?: boolean;
12
+ itemHeight?: number;
13
+ visibleItemCount?: number;
14
+ immediateChange?: boolean;
15
+ onChange?: (event: DatetimePickerChange) => void;
16
+ onPickStart?: () => void;
17
+ onPickEnd?: () => void;
18
+ className?: string;
19
+ style?: CSSProperties;
20
+ };
21
+ export type DatetimePickerViewRef = {
22
+ getSelected: () => DatetimePickerChange;
23
+ getSelectedOptions: () => PickerOption[];
24
+ correctValue: (value: DatetimePickerValue) => DatetimePickerValue;
25
+ getOriginColumns: () => DatetimeColumn[];
26
+ };
27
+ export declare const DatetimePickerView: (props: DatetimeModelProps & {
28
+ disabled?: boolean;
29
+ loading?: boolean;
30
+ itemHeight?: number;
31
+ visibleItemCount?: number;
32
+ immediateChange?: boolean;
33
+ onChange?: (event: DatetimePickerChange) => void;
34
+ onPickStart?: () => void;
35
+ onPickEnd?: () => void;
36
+ className?: string;
37
+ style?: CSSProperties;
38
+ } & import("react").RefAttributes<DatetimePickerViewRef>) => React.ReactElement | null;
@@ -0,0 +1,36 @@
1
+ import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from '@lynx-js/react';
2
+ import { PickerView } from "./PickerView.jsx";
3
+ import { datetimeModel } from './datetimePickerModel.js';
4
+ export const DatetimePickerView = forwardRef(function DatetimePickerView(props, ref) {
5
+ const [inner, setInner] = useState(''), value = props.value ?? inner;
6
+ const { type, minDate, maxDate, minHour, maxHour, minMinute, maxMinute, minSecond, maxSecond, useSecond, boundaryMinDate, boundaryMaxDate, formatter, filter, columnFormatter } = props;
7
+ const modelProps = useMemo(() => ({ value, type, minDate, maxDate, minHour, maxHour, minMinute, maxMinute, minSecond, maxSecond, useSecond, boundaryMinDate, boundaryMaxDate, formatter, filter, columnFormatter }), [value, type, minDate, maxDate, minHour, maxHour, minMinute, maxMinute, minSecond, maxSecond, useSecond, boundaryMinDate, boundaryMaxDate, formatter, filter, columnFormatter]);
8
+ const data = useMemo(() => datetimeModel(modelProps), [modelProps]), picker = useRef(null), callback = useRef(props.onChange);
9
+ callback.current = props.onChange;
10
+ const event = (model) => ({ value: model.value, columns: model.origin, selectedOptions: model.selectedOptions });
11
+ useEffect(() => {
12
+ if (value !== data.value) {
13
+ if (props.value === undefined)
14
+ setInner(data.value);
15
+ callback.current?.(event(data));
16
+ }
17
+ }, [value, data, props.value]);
18
+ const read = () => {
19
+ 'background only';
20
+ return datetimeModel(modelProps, picker.current?.getSelectedValues());
21
+ };
22
+ useImperativeHandle(ref, () => ({ getSelected: () => {
23
+ 'background only';
24
+ return event(read());
25
+ }, getSelectedOptions: () => {
26
+ 'background only';
27
+ return read().selectedOptions;
28
+ }, correctValue: next => datetimeModel({ ...modelProps, value: next }).value, getOriginColumns: () => data.origin.map(column => ({ ...column, values: [...column.values] })) }), [modelProps, data]);
29
+ return <PickerView ref={picker} columns={data.columns} value={data.values} disabled={props.disabled} loading={props.loading} itemHeight={props.itemHeight} visibleItemCount={props.visibleItemCount} immediateChange={props.immediateChange} onPickStart={props.onPickStart} onPickEnd={props.onPickEnd} className={`ui-datetime-picker-view ${props.className ?? ''}`} style={props.style} onChange={selection => {
30
+ 'background only';
31
+ const next = datetimeModel(modelProps, selection.value);
32
+ if (props.value === undefined)
33
+ setInner(next.value);
34
+ callback.current?.(event(next));
35
+ }}/>;
36
+ });
@@ -0,0 +1,64 @@
1
+ import type { ReactNode } from '@lynx-js/react';
2
+ import type { CSSProperties } from '@lynx-js/types';
3
+ import type { ButtonProps } from "./Button.jsx";
4
+ export type DialogResult = {
5
+ action: 'confirm' | 'cancel' | 'modal' | 'close' | 'action';
6
+ value: string;
7
+ index?: number;
8
+ };
9
+ export type DialogAction = Omit<ButtonProps, 'onTap' | 'label'> & {
10
+ text: string;
11
+ action?: 'confirm' | 'cancel' | 'action';
12
+ };
13
+ export type DialogInputProps = {
14
+ placeholder?: string;
15
+ maxlength?: number;
16
+ type?: 'text' | 'number' | 'digit' | 'password' | 'tel' | 'email';
17
+ multiline?: boolean;
18
+ maxlines?: number;
19
+ };
20
+ export type DialogOptions = {
21
+ title?: ReactNode;
22
+ msg?: string;
23
+ type?: 'alert' | 'confirm' | 'prompt';
24
+ theme?: 'button' | 'text';
25
+ actionLayout?: 'horizontal' | 'vertical';
26
+ actions?: readonly DialogAction[];
27
+ showCancelButton?: boolean;
28
+ confirmButtonText?: string;
29
+ cancelButtonText?: string;
30
+ confirmButtonProps?: Partial<DialogAction> | string | null;
31
+ cancelButtonProps?: Partial<DialogAction> | string | null;
32
+ inputValue?: string | number;
33
+ inputProps?: DialogInputProps;
34
+ inputPattern?: RegExp;
35
+ inputValidate?: (value: string) => boolean | string;
36
+ inputError?: string;
37
+ showErr?: boolean;
38
+ beforeConfirm?: (value: string) => boolean | Promise<boolean>;
39
+ icon?: string;
40
+ iconColor?: string;
41
+ headerImage?: string;
42
+ closeOnClickModal?: boolean;
43
+ showClose?: boolean;
44
+ zIndex?: number;
45
+ lazyRender?: boolean;
46
+ };
47
+ export type DialogProps = DialogOptions & {
48
+ requestKey?: number;
49
+ show?: boolean;
50
+ onChange?: (show: boolean) => void;
51
+ onResult?: (result: DialogResult) => void;
52
+ rootPortal?: boolean;
53
+ className?: string;
54
+ style?: CSSProperties;
55
+ children?: ReactNode;
56
+ header?: ReactNode;
57
+ renderActions?: (controls: {
58
+ confirm: () => void;
59
+ cancel: () => void;
60
+ close: () => void;
61
+ pending: boolean;
62
+ }) => ReactNode;
63
+ };
64
+ export declare function Dialog({ requestKey, show, onChange, onResult, title, msg, type, theme, actionLayout, actions, showCancelButton, confirmButtonText, cancelButtonText, confirmButtonProps, cancelButtonProps, inputValue, inputProps, inputPattern, inputValidate, inputError, showErr, beforeConfirm, icon, iconColor, headerImage, closeOnClickModal, showClose, zIndex, lazyRender, rootPortal, className, style, children, header, renderActions }: DialogProps): import("@lynx-js/react").JSX.Element;
@@ -0,0 +1,105 @@
1
+ import { useEffect, useRef, useState } from '@lynx-js/react';
2
+ import { Popup } from "./Popup.jsx";
3
+ import { Button } from "./Button.jsx";
4
+ import { Icon } from "./Icon.jsx";
5
+ function PromptInput({ value, onInput, ...props }) {
6
+ const node = useRef(null);
7
+ const native = useRef(value);
8
+ useEffect(() => { if (native.current !== value)
9
+ node.current?.invoke({ method: 'setValue', params: { value }, success: () => { native.current = value; } }).exec(); }, [value]);
10
+ const common = { ref: node, className: 'ui-dialog-input', 'default-value': value, placeholder: props.placeholder, maxlength: props.maxlength ?? -1, 'set-soft-input-mode': 'nothing', 'avoid-keyboard': false, bindinput: (event) => {
11
+ 'background only';
12
+ native.current = event.detail.value;
13
+ onInput(event.detail.value);
14
+ } };
15
+ return props.multiline ? <textarea {...common} maxlines={props.maxlines ?? 4}/> : <input {...common} type={props.type ?? 'text'} confirm-type="done"/>;
16
+ }
17
+ export function Dialog({ requestKey = 0, show = false, onChange, onResult, title, msg, type = 'alert', theme = 'button', actionLayout = 'horizontal', actions, showCancelButton = type !== 'alert', confirmButtonText = '确定', cancelButtonText = '取消', confirmButtonProps, cancelButtonProps, inputValue = '', inputProps, inputPattern, inputValidate, inputError = '输入内容不正确', showErr = false, beforeConfirm, icon, iconColor, headerImage, closeOnClickModal = false, showClose = false, zIndex = 99, lazyRender = true, rootPortal = false, className = '', style, children, header, renderActions }) {
18
+ const [value, setValue] = useState(String(inputValue));
19
+ const [error, setError] = useState(showErr ? inputError : '');
20
+ const [pending, setPending] = useState(false);
21
+ const [generation, setGeneration] = useState(0);
22
+ const request = useRef(0);
23
+ const busy = useRef(false);
24
+ useEffect(() => {
25
+ request.current++;
26
+ busy.current = false;
27
+ setPending(false);
28
+ if (show) {
29
+ setValue(String(inputValue));
30
+ setError(showErr ? inputError : '');
31
+ setGeneration(v => v + 1);
32
+ }
33
+ return () => { request.current++; busy.current = false; };
34
+ }, [show, inputValue, beforeConfirm, requestKey]);
35
+ const finish = (action, index) => {
36
+ 'background only';
37
+ if (!show)
38
+ return;
39
+ request.current++;
40
+ busy.current = false;
41
+ setPending(false);
42
+ onChange?.(false);
43
+ onResult?.({ action, value, ...(index === undefined ? {} : { index }) });
44
+ };
45
+ const confirm = async (action = 'confirm', index) => {
46
+ 'background only';
47
+ if (!show || busy.current)
48
+ return;
49
+ if (type === 'prompt') {
50
+ const matched = !inputPattern || new RegExp(inputPattern.source, inputPattern.flags).test(value);
51
+ let validated = true;
52
+ try {
53
+ validated = inputValidate?.(value) ?? true;
54
+ }
55
+ catch {
56
+ validated = false;
57
+ }
58
+ if (!matched || validated !== true) {
59
+ setError(typeof validated === 'string' ? validated : inputError);
60
+ return;
61
+ }
62
+ }
63
+ setError('');
64
+ const token = ++request.current;
65
+ busy.current = true;
66
+ try {
67
+ const decision = beforeConfirm?.(value) ?? true;
68
+ if (typeof decision !== 'boolean')
69
+ setPending(true);
70
+ const accepted = await decision;
71
+ if (request.current !== token)
72
+ return;
73
+ busy.current = false;
74
+ setPending(false);
75
+ if (accepted)
76
+ finish(action, index);
77
+ }
78
+ catch {
79
+ if (request.current === token) {
80
+ busy.current = false;
81
+ setPending(false);
82
+ setError('操作失败,请重试');
83
+ }
84
+ }
85
+ };
86
+ const normalize = (props, fallback) => props === null ? null : typeof props === 'string' ? { ...fallback, text: props } : { ...fallback, ...props };
87
+ const buttons = actions ?? [showCancelButton ? normalize(cancelButtonProps, { text: cancelButtonText, action: 'cancel', tone: 'info', variant: 'plain' }) : null, normalize(confirmButtonProps, { text: confirmButtonText, action: 'confirm', tone: 'primary' })].filter((item) => item !== null);
88
+ const iconNames = { success: 'check-circle-fill', danger: 'close-circle-fill', warning: 'exclamation-circle-fill', info: 'info-circle-fill' };
89
+ const iconName = iconNames[icon ?? ''] ?? icon;
90
+ return <Popup show={show} onClose={reason => finish(reason)} position="center" transition="zoom-in" duration={200} modal zIndex={zIndex} lazyRender={lazyRender} rootPortal={rootPortal} closable={showClose} closeOnClickModal={closeOnClickModal} className={`ui-dialog ${className}`} style={{ backgroundColor: 'transparent', ...style }}>
91
+ <view className={`ui-dialog-container ui-dialog-theme-${theme}`}>
92
+ {header ?? (headerImage ? <image className="ui-dialog-header-image" src={headerImage} mode="aspectFill"/> : null)}
93
+ {title || msg || type === 'prompt' || children || icon ? <view className="ui-dialog-body">
94
+ {iconName ? <view className="ui-dialog-icon"><Icon name={iconName} size={40} color={iconColor}/></view> : null}
95
+ {title ? typeof title === 'string' || typeof title === 'number' ? <text className="ui-dialog-title">{title}</text> : title : null}
96
+ {children ?? <>{msg ? <text className={`ui-dialog-message ${title ? 'ui-dialog-message-titled' : ''}`}>{msg}</text> : null}{type === 'prompt' ? <view className={`ui-dialog-input-wrap ${error ? 'ui-dialog-input-error' : ''}`}><PromptInput key={generation} {...inputProps} value={value} onInput={v => { setValue(v); setError(''); }}/></view> : null}</>}
97
+ {error ? <text className="ui-dialog-error">{error}</text> : null}
98
+ </view> : null}
99
+ {renderActions ? renderActions({ confirm: () => { void confirm(); }, cancel: () => finish('cancel'), close: () => finish('close'), pending }) : buttons.length ? <view className={`ui-dialog-actions ui-dialog-actions-${actionLayout}`}>{buttons.map(({ text, action = 'action', ...props }, index) => <view key={index} className="ui-dialog-action"><Button {...props} round={props.round ?? false} block label={text} loading={props.loading || (pending && action !== 'cancel')} disabled={props.disabled || (pending && action === 'cancel')} variant={theme === 'text' ? 'text' : props.variant} onTap={() => { if (action === 'cancel')
100
+ finish('cancel', index);
101
+ else
102
+ void confirm(action, index); }}/></view>)}</view> : null}
103
+ </view>
104
+ </Popup>;
105
+ }
@@ -0,0 +1,16 @@
1
+ import type { ReactNode } from '@lynx-js/react';
2
+ import type { CSSProperties } from '@lynx-js/types';
3
+ export type DividerAlign = 'left' | 'center' | 'right';
4
+ export type DividerProps = {
5
+ children?: ReactNode;
6
+ label?: string;
7
+ align?: DividerAlign;
8
+ contentPosition?: DividerAlign;
9
+ color?: string;
10
+ hairline?: boolean;
11
+ dashed?: boolean;
12
+ vertical?: boolean;
13
+ className?: string;
14
+ style?: CSSProperties;
15
+ };
16
+ export declare function Divider({ children, label, align, contentPosition, color, hairline, dashed, vertical, className, style }: DividerProps): import("@lynx-js/react").JSX.Element;