@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
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from '@lynx-js/react';
|
|
2
|
+
function point(event) {
|
|
3
|
+
'background only';
|
|
4
|
+
const touch = event.touches?.[0] ?? event.changedTouches?.[0] ?? event.detail ?? event;
|
|
5
|
+
const x = touch.clientX ?? touch.pageX ?? touch.x, y = touch.clientY ?? touch.pageY ?? touch.y;
|
|
6
|
+
return Number.isFinite(x) && Number.isFinite(y) ? { x: x, y: y } : undefined;
|
|
7
|
+
}
|
|
8
|
+
export const SwipeAction = forwardRef(function SwipeAction({ value, defaultValue = 'close', disabled = false, beforeClose, onChange, onClick, left, right, children, duration = 600, className = '', style }, ref) {
|
|
9
|
+
const normalize = (status) => status === 'left' && left ? 'left' : status === 'right' && right ? 'right' : 'close';
|
|
10
|
+
const [status, setStatus] = useState(() => normalize(value ?? defaultValue));
|
|
11
|
+
const [widths, setWidths] = useState({ left: 0, right: 0 });
|
|
12
|
+
const [offset, setOffset] = useState();
|
|
13
|
+
const [retainSides, setRetainSides] = useState(status !== 'close');
|
|
14
|
+
const [dragging, setDragging] = useState(false);
|
|
15
|
+
const [pending, setPending] = useState(false);
|
|
16
|
+
const leftRef = useRef(null), rightRef = useRef(null);
|
|
17
|
+
const mounted = useRef(true), generation = useRef(0), busy = useRef(false);
|
|
18
|
+
const suppressTap = useRef(false);
|
|
19
|
+
const releaseTimer = useRef();
|
|
20
|
+
const drag = useRef();
|
|
21
|
+
const callbacks = useRef({ beforeClose, onChange, onClick });
|
|
22
|
+
callbacks.current = { beforeClose, onChange, onClick };
|
|
23
|
+
const live = useRef({ status, disabled, value, left: !!left, right: !!right });
|
|
24
|
+
live.current = { status, disabled, value, left: !!left, right: !!right };
|
|
25
|
+
const base = status === 'left' ? widths.left : status === 'right' ? -widths.right : 0;
|
|
26
|
+
const sidesVisible = status !== 'close' || offset !== undefined || retainSides;
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (status !== 'close' || offset !== undefined) {
|
|
29
|
+
setRetainSides(true);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const timer = setTimeout(() => setRetainSides(false), Number.isFinite(duration) ? Math.max(0, duration) : 600);
|
|
33
|
+
return () => clearTimeout(timer);
|
|
34
|
+
}, [status, offset, duration]);
|
|
35
|
+
const updateWidth = (side, width) => {
|
|
36
|
+
'background only';
|
|
37
|
+
if (!mounted.current || !Number.isFinite(width) || width < 0)
|
|
38
|
+
return;
|
|
39
|
+
setWidths(previous => previous[side] === width ? previous : { ...previous, [side]: width });
|
|
40
|
+
};
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
mounted.current = true;
|
|
43
|
+
const timer = setTimeout(() => {
|
|
44
|
+
for (const [side, node] of [['left', leftRef], ['right', rightRef]])
|
|
45
|
+
node.current?.invoke({ method: 'boundingClientRect', success: (rect) => {
|
|
46
|
+
'background only';
|
|
47
|
+
updateWidth(side, rect.width);
|
|
48
|
+
} }).exec();
|
|
49
|
+
}, 32);
|
|
50
|
+
return () => { mounted.current = false; generation.current++; clearTimeout(timer); clearTimeout(releaseTimer.current); };
|
|
51
|
+
}, []);
|
|
52
|
+
const request = async (next, reason, position, fromProp = false) => {
|
|
53
|
+
'background only';
|
|
54
|
+
if (!mounted.current || live.current.disabled && !fromProp || busy.current)
|
|
55
|
+
return false;
|
|
56
|
+
const previous = live.current.status;
|
|
57
|
+
next = next === 'left' && live.current.left ? 'left' : next === 'right' && live.current.right ? 'right' : 'close';
|
|
58
|
+
if (next === previous)
|
|
59
|
+
return false;
|
|
60
|
+
const token = ++generation.current;
|
|
61
|
+
if (previous !== 'close' && callbacks.current.beforeClose) {
|
|
62
|
+
busy.current = true;
|
|
63
|
+
let accepted = false;
|
|
64
|
+
try {
|
|
65
|
+
const result = callbacks.current.beforeClose(reason, position);
|
|
66
|
+
if (typeof result !== 'boolean')
|
|
67
|
+
setPending(true);
|
|
68
|
+
accepted = await result;
|
|
69
|
+
}
|
|
70
|
+
catch { /* A rejected guard keeps the opened side visible. */ }
|
|
71
|
+
if (!mounted.current || token !== generation.current)
|
|
72
|
+
return false;
|
|
73
|
+
busy.current = false;
|
|
74
|
+
setPending(false);
|
|
75
|
+
if (!accepted) {
|
|
76
|
+
if (fromProp)
|
|
77
|
+
callbacks.current.onChange?.(previous);
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!mounted.current || token !== generation.current)
|
|
82
|
+
return false;
|
|
83
|
+
if (fromProp || live.current.value === undefined) {
|
|
84
|
+
live.current.status = next;
|
|
85
|
+
setStatus(next);
|
|
86
|
+
}
|
|
87
|
+
if (!fromProp)
|
|
88
|
+
callbacks.current.onChange?.(next);
|
|
89
|
+
if (reason === 'click' && previous !== 'close' && next === 'close')
|
|
90
|
+
callbacks.current.onClick?.({ value: position });
|
|
91
|
+
return true;
|
|
92
|
+
};
|
|
93
|
+
const requestRef = useRef(request);
|
|
94
|
+
requestRef.current = request;
|
|
95
|
+
const previousValue = useRef(value);
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
if (previousValue.current === value)
|
|
98
|
+
return;
|
|
99
|
+
previousValue.current = value;
|
|
100
|
+
generation.current++;
|
|
101
|
+
busy.current = false;
|
|
102
|
+
setPending(false);
|
|
103
|
+
drag.current = undefined;
|
|
104
|
+
setOffset(undefined);
|
|
105
|
+
setDragging(false);
|
|
106
|
+
if (value !== undefined)
|
|
107
|
+
void requestRef.current(value, 'value', live.current.status === 'close' ? value === 'left' ? 'left' : 'right' : live.current.status, true);
|
|
108
|
+
}, [value]);
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
generation.current++;
|
|
111
|
+
busy.current = false;
|
|
112
|
+
setPending(false);
|
|
113
|
+
drag.current = undefined;
|
|
114
|
+
setOffset(undefined);
|
|
115
|
+
setDragging(false);
|
|
116
|
+
if (live.current.status === 'left' && !left || live.current.status === 'right' && !right) {
|
|
117
|
+
live.current.status = 'close';
|
|
118
|
+
setStatus('close');
|
|
119
|
+
callbacks.current.onChange?.('close');
|
|
120
|
+
}
|
|
121
|
+
}, [disabled, !!left, !!right]);
|
|
122
|
+
useImperativeHandle(ref, () => ({ close: (reason = 'value', position) => {
|
|
123
|
+
'background only';
|
|
124
|
+
const state = live.current.status;
|
|
125
|
+
return requestRef.current('close', reason, position ?? (state === 'close' ? 'inside' : state));
|
|
126
|
+
} }), []);
|
|
127
|
+
const start = (event) => {
|
|
128
|
+
'background only';
|
|
129
|
+
const p = point(event);
|
|
130
|
+
if (!p || disabled || busy.current || drag.current)
|
|
131
|
+
return;
|
|
132
|
+
clearTimeout(releaseTimer.current);
|
|
133
|
+
suppressTap.current = false;
|
|
134
|
+
drag.current = { ...p, initial: base, next: base, active: false };
|
|
135
|
+
};
|
|
136
|
+
const move = (event) => {
|
|
137
|
+
'background only';
|
|
138
|
+
const state = drag.current, p = point(event);
|
|
139
|
+
if (!state || !p || disabled)
|
|
140
|
+
return;
|
|
141
|
+
const dx = p.x - state.x, dy = p.y - state.y;
|
|
142
|
+
if (!state.active) {
|
|
143
|
+
if (Math.max(Math.abs(dx), Math.abs(dy)) < 5)
|
|
144
|
+
return;
|
|
145
|
+
if (Math.abs(dy) >= Math.abs(dx)) {
|
|
146
|
+
drag.current = undefined;
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
state.active = true;
|
|
150
|
+
suppressTap.current = true;
|
|
151
|
+
setDragging(true);
|
|
152
|
+
}
|
|
153
|
+
state.next = Math.max(-widths.right, Math.min(widths.left, state.initial + dx));
|
|
154
|
+
setOffset(state.next);
|
|
155
|
+
};
|
|
156
|
+
const finish = (cancelled = false) => {
|
|
157
|
+
'background only';
|
|
158
|
+
const state = drag.current;
|
|
159
|
+
if (!state)
|
|
160
|
+
return;
|
|
161
|
+
drag.current = undefined;
|
|
162
|
+
setDragging(false);
|
|
163
|
+
setOffset(undefined);
|
|
164
|
+
if (!state.active)
|
|
165
|
+
return;
|
|
166
|
+
clearTimeout(releaseTimer.current);
|
|
167
|
+
releaseTimer.current = setTimeout(() => { suppressTap.current = false; }, 250);
|
|
168
|
+
if (cancelled)
|
|
169
|
+
return;
|
|
170
|
+
const next = widths.left > 0 && state.next > widths.left / 2 ? 'left' : widths.right > 0 && state.next < -widths.right / 2 ? 'right' : 'close';
|
|
171
|
+
const current = live.current.status;
|
|
172
|
+
void requestRef.current(next, 'swipe', current === 'close' ? next === 'left' ? 'left' : 'right' : current);
|
|
173
|
+
};
|
|
174
|
+
const click = (position) => {
|
|
175
|
+
'background only';
|
|
176
|
+
if (suppressTap.current || disabled || live.current.status === 'close')
|
|
177
|
+
return;
|
|
178
|
+
void requestRef.current('close', 'click', position);
|
|
179
|
+
};
|
|
180
|
+
return <view className={`ui-swipe-action ${disabled ? 'ui-swipe-action-disabled' : ''} ${pending ? 'ui-swipe-action-pending' : ''} ${className}`} style={style}>
|
|
181
|
+
<view className="ui-swipe-track" style={{ transform: `translateX(${offset ?? base}px)`, transitionDuration: `${dragging ? 0 : Number.isFinite(duration) ? Math.max(0, duration) : 600}ms` }} consume-slide-event={disabled ? undefined : [[-45, 45], [135, 180], [-180, -135]]} bindtouchstart={start} bindtouchmove={move} bindtouchend={() => finish()} bindtouchcancel={() => finish(true)} bindmousedown={start} global-bindmousemove={move} global-bindmouseup={() => finish()} global-bindtouchmove={move} global-bindtouchend={() => finish()} global-bindtouchcancel={() => finish(true)}>
|
|
182
|
+
{left ? <view ref={leftRef} flatten={false} className="ui-swipe-side ui-swipe-left" style={{ visibility: sidesVisible ? 'visible' : 'hidden' }} bindlayoutchange={event => updateWidth('left', event.detail.width)} catchtap={() => click('left')}>{left}</view> : null}
|
|
183
|
+
<view className="ui-swipe-body" catchtap={() => click('inside')}>{children}</view>
|
|
184
|
+
{right ? <view ref={rightRef} flatten={false} className="ui-swipe-side ui-swipe-right" style={{ visibility: sidesVisible ? 'visible' : 'hidden' }} bindlayoutchange={event => updateWidth('right', event.detail.width)} catchtap={() => click('right')}>{right}</view> : null}
|
|
185
|
+
</view>
|
|
186
|
+
</view>;
|
|
187
|
+
});
|
package/dist/Swiper.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
3
|
+
import type { ImgMode } from './imgModel.js';
|
|
4
|
+
export type SwiperItem = string | Record<string, unknown>;
|
|
5
|
+
export type SwiperChangeSource = 'autoplay' | 'touch' | 'nav';
|
|
6
|
+
export type SwiperIndicator = {
|
|
7
|
+
type?: 'dots' | 'dots-bar' | 'fraction';
|
|
8
|
+
minShowNum?: number;
|
|
9
|
+
showControls?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type SwiperRef = {
|
|
12
|
+
swipeTo: (index: number) => void;
|
|
13
|
+
swipeNext: () => void;
|
|
14
|
+
swipePrev: () => void;
|
|
15
|
+
};
|
|
16
|
+
export type SwiperProps = {
|
|
17
|
+
list: readonly SwiperItem[];
|
|
18
|
+
current?: number;
|
|
19
|
+
defaultCurrent?: number;
|
|
20
|
+
onChange?: (current: number, source: SwiperChangeSource) => void;
|
|
21
|
+
onClick?: (index: number, item: SwiperItem) => void;
|
|
22
|
+
autoplay?: boolean;
|
|
23
|
+
interval?: number;
|
|
24
|
+
duration?: number;
|
|
25
|
+
loop?: boolean;
|
|
26
|
+
height?: number | string;
|
|
27
|
+
displayMultipleItems?: number;
|
|
28
|
+
previousMargin?: number;
|
|
29
|
+
nextMargin?: number;
|
|
30
|
+
neighborHeight?: number;
|
|
31
|
+
indicator?: boolean | SwiperIndicator;
|
|
32
|
+
indicatorPosition?: 'left' | 'top-left' | 'top' | 'top-right' | 'bottom-left' | 'bottom' | 'bottom-right' | 'right';
|
|
33
|
+
valueKey?: string;
|
|
34
|
+
textKey?: string;
|
|
35
|
+
imageMode?: ImgMode;
|
|
36
|
+
renderItem?: (options: {
|
|
37
|
+
item: SwiperItem;
|
|
38
|
+
index: number;
|
|
39
|
+
}) => ReactNode;
|
|
40
|
+
renderIndicator?: (options: {
|
|
41
|
+
current: number;
|
|
42
|
+
total: number;
|
|
43
|
+
}) => ReactNode;
|
|
44
|
+
customIndicatorClass?: string;
|
|
45
|
+
customItemClass?: string;
|
|
46
|
+
customPrevClass?: string;
|
|
47
|
+
customNextClass?: string;
|
|
48
|
+
customTextClass?: string;
|
|
49
|
+
customTextStyle?: CSSProperties;
|
|
50
|
+
className?: string;
|
|
51
|
+
style?: CSSProperties;
|
|
52
|
+
};
|
|
53
|
+
/** Horizontal paging and touch animations run in lynx-ui's main-thread Swiper. */
|
|
54
|
+
export declare const Swiper: (props: SwiperProps & import("react").RefAttributes<SwiperRef>) => React.ReactElement | null;
|
package/dist/Swiper.jsx
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from '@lynx-js/react';
|
|
2
|
+
import { Swiper as NativeSwiper, SwiperItem as NativeSwiperItem } from '@lynx-js/lynx-ui';
|
|
3
|
+
import { SwiperNav } from "./SwiperNav.jsx";
|
|
4
|
+
import { Img } from "./Img.jsx";
|
|
5
|
+
import { imgDimension } from './imgModel.js';
|
|
6
|
+
import { swiperIndex, swiperNumber } from './swiperModel.js';
|
|
7
|
+
import { swiperCardFrame } from './swiperAnimation.js' with { runtime: 'shared' };
|
|
8
|
+
/** Horizontal paging and touch animations run in lynx-ui's main-thread Swiper. */
|
|
9
|
+
export const Swiper = forwardRef(function Swiper({ list, current, defaultCurrent = 0, onChange, onClick, autoplay = true, interval = 5000, duration = 300, loop = true, height = 192, displayMultipleItems = 1, previousMargin = 0, nextMargin = 0, neighborHeight, indicator = true, indicatorPosition = 'bottom', valueKey = 'value', textKey = 'text', imageMode = 'aspectFill', renderItem, renderIndicator, customIndicatorClass = '', customItemClass = '', customPrevClass = '', customNextClass = '', customTextClass = '', customTextStyle, className = '', style }, ref) {
|
|
10
|
+
const count = list.length, [inner, setInner] = useState(defaultCurrent), actual = swiperIndex(current ?? inner, count, loop), [nativeIndex, setNativeIndex] = useState(actual), [box, setBox] = useState({ width: 0, height: 0 }), [dragging, setDragging] = useState(false), native = useRef(null);
|
|
11
|
+
const pending = useRef(null), previousCurrent = useRef(current), draggingRef = useRef(false), latest = useRef(actual), ready = box.width > 0 && box.height > 0 && count > 0;
|
|
12
|
+
latest.current = actual;
|
|
13
|
+
const data = useMemo(() => [...list], [list]);
|
|
14
|
+
const before = swiperNumber(previousMargin, 0, 0, Math.max(0, box.width - 1)), after = swiperNumber(nextMargin, 0, 0, Math.max(0, box.width - before - 1)), viewport = Math.max(1, box.width - before - after), multiple = Math.max(1, Math.floor(swiperNumber(displayMultipleItems, 1, 1, Math.max(1, count)))), itemWidth = viewport / multiple;
|
|
15
|
+
const card = neighborHeight !== undefined, smallHeight = swiperNumber(neighborHeight, box.height, 0, box.height);
|
|
16
|
+
function cardAnimation(value) {
|
|
17
|
+
'main thread';
|
|
18
|
+
return swiperCardFrame(value, box.height, smallHeight);
|
|
19
|
+
}
|
|
20
|
+
const cardFirstFrame = (value) => swiperCardFrame(value, box.height, smallHeight);
|
|
21
|
+
const change = (next) => {
|
|
22
|
+
'background only';
|
|
23
|
+
const normalized = swiperIndex(next, count, loop), request = pending.current;
|
|
24
|
+
if (request && request.index !== normalized)
|
|
25
|
+
return;
|
|
26
|
+
pending.current = null;
|
|
27
|
+
draggingRef.current = false;
|
|
28
|
+
setDragging(false);
|
|
29
|
+
setNativeIndex(normalized);
|
|
30
|
+
if (normalized === latest.current && !request)
|
|
31
|
+
return;
|
|
32
|
+
if (current === undefined) {
|
|
33
|
+
latest.current = normalized;
|
|
34
|
+
setInner(normalized);
|
|
35
|
+
}
|
|
36
|
+
if (!request || request.notify)
|
|
37
|
+
onChange?.(normalized, request?.source ?? 'touch');
|
|
38
|
+
};
|
|
39
|
+
const move = (target, source = 'nav') => {
|
|
40
|
+
'background only';
|
|
41
|
+
if (!ready || (draggingRef.current && !pending.current) || !native.current)
|
|
42
|
+
return;
|
|
43
|
+
const next = swiperIndex(target, count, loop);
|
|
44
|
+
if (next === latest.current)
|
|
45
|
+
return;
|
|
46
|
+
pending.current = { index: next, source, notify: true };
|
|
47
|
+
if (loop && target === latest.current + 1)
|
|
48
|
+
native.current.swipeNext();
|
|
49
|
+
else if (loop && target === latest.current - 1)
|
|
50
|
+
native.current.swipePrev();
|
|
51
|
+
else
|
|
52
|
+
native.current.swipeTo(next, { animate: true });
|
|
53
|
+
};
|
|
54
|
+
useImperativeHandle(ref, () => ({ swipeTo: index => move(index), swipeNext: () => move(latest.current + 1), swipePrev: () => move(latest.current - 1) }), [ready, count, loop, actual]);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (!ready || dragging)
|
|
57
|
+
return;
|
|
58
|
+
const propChanged = previousCurrent.current !== current;
|
|
59
|
+
previousCurrent.current = current;
|
|
60
|
+
if (actual === nativeIndex || pending.current?.index === actual)
|
|
61
|
+
return;
|
|
62
|
+
pending.current = { index: actual, source: 'nav', notify: propChanged };
|
|
63
|
+
native.current?.swipeTo(actual, { animate: propChanged });
|
|
64
|
+
}, [actual, current, nativeIndex, ready, count, loop, dragging]);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (!ready || !autoplay || dragging || count <= 1 || (!loop && actual === count - 1))
|
|
67
|
+
return;
|
|
68
|
+
const timer = setTimeout(() => move(latest.current + 1, 'autoplay'), swiperNumber(interval, 5000, 16));
|
|
69
|
+
return () => clearTimeout(timer);
|
|
70
|
+
}, [ready, autoplay, dragging, count, loop, actual, interval]);
|
|
71
|
+
const config = typeof indicator === 'object' ? indicator : {}, slot = (node) => typeof node === 'string' || typeof node === 'number' ? <text>{node}</text> : node;
|
|
72
|
+
return <view className={`ui-swiper ${card ? 'ui-swiper-card-motion' : ''} ${className}`} style={{ height: imgDimension(height, 192), ...style }} flatten={false} bindtouchstart={() => {
|
|
73
|
+
'background only';
|
|
74
|
+
pending.current = null;
|
|
75
|
+
}}>
|
|
76
|
+
<view className="ui-swiper-measure" flatten={false} user-interaction-enabled={false} event-through bindlayoutchange={event => { const { width: w, height: h } = event.detail; if (w >= 0 && h >= 0 && Number.isFinite(w) && Number.isFinite(h))
|
|
77
|
+
setBox(previous => previous.width === w && previous.height === h ? previous : { width: w, height: h }); }}/>
|
|
78
|
+
{ready ? <view className="ui-swiper-clip"><view className="ui-swiper-native" style={{ marginLeft: `${before}px`, width: `${viewport}px`, height: `${box.height}px` }}><NativeSwiper ref={native} swiperKey={`${count}:${loop}:${viewport}:${multiple}:${box.height}`} data={data} itemWidth={itemWidth} containerWidth={viewport} itemHeight={box.height} initialIndex={actual} loop={loop && count > 1} duration={swiperNumber(duration, 300)} autoPlay={false} loopDuplicateCount={Math.min(count, Math.max(2, multiple + 1))} main-thread:customAnimation={card ? cardAnimation : undefined} customAnimationFirstScreen={card ? cardFirstFrame : undefined} experimentalHorizontalSwipeOnly mode="normal" modeConfig={{ align: 'start' }} onSwipeStart={() => {
|
|
79
|
+
'background only';
|
|
80
|
+
draggingRef.current = true;
|
|
81
|
+
setDragging(true);
|
|
82
|
+
}} onSwipeStop={change} style={{ overflow: 'visible' }}>
|
|
83
|
+
{({ item, index }) => <NativeSwiperItem><view className={`ui-swiper-item ${customItemClass} ${index === swiperIndex(actual - 1, count, loop) ? customPrevClass : ''} ${index === swiperIndex(actual + 1, count, loop) ? customNextClass : ''}`} style={{ width: `${itemWidth}px`, height: card ? '100%' : `${box.height}px` }} bindtap={() => {
|
|
84
|
+
'background only';
|
|
85
|
+
if (!draggingRef.current)
|
|
86
|
+
onClick?.(index, item);
|
|
87
|
+
}}>
|
|
88
|
+
{renderItem ? slot(renderItem({ item, index })) : <Img className="ui-swiper-image" width="100%" height="100%" src={typeof item === 'string' ? item : typeof item[valueKey] === 'string' ? item[valueKey] : ''} mode={imageMode} showLoading={false} showError={false}/>}
|
|
89
|
+
{typeof item !== 'string' && item[textKey] !== undefined ? <text className={`ui-swiper-title ${customTextClass}`} style={customTextStyle}>{String(item[textKey])}</text> : null}
|
|
90
|
+
</view></NativeSwiperItem>}
|
|
91
|
+
</NativeSwiper></view></view> : null}
|
|
92
|
+
{renderIndicator ? slot(renderIndicator({ current: actual, total: count })) : indicator !== false ? <SwiperNav current={actual} total={count} type={config.type} minShowNum={config.minShowNum} showControls={config.showControls} indicatorPosition={indicatorPosition} className={customIndicatorClass} hidePrev={!loop && actual === 0} hideNext={!loop && actual === count - 1} onSelect={index => move(index)} onChange={({ dir }) => move(actual + (dir === 'next' ? 1 : -1))}/> : null}
|
|
93
|
+
</view>;
|
|
94
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
2
|
+
export type SwiperNavProps = {
|
|
3
|
+
current?: number;
|
|
4
|
+
total?: number;
|
|
5
|
+
type?: 'dots' | 'dots-bar' | 'fraction';
|
|
6
|
+
indicatorPosition?: 'left' | 'top-left' | 'top' | 'top-right' | 'bottom-left' | 'bottom' | 'bottom-right' | 'right';
|
|
7
|
+
minShowNum?: number;
|
|
8
|
+
showControls?: boolean;
|
|
9
|
+
hidePrev?: boolean;
|
|
10
|
+
hideNext?: boolean;
|
|
11
|
+
onChange?: (event: {
|
|
12
|
+
dir: 'prev' | 'next';
|
|
13
|
+
}) => void;
|
|
14
|
+
onSelect?: (index: number) => void;
|
|
15
|
+
className?: string;
|
|
16
|
+
style?: CSSProperties;
|
|
17
|
+
};
|
|
18
|
+
export declare function SwiperNav({ current, total, type, indicatorPosition, minShowNum, showControls, hidePrev, hideNext, onChange, onSelect, className, style }: SwiperNavProps): import("@lynx-js/react").JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Icon } from "./Icon.jsx";
|
|
2
|
+
export function SwiperNav({ current = 0, total = 0, type = 'dots', indicatorPosition = 'bottom', minShowNum = 2, showControls = false, hidePrev = false, hideNext = false, onChange, onSelect, className = '', style }) {
|
|
3
|
+
const count = Number.isFinite(total) ? Math.max(0, Math.floor(total)) : 0, index = Number.isFinite(current) ? Math.max(0, Math.min(count - 1, Math.floor(current))) : 0;
|
|
4
|
+
return <>
|
|
5
|
+
{count >= Math.max(1, Number.isFinite(minShowNum) ? minShowNum : 2) ? <view className={`ui-swiper-indicator ui-swiper-indicator-${type} ui-swiper-indicator-${indicatorPosition} ${className}`} style={style}>
|
|
6
|
+
{type === 'fraction' ? <text className="ui-swiper-fraction">{`${index + 1}/${count}`}</text> : Array.from({ length: count }, (_, i) => <view key={i} className={`ui-swiper-dot ${type === 'dots-bar' ? 'ui-swiper-dot-bar' : ''} ${i === index ? 'ui-swiper-dot-active' : ''}`} catchtap={onSelect ? () => onSelect(i) : undefined}/>)}
|
|
7
|
+
</view> : null}
|
|
8
|
+
{showControls && count > 1 ? <>{!hidePrev ? <view className="ui-swiper-control ui-swiper-control-prev" catchtap={() => onChange?.({ dir: 'prev' })} accessibility-element accessibility-traits="button" accessibility-label="上一张"><Icon name="arrow-left" size={16} color="#fff"/></view> : null}{!hideNext ? <view className="ui-swiper-control ui-swiper-control-next" catchtap={() => onChange?.({ dir: 'next' })} accessibility-element accessibility-traits="button" accessibility-label="下一张"><Icon name="arrow-right" size={16} color="#fff"/></view> : null}</> : null}
|
|
9
|
+
</>;
|
|
10
|
+
}
|
package/dist/Switch.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
3
|
+
import type { LoadingProps } from "./Loading.jsx";
|
|
4
|
+
export type SwitchValue = boolean | string | number;
|
|
5
|
+
export type SwitchProps = {
|
|
6
|
+
value?: SwitchValue;
|
|
7
|
+
defaultValue?: SwitchValue;
|
|
8
|
+
onChange?: (event: {
|
|
9
|
+
value: SwitchValue;
|
|
10
|
+
}) => void;
|
|
11
|
+
activeValue?: SwitchValue;
|
|
12
|
+
inactiveValue?: SwitchValue;
|
|
13
|
+
activeColor?: string;
|
|
14
|
+
inactiveColor?: string;
|
|
15
|
+
size?: number | string;
|
|
16
|
+
shape?: 'round' | 'square';
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
loading?: boolean;
|
|
19
|
+
loadingProps?: Partial<LoadingProps>;
|
|
20
|
+
activeText?: string;
|
|
21
|
+
inactiveText?: string;
|
|
22
|
+
activeIcon?: string | ReactNode;
|
|
23
|
+
inactiveIcon?: string | ReactNode;
|
|
24
|
+
activeActionIcon?: string | ReactNode;
|
|
25
|
+
inactiveActionIcon?: string | ReactNode;
|
|
26
|
+
beforeChange?: (value: SwitchValue) => boolean | Promise<boolean>;
|
|
27
|
+
className?: string;
|
|
28
|
+
style?: CSSProperties;
|
|
29
|
+
accessibilityLabel?: string;
|
|
30
|
+
};
|
|
31
|
+
export declare function Switch({ value, defaultValue, onChange, activeValue, inactiveValue, activeColor, inactiveColor, size, shape, disabled: disabledProp, loading, loadingProps, activeText, inactiveText, activeIcon, inactiveIcon, activeActionIcon, inactiveActionIcon, beforeChange, className, style, accessibilityLabel }: SwitchProps): import("@lynx-js/react").JSX.Element;
|
package/dist/Switch.jsx
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { FormFieldContext } from './formContext.js';
|
|
2
|
+
import { useContext, useEffect, useRef, useState } from '@lynx-js/react';
|
|
3
|
+
import { Icon } from "./Icon.jsx";
|
|
4
|
+
import { Loading } from "./Loading.jsx";
|
|
5
|
+
import { loadingDimension } from './loadingModel.js';
|
|
6
|
+
export function Switch({ value, defaultValue = false, onChange, activeValue = true, inactiveValue = false, activeColor, inactiveColor, size = 26, shape = 'round', disabled: disabledProp, loading = false, loadingProps, activeText = '', inactiveText = '', activeIcon, inactiveIcon, activeActionIcon, inactiveActionIcon, beforeChange, className = '', style, accessibilityLabel = '开关' }) {
|
|
7
|
+
const field = useContext(FormFieldContext), disabled = disabledProp ?? field?.disabled ?? false;
|
|
8
|
+
const [inner, setInner] = useState(defaultValue);
|
|
9
|
+
const [pending, setPending] = useState(false);
|
|
10
|
+
const sequence = useRef(0);
|
|
11
|
+
const busy = useRef(false);
|
|
12
|
+
useEffect(() => { sequence.current++; busy.current = false; setPending(false); return () => { sequence.current++; }; }, [value, activeValue, inactiveValue, disabled, loading]);
|
|
13
|
+
const active = (value === undefined ? inner : value) === activeValue;
|
|
14
|
+
const icon = active ? activeIcon : inactiveIcon;
|
|
15
|
+
const actionIcon = active ? activeActionIcon : inactiveActionIcon;
|
|
16
|
+
const toggle = async () => {
|
|
17
|
+
'background only';
|
|
18
|
+
if (disabled || loading || busy.current)
|
|
19
|
+
return;
|
|
20
|
+
const next = active ? inactiveValue : activeValue;
|
|
21
|
+
const token = ++sequence.current;
|
|
22
|
+
busy.current = true;
|
|
23
|
+
try {
|
|
24
|
+
const decision = beforeChange?.(next) ?? true;
|
|
25
|
+
if (typeof decision !== 'boolean')
|
|
26
|
+
setPending(true);
|
|
27
|
+
if (!await decision || sequence.current !== token)
|
|
28
|
+
return;
|
|
29
|
+
if (value === undefined)
|
|
30
|
+
setInner(next);
|
|
31
|
+
onChange?.({ value: next });
|
|
32
|
+
}
|
|
33
|
+
catch { /* A rejected guard cancels the requested change. */ }
|
|
34
|
+
finally {
|
|
35
|
+
if (sequence.current === token) {
|
|
36
|
+
busy.current = false;
|
|
37
|
+
setPending(false);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const controlStyle = { '--ui-switch-size': loadingDimension(size), backgroundColor: active ? activeColor : inactiveColor, ...style };
|
|
42
|
+
return <view className={`ui-switch ui-switch-${shape} ${active ? 'ui-switch-active' : ''} ${disabled ? 'ui-switch-disabled' : ''} ${className}`} style={controlStyle} bindtap={() => { void toggle(); }} accessibility-element accessibility-traits="button" accessibility-label={`${accessibilityLabel},${active ? '开启' : '关闭'}`}>
|
|
43
|
+
<view className="ui-switch-label">{icon ? typeof icon === 'string' ? <Icon name={icon} size={13} color="#fff"/> : icon : <text>{active ? activeText : inactiveText}</text>}</view>
|
|
44
|
+
<view className="ui-switch-action">{loading || pending ? <Loading size={14} color={activeColor ?? '#1c64fd'} {...loadingProps}/> : actionIcon ? typeof actionIcon === 'string' ? <Icon name={actionIcon} size={16} color={active ? activeColor ?? '#1c64fd' : '#a9acb8'}/> : actionIcon : null}</view>
|
|
45
|
+
</view>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type SyncedInputProps = {
|
|
2
|
+
className?: string;
|
|
3
|
+
value: string;
|
|
4
|
+
placeholder?: string;
|
|
5
|
+
maxlength?: number;
|
|
6
|
+
softInputMode?: 'unspecified' | 'nothing' | 'pan' | 'resize';
|
|
7
|
+
avoidKeyboard?: boolean;
|
|
8
|
+
onInput: (value: string) => void;
|
|
9
|
+
onBlur?: () => void;
|
|
10
|
+
};
|
|
11
|
+
export declare function SyncedInput({ className, value, placeholder, maxlength, softInputMode, avoidKeyboard, onInput, onBlur }: SyncedInputProps): import("@lynx-js/react").JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useEffect, useRef } from '@lynx-js/react';
|
|
2
|
+
export function SyncedInput({ className, value, placeholder, maxlength, softInputMode = 'nothing', avoidKeyboard = false, onInput, onBlur }) {
|
|
3
|
+
const inputRef = useRef(null);
|
|
4
|
+
const nativeValue = useRef(null);
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
if (nativeValue.current === value)
|
|
7
|
+
return;
|
|
8
|
+
inputRef.current?.invoke({
|
|
9
|
+
method: 'setValue',
|
|
10
|
+
params: { value },
|
|
11
|
+
success: () => { nativeValue.current = value; },
|
|
12
|
+
}).exec();
|
|
13
|
+
}, [value]);
|
|
14
|
+
return <input ref={inputRef} className={className} default-value={value} placeholder={placeholder} maxlength={maxlength} set-soft-input-mode={softInputMode} avoid-keyboard={avoidKeyboard} bindinput={(event) => {
|
|
15
|
+
nativeValue.current = event.detail.value;
|
|
16
|
+
onInput(event.detail.value);
|
|
17
|
+
}} bindblur={() => onBlur?.()}/>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type SyncedTextareaProps = {
|
|
2
|
+
className?: string;
|
|
3
|
+
value: string;
|
|
4
|
+
placeholder?: string;
|
|
5
|
+
maxlength?: number;
|
|
6
|
+
maxlines?: number;
|
|
7
|
+
onInput: (value: string) => void;
|
|
8
|
+
onBlur?: () => void;
|
|
9
|
+
};
|
|
10
|
+
export declare function SyncedTextarea({ className, value, placeholder, maxlength, maxlines, onInput, onBlur }: SyncedTextareaProps): import("@lynx-js/react").JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useEffect, useRef } from '@lynx-js/react';
|
|
2
|
+
export function SyncedTextarea({ className, value, placeholder, maxlength, maxlines, onInput, onBlur }) {
|
|
3
|
+
const textareaRef = useRef(null);
|
|
4
|
+
const nativeValue = useRef(null);
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
if (nativeValue.current === value)
|
|
7
|
+
return;
|
|
8
|
+
textareaRef.current?.invoke({
|
|
9
|
+
method: 'setValue',
|
|
10
|
+
params: { value },
|
|
11
|
+
success: () => { nativeValue.current = value; },
|
|
12
|
+
}).exec();
|
|
13
|
+
}, [value]);
|
|
14
|
+
return <textarea ref={textareaRef} className={className} default-value={value} placeholder={placeholder} maxlength={maxlength} maxlines={maxlines} set-soft-input-mode="nothing" avoid-keyboard={false} bindinput={(event) => {
|
|
15
|
+
nativeValue.current = event.detail.value;
|
|
16
|
+
onInput(event.detail.value);
|
|
17
|
+
}} bindblur={() => onBlur?.()}/>;
|
|
18
|
+
}
|
package/dist/Tabbar.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { BadgeProps } from "./Badge.jsx";
|
|
3
|
+
import type { TabbarBeforeChange, TabbarValue } from './tabbarModel.js';
|
|
4
|
+
export type TabbarItem = {
|
|
5
|
+
name?: TabbarValue;
|
|
6
|
+
title?: string;
|
|
7
|
+
icon?: string;
|
|
8
|
+
value?: string | number;
|
|
9
|
+
isDot?: boolean;
|
|
10
|
+
max?: number;
|
|
11
|
+
badgeProps?: Omit<BadgeProps, 'children'>;
|
|
12
|
+
renderIcon?: (state: {
|
|
13
|
+
active: boolean;
|
|
14
|
+
}) => ReactNode;
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
className?: string;
|
|
17
|
+
};
|
|
18
|
+
export type TabbarProps = {
|
|
19
|
+
items: readonly TabbarItem[];
|
|
20
|
+
value?: TabbarValue;
|
|
21
|
+
defaultValue?: TabbarValue;
|
|
22
|
+
onChange?: (event: {
|
|
23
|
+
value: TabbarValue;
|
|
24
|
+
}) => void;
|
|
25
|
+
beforeChange?: TabbarBeforeChange;
|
|
26
|
+
fixed?: boolean;
|
|
27
|
+
placeholder?: boolean;
|
|
28
|
+
bordered?: boolean;
|
|
29
|
+
safeAreaInsetBottom?: boolean;
|
|
30
|
+
bottomSafeAreaHeight?: number;
|
|
31
|
+
shape?: 'default' | 'round';
|
|
32
|
+
activeColor?: string;
|
|
33
|
+
inactiveColor?: string;
|
|
34
|
+
zIndex?: number;
|
|
35
|
+
className?: string;
|
|
36
|
+
};
|
|
37
|
+
export declare function Tabbar({ items, value, defaultValue, onChange, beforeChange, fixed, placeholder, bordered, safeAreaInsetBottom, bottomSafeAreaHeight, shape, activeColor, inactiveColor, zIndex, className }: TabbarProps): import("@lynx-js/react").JSX.Element;
|
package/dist/Tabbar.jsx
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from '@lynx-js/react';
|
|
2
|
+
import { Icon } from "./Icon.jsx";
|
|
3
|
+
import { Badge } from "./Badge.jsx";
|
|
4
|
+
import { createTabbarGuard, tabbarBadge } from './tabbarModel.js';
|
|
5
|
+
export function Tabbar({ items, value, defaultValue = 0, onChange, beforeChange, fixed = false, placeholder = false, bordered = false, safeAreaInsetBottom = false, bottomSafeAreaHeight = 0, shape = 'default', activeColor, inactiveColor, zIndex = 10, className = '' }) {
|
|
6
|
+
const [inner, setInner] = useState(defaultValue);
|
|
7
|
+
const selected = value ?? inner;
|
|
8
|
+
const guard = useRef(createTabbarGuard());
|
|
9
|
+
const names = JSON.stringify(items.map((item, index) => item.name ?? index));
|
|
10
|
+
useEffect(() => { guard.current.cancel(); }, [selected, names]);
|
|
11
|
+
useEffect(() => () => guard.current.cancel(), []);
|
|
12
|
+
const change = (next) => {
|
|
13
|
+
'background only';
|
|
14
|
+
if (next === selected) {
|
|
15
|
+
guard.current.cancel();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
void guard.current.request(next, beforeChange, () => {
|
|
19
|
+
'background only';
|
|
20
|
+
if (value === undefined)
|
|
21
|
+
setInner(next);
|
|
22
|
+
onChange?.({ value: next });
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
const safe = safeAreaInsetBottom && Number.isFinite(bottomSafeAreaHeight) ? Math.max(0, bottomSafeAreaHeight) : 0;
|
|
26
|
+
const bar = <view className={`ui-tabbar ${shape === 'round' ? 'ui-tabbar-round' : bordered ? 'ui-tabbar-bordered' : ''} ${fixed ? 'ui-tabbar-fixed' : ''} ${className}`} style={{ height: `${50 + (fixed && shape === 'default' ? safe : 0)}px`, paddingBottom: `${fixed && shape === 'default' ? safe : 0}px`, ...(fixed ? { bottom: `${shape === 'round' ? safe : 0}px`, zIndex } : {}) }}>
|
|
27
|
+
{items.map((item, index) => {
|
|
28
|
+
const name = item.name ?? index;
|
|
29
|
+
const active = name === selected;
|
|
30
|
+
const color = active ? activeColor : inactiveColor;
|
|
31
|
+
const badge = tabbarBadge(item.value, item.badgeProps?.max ?? item.max);
|
|
32
|
+
return <view key={`${typeof name}:${name}`} className={`ui-tabbar-item ${active ? 'ui-tabbar-item-active' : ''} ${item.className ?? ''}`} accessibility-element accessibility-traits="button" accessibility-label={`${item.title ?? '标签'}${active ? ',已选中' : ''}`} bindtap={() => {
|
|
33
|
+
'background only';
|
|
34
|
+
change(name);
|
|
35
|
+
}}>
|
|
36
|
+
{item.children ?? <view className="ui-tabbar-item-body">
|
|
37
|
+
<Badge value={badge} max={item.max ?? 99} isDot={item.isDot} showZero {...item.badgeProps} className={`ui-tabbar-item-icon ${item.badgeProps?.className ?? ''}`}>
|
|
38
|
+
{item.renderIcon ? item.renderIcon({ active }) : item.icon ? color ? <Icon name={item.icon} size={24} color={color}/> : active ? <><Icon className="ui-tabbar-icon-light" name={item.icon} size={24} color="#f86100"/><Icon className="ui-tabbar-icon-dark" name={item.icon} size={24} color="#ff812e"/></> : <Icon name={item.icon} size={24}/> : null}
|
|
39
|
+
</Badge>
|
|
40
|
+
{item.title ? <text className="ui-tabbar-item-title" style={color ? { color } : undefined}>{item.title}</text> : null}
|
|
41
|
+
</view>}
|
|
42
|
+
</view>;
|
|
43
|
+
})}
|
|
44
|
+
</view>;
|
|
45
|
+
return <>{fixed && placeholder ? <view className="ui-tabbar-placeholder" style={{ height: `${50 + safe}px` }}/> : null}{bar}</>;
|
|
46
|
+
}
|
package/dist/Table.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
3
|
+
import type { SortButtonValue } from "./SortButton.jsx";
|
|
4
|
+
import type { TableSpan } from './tableModel.js';
|
|
5
|
+
export type TableColumn<T> = {
|
|
6
|
+
prop: keyof T & string;
|
|
7
|
+
label?: string;
|
|
8
|
+
width?: number | string;
|
|
9
|
+
sortable?: boolean;
|
|
10
|
+
fixed?: boolean;
|
|
11
|
+
align?: 'left' | 'center' | 'right';
|
|
12
|
+
render?: (scope: {
|
|
13
|
+
row: T;
|
|
14
|
+
index: number;
|
|
15
|
+
}) => ReactNode;
|
|
16
|
+
};
|
|
17
|
+
export type TableSortEvent<T> = Omit<TableColumn<T>, 'render'> & {
|
|
18
|
+
sortDirection: SortButtonValue;
|
|
19
|
+
};
|
|
20
|
+
export type TableSpanScope<T> = {
|
|
21
|
+
row: T;
|
|
22
|
+
column: TableColumn<T>;
|
|
23
|
+
rowIndex: number;
|
|
24
|
+
columnIndex: number;
|
|
25
|
+
};
|
|
26
|
+
export type TableProps<T> = {
|
|
27
|
+
data: readonly T[];
|
|
28
|
+
columns: readonly TableColumn<T>[];
|
|
29
|
+
border?: boolean;
|
|
30
|
+
stripe?: boolean;
|
|
31
|
+
height?: number | string;
|
|
32
|
+
rowHeight?: number;
|
|
33
|
+
showHeader?: boolean;
|
|
34
|
+
ellipsis?: boolean;
|
|
35
|
+
index?: boolean | Partial<TableColumn<T>>;
|
|
36
|
+
fixedHeader?: boolean;
|
|
37
|
+
/** Cell padding in px: one value or [vertical, horizontal]. */
|
|
38
|
+
cellPadding?: number | readonly [number, number];
|
|
39
|
+
spanMethod?: (scope: TableSpanScope<T>) => TableSpan | readonly number[] | void;
|
|
40
|
+
virtual?: boolean;
|
|
41
|
+
buffer?: number;
|
|
42
|
+
rowKey?: keyof T | ((row: T, index: number) => string | number);
|
|
43
|
+
onSortMethod?: (column: TableSortEvent<T>) => void;
|
|
44
|
+
onRowClick?: (event: {
|
|
45
|
+
rowIndex: number;
|
|
46
|
+
}) => void;
|
|
47
|
+
className?: string;
|
|
48
|
+
style?: CSSProperties;
|
|
49
|
+
};
|
|
50
|
+
/** Bounded tables use native scroll-views; virtual mode mounts only a buffered row window. */
|
|
51
|
+
export declare function Table<T>({ data, columns, border, stripe, height, rowHeight, showHeader, ellipsis, index, fixedHeader, cellPadding, spanMethod, virtual, buffer, rowKey, onSortMethod, onRowClick, className, style }: TableProps<T>): import("@lynx-js/react").JSX.Element;
|