@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,136 @@
|
|
|
1
|
+
import { forwardRef, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState } from '@lynx-js/react';
|
|
2
|
+
import { ActionSheet } from "./ActionSheet.jsx";
|
|
3
|
+
import { Radio, RadioGroup } from "./Radio.jsx";
|
|
4
|
+
import { Checkbox, CheckboxGroup } from "./Checkbox.jsx";
|
|
5
|
+
import { Search } from "./Search.jsx";
|
|
6
|
+
import { Button } from "./Button.jsx";
|
|
7
|
+
import { Icon } from "./Icon.jsx";
|
|
8
|
+
import { Loading } from "./Loading.jsx";
|
|
9
|
+
import { FormFieldContext } from './formContext.js';
|
|
10
|
+
export const SelectPicker = forwardRef(function SelectPicker({ value, visible, onVisibleChange, columns, type = 'checkbox', title = '选择器', min = 0, max = 0, disabled: disabledProp, loading = false, filterable = false, filterPlaceholder = '搜索', confirmButtonText = '确认', showConfirm = true, valueKey = 'value', labelKey = 'label', checkedColor, selectSize, loadingColor = '#4D80F0', beforeConfirm, onChange, onConfirm, onCancel, onClose, onOpen, closeOnClickModal = true, scrollIntoView = true, rootPortal = false, zIndex = 100, safeAreaInsetBottom = true, safeAreaBottom = 0, className = '', style, contentClassName = '' }, ref) {
|
|
11
|
+
const field = useContext(FormFieldContext), disabled = disabledProp ?? field?.disabled ?? false;
|
|
12
|
+
const [innerVisible, setInnerVisible] = useState(false), show = visible ?? innerVisible;
|
|
13
|
+
const [draft, setDraft] = useState([]), [query, setQuery] = useState(''), [busy, setBusy] = useState(false);
|
|
14
|
+
const generation = useRef(0), pending = useRef(false), current = useRef(draft), scroll = useRef(null), offset = useRef(0), openCallback = useRef(onOpen);
|
|
15
|
+
current.current = draft;
|
|
16
|
+
openCallback.current = onOpen;
|
|
17
|
+
const data = useMemo(() => columns.flatMap(item => {
|
|
18
|
+
const record = item, optionValue = record[valueKey];
|
|
19
|
+
if (!['string', 'number', 'boolean'].includes(typeof optionValue))
|
|
20
|
+
return [];
|
|
21
|
+
return [{ ...record, value: optionValue, label: String(record[labelKey] ?? optionValue), disabled: !!record.disabled }];
|
|
22
|
+
}), [columns, valueKey, labelKey]);
|
|
23
|
+
const snapshot = useMemo(() => ({ value, columns, type, valueKey, labelKey, show, disabled, loading }), [value, columns, type, valueKey, labelKey, show, disabled, loading]);
|
|
24
|
+
const latest = useRef(snapshot);
|
|
25
|
+
latest.current = snapshot;
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
generation.current++;
|
|
28
|
+
pending.current = false;
|
|
29
|
+
setBusy(false);
|
|
30
|
+
if (show) {
|
|
31
|
+
const next = type === 'checkbox' ? Array.isArray(value) ? [...value] : [] : typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean' ? value : '';
|
|
32
|
+
current.current = next;
|
|
33
|
+
setDraft(next);
|
|
34
|
+
setQuery('');
|
|
35
|
+
}
|
|
36
|
+
}, [snapshot]);
|
|
37
|
+
useEffect(() => { if (show)
|
|
38
|
+
openCallback.current?.(); }, [show]);
|
|
39
|
+
useEffect(() => () => { generation.current++; }, []);
|
|
40
|
+
const changeVisible = (next) => {
|
|
41
|
+
'background only';
|
|
42
|
+
if (visible === undefined)
|
|
43
|
+
setInnerVisible(next);
|
|
44
|
+
onVisibleChange?.(next);
|
|
45
|
+
};
|
|
46
|
+
const close = () => {
|
|
47
|
+
'background only';
|
|
48
|
+
generation.current++;
|
|
49
|
+
pending.current = false;
|
|
50
|
+
setBusy(false);
|
|
51
|
+
if (show) {
|
|
52
|
+
changeVisible(false);
|
|
53
|
+
onClose?.();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const cancel = () => {
|
|
57
|
+
'background only';
|
|
58
|
+
if (show) {
|
|
59
|
+
onCancel?.();
|
|
60
|
+
close();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
useImperativeHandle(ref, () => ({ open: () => {
|
|
64
|
+
'background only';
|
|
65
|
+
if (!show && !disabled)
|
|
66
|
+
changeVisible(true);
|
|
67
|
+
}, close }), [show, disabled, visible, onVisibleChange, onClose]);
|
|
68
|
+
const confirm = async (next = current.current) => {
|
|
69
|
+
'background only';
|
|
70
|
+
if (!show || disabled || loading || pending.current)
|
|
71
|
+
return;
|
|
72
|
+
const selection = Array.isArray(next) ? next : [next];
|
|
73
|
+
if (type === 'checkbox' && (selection.length < Math.max(0, min) || max > 0 && selection.length > max))
|
|
74
|
+
return;
|
|
75
|
+
pending.current = true;
|
|
76
|
+
setBusy(true);
|
|
77
|
+
const ticket = ++generation.current, source = latest.current;
|
|
78
|
+
try {
|
|
79
|
+
if (!await (beforeConfirm?.(next) ?? true) || ticket !== generation.current || source !== latest.current)
|
|
80
|
+
return;
|
|
81
|
+
onConfirm?.({ value: next, selectedItems: selection.flatMap(value => { const item = data.find(item => item.value === value); return item ? [item] : []; }) });
|
|
82
|
+
close();
|
|
83
|
+
}
|
|
84
|
+
catch { /* Rejection preserves the current draft. */ }
|
|
85
|
+
finally {
|
|
86
|
+
if (ticket === generation.current) {
|
|
87
|
+
pending.current = false;
|
|
88
|
+
setBusy(false);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const update = (next) => {
|
|
93
|
+
'background only';
|
|
94
|
+
if (disabled || loading || busy || !show)
|
|
95
|
+
return;
|
|
96
|
+
current.current = next;
|
|
97
|
+
setDraft(next);
|
|
98
|
+
onChange?.({ value: next });
|
|
99
|
+
if (type === 'radio' && !showConfirm)
|
|
100
|
+
void confirm(next);
|
|
101
|
+
};
|
|
102
|
+
const items = data.filter(item => item.label.toLowerCase().includes(query.toLowerCase()));
|
|
103
|
+
const label = (item) => {
|
|
104
|
+
const index = item.label.toLowerCase().indexOf(query.toLowerCase());
|
|
105
|
+
return query && index >= 0 ? <text className="ui-select-picker-label" text-maxline="1">{item.label.slice(0, index)}<text className="ui-select-picker-text-active">{item.label.slice(index, index + query.length)}</text>{item.label.slice(index + query.length)}</text> : item.label;
|
|
106
|
+
};
|
|
107
|
+
const reveal = () => {
|
|
108
|
+
'background only';
|
|
109
|
+
if (!scrollIntoView)
|
|
110
|
+
return;
|
|
111
|
+
const selected = Array.isArray(current.current) ? current.current[0] : current.current, index = data.findIndex(item => item.value === selected), row = selectSize === 'large' ? 58 : 54, top = index * row;
|
|
112
|
+
if (index < 0 || top >= offset.current && top + row <= offset.current + 375)
|
|
113
|
+
return;
|
|
114
|
+
scroll.current?.invoke({ method: 'scrollTo', params: { offset: Math.max(0, top - 375 / 2), smooth: true } }).exec();
|
|
115
|
+
};
|
|
116
|
+
return <ActionSheet show={show} onClose={cancel} onAfterEnter={reveal} title={title} titleClassName="ui-select-picker-header" renderClose={() => <view className="ui-select-picker-close"><Icon name="close" size={24} color="#4e5369" className="ui-select-picker-close-light"/><Icon name="close" size={24} color="#6b7085" className="ui-select-picker-close-dark"/></view>} closeOnClickModal={closeOnClickModal} rootPortal={rootPortal} zIndex={zIndex} safeAreaInsetBottom={safeAreaInsetBottom} safeAreaBottom={safeAreaBottom} className={`ui-select-picker ${className}`} style={style}>
|
|
117
|
+
{filterable ? <Search value={query} onChange={({ value }) => {
|
|
118
|
+
'background only';
|
|
119
|
+
setQuery(value);
|
|
120
|
+
offset.current = 0;
|
|
121
|
+
scroll.current?.invoke({ method: 'scrollTo', params: { offset: 0, smooth: false } }).exec();
|
|
122
|
+
}} placeholder={filterPlaceholder} hideCancel placeholderLeft disabled={loading || busy}/> : null}
|
|
123
|
+
<view className="ui-select-picker-content"><scroll-view ref={scroll} className={`ui-select-picker-scroll ${loading ? 'ui-select-picker-is-loading' : ''} ${contentClassName}`} scroll-orientation="vertical" enable-scroll={!loading} scroll-bar-enable={false} bindscroll={event => {
|
|
124
|
+
'background only';
|
|
125
|
+
offset.current = event.detail.scrollTop;
|
|
126
|
+
}}>
|
|
127
|
+
{type === 'checkbox' ? <CheckboxGroup value={Array.isArray(draft) ? draft : []} min={min} max={max} disabled={disabled || busy} readonly={loading} onChange={({ value }) => update(value)} placement="right" type="square" size={selectSize} checkedColor={checkedColor}>{items.map(item => <Checkbox key={`${typeof item.value}:${item.value}`} name={item.value} disabled={item.disabled} className="ui-select-picker-option" labelClassName="ui-select-picker-choice-label">{label(item)}</Checkbox>)}</CheckboxGroup> : <RadioGroup value={Array.isArray(draft) ? null : draft} disabled={disabled || busy} readonly={loading} placement="right" size={selectSize} checkedColor={checkedColor} onChange={value => {
|
|
128
|
+
'background only';
|
|
129
|
+
if (value !== null)
|
|
130
|
+
update(value);
|
|
131
|
+
}}>{items.map(item => <Radio key={`${typeof item.value}:${item.value}`} value={item.value} disabled={item.disabled} className="ui-select-picker-option" labelClassName="ui-select-picker-choice-label">{label(item)}</Radio>)}</RadioGroup>}
|
|
132
|
+
{!items.length ? <text className="ui-picker-empty">暂无数据</text> : null}
|
|
133
|
+
</scroll-view>{loading ? <view className="ui-select-picker-loading"><Loading size={48} color={loadingColor}/></view> : null}</view>
|
|
134
|
+
{type === 'checkbox' || showConfirm ? <view className="ui-select-picker-footer"><view className="ui-select-picker-footer-line"/><Button block size="large" label={confirmButtonText} loading={busy} disabled={disabled || loading || busy} onTap={() => void confirm()}/></view> : null}
|
|
135
|
+
</ActionSheet>;
|
|
136
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
3
|
+
import type { BadgeProps } from "./Badge.jsx";
|
|
4
|
+
import type { SidebarBeforeChange, SidebarValue } from './sidebarModel.js';
|
|
5
|
+
export type SidebarBadgeProps = Omit<BadgeProps, 'children'>;
|
|
6
|
+
export type SidebarItem = {
|
|
7
|
+
value: SidebarValue;
|
|
8
|
+
label: string;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
icon?: string;
|
|
11
|
+
renderIcon?: (state: {
|
|
12
|
+
active: boolean;
|
|
13
|
+
disabled: boolean;
|
|
14
|
+
}) => ReactNode;
|
|
15
|
+
badge?: string | number;
|
|
16
|
+
isDot?: boolean;
|
|
17
|
+
max?: number;
|
|
18
|
+
badgeProps?: SidebarBadgeProps;
|
|
19
|
+
className?: string;
|
|
20
|
+
style?: CSSProperties;
|
|
21
|
+
};
|
|
22
|
+
export type SidebarProps = {
|
|
23
|
+
items: readonly SidebarItem[];
|
|
24
|
+
value?: SidebarValue;
|
|
25
|
+
defaultValue?: SidebarValue;
|
|
26
|
+
beforeChange?: SidebarBeforeChange;
|
|
27
|
+
onChange?: (event: {
|
|
28
|
+
value: SidebarValue;
|
|
29
|
+
label: string;
|
|
30
|
+
}) => void;
|
|
31
|
+
className?: string;
|
|
32
|
+
style?: CSSProperties;
|
|
33
|
+
};
|
|
34
|
+
export declare function Sidebar({ items, value, defaultValue, beforeChange, onChange, className, style }: SidebarProps): import("@lynx-js/react").JSX.Element;
|
package/dist/Sidebar.jsx
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from '@lynx-js/react';
|
|
2
|
+
import { Icon } from "./Icon.jsx";
|
|
3
|
+
import { Badge } from "./Badge.jsx";
|
|
4
|
+
import { createSidebarGuard, sidebarBadge } from './sidebarModel.js';
|
|
5
|
+
export function Sidebar({ items, value, defaultValue = 0, beforeChange, onChange, className = '', style }) {
|
|
6
|
+
const [inner, setInner] = useState(defaultValue);
|
|
7
|
+
const selected = value ?? inner;
|
|
8
|
+
const activeIndex = items.findIndex(item => item.value === selected);
|
|
9
|
+
const guard = useRef(createSidebarGuard());
|
|
10
|
+
const identity = JSON.stringify(items.map(item => [item.value, item.label, !!item.disabled]));
|
|
11
|
+
useEffect(() => { guard.current.cancel(); }, [selected, identity, value]);
|
|
12
|
+
useEffect(() => () => guard.current.cancel(), []);
|
|
13
|
+
const change = (item) => {
|
|
14
|
+
'background only';
|
|
15
|
+
if (item.disabled)
|
|
16
|
+
return;
|
|
17
|
+
if (item.value === selected) {
|
|
18
|
+
guard.current.cancel();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
void guard.current.request(item.value, beforeChange, () => {
|
|
22
|
+
'background only';
|
|
23
|
+
if (value === undefined)
|
|
24
|
+
setInner(item.value);
|
|
25
|
+
onChange?.({ value: item.value, label: item.label });
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
return <view className={`ui-sidebar ${className}`} style={style}>
|
|
29
|
+
{items.map((item, index) => {
|
|
30
|
+
const active = index === activeIndex;
|
|
31
|
+
const disabled = !!item.disabled;
|
|
32
|
+
const badge = sidebarBadge(item.badge, item.badgeProps?.max ?? item.max);
|
|
33
|
+
return <view key={`${typeof item.value}:${item.value}`} className={`ui-sidebar-item ${active ? 'ui-sidebar-active' : ''} ${disabled ? 'ui-sidebar-disabled' : ''} ${activeIndex >= 0 && index === activeIndex - 1 ? 'ui-sidebar-prefix' : ''} ${activeIndex >= 0 && index === activeIndex + 1 ? 'ui-sidebar-suffix' : ''} ${item.className ?? ''}`} style={item.style} accessibility-element accessibility-traits={disabled ? 'disabled' : 'button'} accessibility-label={`${item.label}${active ? ',已选中' : ''}${disabled ? ',已禁用' : ''}`} bindtap={() => {
|
|
34
|
+
'background only';
|
|
35
|
+
change(item);
|
|
36
|
+
}}>
|
|
37
|
+
{active ? <view className="ui-sidebar-indicator"/> : null}
|
|
38
|
+
{item.renderIcon || item.icon ? <view className="ui-sidebar-icon">{item.renderIcon ? item.renderIcon({ active, disabled }) : <><Icon className="ui-sidebar-icon-light" name={item.icon} size={18} color={disabled ? '#c9cbd4' : active ? '#f86100' : '#1d1f29'}/><Icon className="ui-sidebar-icon-dark" name={item.icon} size={18} color={disabled ? '#4e5369' : active ? '#ff812e' : '#e5e6eb'}/></>}</view> : null}
|
|
39
|
+
<Badge value={badge} max={item.max ?? 99} isDot={item.isDot} showZero {...item.badgeProps} className={`ui-sidebar-label-wrap ${item.badgeProps?.className ?? ''}`}><text className="ui-sidebar-label">{item.label}</text></Badge>
|
|
40
|
+
</view>;
|
|
41
|
+
})}
|
|
42
|
+
</view>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { CSSProperties, TouchEvent, MouseEvent } from '@lynx-js/types';
|
|
3
|
+
import type { SignatureResult, SignatureStroke } from './signatureModel.js';
|
|
4
|
+
export type { SignaturePoint, SignatureResult, SignatureStroke } from './signatureModel.js';
|
|
5
|
+
export type SignatureRef = {
|
|
6
|
+
init: (forceUpdate?: boolean) => Promise<void>;
|
|
7
|
+
clear: () => void;
|
|
8
|
+
confirm: () => SignatureResult;
|
|
9
|
+
revoke: () => void;
|
|
10
|
+
restore: () => void;
|
|
11
|
+
};
|
|
12
|
+
export type SignatureFooter = SignatureRef & {
|
|
13
|
+
currentStep: number;
|
|
14
|
+
historyList: readonly SignatureStroke[];
|
|
15
|
+
canUndo: boolean;
|
|
16
|
+
canRedo: boolean;
|
|
17
|
+
};
|
|
18
|
+
export type SignatureProps = {
|
|
19
|
+
width?: number | string;
|
|
20
|
+
height?: number;
|
|
21
|
+
penColor?: string;
|
|
22
|
+
lineWidth?: number;
|
|
23
|
+
backgroundColor?: string;
|
|
24
|
+
exportScale?: number;
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
disableScroll?: boolean;
|
|
27
|
+
enableHistory?: boolean;
|
|
28
|
+
step?: number;
|
|
29
|
+
pressure?: boolean;
|
|
30
|
+
minWidth?: number;
|
|
31
|
+
maxWidth?: number;
|
|
32
|
+
minSpeed?: number;
|
|
33
|
+
clearText?: string;
|
|
34
|
+
confirmText?: string;
|
|
35
|
+
revokeText?: string;
|
|
36
|
+
restoreText?: string;
|
|
37
|
+
renderFooter?: (actions: SignatureFooter) => ReactNode;
|
|
38
|
+
onStart?: (event: TouchEvent | MouseEvent) => void;
|
|
39
|
+
onSigning?: (event: TouchEvent | MouseEvent) => void;
|
|
40
|
+
onEnd?: (event: TouchEvent | MouseEvent) => void;
|
|
41
|
+
onConfirm?: (result: SignatureResult) => void;
|
|
42
|
+
onClear?: () => void;
|
|
43
|
+
className?: string;
|
|
44
|
+
style?: CSSProperties;
|
|
45
|
+
};
|
|
46
|
+
export declare const Signature: (props: SignatureProps & import("react").RefAttributes<SignatureRef>) => React.ReactElement | null;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from '@lynx-js/react';
|
|
2
|
+
import { Button } from "./Button.jsx";
|
|
3
|
+
import { signatureNumber, signaturePng, signatureSvg, signatureWidth } from './signatureModel.js';
|
|
4
|
+
const emptyResult = (error) => ({ success: false, dataUrl: '', width: 0, height: 0, error });
|
|
5
|
+
export const Signature = forwardRef(function Signature({ width = '100%', height = 150, penColor = '#000', lineWidth = 3, backgroundColor = 'transparent', exportScale = 1, disabled = false, disableScroll = true, enableHistory = false, step = 1, pressure = false, minWidth = 2, maxWidth = 6, minSpeed = 1.5, clearText = '清空', confirmText = '确认', revokeText = '撤销', restoreText = '恢复', renderFooter, onStart, onSigning, onEnd, onConfirm, onClear, className = '', style }, ref) {
|
|
6
|
+
const board = useRef(null), size = useRef({ width: 300, height: signatureNumber(height, 150, 1) }), [dimensions, setDimensions] = useState(size.current);
|
|
7
|
+
const history = useRef([]), redo = useRef([]), gesture = useRef(), sequence = useRef(0), mounted = useRef(true), [revision, redraw] = useState(0), [drawing, setDrawing] = useState(false);
|
|
8
|
+
const refresh = () => {
|
|
9
|
+
'background only';
|
|
10
|
+
redraw(n => n + 1);
|
|
11
|
+
};
|
|
12
|
+
const cancel = () => {
|
|
13
|
+
'background only';
|
|
14
|
+
sequence.current++;
|
|
15
|
+
gesture.current = undefined;
|
|
16
|
+
setDrawing(false);
|
|
17
|
+
refresh();
|
|
18
|
+
};
|
|
19
|
+
const resize = (w, h) => {
|
|
20
|
+
'background only';
|
|
21
|
+
if (!mounted.current || !Number.isFinite(w) || !Number.isFinite(h) || w <= 0 || h <= 0)
|
|
22
|
+
return;
|
|
23
|
+
if (size.current.width !== w || size.current.height !== h) {
|
|
24
|
+
cancel();
|
|
25
|
+
size.current = { width: w, height: h };
|
|
26
|
+
setDimensions(size.current);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const measure = () => {
|
|
30
|
+
'background only';
|
|
31
|
+
return new Promise(resolve => { if (!board.current) {
|
|
32
|
+
resolve(undefined);
|
|
33
|
+
return;
|
|
34
|
+
} board.current.invoke({ method: 'boundingClientRect', success: value => { const r = value; resolve(Number.isFinite(r.left) && Number.isFinite(r.top) && r.width > 0 && r.height > 0 ? r : undefined); }, fail: () => resolve(undefined) }).exec(); });
|
|
35
|
+
};
|
|
36
|
+
const init = async (forceUpdate = false) => {
|
|
37
|
+
'background only';
|
|
38
|
+
const ticket = sequence.current, r = await measure();
|
|
39
|
+
if (!r || ticket !== sequence.current || !mounted.current)
|
|
40
|
+
return;
|
|
41
|
+
resize(r.width, r.height);
|
|
42
|
+
if (forceUpdate)
|
|
43
|
+
refresh();
|
|
44
|
+
};
|
|
45
|
+
const clear = () => {
|
|
46
|
+
'background only';
|
|
47
|
+
cancel();
|
|
48
|
+
history.current = [];
|
|
49
|
+
redo.current = [];
|
|
50
|
+
refresh();
|
|
51
|
+
onClear?.();
|
|
52
|
+
};
|
|
53
|
+
const confirm = () => {
|
|
54
|
+
'background only';
|
|
55
|
+
let result;
|
|
56
|
+
try {
|
|
57
|
+
if (gesture.current)
|
|
58
|
+
result = emptyResult('请结束书写后再确认');
|
|
59
|
+
else if (!history.current.length)
|
|
60
|
+
result = emptyResult('请先签名');
|
|
61
|
+
else
|
|
62
|
+
result = signaturePng(history.current, size.current.width, size.current.height, exportScale, backgroundColor);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
result = emptyResult(error instanceof Error ? error.message : '导出失败');
|
|
66
|
+
}
|
|
67
|
+
onConfirm?.(result);
|
|
68
|
+
return result;
|
|
69
|
+
};
|
|
70
|
+
const revoke = () => {
|
|
71
|
+
'background only';
|
|
72
|
+
if (!enableHistory || !history.current.length)
|
|
73
|
+
return;
|
|
74
|
+
cancel();
|
|
75
|
+
const count = Math.min(history.current.length, Math.floor(signatureNumber(step, 1, 1)));
|
|
76
|
+
redo.current = [...history.current.splice(-count), ...redo.current];
|
|
77
|
+
refresh();
|
|
78
|
+
};
|
|
79
|
+
const restore = () => {
|
|
80
|
+
'background only';
|
|
81
|
+
if (!enableHistory || !redo.current.length)
|
|
82
|
+
return;
|
|
83
|
+
cancel();
|
|
84
|
+
const count = Math.min(redo.current.length, Math.floor(signatureNumber(step, 1, 1)));
|
|
85
|
+
history.current.push(...redo.current.splice(0, count));
|
|
86
|
+
refresh();
|
|
87
|
+
};
|
|
88
|
+
useImperativeHandle(ref, () => ({ init, clear, confirm, revoke, restore }));
|
|
89
|
+
useEffect(() => () => { mounted.current = false; sequence.current++; gesture.current = undefined; }, []);
|
|
90
|
+
useEffect(() => { if (disabled)
|
|
91
|
+
cancel(); }, [disabled]);
|
|
92
|
+
const raw = (event, id) => {
|
|
93
|
+
'background only';
|
|
94
|
+
const e = event;
|
|
95
|
+
const touch = e.touches?.find(t => id === undefined || t.identifier === id) ?? e.changedTouches?.find(t => id === undefined || t.identifier === id);
|
|
96
|
+
const p = touch ?? event;
|
|
97
|
+
const x = p.clientX ?? p.x, y = p.clientY ?? p.y;
|
|
98
|
+
return Number.isFinite(x) && Number.isFinite(y) ? { x, y, time: Date.now() } : undefined;
|
|
99
|
+
};
|
|
100
|
+
const append = (g) => {
|
|
101
|
+
'background only';
|
|
102
|
+
if (!g.rect)
|
|
103
|
+
return;
|
|
104
|
+
while (g.raw.length) {
|
|
105
|
+
const point = g.raw.shift(), last = g.stroke.points.at(-1), x = Math.max(0, Math.min(g.rect.width, point.x - g.rect.left)), y = Math.max(0, Math.min(g.rect.height, point.y - g.rect.top));
|
|
106
|
+
if (last && Math.hypot(x - last.x, y - last.y) < .3)
|
|
107
|
+
continue;
|
|
108
|
+
const initial = pressure ? (signatureNumber(minWidth, 2, .1) + Math.max(signatureNumber(minWidth, 2, .1), signatureNumber(maxWidth, 6, .1))) / 2 : signatureNumber(lineWidth, 3, .1);
|
|
109
|
+
const next = { x, y, time: point.time, width: pressure && last ? signatureWidth(Math.hypot(x - last.x, y - last.y) / Math.max(1, point.time - last.time), last.width, minWidth, maxWidth, minSpeed) : initial };
|
|
110
|
+
g.stroke.points.push(next);
|
|
111
|
+
}
|
|
112
|
+
refresh();
|
|
113
|
+
};
|
|
114
|
+
const commit = (g) => {
|
|
115
|
+
'background only';
|
|
116
|
+
if (g !== gesture.current || !g.ended || !g.rect)
|
|
117
|
+
return;
|
|
118
|
+
append(g);
|
|
119
|
+
if (g.stroke.points.length) {
|
|
120
|
+
history.current.push(g.stroke);
|
|
121
|
+
redo.current = [];
|
|
122
|
+
}
|
|
123
|
+
gesture.current = undefined;
|
|
124
|
+
setDrawing(false);
|
|
125
|
+
refresh();
|
|
126
|
+
onEnd?.(g.ended);
|
|
127
|
+
};
|
|
128
|
+
const begin = async (event) => {
|
|
129
|
+
'background only';
|
|
130
|
+
if (disabled || gesture.current)
|
|
131
|
+
return;
|
|
132
|
+
const touch = event;
|
|
133
|
+
if ((touch.touches?.length ?? 1) > 1)
|
|
134
|
+
return;
|
|
135
|
+
const p = raw(event);
|
|
136
|
+
if (!p)
|
|
137
|
+
return;
|
|
138
|
+
const g = { ticket: ++sequence.current, id: touch.touches?.[0]?.identifier, raw: [p], stroke: { color: penColor, points: [] } };
|
|
139
|
+
gesture.current = g;
|
|
140
|
+
setDrawing(true);
|
|
141
|
+
onStart?.(event);
|
|
142
|
+
const rect = await measure();
|
|
143
|
+
if (!mounted.current || gesture.current !== g || sequence.current !== g.ticket)
|
|
144
|
+
return;
|
|
145
|
+
if (!rect) {
|
|
146
|
+
cancel();
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
size.current = { width: rect.width, height: rect.height };
|
|
150
|
+
setDimensions(size.current);
|
|
151
|
+
g.rect = rect;
|
|
152
|
+
append(g);
|
|
153
|
+
commit(g);
|
|
154
|
+
};
|
|
155
|
+
const move = (event) => {
|
|
156
|
+
'background only';
|
|
157
|
+
const g = gesture.current;
|
|
158
|
+
if (!g || disabled)
|
|
159
|
+
return;
|
|
160
|
+
if ((event.touches?.length ?? 1) > 1) {
|
|
161
|
+
cancel();
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const p = raw(event, g.id);
|
|
165
|
+
if (!p)
|
|
166
|
+
return;
|
|
167
|
+
g.raw.push(p);
|
|
168
|
+
append(g);
|
|
169
|
+
onSigning?.(event);
|
|
170
|
+
};
|
|
171
|
+
const end = (event) => {
|
|
172
|
+
'background only';
|
|
173
|
+
const g = gesture.current;
|
|
174
|
+
if (!g)
|
|
175
|
+
return;
|
|
176
|
+
const changed = event.changedTouches;
|
|
177
|
+
if (g.id !== undefined && changed?.length && !changed.some(t => t.identifier === g.id))
|
|
178
|
+
return;
|
|
179
|
+
const p = raw(event, g.id);
|
|
180
|
+
if (p)
|
|
181
|
+
g.raw.push(p);
|
|
182
|
+
g.ended = event;
|
|
183
|
+
commit(g);
|
|
184
|
+
};
|
|
185
|
+
const strokes = [...history.current, ...(gesture.current?.stroke.points.length ? [gesture.current.stroke] : [])];
|
|
186
|
+
void revision;
|
|
187
|
+
const actions = { init, clear, confirm, revoke, restore, currentStep: history.current.length, historyList: [...history.current, ...redo.current], canUndo: enableHistory && history.current.length > 0, canRedo: enableHistory && redo.current.length > 0 };
|
|
188
|
+
return <view className={`ui-signature ${disabled ? 'ui-signature-disabled' : ''} ${className}`} style={{ width: typeof width === 'number' ? `${signatureNumber(width, 300)}px` : width, ...style }}>
|
|
189
|
+
<view className="ui-signature-content"><view ref={board} flatten={false} className="ui-signature-board" style={{ height: `${signatureNumber(height, 150, 1)}px` }} bindlayoutchange={event => resize(event.detail.width, event.detail.height)} consume-slide-event={!disabled && disableScroll ? [[-180, 180]] : undefined} catchtouchstart={event => {
|
|
190
|
+
'background only';
|
|
191
|
+
void begin(event);
|
|
192
|
+
}} catchtouchmove={move} catchtouchend={end} catchtouchcancel={cancel} catchmousedown={event => {
|
|
193
|
+
'background only';
|
|
194
|
+
void begin(event);
|
|
195
|
+
}} global-bindmousemove={drawing ? move : undefined} global-bindmouseup={drawing ? end : undefined} global-bindtouchend={drawing ? end : undefined} global-bindtouchcancel={drawing ? cancel : undefined} accessibility-element accessibility-label={disabled ? '签名板已禁用' : '签名板'}>
|
|
196
|
+
<svg className="ui-signature-svg" content={signatureSvg(strokes, dimensions.width, dimensions.height, backgroundColor)} style={{ width: '100%', height: '100%' }} user-interaction-enabled={false}/>
|
|
197
|
+
</view></view>
|
|
198
|
+
<view className="ui-signature-footer">{renderFooter ? renderFooter(actions) : <>{enableHistory ? <><Button size="small" label={revokeText} onTap={revoke} disabled={!actions.canUndo}/><Button size="small" label={restoreText} onTap={restore} disabled={!actions.canRedo}/></> : null}<Button size="small" label={clearText} onTap={clear}/><Button size="small" label={confirmText} onTap={() => {
|
|
199
|
+
'background only';
|
|
200
|
+
confirm();
|
|
201
|
+
}}/></>}</view>
|
|
202
|
+
</view>;
|
|
203
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
3
|
+
export type SkeletonTheme = 'avatar' | 'image' | 'text' | 'paragraph';
|
|
4
|
+
export type SkeletonCell = {
|
|
5
|
+
type?: 'text' | 'rect' | 'circle';
|
|
6
|
+
size?: number | string;
|
|
7
|
+
width?: number | string;
|
|
8
|
+
height?: number | string;
|
|
9
|
+
margin?: number | string;
|
|
10
|
+
marginLeft?: number | string;
|
|
11
|
+
marginRight?: number | string;
|
|
12
|
+
borderRadius?: number | string;
|
|
13
|
+
background?: string;
|
|
14
|
+
backgroundColor?: string;
|
|
15
|
+
};
|
|
16
|
+
export type SkeletonRow = number | SkeletonCell | readonly SkeletonCell[];
|
|
17
|
+
export type SkeletonProps = {
|
|
18
|
+
theme?: SkeletonTheme;
|
|
19
|
+
rowCol?: readonly SkeletonRow[];
|
|
20
|
+
loading?: boolean;
|
|
21
|
+
animation?: '' | 'gradient' | 'flashed';
|
|
22
|
+
children?: ReactNode;
|
|
23
|
+
className?: string;
|
|
24
|
+
style?: CSSProperties;
|
|
25
|
+
};
|
|
26
|
+
export declare function skeletonRows(rowCol: readonly SkeletonRow[] | undefined, theme: SkeletonTheme): SkeletonCell[][];
|
|
27
|
+
export declare function Skeleton({ theme, rowCol, loading, animation, children, className, style }: SkeletonProps): import("@lynx-js/react").JSX.Element;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { imgDimension } from './imgModel.js';
|
|
2
|
+
const themes = {
|
|
3
|
+
avatar: [{ type: 'circle', size: 64 }], image: [{ type: 'rect', size: 64 }],
|
|
4
|
+
text: [1, [{ width: '24%', height: 16, marginRight: 16 }, { width: '76%', height: 16 }]], paragraph: [1, 1, 1, { width: '55%' }],
|
|
5
|
+
};
|
|
6
|
+
export function skeletonRows(rowCol, theme) {
|
|
7
|
+
return (rowCol?.length ? rowCol : themes[theme]).map(row => typeof row === 'number' ? Array.from({ length: Number.isFinite(row) ? Math.max(0, Math.min(100, Math.floor(row))) : 0 }, () => ({})) : Array.isArray(row) ? [...row] : [row]);
|
|
8
|
+
}
|
|
9
|
+
function cellStyle(cell) {
|
|
10
|
+
const style = {};
|
|
11
|
+
if (cell.size !== undefined) {
|
|
12
|
+
style.width = imgDimension(cell.size, 16);
|
|
13
|
+
style.height = style.width;
|
|
14
|
+
}
|
|
15
|
+
for (const key of ['width', 'height', 'margin', 'marginLeft', 'marginRight', 'borderRadius'])
|
|
16
|
+
if (cell[key] !== undefined)
|
|
17
|
+
style[key] = typeof cell[key] === 'number' && key.startsWith('margin') ? `${Number.isFinite(cell[key]) ? cell[key] : 0}px` : imgDimension(cell[key], 0);
|
|
18
|
+
if (cell.background !== undefined)
|
|
19
|
+
style.background = cell.background;
|
|
20
|
+
if (cell.backgroundColor !== undefined)
|
|
21
|
+
style.backgroundColor = cell.backgroundColor;
|
|
22
|
+
return style;
|
|
23
|
+
}
|
|
24
|
+
export function Skeleton({ theme = 'text', rowCol, loading = true, animation = '', children, className = '', style }) {
|
|
25
|
+
const rows = skeletonRows(rowCol, theme);
|
|
26
|
+
return <view className={`ui-skeleton ${className}`} style={style} accessibility-element={loading} accessibility-label={loading ? '加载中' : undefined}>
|
|
27
|
+
{loading ? <view className="ui-skeleton-content">{rows.map((row, index) => <view className={`ui-skeleton-row ${index === rows.length - 1 ? 'ui-skeleton-row-last' : ''}`} key={index}>{row.map((cell, col) => <view className={`ui-skeleton-col ui-skeleton-${cell.type || 'text'} ${animation ? `ui-skeleton-animation-${animation}` : ''}`} key={col} style={{ ...(row.length > 1 && typeof (rowCol?.length ? rowCol : themes[theme])[index] === 'number' ? { flex: 1, width: undefined, marginRight: col < row.length - 1 ? '12px' : 0 } : {}), ...cellStyle(cell) }}>{animation === 'gradient' ? <view className="ui-skeleton-shimmer"/> : null}</view>)}</view>)}</view> : typeof children === 'string' || typeof children === 'number' ? <text>{children}</text> : children}
|
|
28
|
+
</view>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
3
|
+
export type SlideVerifyRef = {
|
|
4
|
+
init: () => Promise<void>;
|
|
5
|
+
reset: () => void;
|
|
6
|
+
};
|
|
7
|
+
export type SlideVerifyProps = {
|
|
8
|
+
width?: number | string;
|
|
9
|
+
height?: number | string;
|
|
10
|
+
tolerance?: number;
|
|
11
|
+
text?: ReactNode;
|
|
12
|
+
successText?: ReactNode;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
backgroundColor?: string;
|
|
15
|
+
activeBackgroundColor?: string;
|
|
16
|
+
icon?: string;
|
|
17
|
+
successIcon?: string;
|
|
18
|
+
iconSize?: number;
|
|
19
|
+
successIconSize?: number;
|
|
20
|
+
renderIcon?: ReactNode;
|
|
21
|
+
renderSuccessIcon?: ReactNode;
|
|
22
|
+
onSuccess?: () => void;
|
|
23
|
+
onFail?: () => void;
|
|
24
|
+
className?: string;
|
|
25
|
+
style?: CSSProperties;
|
|
26
|
+
};
|
|
27
|
+
export declare const SlideVerify: (props: SlideVerifyProps & import("react").RefAttributes<SlideVerifyRef>) => React.ReactElement | null;
|