@daisu-ui/ui 0.0.0-stage → 0.1.0-beta.3
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.
- package/CHANGELOG.md +58 -0
- package/LICENSE +21 -0
- package/README.md +93 -2
- package/THIRD_PARTY_NOTICES.md +19 -0
- package/dist/ActionSheet.d.ts +45 -0
- package/dist/ActionSheet.jsx +37 -0
- package/dist/AnchoredBubble.d.ts +36 -0
- package/dist/AnchoredBubble.jsx +120 -0
- package/dist/Avatar.d.ts +35 -0
- package/dist/Avatar.jsx +29 -0
- package/dist/Backtop.d.ts +22 -0
- package/dist/Backtop.jsx +18 -0
- package/dist/Badge.d.ts +19 -0
- package/dist/Badge.jsx +11 -0
- package/dist/BarCode.d.ts +20 -0
- package/dist/BarCode.jsx +38 -0
- package/dist/Button.d.ts +21 -0
- package/dist/Button.jsx +19 -0
- package/dist/Calendar.d.ts +90 -0
- package/dist/Calendar.jsx +164 -0
- package/dist/CalendarView.d.ts +51 -0
- package/dist/CalendarView.jsx +136 -0
- package/dist/Card.d.ts +21 -0
- package/dist/Card.jsx +21 -0
- package/dist/Cascader.d.ts +75 -0
- package/dist/Cascader.jsx +212 -0
- package/dist/Cell.d.ts +34 -0
- package/dist/Cell.jsx +37 -0
- package/dist/Checkbox.d.ts +50 -0
- package/dist/Checkbox.jsx +74 -0
- package/dist/Circle.d.ts +19 -0
- package/dist/Circle.jsx +35 -0
- package/dist/Collapse.d.ts +31 -0
- package/dist/Collapse.jsx +61 -0
- package/dist/ConfigProvider.d.ts +15 -0
- package/dist/ConfigProvider.jsx +20 -0
- package/dist/CountDown.d.ts +20 -0
- package/dist/CountDown.jsx +15 -0
- package/dist/CountTo.d.ts +28 -0
- package/dist/CountTo.jsx +27 -0
- package/dist/Curtain.d.ts +29 -0
- package/dist/Curtain.jsx +51 -0
- package/dist/DatetimePicker.d.ts +46 -0
- package/dist/DatetimePicker.jsx +138 -0
- package/dist/DatetimePickerView.d.ts +38 -0
- package/dist/DatetimePickerView.jsx +36 -0
- package/dist/Dialog.d.ts +64 -0
- package/dist/Dialog.jsx +105 -0
- package/dist/Divider.d.ts +16 -0
- package/dist/Divider.jsx +9 -0
- package/dist/DropMenu.d.ts +55 -0
- package/dist/DropMenu.jsx +210 -0
- package/dist/Empty.d.ts +14 -0
- package/dist/Empty.jsx +14 -0
- package/dist/EmptyState.d.ts +6 -0
- package/dist/EmptyState.jsx +9 -0
- package/dist/Fab.d.ts +30 -0
- package/dist/Fab.jsx +127 -0
- package/dist/FloatingPanel.d.ts +21 -0
- package/dist/FloatingPanel.jsx +102 -0
- package/dist/Form.d.ts +63 -0
- package/dist/Form.jsx +108 -0
- package/dist/FormFieldRow.d.ts +56 -0
- package/dist/FormFieldRow.jsx +63 -0
- package/dist/Gap.d.ts +10 -0
- package/dist/Gap.jsx +14 -0
- package/dist/Grid.d.ts +47 -0
- package/dist/Grid.jsx +31 -0
- package/dist/Icon.d.ts +11 -0
- package/dist/Icon.jsx +12 -0
- package/dist/ImagePreview.d.ts +62 -0
- package/dist/ImagePreview.jsx +78 -0
- package/dist/Img.d.ts +28 -0
- package/dist/Img.jsx +59 -0
- package/dist/ImgCropper.d.ts +74 -0
- package/dist/ImgCropper.jsx +114 -0
- package/dist/IndexBar.d.ts +36 -0
- package/dist/IndexBar.jsx +149 -0
- package/dist/Input.d.ts +11 -0
- package/dist/Input.jsx +3 -0
- package/dist/InputNumber.d.ts +32 -0
- package/dist/InputNumber.jsx +165 -0
- package/dist/Keyboard.d.ts +37 -0
- package/dist/Keyboard.jsx +130 -0
- package/dist/Layout.d.ts +31 -0
- package/dist/Layout.jsx +14 -0
- package/dist/Loading.d.ts +18 -0
- package/dist/Loading.jsx +15 -0
- package/dist/Loadmore.d.ts +18 -0
- package/dist/Loadmore.jsx +16 -0
- package/dist/Navbar.d.ts +35 -0
- package/dist/Navbar.jsx +50 -0
- package/dist/NoticeBar.d.ts +30 -0
- package/dist/NoticeBar.jsx +86 -0
- package/dist/Notify.d.ts +34 -0
- package/dist/Notify.jsx +52 -0
- package/dist/NumberStepper.d.ts +11 -0
- package/dist/NumberStepper.jsx +41 -0
- package/dist/Overlay.d.ts +16 -0
- package/dist/Overlay.jsx +12 -0
- package/dist/PagedList.d.ts +13 -0
- package/dist/PagedList.jsx +36 -0
- package/dist/Pagination.d.ts +29 -0
- package/dist/Pagination.jsx +33 -0
- package/dist/PasswordInput.d.ts +16 -0
- package/dist/PasswordInput.jsx +20 -0
- package/dist/Picker.d.ts +61 -0
- package/dist/Picker.jsx +80 -0
- package/dist/PickerView.d.ts +43 -0
- package/dist/PickerView.jsx +142 -0
- package/dist/Popover.d.ts +23 -0
- package/dist/Popover.jsx +35 -0
- package/dist/Popup.d.ts +30 -0
- package/dist/Popup.jsx +32 -0
- package/dist/Progress.d.ts +17 -0
- package/dist/Progress.jsx +45 -0
- package/dist/QrCode.d.ts +46 -0
- package/dist/QrCode.jsx +67 -0
- package/dist/Radio.d.ts +21 -0
- package/dist/Radio.jsx +34 -0
- package/dist/Rate.d.ts +25 -0
- package/dist/Rate.jsx +39 -0
- package/dist/Resize.d.ts +17 -0
- package/dist/Resize.jsx +17 -0
- package/dist/RichText.d.ts +133 -0
- package/dist/RichText.jsx +288 -0
- package/dist/RootPortal.d.ts +11 -0
- package/dist/RootPortal.jsx +19 -0
- package/dist/Search.d.ts +39 -0
- package/dist/Search.jsx +94 -0
- package/dist/Segmented.d.ts +18 -0
- package/dist/Segmented.jsx +35 -0
- package/dist/SelectPicker.d.ts +54 -0
- package/dist/SelectPicker.jsx +136 -0
- package/dist/Sidebar.d.ts +34 -0
- package/dist/Sidebar.jsx +43 -0
- package/dist/Signature.d.ts +46 -0
- package/dist/Signature.jsx +203 -0
- package/dist/Skeleton.d.ts +27 -0
- package/dist/Skeleton.jsx +29 -0
- package/dist/SlideVerify.d.ts +27 -0
- package/dist/SlideVerify.jsx +138 -0
- package/dist/Slider.d.ts +21 -0
- package/dist/Slider.jsx +131 -0
- package/dist/SortButton.d.ts +16 -0
- package/dist/SortButton.jsx +19 -0
- package/dist/Steps.d.ts +23 -0
- package/dist/Steps.jsx +25 -0
- package/dist/Sticky.d.ts +17 -0
- package/dist/Sticky.jsx +69 -0
- package/dist/SwipeAction.d.ts +27 -0
- package/dist/SwipeAction.jsx +187 -0
- package/dist/Swiper.d.ts +54 -0
- package/dist/Swiper.jsx +94 -0
- package/dist/SwiperNav.d.ts +18 -0
- package/dist/SwiperNav.jsx +10 -0
- package/dist/Switch.d.ts +31 -0
- package/dist/Switch.jsx +46 -0
- package/dist/SyncedInput.d.ts +12 -0
- package/dist/SyncedInput.jsx +18 -0
- package/dist/SyncedTextarea.d.ts +11 -0
- package/dist/SyncedTextarea.jsx +18 -0
- package/dist/Tabbar.d.ts +37 -0
- package/dist/Tabbar.jsx +46 -0
- package/dist/Table.d.ts +51 -0
- package/dist/Table.jsx +125 -0
- package/dist/Tabs.d.ts +65 -0
- package/dist/Tabs.jsx +132 -0
- package/dist/Tag.d.ts +33 -0
- package/dist/Tag.jsx +63 -0
- package/dist/Text.d.ts +19 -0
- package/dist/Text.jsx +7 -0
- package/dist/TextField.d.ts +89 -0
- package/dist/TextField.jsx +149 -0
- package/dist/Textarea.d.ts +22 -0
- package/dist/Textarea.jsx +3 -0
- package/dist/Toast.d.ts +36 -0
- package/dist/Toast.jsx +30 -0
- package/dist/Tooltip.d.ts +8 -0
- package/dist/Tooltip.jsx +5 -0
- package/dist/Tour.d.ts +85 -0
- package/dist/Tour.jsx +150 -0
- package/dist/Transition.d.ts +32 -0
- package/dist/Transition.jsx +43 -0
- package/dist/Upload.d.ts +64 -0
- package/dist/Upload.jsx +163 -0
- package/dist/VideoPreview.d.ts +47 -0
- package/dist/VideoPreview.jsx +59 -0
- package/dist/Watermark.d.ts +36 -0
- package/dist/Watermark.jsx +18 -0
- package/dist/action-sheet.css +19 -0
- package/dist/avatar.css +23 -0
- package/dist/avatarModel.d.ts +8 -0
- package/dist/avatarModel.js +17 -0
- package/dist/backtop.css +6 -0
- package/dist/badge.css +15 -0
- package/dist/badgeModel.d.ts +2 -0
- package/dist/badgeModel.js +18 -0
- package/dist/bar-code.css +5 -0
- package/dist/barCodeModel.d.ts +80 -0
- package/dist/barCodeModel.js +99 -0
- package/dist/bubble.css +14 -0
- package/dist/bubblePosition.d.ts +19 -0
- package/dist/bubblePosition.js +41 -0
- package/dist/button.css +56 -0
- package/dist/calendar.css +56 -0
- package/dist/calendarModel.d.ts +62 -0
- package/dist/calendarModel.js +141 -0
- package/dist/card.css +8 -0
- package/dist/cascader.css +16 -0
- package/dist/cascaderModel.d.ts +21 -0
- package/dist/cascaderModel.js +32 -0
- package/dist/cell.css +41 -0
- package/dist/choice.css +27 -0
- package/dist/choice.d.ts +28 -0
- package/dist/choice.jsx +16 -0
- package/dist/circle.css +4 -0
- package/dist/circleModel.d.ts +15 -0
- package/dist/circleModel.js +31 -0
- package/dist/config-provider.css +2 -0
- package/dist/configContext.d.ts +23 -0
- package/dist/configContext.js +24 -0
- package/dist/configTheme.d.ts +3 -0
- package/dist/configTheme.js +22 -0
- package/dist/count-down.css +2 -0
- package/dist/count-to.css +8 -0
- package/dist/countDownModel.d.ts +11 -0
- package/dist/countDownModel.js +7 -0
- package/dist/countToModel.d.ts +3 -0
- package/dist/countToModel.js +3 -0
- package/dist/curtain.css +10 -0
- package/dist/datetime-picker.css +11 -0
- package/dist/datetimePickerModel.d.ts +47 -0
- package/dist/datetimePickerModel.js +128 -0
- package/dist/dialog.css +23 -0
- package/dist/divider.css +14 -0
- package/dist/drop-menu.css +28 -0
- package/dist/empty.css +7 -0
- package/dist/fab.css +23 -0
- package/dist/fabModel.d.ts +26 -0
- package/dist/fabModel.js +16 -0
- package/dist/floating-panel.css +6 -0
- package/dist/floatingPanelModel.d.ts +3 -0
- package/dist/floatingPanelModel.js +10 -0
- package/dist/form.css +10 -0
- package/dist/formContext.d.ts +7 -0
- package/dist/formContext.js +2 -0
- package/dist/formModel.d.ts +38 -0
- package/dist/formModel.js +16 -0
- package/dist/gap.css +1 -0
- package/dist/grid.css +17 -0
- package/dist/icon.css +8 -0
- package/dist/icons/LICENSE.tabler +21 -0
- package/dist/icons/paths.d.ts +309 -0
- package/dist/icons/paths.js +310 -0
- package/dist/icons/render.d.ts +2 -0
- package/dist/icons/render.js +5 -0
- package/dist/image-preview.css +8 -0
- package/dist/img-cropper.css +1 -0
- package/dist/img.css +5 -0
- package/dist/imgCropperModel.d.ts +55 -0
- package/dist/imgCropperModel.js +41 -0
- package/dist/imgModel.d.ts +13 -0
- package/dist/imgModel.js +22 -0
- package/dist/index-bar.css +12 -0
- package/dist/index.d.ts +200 -0
- package/dist/index.js +99 -0
- package/dist/indexBarModel.d.ts +19 -0
- package/dist/indexBarModel.js +37 -0
- package/dist/input-number.css +24 -0
- package/dist/inputNumberModel.d.ts +23 -0
- package/dist/inputNumberModel.js +40 -0
- package/dist/keyboard.css +26 -0
- package/dist/keyboardModel.d.ts +11 -0
- package/dist/keyboardModel.js +34 -0
- package/dist/layout.css +2 -0
- package/dist/legacy/RadioGroup.d.ts +13 -0
- package/dist/legacy/RadioGroup.jsx +13 -0
- package/dist/legacy-controls.css +87 -0
- package/dist/loading.css +31 -0
- package/dist/loadingModel.d.ts +2 -0
- package/dist/loadingModel.js +21 -0
- package/dist/loadmore.css +5 -0
- package/dist/navbar.css +16 -0
- package/dist/notice-bar.css +19 -0
- package/dist/notify.css +14 -0
- package/dist/overlay.css +2 -0
- package/dist/pagination.css +12 -0
- package/dist/paginationModel.d.ts +6 -0
- package/dist/paginationModel.js +7 -0
- package/dist/password-input.css +14 -0
- package/dist/passwordInputModel.d.ts +6 -0
- package/dist/passwordInputModel.js +11 -0
- package/dist/picker.css +42 -0
- package/dist/pickerModel.d.ts +32 -0
- package/dist/pickerModel.js +49 -0
- package/dist/popover.css +5 -0
- package/dist/popup.css +17 -0
- package/dist/progress.css +16 -0
- package/dist/progressModel.d.ts +12 -0
- package/dist/progressModel.js +19 -0
- package/dist/qr-code.css +4 -0
- package/dist/qrCodeModel.d.ts +36 -0
- package/dist/qrCodeModel.js +61 -0
- package/dist/rate.css +20 -0
- package/dist/rateModel.d.ts +4 -0
- package/dist/rateModel.js +38 -0
- package/dist/resize.css +2 -0
- package/dist/rich-text.css +19 -0
- package/dist/richTextMedia.d.ts +28 -0
- package/dist/richTextMedia.js +3 -0
- package/dist/richTextModel.d.ts +52 -0
- package/dist/richTextModel.js +195 -0
- package/dist/root-portal.css +1 -0
- package/dist/router/RouterView.d.ts +21 -0
- package/dist/router/RouterView.jsx +120 -0
- package/dist/router/core.d.ts +85 -0
- package/dist/router/core.js +255 -0
- package/dist/router/hooks.d.ts +17 -0
- package/dist/router/hooks.jsx +71 -0
- package/dist/router/index.d.ts +5 -0
- package/dist/router/index.js +3 -0
- package/dist/router/location.d.ts +8 -0
- package/dist/router/location.js +46 -0
- package/dist/router/router.css +7 -0
- package/dist/router/runtime.d.ts +1 -0
- package/dist/router/runtime.js +25 -0
- package/dist/search.css +23 -0
- package/dist/segmented.css +19 -0
- package/dist/segmentedModel.d.ts +10 -0
- package/dist/segmentedModel.js +8 -0
- package/dist/sidebar.css +18 -0
- package/dist/sidebarModel.d.ts +8 -0
- package/dist/sidebarModel.js +27 -0
- package/dist/signature.css +5 -0
- package/dist/signatureModel.d.ts +23 -0
- package/dist/signatureModel.js +80 -0
- package/dist/skeleton.css +16 -0
- package/dist/slide-verify.css +7 -0
- package/dist/slider.css +49 -0
- package/dist/sliderModel.d.ts +10 -0
- package/dist/sliderModel.js +27 -0
- package/dist/sort-button.css +12 -0
- package/dist/steps.css +35 -0
- package/dist/sticky.css +7 -0
- package/dist/styles.css +136 -0
- package/dist/styles.d.ts +1 -0
- package/dist/swipe-action.css +6 -0
- package/dist/swiper.css +27 -0
- package/dist/swiperAnimation.d.ts +3 -0
- package/dist/swiperAnimation.js +6 -0
- package/dist/swiperModel.d.ts +2 -0
- package/dist/swiperModel.js +3 -0
- package/dist/switch.css +12 -0
- package/dist/tabbar.css +17 -0
- package/dist/tabbarModel.d.ts +8 -0
- package/dist/tabbarModel.js +27 -0
- package/dist/table.css +21 -0
- package/dist/tableModel.d.ts +10 -0
- package/dist/tableModel.js +17 -0
- package/dist/tabs.css +31 -0
- package/dist/tabsModel.d.ts +7 -0
- package/dist/tabsModel.js +14 -0
- package/dist/tag.css +66 -0
- package/dist/text-field.css +15 -0
- package/dist/text.css +7 -0
- package/dist/textModel.d.ts +3 -0
- package/dist/textModel.js +24 -0
- package/dist/toast.css +13 -0
- package/dist/tokens.d.ts +34 -0
- package/dist/tokens.js +10 -0
- package/dist/tour.css +8 -0
- package/dist/transition.css +12 -0
- package/dist/upload.css +11 -0
- package/dist/useCountDown.d.ts +14 -0
- package/dist/useCountDown.js +73 -0
- package/dist/useDialog.d.ts +9 -0
- package/dist/useDialog.js +33 -0
- package/dist/useImagePreview.d.ts +7 -0
- package/dist/useImagePreview.js +17 -0
- package/dist/useNotify.d.ts +9 -0
- package/dist/useNotify.js +26 -0
- package/dist/usePressState.d.ts +6 -0
- package/dist/usePressState.js +17 -0
- package/dist/useToast.d.ts +11 -0
- package/dist/useToast.js +23 -0
- package/dist/useVideoPreview.d.ts +7 -0
- package/dist/useVideoPreview.js +17 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +4 -0
- package/dist/video-preview.css +7 -0
- package/dist/watermark.css +6 -0
- package/dist/web/imgCropperElement.d.ts +2 -0
- package/dist/web/imgCropperElement.js +309 -0
- package/dist/web/index.d.ts +6 -0
- package/dist/web/index.js +6 -0
- package/dist/web/qrCodeExportElement.d.ts +4 -0
- package/dist/web/qrCodeExportElement.js +70 -0
- package/dist/web/richTextMediaElement.d.ts +2 -0
- package/dist/web/richTextMediaElement.js +276 -0
- 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;
|
package/dist/CountTo.jsx
ADDED
|
@@ -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;
|
package/dist/Curtain.jsx
ADDED
|
@@ -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
|
+
});
|
package/dist/Dialog.d.ts
ADDED
|
@@ -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;
|
package/dist/Dialog.jsx
ADDED
|
@@ -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;
|