@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.
- package/CHANGELOG.md +67 -0
- package/LICENSE +21 -0
- package/README.md +179 -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/brand/logo.svg +8 -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
package/dist/Form.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
3
|
+
import type { FormModel, FormSchema, FormValidateResult, FormValidateTrigger } from './formModel.js';
|
|
4
|
+
export type FormRef = {
|
|
5
|
+
validate: (prop?: string | readonly string[]) => Promise<FormValidateResult>;
|
|
6
|
+
reset: (prop?: string | readonly string[]) => void;
|
|
7
|
+
};
|
|
8
|
+
type FormLayout = {
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
border?: boolean;
|
|
11
|
+
center?: boolean;
|
|
12
|
+
size?: 'medium' | 'large';
|
|
13
|
+
titleWidth?: number | string;
|
|
14
|
+
layout?: 'horizontal' | 'vertical';
|
|
15
|
+
valueAlign?: 'left' | 'center' | 'right';
|
|
16
|
+
asteriskPosition?: 'start' | 'end';
|
|
17
|
+
hideAsterisk?: boolean;
|
|
18
|
+
ellipsis?: boolean;
|
|
19
|
+
};
|
|
20
|
+
export type FormProps = FormLayout & {
|
|
21
|
+
model: FormModel;
|
|
22
|
+
schema?: FormSchema;
|
|
23
|
+
validateTrigger?: FormValidateTrigger | readonly FormValidateTrigger[];
|
|
24
|
+
resetOnChange?: boolean;
|
|
25
|
+
errorType?: 'message' | 'toast' | 'none';
|
|
26
|
+
onValidate?: (result: FormValidateResult) => void;
|
|
27
|
+
onValidateError?: (error: unknown) => void;
|
|
28
|
+
className?: string;
|
|
29
|
+
style?: CSSProperties;
|
|
30
|
+
children?: ReactNode;
|
|
31
|
+
};
|
|
32
|
+
export declare const Form: (props: FormLayout & {
|
|
33
|
+
model: FormModel;
|
|
34
|
+
schema?: FormSchema;
|
|
35
|
+
validateTrigger?: FormValidateTrigger | readonly FormValidateTrigger[];
|
|
36
|
+
resetOnChange?: boolean;
|
|
37
|
+
errorType?: "message" | "toast" | "none";
|
|
38
|
+
onValidate?: (result: FormValidateResult) => void;
|
|
39
|
+
onValidateError?: (error: unknown) => void;
|
|
40
|
+
className?: string;
|
|
41
|
+
style?: CSSProperties;
|
|
42
|
+
children?: ReactNode;
|
|
43
|
+
} & import("react").RefAttributes<FormRef>) => React.ReactElement | null;
|
|
44
|
+
export type FormItemProps = FormLayout & {
|
|
45
|
+
prop?: string;
|
|
46
|
+
title?: ReactNode;
|
|
47
|
+
value?: string | number;
|
|
48
|
+
placeholder?: string;
|
|
49
|
+
prefixIcon?: string;
|
|
50
|
+
iconSize?: number;
|
|
51
|
+
icon?: ReactNode;
|
|
52
|
+
label?: string;
|
|
53
|
+
required?: boolean;
|
|
54
|
+
validateTrigger?: FormProps['validateTrigger'];
|
|
55
|
+
clickable?: boolean;
|
|
56
|
+
isLink?: boolean;
|
|
57
|
+
onTap?: () => void;
|
|
58
|
+
className?: string;
|
|
59
|
+
style?: CSSProperties;
|
|
60
|
+
children?: ReactNode;
|
|
61
|
+
};
|
|
62
|
+
export declare function FormItem({ prop, title, value, placeholder, prefixIcon, iconSize, icon, label, required, validateTrigger, clickable, isLink, onTap, className, style, children, ...layout }: FormItemProps): import("@lynx-js/react").JSX.Element;
|
|
63
|
+
export {};
|
package/dist/Form.jsx
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { createContext, forwardRef, useContext, useEffect, useImperativeHandle, useRef, useState } from '@lynx-js/react';
|
|
2
|
+
import { Cell } from "./Cell.jsx";
|
|
3
|
+
import { Icon } from "./Icon.jsx";
|
|
4
|
+
import { Toast } from "./Toast.jsx";
|
|
5
|
+
import { useToast } from './useToast.js';
|
|
6
|
+
import { FormFieldContext } from './formContext.js';
|
|
7
|
+
import { copyFormValue, equalFormValue, formPath, formValue, includesFormPath } from './formModel.js';
|
|
8
|
+
const FormContext = createContext(undefined);
|
|
9
|
+
const triggers = (value, target) => Array.isArray(value) ? value.includes(target) : value === target;
|
|
10
|
+
export const Form = forwardRef(function Form(props, ref) {
|
|
11
|
+
const { model, schema, resetOnChange = true, errorType = 'message', className = '', style, children } = props;
|
|
12
|
+
const [errors, setErrors] = useState([]);
|
|
13
|
+
const fields = useRef(new Map()), tickets = useRef(new Map()), mounted = useRef(true), previous = useRef(copyFormValue(model)), latest = useRef(props);
|
|
14
|
+
latest.current = props;
|
|
15
|
+
const toast = useToast();
|
|
16
|
+
const invalidate = (path) => {
|
|
17
|
+
'background only';
|
|
18
|
+
tickets.current.set(path, (tickets.current.get(path) ?? 0) + 1);
|
|
19
|
+
};
|
|
20
|
+
const selected = (prop) => {
|
|
21
|
+
'background only';
|
|
22
|
+
const paths = prop === undefined ? undefined : (typeof prop === 'string' ? [prop] : prop).map(formPath);
|
|
23
|
+
return [...fields.current.keys()].filter(key => !paths || paths.some(path => includesFormPath(path, key) || includesFormPath(key, path)));
|
|
24
|
+
};
|
|
25
|
+
const reset = prop => {
|
|
26
|
+
'background only';
|
|
27
|
+
const keys = selected(prop);
|
|
28
|
+
keys.forEach(invalidate);
|
|
29
|
+
setErrors(old => old.filter(error => !keys.includes(error.prop)));
|
|
30
|
+
};
|
|
31
|
+
const validate = async (prop) => {
|
|
32
|
+
'background only';
|
|
33
|
+
const keys = selected(prop), snapshot = copyFormValue(latest.current.model), currentSchema = latest.current.schema;
|
|
34
|
+
const versions = new Map(keys.map(key => { invalidate(key); return [key, tickets.current.get(key)]; }));
|
|
35
|
+
const issues = currentSchema ? await currentSchema.validate(snapshot) : [];
|
|
36
|
+
// A cross-field rule can depend on any model field. Never apply an old snapshot.
|
|
37
|
+
const stale = !mounted.current || currentSchema !== latest.current.schema || !equalFormValue(snapshot, latest.current.model) || keys.some(key => !fields.current.has(key) || versions.get(key) !== tickets.current.get(key));
|
|
38
|
+
if (stale)
|
|
39
|
+
return { valid: false, errors: [], outOfDate: true };
|
|
40
|
+
const next = keys.flatMap(key => { const issue = issues.find(issue => { const path = formPath(issue.path); return !path || includesFormPath(key, path); }); return issue ? [{ prop: key, message: issue.message }] : []; });
|
|
41
|
+
setErrors(old => [...old.filter(error => !keys.includes(error.prop)), ...next]);
|
|
42
|
+
if (latest.current.errorType === 'toast' && next.length)
|
|
43
|
+
toast.show(next[0].message);
|
|
44
|
+
const result = { valid: next.length === 0, errors: next };
|
|
45
|
+
latest.current.onValidate?.(result);
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
48
|
+
const validateRef = useRef(validate);
|
|
49
|
+
validateRef.current = validate;
|
|
50
|
+
useImperativeHandle(ref, () => ({ validate, reset }), []);
|
|
51
|
+
useEffect(() => { mounted.current = true; return () => { mounted.current = false; tickets.current.clear(); }; }, []);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
const changed = [...fields.current.keys()].filter(key => !equalFormValue(formValue(previous.current, key), formValue(model, key)));
|
|
54
|
+
previous.current = copyFormValue(model);
|
|
55
|
+
if (!changed.length)
|
|
56
|
+
return;
|
|
57
|
+
changed.forEach(invalidate);
|
|
58
|
+
if (resetOnChange)
|
|
59
|
+
setErrors(old => old.filter(error => !changed.includes(error.prop)));
|
|
60
|
+
const automatic = changed.filter(key => triggers(fields.current.get(key)?.trigger ?? props.validateTrigger ?? 'submit', 'change'));
|
|
61
|
+
if (automatic.length)
|
|
62
|
+
void validateRef.current(automatic).catch(error => latest.current.onValidateError?.(error));
|
|
63
|
+
});
|
|
64
|
+
const register = (path, field) => {
|
|
65
|
+
'background only';
|
|
66
|
+
if (fields.current.has(path))
|
|
67
|
+
throw new Error(`Duplicate FormItem prop: ${path}`);
|
|
68
|
+
fields.current.set(path, field);
|
|
69
|
+
return () => {
|
|
70
|
+
'background only';
|
|
71
|
+
if (fields.current.get(path)?.token !== field.token)
|
|
72
|
+
return;
|
|
73
|
+
fields.current.delete(path);
|
|
74
|
+
invalidate(path);
|
|
75
|
+
setErrors(old => fields.current.has(path) ? old : old.filter(error => error.prop !== path));
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
const blur = (path) => {
|
|
79
|
+
'background only';
|
|
80
|
+
if (triggers(fields.current.get(path)?.trigger ?? latest.current.validateTrigger ?? 'submit', 'blur'))
|
|
81
|
+
void validateRef.current(path).catch(error => latest.current.onValidateError?.(error));
|
|
82
|
+
};
|
|
83
|
+
return <FormContext.Provider value={{ props, errors: errorType === 'message' ? errors : [], register, blur }}><view className={`ui-form ${className}`} style={style}>{children}<Toast {...toast.props}/></view></FormContext.Provider>;
|
|
84
|
+
});
|
|
85
|
+
export function FormItem({ prop, title, value, placeholder, prefixIcon, iconSize = 16, icon, label, required, validateTrigger, clickable, isLink, onTap, className = '', style, children, ...layout }) {
|
|
86
|
+
const form = useContext(FormContext), path = prop === undefined ? undefined : formPath(prop), stable = useRef({});
|
|
87
|
+
const settings = { ...form?.props, ...Object.fromEntries(Object.entries(layout).filter(([, value]) => value !== undefined)) };
|
|
88
|
+
const disabled = settings.disabled ?? false;
|
|
89
|
+
const formRef = useRef(form);
|
|
90
|
+
formRef.current = form;
|
|
91
|
+
useEffect(() => { if (path !== undefined && formRef.current)
|
|
92
|
+
return formRef.current.register(path, { trigger: validateTrigger, token: stable.current }); }, [path, validateTrigger]);
|
|
93
|
+
const error = form?.errors.find(error => error.prop === path)?.message;
|
|
94
|
+
const width = settings.titleWidth ?? 98;
|
|
95
|
+
return <FormFieldContext.Provider value={{ disabled, compact: true, error: !!error, onBlur: () => {
|
|
96
|
+
'background only';
|
|
97
|
+
if (path !== undefined)
|
|
98
|
+
formRef.current?.blur(path);
|
|
99
|
+
} }}><view className={`ui-form-item ${disabled ? 'ui-form-item-disabled' : ''} ${className}`} style={style}>
|
|
100
|
+
<Cell title={title} description={label} value={value === undefined ? undefined : String(value)} placeholder={placeholder} icon={icon ?? (prefixIcon ? <Icon name={prefixIcon} size={iconSize}/> : undefined)} required={!settings.hideAsterisk && (required ?? (path !== undefined ? form?.props.schema?.isRequired?.(path) : false) ?? false)} markerSide={settings.asteriskPosition === 'end' ? 'after' : 'before'} titleWidth={typeof width === 'number' ? `${width}px` : width} border={settings.border ?? false} center={settings.center} size={settings.size} vertical={settings.layout === 'vertical'} valueAlign={settings.valueAlign ?? 'left'} ellipsis={settings.ellipsis} clickable={!disabled && clickable} arrow={isLink} onTap={() => {
|
|
101
|
+
'background only';
|
|
102
|
+
if (!disabled)
|
|
103
|
+
onTap?.();
|
|
104
|
+
}}>
|
|
105
|
+
<view className="ui-form-item-content">{children ?? <text className={(value === undefined || value === '') && placeholder ? 'ui-form-item-placeholder' : 'ui-form-item-value'}>{value === undefined || value === '' ? placeholder ?? '' : value}</text>}{error ? <text className="ui-form-item-error">{error}</text> : null}</view>
|
|
106
|
+
</Cell>
|
|
107
|
+
</view></FormFieldContext.Provider>;
|
|
108
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { JSX } from '@lynx-js/react';
|
|
2
|
+
import type { RadioOption } from "./legacy/RadioGroup.jsx";
|
|
3
|
+
type CommonProps = {
|
|
4
|
+
label: string;
|
|
5
|
+
required?: boolean;
|
|
6
|
+
last?: boolean;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
error?: string;
|
|
9
|
+
};
|
|
10
|
+
type FormInputRowProps = CommonProps & {
|
|
11
|
+
value: string;
|
|
12
|
+
onInput: (value: string) => void;
|
|
13
|
+
maxlength?: number;
|
|
14
|
+
placeholder?: string;
|
|
15
|
+
clearable?: boolean;
|
|
16
|
+
onBlur?: () => void;
|
|
17
|
+
};
|
|
18
|
+
type FormSelectRowProps = CommonProps & {
|
|
19
|
+
value?: string;
|
|
20
|
+
placeholder: string;
|
|
21
|
+
onTap: () => void;
|
|
22
|
+
onClear: () => void;
|
|
23
|
+
clearable?: boolean;
|
|
24
|
+
};
|
|
25
|
+
type FormTextareaRowProps = CommonProps & {
|
|
26
|
+
value: string;
|
|
27
|
+
onInput: (value: string) => void;
|
|
28
|
+
onBlur?: () => void;
|
|
29
|
+
maxlength?: number;
|
|
30
|
+
maxlines?: number;
|
|
31
|
+
placeholder?: string;
|
|
32
|
+
showWordLimit?: boolean;
|
|
33
|
+
};
|
|
34
|
+
type FormRadioRowProps = CommonProps & {
|
|
35
|
+
value: string;
|
|
36
|
+
options: RadioOption[];
|
|
37
|
+
onChange: (value: string) => void;
|
|
38
|
+
};
|
|
39
|
+
type FormNumberRowProps = CommonProps & {
|
|
40
|
+
value: string;
|
|
41
|
+
onChange: (value: string) => void;
|
|
42
|
+
onBlur?: () => void;
|
|
43
|
+
min?: number;
|
|
44
|
+
max?: number;
|
|
45
|
+
step?: number;
|
|
46
|
+
};
|
|
47
|
+
type FormFieldRowProps = CommonProps & {
|
|
48
|
+
children: JSX.Element;
|
|
49
|
+
};
|
|
50
|
+
export declare function FormFieldRow({ label, required, disabled, last, error, children }: FormFieldRowProps): JSX.Element;
|
|
51
|
+
export declare function FormInputRow({ label, value, onInput, onBlur, error, required, disabled, last, maxlength, placeholder, clearable }: FormInputRowProps): JSX.Element;
|
|
52
|
+
export declare function FormSelectRow({ label, value, placeholder, onTap, onClear, error, required, disabled, last, clearable }: FormSelectRowProps): JSX.Element;
|
|
53
|
+
export declare function FormRadioRow({ label, value, options, onChange, error, required, disabled, last }: FormRadioRowProps): JSX.Element;
|
|
54
|
+
export declare function FormNumberRow({ label, value, onChange, onBlur, min, max, step, error, required, disabled, last }: FormNumberRowProps): JSX.Element;
|
|
55
|
+
export declare function FormTextareaRow({ label, value, onInput, onBlur, error, required, disabled, last, maxlength, maxlines, placeholder, showWordLimit }: FormTextareaRowProps): JSX.Element;
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { NumberStepper } from "./NumberStepper.jsx";
|
|
2
|
+
import { RadioGroup } from "./legacy/RadioGroup.jsx";
|
|
3
|
+
import { SyncedInput } from "./SyncedInput.jsx";
|
|
4
|
+
import { SyncedTextarea } from "./SyncedTextarea.jsx";
|
|
5
|
+
function FieldLabel({ label, required }) {
|
|
6
|
+
return <view className="form-field-label">{required ? <text className="form-field-required">*</text> : null}<text>{label}</text></view>;
|
|
7
|
+
}
|
|
8
|
+
export function FormFieldRow({ label, required = false, disabled = false, last = false, error, children }) {
|
|
9
|
+
return <view className={`form-field-row ${last ? 'form-field-row-last' : ''} ${disabled ? 'form-field-disabled' : ''} ${error ? 'form-field-row-error' : ''}`}>
|
|
10
|
+
<FieldLabel label={label} required={required}/>
|
|
11
|
+
<view className="form-field-body">
|
|
12
|
+
{children}
|
|
13
|
+
{error ? <text className="form-field-error">{error}</text> : null}
|
|
14
|
+
</view>
|
|
15
|
+
<view className="form-field-divider"/>
|
|
16
|
+
</view>;
|
|
17
|
+
}
|
|
18
|
+
function ClearButton({ onClear }) {
|
|
19
|
+
return <view className="form-field-clear" bindtap={onClear}><text>×</text></view>;
|
|
20
|
+
}
|
|
21
|
+
export function FormInputRow({ label, value, onInput, onBlur, error, required = false, disabled = false, last = false, maxlength, placeholder = '请输入', clearable = true }) {
|
|
22
|
+
return <FormFieldRow label={label} required={required} disabled={disabled} last={last} error={error}>
|
|
23
|
+
<view className="form-field-control">
|
|
24
|
+
<SyncedInput className="form-field-input" value={value} maxlength={maxlength} placeholder={placeholder} onInput={onInput} onBlur={onBlur}/>
|
|
25
|
+
{clearable && value ? <ClearButton onClear={() => onInput('')}/> : null}
|
|
26
|
+
</view>
|
|
27
|
+
</FormFieldRow>;
|
|
28
|
+
}
|
|
29
|
+
export function FormSelectRow({ label, value, placeholder, onTap, onClear, error, required = false, disabled = false, last = false, clearable = true }) {
|
|
30
|
+
return <FormFieldRow label={label} required={required} disabled={disabled} last={last} error={error}>
|
|
31
|
+
<view className="form-field-control form-field-select-control">
|
|
32
|
+
<view className="form-field-select-value" bindtap={() => { if (!disabled)
|
|
33
|
+
onTap(); }}>
|
|
34
|
+
<text className={value ? 'form-field-value' : 'form-field-placeholder'}>{value || placeholder}</text>
|
|
35
|
+
</view>
|
|
36
|
+
{clearable && value && !disabled ? <ClearButton onClear={onClear}/> : null}
|
|
37
|
+
<view className="form-field-chevron" bindtap={() => { if (!disabled)
|
|
38
|
+
onTap(); }}><text>›</text></view>
|
|
39
|
+
</view>
|
|
40
|
+
</FormFieldRow>;
|
|
41
|
+
}
|
|
42
|
+
export function FormRadioRow({ label, value, options, onChange, error, required = false, disabled = false, last = false }) {
|
|
43
|
+
return <FormFieldRow label={label} required={required} disabled={disabled} last={last} error={error}>
|
|
44
|
+
<RadioGroup value={value} options={options} onChange={onChange} disabled={disabled}/>
|
|
45
|
+
</FormFieldRow>;
|
|
46
|
+
}
|
|
47
|
+
export function FormNumberRow({ label, value, onChange, onBlur, min, max, step, error, required = false, disabled = false, last = false }) {
|
|
48
|
+
return <FormFieldRow label={label} required={required} disabled={disabled} last={last} error={error}>
|
|
49
|
+
<NumberStepper value={value} onChange={onChange} onBlur={onBlur} min={min} max={max} step={step} disabled={disabled}/>
|
|
50
|
+
</FormFieldRow>;
|
|
51
|
+
}
|
|
52
|
+
export function FormTextareaRow({ label, value, onInput, onBlur, error, required = false, disabled = false, last = false, maxlength = 2000, maxlines = 6, placeholder = '请输入', showWordLimit = true }) {
|
|
53
|
+
return <view className={`form-textarea-row ${last ? 'form-field-row-last' : ''} ${disabled ? 'form-field-disabled' : ''} ${error ? 'form-field-row-error' : ''}`}>
|
|
54
|
+
<FieldLabel label={label} required={required}/>
|
|
55
|
+
<view className="form-textarea-box">
|
|
56
|
+
<SyncedTextarea className="form-textarea-input" value={value} maxlength={maxlength} maxlines={maxlines} placeholder={placeholder} onInput={next => { if (!disabled)
|
|
57
|
+
onInput(next); }} onBlur={onBlur}/>
|
|
58
|
+
{showWordLimit ? <text className="form-textarea-count">{value.length} / {maxlength}</text> : null}
|
|
59
|
+
</view>
|
|
60
|
+
{error ? <text className="form-textarea-error">{error}</text> : null}
|
|
61
|
+
<view className="form-field-divider"/>
|
|
62
|
+
</view>;
|
|
63
|
+
}
|
package/dist/Gap.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
2
|
+
export type GapProps = {
|
|
3
|
+
height?: number | string;
|
|
4
|
+
bgColor?: string;
|
|
5
|
+
safeAreaBottom?: boolean;
|
|
6
|
+
bottomSafeAreaHeight?: number;
|
|
7
|
+
className?: string;
|
|
8
|
+
style?: CSSProperties;
|
|
9
|
+
};
|
|
10
|
+
export declare function Gap({ height, bgColor, safeAreaBottom, bottomSafeAreaHeight, className, style }: GapProps): import("@lynx-js/react").JSX.Element;
|
package/dist/Gap.jsx
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Keep rpx examples portable: 750 design units equal the viewport width. */
|
|
2
|
+
function heightValue(value) {
|
|
3
|
+
if (typeof value === 'number')
|
|
4
|
+
return `${Number.isFinite(value) ? Math.max(0, value) : 14}px`;
|
|
5
|
+
const input = value.trim();
|
|
6
|
+
if (/^-?\d+(?:\.\d+)?$/.test(input))
|
|
7
|
+
return `${Math.max(0, Number(input))}px`;
|
|
8
|
+
const rpx = /^(-?\d+(?:\.\d+)?)rpx$/.exec(input);
|
|
9
|
+
return rpx ? `${Math.max(0, Number(rpx[1])) / 7.5}vw` : input || '14px';
|
|
10
|
+
}
|
|
11
|
+
export function Gap({ height = 14, bgColor, safeAreaBottom = false, bottomSafeAreaHeight = 0, className = '', style }) {
|
|
12
|
+
const safe = Number.isFinite(bottomSafeAreaHeight) ? Math.max(0, bottomSafeAreaHeight) : 0;
|
|
13
|
+
return <view className={`ui-gap ${safeAreaBottom ? 'ui-gap-safe' : ''} ${className}`} style={{ height: heightValue(height), backgroundColor: bgColor, ...(safeAreaBottom ? { paddingBottom: `${safe}px` } : {}), ...style }}/>;
|
|
14
|
+
}
|
package/dist/Grid.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { CSSProperties, TouchEvent } from '@lynx-js/types';
|
|
3
|
+
import type { BadgeProps } from "./Badge.jsx";
|
|
4
|
+
export type GridNavigation = (url: string, options: {
|
|
5
|
+
replace: boolean;
|
|
6
|
+
}) => void;
|
|
7
|
+
export type GridProps = {
|
|
8
|
+
column?: number;
|
|
9
|
+
border?: boolean;
|
|
10
|
+
gutter?: number;
|
|
11
|
+
square?: boolean;
|
|
12
|
+
clickable?: boolean;
|
|
13
|
+
bgColor?: string;
|
|
14
|
+
hoverClass?: string;
|
|
15
|
+
center?: boolean;
|
|
16
|
+
direction?: 'vertical' | 'horizontal';
|
|
17
|
+
reverse?: boolean;
|
|
18
|
+
iconSize?: number;
|
|
19
|
+
onNavigate?: GridNavigation;
|
|
20
|
+
children?: ReactNode;
|
|
21
|
+
className?: string;
|
|
22
|
+
style?: CSSProperties;
|
|
23
|
+
};
|
|
24
|
+
export type GridItemProps = {
|
|
25
|
+
text?: ReactNode;
|
|
26
|
+
icon?: string;
|
|
27
|
+
iconColor?: string;
|
|
28
|
+
iconSize?: number;
|
|
29
|
+
renderIcon?: ReactNode;
|
|
30
|
+
children?: ReactNode;
|
|
31
|
+
isDot?: boolean;
|
|
32
|
+
value?: string | number;
|
|
33
|
+
max?: number;
|
|
34
|
+
type?: BadgeProps['type'];
|
|
35
|
+
badgeProps?: BadgeProps;
|
|
36
|
+
ellipsis?: boolean;
|
|
37
|
+
url?: string;
|
|
38
|
+
linkType?: 'push' | 'replace';
|
|
39
|
+
onNavigate?: GridNavigation;
|
|
40
|
+
onItemClick?: (event: TouchEvent) => void;
|
|
41
|
+
className?: string;
|
|
42
|
+
textClassName?: string;
|
|
43
|
+
iconClassName?: string;
|
|
44
|
+
style?: CSSProperties;
|
|
45
|
+
};
|
|
46
|
+
export declare function Grid({ column, border, gutter, square, clickable, bgColor, hoverClass, center, direction, reverse, iconSize, onNavigate, children, className, style }: GridProps): import("@lynx-js/react").JSX.Element;
|
|
47
|
+
export declare function GridItem({ text, icon, iconColor, iconSize, renderIcon, children, isDot, value, max, type, badgeProps, ellipsis, url, linkType, onNavigate, onItemClick, className, textClassName, iconClassName, style }: GridItemProps): import("@lynx-js/react").JSX.Element;
|
package/dist/Grid.jsx
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Children, createContext, useContext, useState } from '@lynx-js/react';
|
|
2
|
+
import { Badge } from "./Badge.jsx";
|
|
3
|
+
import { Icon } from "./Icon.jsx";
|
|
4
|
+
import { useConfigProvider } from './configContext.js';
|
|
5
|
+
import { usePressState } from './usePressState.js';
|
|
6
|
+
const GridContext = createContext(undefined);
|
|
7
|
+
export function Grid({ column, border = false, gutter = 0, square = false, clickable = false, bgColor, hoverClass = '', center = true, direction = 'vertical', reverse = false, iconSize = 32, onNavigate, children, className = '', style }) {
|
|
8
|
+
const items = Children.toArray(children).filter(item => item !== null && item !== undefined && typeof item !== 'boolean'), count = items.length;
|
|
9
|
+
const columns = column !== undefined && Number.isFinite(column) && column > 0 ? Math.max(1, Math.floor(column)) : Math.max(1, count), spacing = Number.isFinite(gutter) ? Math.max(0, gutter) : 0, [width, setWidth] = useState(0);
|
|
10
|
+
const shared = { columns, count, spacing, column, border, square, clickable, bgColor, hoverClass, center, direction, reverse, iconSize, onNavigate, cellSize: Math.max(0, width - spacing) / columns };
|
|
11
|
+
return <view className={`ui-grid ${className}`} style={{ paddingLeft: `${spacing}px`, marginBottom: square && spacing ? `${-spacing}px` : undefined, ...style }} bindlayoutchange={event => setWidth(event.detail.width)}>{items.map((item, index) => <GridContext.Provider key={typeof item === 'object' && item !== null && 'key' in item && item.key !== null && item.key !== undefined ? String(item.key) : index} value={{ ...shared, index }}>{item}</GridContext.Provider>)}</view>;
|
|
12
|
+
}
|
|
13
|
+
export function GridItem({ text, icon, iconColor, iconSize, renderIcon, children, isDot, value, max, type, badgeProps, ellipsis = false, url, linkType = 'push', onNavigate, onItemClick, className = '', textClassName = '', iconClassName = '', style }) {
|
|
14
|
+
const grid = useContext(GridContext), config = useConfigProvider(), press = usePressState(grid?.clickable ?? false), spacing = grid?.spacing ?? 0, columns = grid?.columns ?? 1, index = grid?.index ?? 0, hasIcon = renderIcon !== undefined || !!icon;
|
|
15
|
+
const badge = { max: 99, ...badgeProps, ...(value !== undefined ? { value } : {}), ...(isDot !== undefined ? { isDot } : {}), ...(max !== undefined ? { max } : {}), ...(type !== undefined ? { type } : {}) };
|
|
16
|
+
const tap = (event) => {
|
|
17
|
+
'background only';
|
|
18
|
+
if (grid && !grid.clickable)
|
|
19
|
+
return;
|
|
20
|
+
onItemClick?.(event);
|
|
21
|
+
if (url)
|
|
22
|
+
(onNavigate ?? grid?.onNavigate)?.(url, { replace: linkType === 'replace' });
|
|
23
|
+
};
|
|
24
|
+
const horizontal = grid?.direction === 'horizontal', reverse = grid?.reverse;
|
|
25
|
+
return <view className={`ui-grid-item ${grid?.square ? 'ui-grid-item-square' : ''} ${className}`} style={{ width: `${100 / columns}%`, flexBasis: `${100 / columns}%`, paddingRight: `${spacing}px`, ...(grid?.square ? { height: `${grid.cellSize}px` } : index >= columns ? { marginTop: `${spacing}px` } : {}), ...style }} bindtap={tap} accessibility-element={!!grid?.clickable} accessibility-traits={grid?.clickable ? 'button' : undefined} accessibility-label={typeof text === 'string' ? text : undefined}>
|
|
26
|
+
<view className={`ui-grid-item-content ${horizontal ? 'ui-grid-horizontal' : ''} ${reverse ? 'ui-grid-reverse' : ''} ${grid?.center === false ? '' : 'ui-grid-center'} ${press.pressed ? `ui-grid-item-pressed ${grid?.hoverClass ?? ''}` : ''}`} style={{ backgroundColor: grid?.bgColor, ...(grid?.square && spacing ? { marginBottom: `${spacing}px` } : {}), ...(grid?.border && spacing ? { borderWidth: '.5px', borderStyle: 'solid', borderColor: 'var(--cso-ui-line)' } : {}) }} bindtouchstart={press.start} bindtouchend={press.end} bindtouchcancel={press.end} bindmousedown={press.start} bindmouseup={press.end} bindmouseleave={press.end}>
|
|
27
|
+
{children ?? <>{hasIcon ? <view className={`ui-grid-item-icon ${iconClassName}`}><Badge {...badge}>{renderIcon ?? <Icon name={icon} size={iconSize ?? grid?.iconSize ?? 32} color={iconColor ?? (config.theme === 'dark' ? '#e5e6eb' : '#4e5369')}/>}</Badge></view> : null}{text !== undefined ? <view className={`ui-grid-item-text ${hasIcon ? 'ui-grid-item-text-spaced' : ''} ${textClassName}`}><>{typeof text === 'string' || typeof text === 'number' ? <text className="ui-grid-item-label" text-maxline={ellipsis ? '1' : undefined} text-overflow={ellipsis ? 'ellipsis' : undefined}>{text}</text> : text}</></view> : null}</>}
|
|
28
|
+
{grid?.border && !spacing ? <>{index >= columns ? <view className="ui-grid-line-top"/> : null}{index % columns !== columns - 1 && index !== grid.count - 1 ? <view className="ui-grid-line-right"/> : null}</> : null}
|
|
29
|
+
</view>
|
|
30
|
+
</view>;
|
|
31
|
+
}
|
package/dist/Icon.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IconName } from './icons/paths.js';
|
|
2
|
+
export type IconProps = {
|
|
3
|
+
name: IconName | (string & {});
|
|
4
|
+
color?: string;
|
|
5
|
+
size?: number;
|
|
6
|
+
className?: string;
|
|
7
|
+
accessibilityLabel?: string;
|
|
8
|
+
onTap?: () => void;
|
|
9
|
+
};
|
|
10
|
+
/** Bundled SVG glyphs, rendered without icon fonts or pseudo-elements. */
|
|
11
|
+
export declare function Icon({ name, color, size, className, accessibilityLabel, onTap }: IconProps): import("@lynx-js/react").JSX.Element;
|
package/dist/Icon.jsx
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { glyphSvg } from './icons/render.js';
|
|
2
|
+
import { iconPaths } from './icons/paths.js';
|
|
3
|
+
/** Bundled SVG glyphs, rendered without icon fonts or pseudo-elements. */
|
|
4
|
+
export function Icon({ name, color, size = 16, className = '', accessibilityLabel, onTap }) {
|
|
5
|
+
const dimension = Number.isFinite(size) ? Math.max(0, size) : 16;
|
|
6
|
+
const path = iconPaths[name];
|
|
7
|
+
const imageSource = /^(https?:\/\/|\/|\.\/|\.\.\/|data:image\/)/.test(name);
|
|
8
|
+
const markup = (color) => glyphSvg(path, color);
|
|
9
|
+
return <view className={`ui-icon ${color ? '' : 'ui-icon-auto'} ${className}`} style={{ width: `${dimension}px`, height: `${dimension}px` }} accessibility-element={!!accessibilityLabel || !!onTap} accessibility-traits={onTap ? 'button' : 'image'} accessibility-label={accessibilityLabel ?? name} bindtap={onTap}>
|
|
10
|
+
{path ? color ? <svg className="ui-icon-svg" content={markup(color)}/> : <><svg className="ui-icon-svg ui-icon-light" content={markup('#1d1f29')}/><svg className="ui-icon-svg ui-icon-dark" content={markup('#e5e6eb')}/></> : imageSource ? /\.svg(?:[?#]|$)/i.test(name) ? <svg className="ui-icon-svg" src={name}/> : <image className="ui-icon-svg" src={name} mode="aspectFit"/> : null}
|
|
11
|
+
</view>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
3
|
+
export type ImagePreviewOptions = {
|
|
4
|
+
images?: readonly string[];
|
|
5
|
+
startPosition?: number;
|
|
6
|
+
showIndex?: boolean;
|
|
7
|
+
loop?: boolean;
|
|
8
|
+
closeable?: boolean;
|
|
9
|
+
closeIcon?: string;
|
|
10
|
+
closeIconPosition?: 'top-left' | 'top-right';
|
|
11
|
+
closeOnClick?: boolean;
|
|
12
|
+
zIndex?: number;
|
|
13
|
+
onOpen?: () => void;
|
|
14
|
+
onClose?: () => void;
|
|
15
|
+
onChange?: (index: number) => void;
|
|
16
|
+
onClick?: (index: number) => void;
|
|
17
|
+
onLongPress?: (index: number) => void;
|
|
18
|
+
};
|
|
19
|
+
export type ImagePreviewSlot = {
|
|
20
|
+
current: number;
|
|
21
|
+
total: number;
|
|
22
|
+
images: readonly string[];
|
|
23
|
+
close: () => void;
|
|
24
|
+
};
|
|
25
|
+
export type ImagePreviewProps = ImagePreviewOptions & {
|
|
26
|
+
show?: boolean;
|
|
27
|
+
onShowChange?: (show: boolean) => void;
|
|
28
|
+
options?: ImagePreviewOptions;
|
|
29
|
+
requestKey?: number;
|
|
30
|
+
rootPortal?: boolean;
|
|
31
|
+
duration?: number;
|
|
32
|
+
renderClose?: (close: () => void) => ReactNode;
|
|
33
|
+
renderIndicator?: (info: {
|
|
34
|
+
current: number;
|
|
35
|
+
total: number;
|
|
36
|
+
}) => ReactNode;
|
|
37
|
+
renderContent?: (info: ImagePreviewSlot) => ReactNode;
|
|
38
|
+
className?: string;
|
|
39
|
+
style?: CSSProperties;
|
|
40
|
+
};
|
|
41
|
+
export type ImagePreviewRef = {
|
|
42
|
+
open: (input?: readonly string[] | ImagePreviewOptions) => void;
|
|
43
|
+
close: () => void;
|
|
44
|
+
setActive: (index: number) => void;
|
|
45
|
+
};
|
|
46
|
+
/** Native image fitting, main-thread paging and the shared scroll-locking overlay. */
|
|
47
|
+
export declare const ImagePreview: (props: ImagePreviewOptions & {
|
|
48
|
+
show?: boolean;
|
|
49
|
+
onShowChange?: (show: boolean) => void;
|
|
50
|
+
options?: ImagePreviewOptions;
|
|
51
|
+
requestKey?: number;
|
|
52
|
+
rootPortal?: boolean;
|
|
53
|
+
duration?: number;
|
|
54
|
+
renderClose?: (close: () => void) => ReactNode;
|
|
55
|
+
renderIndicator?: (info: {
|
|
56
|
+
current: number;
|
|
57
|
+
total: number;
|
|
58
|
+
}) => ReactNode;
|
|
59
|
+
renderContent?: (info: ImagePreviewSlot) => ReactNode;
|
|
60
|
+
className?: string;
|
|
61
|
+
style?: CSSProperties;
|
|
62
|
+
} & import("react").RefAttributes<ImagePreviewRef>) => React.ReactElement | null;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from '@lynx-js/react';
|
|
2
|
+
import { Icon } from "./Icon.jsx";
|
|
3
|
+
import { Img } from "./Img.jsx";
|
|
4
|
+
import { Overlay } from "./Overlay.jsx";
|
|
5
|
+
import { Swiper } from "./Swiper.jsx";
|
|
6
|
+
import { swiperIndex } from './swiperModel.js';
|
|
7
|
+
const emptyImages = [];
|
|
8
|
+
/** Native image fitting, main-thread paging and the shared scroll-locking overlay. */
|
|
9
|
+
export const ImagePreview = forwardRef(function ImagePreview({ show, onShowChange, options, requestKey = 0, rootPortal = false, duration = 300, renderClose, renderIndicator, renderContent, className = '', style, ...defaults }, ref) {
|
|
10
|
+
const [innerShow, setInnerShow] = useState(false), [imperative, setImperative] = useState({}), [revision, setRevision] = useState(0);
|
|
11
|
+
const settings = { ...defaults, ...options, ...imperative }, visible = show ?? innerShow;
|
|
12
|
+
const [active, setActive] = useState(visible);
|
|
13
|
+
const { images = emptyImages, startPosition = 0, showIndex = true, loop = true, closeable = true, closeIcon = 'close', closeIconPosition = 'top-right', closeOnClick = true, zIndex = 1000 } = settings;
|
|
14
|
+
const [current, setCurrent] = useState(() => swiperIndex(startPosition, images.length, false)), index = swiperIndex(current, images.length, false);
|
|
15
|
+
const state = useRef({ visible, index, settings, onShowChange }), closing = useRef(false), wasVisible = useRef(false);
|
|
16
|
+
state.current = { visible, index, settings, onShowChange };
|
|
17
|
+
const close = () => {
|
|
18
|
+
'background only';
|
|
19
|
+
if (!state.current.visible || closing.current)
|
|
20
|
+
return;
|
|
21
|
+
closing.current = true;
|
|
22
|
+
setInnerShow(false);
|
|
23
|
+
state.current.onShowChange?.(false);
|
|
24
|
+
};
|
|
25
|
+
useImperativeHandle(ref, () => ({ open(input) {
|
|
26
|
+
'background only';
|
|
27
|
+
setImperative(input === undefined ? {} : Array.isArray(input) ? { images: input } : input);
|
|
28
|
+
setRevision(value => value + 1);
|
|
29
|
+
closing.current = false;
|
|
30
|
+
setInnerShow(true);
|
|
31
|
+
state.current.onShowChange?.(true);
|
|
32
|
+
}, close, setActive(value) {
|
|
33
|
+
'background only';
|
|
34
|
+
setCurrent(swiperIndex(value, state.current.settings.images?.length ?? 0, false));
|
|
35
|
+
} }), []);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (!visible)
|
|
38
|
+
return;
|
|
39
|
+
setActive(true);
|
|
40
|
+
closing.current = false;
|
|
41
|
+
setCurrent(swiperIndex(startPosition, images.length, false));
|
|
42
|
+
}, [visible, requestKey, revision, startPosition, images]);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (visible && !wasVisible.current)
|
|
45
|
+
state.current.settings.onOpen?.();
|
|
46
|
+
else if (!visible && wasVisible.current)
|
|
47
|
+
state.current.settings.onClose?.();
|
|
48
|
+
wasVisible.current = visible;
|
|
49
|
+
}, [visible]);
|
|
50
|
+
const slot = (node) => typeof node === 'string' || typeof node === 'number' ? <text>{node}</text> : node;
|
|
51
|
+
return <Overlay show={visible} duration={duration} rootPortal={rootPortal} zIndex={zIndex} lockScroll className={`ui-image-preview ${className}`} style={style} onAfterLeave={() => {
|
|
52
|
+
'background only';
|
|
53
|
+
closing.current = false;
|
|
54
|
+
setActive(false);
|
|
55
|
+
}}>
|
|
56
|
+
{active ? <Swiper key={`${requestKey}:${revision}`} list={images} height="100%" current={index} autoplay={false} loop={loop} indicator={false} className="ui-image-preview-swiper" onChange={next => {
|
|
57
|
+
'background only';
|
|
58
|
+
if (!state.current.visible || closing.current)
|
|
59
|
+
return;
|
|
60
|
+
setCurrent(next);
|
|
61
|
+
state.current.settings.onChange?.(next);
|
|
62
|
+
}} onClick={clicked => {
|
|
63
|
+
'background only';
|
|
64
|
+
if (!state.current.visible || closing.current)
|
|
65
|
+
return;
|
|
66
|
+
state.current.settings.onClick?.(clicked);
|
|
67
|
+
if (closeOnClick)
|
|
68
|
+
close();
|
|
69
|
+
}} renderItem={({ item, index: itemIndex }) => <view className="ui-image-preview-item" bindlongpress={() => {
|
|
70
|
+
'background only';
|
|
71
|
+
if (state.current.visible && !closing.current)
|
|
72
|
+
state.current.settings.onLongPress?.(itemIndex);
|
|
73
|
+
}}><Img src={String(item)} width="100%" height="100%" mode="aspectFit" showLoading={false} showError={false}/></view>}/> : null}
|
|
74
|
+
{renderIndicator ? <view className="ui-image-preview-custom-indicator" event-through>{slot(renderIndicator({ current: index, total: images.length }))}</view> : showIndex && images.length > 1 ? <text className="ui-image-preview-index">{`${index + 1} / ${images.length}`}</text> : null}
|
|
75
|
+
{renderClose ? <view className="ui-image-preview-custom-close" catchtap={() => { }}>{slot(renderClose(close))}</view> : closeable ? <view className={`ui-image-preview-close ui-image-preview-close-${closeIconPosition}`} catchtap={close} accessibility-element accessibility-traits="button" accessibility-label="关闭图片预览"><Icon name={closeIcon} size={24} color="#fff"/></view> : null}
|
|
76
|
+
{renderContent ? <view className="ui-image-preview-content" event-through>{slot(renderContent({ current: index, total: images.length, images, close }))}</view> : null}
|
|
77
|
+
</Overlay>;
|
|
78
|
+
});
|
package/dist/Img.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { BaseEvent, CSSProperties, ImageErrorEvent, ImageLoadEvent } from '@lynx-js/types';
|
|
3
|
+
import type { ImgMode } from './imgModel.js';
|
|
4
|
+
export type ImgPreview = (url: string) => void | Promise<void>;
|
|
5
|
+
export type ImgProps = {
|
|
6
|
+
src?: string;
|
|
7
|
+
previewSrc?: string;
|
|
8
|
+
width?: number | string;
|
|
9
|
+
height?: number | string;
|
|
10
|
+
mode?: ImgMode;
|
|
11
|
+
round?: boolean;
|
|
12
|
+
radius?: number | string;
|
|
13
|
+
showLoading?: boolean;
|
|
14
|
+
showError?: boolean;
|
|
15
|
+
loading?: ReactNode;
|
|
16
|
+
error?: ReactNode;
|
|
17
|
+
enablePreview?: boolean;
|
|
18
|
+
onPreview?: ImgPreview;
|
|
19
|
+
onPreviewError?: (error: Error) => void;
|
|
20
|
+
onClick?: () => void;
|
|
21
|
+
onLoad?: (event: BaseEvent<'load', ImageLoadEvent>) => void;
|
|
22
|
+
onError?: (event: BaseEvent<'error', ImageErrorEvent>) => void;
|
|
23
|
+
alt?: string;
|
|
24
|
+
customImage?: string;
|
|
25
|
+
className?: string;
|
|
26
|
+
style?: CSSProperties;
|
|
27
|
+
};
|
|
28
|
+
export declare function Img(props: ImgProps): import("@lynx-js/react").JSX.Element;
|