@daisu-ui/ui 0.0.0-stage → 0.1.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +67 -0
- package/LICENSE +21 -0
- package/README.md +179 -2
- package/THIRD_PARTY_NOTICES.md +19 -0
- package/dist/ActionSheet.d.ts +45 -0
- package/dist/ActionSheet.jsx +37 -0
- package/dist/AnchoredBubble.d.ts +36 -0
- package/dist/AnchoredBubble.jsx +120 -0
- package/dist/Avatar.d.ts +35 -0
- package/dist/Avatar.jsx +29 -0
- package/dist/Backtop.d.ts +22 -0
- package/dist/Backtop.jsx +18 -0
- package/dist/Badge.d.ts +19 -0
- package/dist/Badge.jsx +11 -0
- package/dist/BarCode.d.ts +20 -0
- package/dist/BarCode.jsx +38 -0
- package/dist/Button.d.ts +21 -0
- package/dist/Button.jsx +19 -0
- package/dist/Calendar.d.ts +90 -0
- package/dist/Calendar.jsx +164 -0
- package/dist/CalendarView.d.ts +51 -0
- package/dist/CalendarView.jsx +136 -0
- package/dist/Card.d.ts +21 -0
- package/dist/Card.jsx +21 -0
- package/dist/Cascader.d.ts +75 -0
- package/dist/Cascader.jsx +212 -0
- package/dist/Cell.d.ts +34 -0
- package/dist/Cell.jsx +37 -0
- package/dist/Checkbox.d.ts +50 -0
- package/dist/Checkbox.jsx +74 -0
- package/dist/Circle.d.ts +19 -0
- package/dist/Circle.jsx +35 -0
- package/dist/Collapse.d.ts +31 -0
- package/dist/Collapse.jsx +61 -0
- package/dist/ConfigProvider.d.ts +15 -0
- package/dist/ConfigProvider.jsx +20 -0
- package/dist/CountDown.d.ts +20 -0
- package/dist/CountDown.jsx +15 -0
- package/dist/CountTo.d.ts +28 -0
- package/dist/CountTo.jsx +27 -0
- package/dist/Curtain.d.ts +29 -0
- package/dist/Curtain.jsx +51 -0
- package/dist/DatetimePicker.d.ts +46 -0
- package/dist/DatetimePicker.jsx +138 -0
- package/dist/DatetimePickerView.d.ts +38 -0
- package/dist/DatetimePickerView.jsx +36 -0
- package/dist/Dialog.d.ts +64 -0
- package/dist/Dialog.jsx +105 -0
- package/dist/Divider.d.ts +16 -0
- package/dist/Divider.jsx +9 -0
- package/dist/DropMenu.d.ts +55 -0
- package/dist/DropMenu.jsx +210 -0
- package/dist/Empty.d.ts +14 -0
- package/dist/Empty.jsx +14 -0
- package/dist/EmptyState.d.ts +6 -0
- package/dist/EmptyState.jsx +9 -0
- package/dist/Fab.d.ts +30 -0
- package/dist/Fab.jsx +127 -0
- package/dist/FloatingPanel.d.ts +21 -0
- package/dist/FloatingPanel.jsx +102 -0
- package/dist/Form.d.ts +63 -0
- package/dist/Form.jsx +108 -0
- package/dist/FormFieldRow.d.ts +56 -0
- package/dist/FormFieldRow.jsx +63 -0
- package/dist/Gap.d.ts +10 -0
- package/dist/Gap.jsx +14 -0
- package/dist/Grid.d.ts +47 -0
- package/dist/Grid.jsx +31 -0
- package/dist/Icon.d.ts +11 -0
- package/dist/Icon.jsx +12 -0
- package/dist/ImagePreview.d.ts +62 -0
- package/dist/ImagePreview.jsx +78 -0
- package/dist/Img.d.ts +28 -0
- package/dist/Img.jsx +59 -0
- package/dist/ImgCropper.d.ts +74 -0
- package/dist/ImgCropper.jsx +114 -0
- package/dist/IndexBar.d.ts +36 -0
- package/dist/IndexBar.jsx +149 -0
- package/dist/Input.d.ts +11 -0
- package/dist/Input.jsx +3 -0
- package/dist/InputNumber.d.ts +32 -0
- package/dist/InputNumber.jsx +165 -0
- package/dist/Keyboard.d.ts +37 -0
- package/dist/Keyboard.jsx +130 -0
- package/dist/Layout.d.ts +31 -0
- package/dist/Layout.jsx +14 -0
- package/dist/Loading.d.ts +18 -0
- package/dist/Loading.jsx +15 -0
- package/dist/Loadmore.d.ts +18 -0
- package/dist/Loadmore.jsx +16 -0
- package/dist/Navbar.d.ts +35 -0
- package/dist/Navbar.jsx +50 -0
- package/dist/NoticeBar.d.ts +30 -0
- package/dist/NoticeBar.jsx +86 -0
- package/dist/Notify.d.ts +34 -0
- package/dist/Notify.jsx +52 -0
- package/dist/NumberStepper.d.ts +11 -0
- package/dist/NumberStepper.jsx +41 -0
- package/dist/Overlay.d.ts +16 -0
- package/dist/Overlay.jsx +12 -0
- package/dist/PagedList.d.ts +13 -0
- package/dist/PagedList.jsx +36 -0
- package/dist/Pagination.d.ts +29 -0
- package/dist/Pagination.jsx +33 -0
- package/dist/PasswordInput.d.ts +16 -0
- package/dist/PasswordInput.jsx +20 -0
- package/dist/Picker.d.ts +61 -0
- package/dist/Picker.jsx +80 -0
- package/dist/PickerView.d.ts +43 -0
- package/dist/PickerView.jsx +142 -0
- package/dist/Popover.d.ts +23 -0
- package/dist/Popover.jsx +35 -0
- package/dist/Popup.d.ts +30 -0
- package/dist/Popup.jsx +32 -0
- package/dist/Progress.d.ts +17 -0
- package/dist/Progress.jsx +45 -0
- package/dist/QrCode.d.ts +46 -0
- package/dist/QrCode.jsx +67 -0
- package/dist/Radio.d.ts +21 -0
- package/dist/Radio.jsx +34 -0
- package/dist/Rate.d.ts +25 -0
- package/dist/Rate.jsx +39 -0
- package/dist/Resize.d.ts +17 -0
- package/dist/Resize.jsx +17 -0
- package/dist/RichText.d.ts +133 -0
- package/dist/RichText.jsx +288 -0
- package/dist/RootPortal.d.ts +11 -0
- package/dist/RootPortal.jsx +19 -0
- package/dist/Search.d.ts +39 -0
- package/dist/Search.jsx +94 -0
- package/dist/Segmented.d.ts +18 -0
- package/dist/Segmented.jsx +35 -0
- package/dist/SelectPicker.d.ts +54 -0
- package/dist/SelectPicker.jsx +136 -0
- package/dist/Sidebar.d.ts +34 -0
- package/dist/Sidebar.jsx +43 -0
- package/dist/Signature.d.ts +46 -0
- package/dist/Signature.jsx +203 -0
- package/dist/Skeleton.d.ts +27 -0
- package/dist/Skeleton.jsx +29 -0
- package/dist/SlideVerify.d.ts +27 -0
- package/dist/SlideVerify.jsx +138 -0
- package/dist/Slider.d.ts +21 -0
- package/dist/Slider.jsx +131 -0
- package/dist/SortButton.d.ts +16 -0
- package/dist/SortButton.jsx +19 -0
- package/dist/Steps.d.ts +23 -0
- package/dist/Steps.jsx +25 -0
- package/dist/Sticky.d.ts +17 -0
- package/dist/Sticky.jsx +69 -0
- package/dist/SwipeAction.d.ts +27 -0
- package/dist/SwipeAction.jsx +187 -0
- package/dist/Swiper.d.ts +54 -0
- package/dist/Swiper.jsx +94 -0
- package/dist/SwiperNav.d.ts +18 -0
- package/dist/SwiperNav.jsx +10 -0
- package/dist/Switch.d.ts +31 -0
- package/dist/Switch.jsx +46 -0
- package/dist/SyncedInput.d.ts +12 -0
- package/dist/SyncedInput.jsx +18 -0
- package/dist/SyncedTextarea.d.ts +11 -0
- package/dist/SyncedTextarea.jsx +18 -0
- package/dist/Tabbar.d.ts +37 -0
- package/dist/Tabbar.jsx +46 -0
- package/dist/Table.d.ts +51 -0
- package/dist/Table.jsx +125 -0
- package/dist/Tabs.d.ts +65 -0
- package/dist/Tabs.jsx +132 -0
- package/dist/Tag.d.ts +33 -0
- package/dist/Tag.jsx +63 -0
- package/dist/Text.d.ts +19 -0
- package/dist/Text.jsx +7 -0
- package/dist/TextField.d.ts +89 -0
- package/dist/TextField.jsx +149 -0
- package/dist/Textarea.d.ts +22 -0
- package/dist/Textarea.jsx +3 -0
- package/dist/Toast.d.ts +36 -0
- package/dist/Toast.jsx +30 -0
- package/dist/Tooltip.d.ts +8 -0
- package/dist/Tooltip.jsx +5 -0
- package/dist/Tour.d.ts +85 -0
- package/dist/Tour.jsx +150 -0
- package/dist/Transition.d.ts +32 -0
- package/dist/Transition.jsx +43 -0
- package/dist/Upload.d.ts +64 -0
- package/dist/Upload.jsx +163 -0
- package/dist/VideoPreview.d.ts +47 -0
- package/dist/VideoPreview.jsx +59 -0
- package/dist/Watermark.d.ts +36 -0
- package/dist/Watermark.jsx +18 -0
- package/dist/action-sheet.css +19 -0
- package/dist/avatar.css +23 -0
- package/dist/avatarModel.d.ts +8 -0
- package/dist/avatarModel.js +17 -0
- package/dist/backtop.css +6 -0
- package/dist/badge.css +15 -0
- package/dist/badgeModel.d.ts +2 -0
- package/dist/badgeModel.js +18 -0
- package/dist/bar-code.css +5 -0
- package/dist/barCodeModel.d.ts +80 -0
- package/dist/barCodeModel.js +99 -0
- package/dist/brand/logo.svg +8 -0
- package/dist/bubble.css +14 -0
- package/dist/bubblePosition.d.ts +19 -0
- package/dist/bubblePosition.js +41 -0
- package/dist/button.css +56 -0
- package/dist/calendar.css +56 -0
- package/dist/calendarModel.d.ts +62 -0
- package/dist/calendarModel.js +141 -0
- package/dist/card.css +8 -0
- package/dist/cascader.css +16 -0
- package/dist/cascaderModel.d.ts +21 -0
- package/dist/cascaderModel.js +32 -0
- package/dist/cell.css +41 -0
- package/dist/choice.css +27 -0
- package/dist/choice.d.ts +28 -0
- package/dist/choice.jsx +16 -0
- package/dist/circle.css +4 -0
- package/dist/circleModel.d.ts +15 -0
- package/dist/circleModel.js +31 -0
- package/dist/config-provider.css +2 -0
- package/dist/configContext.d.ts +23 -0
- package/dist/configContext.js +24 -0
- package/dist/configTheme.d.ts +3 -0
- package/dist/configTheme.js +22 -0
- package/dist/count-down.css +2 -0
- package/dist/count-to.css +8 -0
- package/dist/countDownModel.d.ts +11 -0
- package/dist/countDownModel.js +7 -0
- package/dist/countToModel.d.ts +3 -0
- package/dist/countToModel.js +3 -0
- package/dist/curtain.css +10 -0
- package/dist/datetime-picker.css +11 -0
- package/dist/datetimePickerModel.d.ts +47 -0
- package/dist/datetimePickerModel.js +128 -0
- package/dist/dialog.css +23 -0
- package/dist/divider.css +14 -0
- package/dist/drop-menu.css +28 -0
- package/dist/empty.css +7 -0
- package/dist/fab.css +23 -0
- package/dist/fabModel.d.ts +26 -0
- package/dist/fabModel.js +16 -0
- package/dist/floating-panel.css +6 -0
- package/dist/floatingPanelModel.d.ts +3 -0
- package/dist/floatingPanelModel.js +10 -0
- package/dist/form.css +10 -0
- package/dist/formContext.d.ts +7 -0
- package/dist/formContext.js +2 -0
- package/dist/formModel.d.ts +38 -0
- package/dist/formModel.js +16 -0
- package/dist/gap.css +1 -0
- package/dist/grid.css +17 -0
- package/dist/icon.css +8 -0
- package/dist/icons/LICENSE.tabler +21 -0
- package/dist/icons/paths.d.ts +309 -0
- package/dist/icons/paths.js +310 -0
- package/dist/icons/render.d.ts +2 -0
- package/dist/icons/render.js +5 -0
- package/dist/image-preview.css +8 -0
- package/dist/img-cropper.css +1 -0
- package/dist/img.css +5 -0
- package/dist/imgCropperModel.d.ts +55 -0
- package/dist/imgCropperModel.js +41 -0
- package/dist/imgModel.d.ts +13 -0
- package/dist/imgModel.js +22 -0
- package/dist/index-bar.css +12 -0
- package/dist/index.d.ts +200 -0
- package/dist/index.js +99 -0
- package/dist/indexBarModel.d.ts +19 -0
- package/dist/indexBarModel.js +37 -0
- package/dist/input-number.css +24 -0
- package/dist/inputNumberModel.d.ts +23 -0
- package/dist/inputNumberModel.js +40 -0
- package/dist/keyboard.css +26 -0
- package/dist/keyboardModel.d.ts +11 -0
- package/dist/keyboardModel.js +34 -0
- package/dist/layout.css +2 -0
- package/dist/legacy/RadioGroup.d.ts +13 -0
- package/dist/legacy/RadioGroup.jsx +13 -0
- package/dist/legacy-controls.css +87 -0
- package/dist/loading.css +31 -0
- package/dist/loadingModel.d.ts +2 -0
- package/dist/loadingModel.js +21 -0
- package/dist/loadmore.css +5 -0
- package/dist/navbar.css +16 -0
- package/dist/notice-bar.css +19 -0
- package/dist/notify.css +14 -0
- package/dist/overlay.css +2 -0
- package/dist/pagination.css +12 -0
- package/dist/paginationModel.d.ts +6 -0
- package/dist/paginationModel.js +7 -0
- package/dist/password-input.css +14 -0
- package/dist/passwordInputModel.d.ts +6 -0
- package/dist/passwordInputModel.js +11 -0
- package/dist/picker.css +42 -0
- package/dist/pickerModel.d.ts +32 -0
- package/dist/pickerModel.js +49 -0
- package/dist/popover.css +5 -0
- package/dist/popup.css +17 -0
- package/dist/progress.css +16 -0
- package/dist/progressModel.d.ts +12 -0
- package/dist/progressModel.js +19 -0
- package/dist/qr-code.css +4 -0
- package/dist/qrCodeModel.d.ts +36 -0
- package/dist/qrCodeModel.js +61 -0
- package/dist/rate.css +20 -0
- package/dist/rateModel.d.ts +4 -0
- package/dist/rateModel.js +38 -0
- package/dist/resize.css +2 -0
- package/dist/rich-text.css +19 -0
- package/dist/richTextMedia.d.ts +28 -0
- package/dist/richTextMedia.js +3 -0
- package/dist/richTextModel.d.ts +52 -0
- package/dist/richTextModel.js +195 -0
- package/dist/root-portal.css +1 -0
- package/dist/router/RouterView.d.ts +21 -0
- package/dist/router/RouterView.jsx +120 -0
- package/dist/router/core.d.ts +85 -0
- package/dist/router/core.js +255 -0
- package/dist/router/hooks.d.ts +17 -0
- package/dist/router/hooks.jsx +71 -0
- package/dist/router/index.d.ts +5 -0
- package/dist/router/index.js +3 -0
- package/dist/router/location.d.ts +8 -0
- package/dist/router/location.js +46 -0
- package/dist/router/router.css +7 -0
- package/dist/router/runtime.d.ts +1 -0
- package/dist/router/runtime.js +25 -0
- package/dist/search.css +23 -0
- package/dist/segmented.css +19 -0
- package/dist/segmentedModel.d.ts +10 -0
- package/dist/segmentedModel.js +8 -0
- package/dist/sidebar.css +18 -0
- package/dist/sidebarModel.d.ts +8 -0
- package/dist/sidebarModel.js +27 -0
- package/dist/signature.css +5 -0
- package/dist/signatureModel.d.ts +23 -0
- package/dist/signatureModel.js +80 -0
- package/dist/skeleton.css +16 -0
- package/dist/slide-verify.css +7 -0
- package/dist/slider.css +49 -0
- package/dist/sliderModel.d.ts +10 -0
- package/dist/sliderModel.js +27 -0
- package/dist/sort-button.css +12 -0
- package/dist/steps.css +35 -0
- package/dist/sticky.css +7 -0
- package/dist/styles.css +136 -0
- package/dist/styles.d.ts +1 -0
- package/dist/swipe-action.css +6 -0
- package/dist/swiper.css +27 -0
- package/dist/swiperAnimation.d.ts +3 -0
- package/dist/swiperAnimation.js +6 -0
- package/dist/swiperModel.d.ts +2 -0
- package/dist/swiperModel.js +3 -0
- package/dist/switch.css +12 -0
- package/dist/tabbar.css +17 -0
- package/dist/tabbarModel.d.ts +8 -0
- package/dist/tabbarModel.js +27 -0
- package/dist/table.css +21 -0
- package/dist/tableModel.d.ts +10 -0
- package/dist/tableModel.js +17 -0
- package/dist/tabs.css +31 -0
- package/dist/tabsModel.d.ts +7 -0
- package/dist/tabsModel.js +14 -0
- package/dist/tag.css +66 -0
- package/dist/text-field.css +15 -0
- package/dist/text.css +7 -0
- package/dist/textModel.d.ts +3 -0
- package/dist/textModel.js +24 -0
- package/dist/toast.css +13 -0
- package/dist/tokens.d.ts +34 -0
- package/dist/tokens.js +10 -0
- package/dist/tour.css +8 -0
- package/dist/transition.css +12 -0
- package/dist/upload.css +11 -0
- package/dist/useCountDown.d.ts +14 -0
- package/dist/useCountDown.js +73 -0
- package/dist/useDialog.d.ts +9 -0
- package/dist/useDialog.js +33 -0
- package/dist/useImagePreview.d.ts +7 -0
- package/dist/useImagePreview.js +17 -0
- package/dist/useNotify.d.ts +9 -0
- package/dist/useNotify.js +26 -0
- package/dist/usePressState.d.ts +6 -0
- package/dist/usePressState.js +17 -0
- package/dist/useToast.d.ts +11 -0
- package/dist/useToast.js +23 -0
- package/dist/useVideoPreview.d.ts +7 -0
- package/dist/useVideoPreview.js +17 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +4 -0
- package/dist/video-preview.css +7 -0
- package/dist/watermark.css +6 -0
- package/dist/web/imgCropperElement.d.ts +2 -0
- package/dist/web/imgCropperElement.js +309 -0
- package/dist/web/index.d.ts +6 -0
- package/dist/web/index.js +6 -0
- package/dist/web/qrCodeExportElement.d.ts +4 -0
- package/dist/web/qrCodeExportElement.js +70 -0
- package/dist/web/richTextMediaElement.d.ts +2 -0
- package/dist/web/richTextMediaElement.js +276 -0
- package/package.json +98 -4
package/dist/Divider.jsx
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function Divider({ children, label, align = 'center', contentPosition = align, color, hairline = true, dashed = false, vertical = false, className = '', style }) {
|
|
2
|
+
const content = children ?? label;
|
|
3
|
+
const hasContent = !vertical && content !== undefined && content !== null && content !== false && content !== '';
|
|
4
|
+
const line = <view className="ui-divider-line"/>;
|
|
5
|
+
return <view className={`ui-divider ui-divider-${contentPosition} ${hasContent ? 'ui-divider-with-content' : ''} ${hairline ? 'ui-divider-hairline' : ''} ${dashed ? 'ui-divider-dashed' : ''} ${vertical ? 'ui-divider-vertical' : ''} ${className}`} style={style}>
|
|
6
|
+
{line}
|
|
7
|
+
{hasContent ? <><view className="ui-divider-content">{typeof content === 'string' || typeof content === 'number' ? <text className="ui-divider-label" style={{ color }}>{content}</text> : content}</view><view className="ui-divider-line"/></> : null}
|
|
8
|
+
</view>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
3
|
+
export type DropMenuProps = {
|
|
4
|
+
zIndex?: number;
|
|
5
|
+
direction?: 'down' | 'up';
|
|
6
|
+
topOffset?: number;
|
|
7
|
+
modal?: boolean;
|
|
8
|
+
closeOnClickModal?: boolean;
|
|
9
|
+
duration?: number;
|
|
10
|
+
className?: string;
|
|
11
|
+
style?: CSSProperties;
|
|
12
|
+
children?: ReactNode;
|
|
13
|
+
};
|
|
14
|
+
export type DropMenuValue = string | number;
|
|
15
|
+
export type DropMenuOption = Record<string, unknown>;
|
|
16
|
+
export type DropMenuItemRef = {
|
|
17
|
+
getShowPop: () => boolean;
|
|
18
|
+
open: () => void;
|
|
19
|
+
close: () => void;
|
|
20
|
+
toggle: () => void;
|
|
21
|
+
};
|
|
22
|
+
export type DropMenuItemProps = {
|
|
23
|
+
value?: DropMenuValue;
|
|
24
|
+
defaultValue?: DropMenuValue;
|
|
25
|
+
onChange?: (event: {
|
|
26
|
+
value: DropMenuValue;
|
|
27
|
+
selectedItem: DropMenuOption;
|
|
28
|
+
}) => void;
|
|
29
|
+
options?: readonly DropMenuOption[];
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
title?: string;
|
|
32
|
+
icon?: string;
|
|
33
|
+
iconSize?: number;
|
|
34
|
+
iconName?: string;
|
|
35
|
+
activeColor?: string;
|
|
36
|
+
beforeToggle?: (event: {
|
|
37
|
+
status: boolean;
|
|
38
|
+
}) => boolean | Promise<boolean>;
|
|
39
|
+
valueKey?: string;
|
|
40
|
+
labelKey?: string;
|
|
41
|
+
tipKey?: string;
|
|
42
|
+
popupClassName?: string;
|
|
43
|
+
popupStyle?: CSSProperties;
|
|
44
|
+
popupHeight?: string | number;
|
|
45
|
+
rootPortal?: boolean;
|
|
46
|
+
className?: string;
|
|
47
|
+
style?: CSSProperties;
|
|
48
|
+
children?: ReactNode;
|
|
49
|
+
onOpen?: () => void;
|
|
50
|
+
onOpened?: () => void;
|
|
51
|
+
onClose?: () => void;
|
|
52
|
+
onClosed?: () => void;
|
|
53
|
+
};
|
|
54
|
+
export declare function DropMenu({ zIndex, direction, topOffset, modal, closeOnClickModal, duration, className, style, children }: DropMenuProps): import("@lynx-js/react").JSX.Element;
|
|
55
|
+
export declare const DropMenuItem: (props: DropMenuItemProps & import("react").RefAttributes<DropMenuItemRef>) => React.ReactElement | null;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { createContext, forwardRef, useContext, useEffect, useImperativeHandle, useRef, useState } from '@lynx-js/react';
|
|
2
|
+
import { Icon } from "./Icon.jsx";
|
|
3
|
+
import { Overlay } from "./Overlay.jsx";
|
|
4
|
+
import { RootPortal } from "./RootPortal.jsx";
|
|
5
|
+
import { Transition } from "./Transition.jsx";
|
|
6
|
+
const MenuContext = createContext(undefined);
|
|
7
|
+
function anchorStyle(rect, direction, topOffset = 0) {
|
|
8
|
+
return direction === 'down' ? { top: `${Math.max(0, rect?.bottom ?? 0)}px`, bottom: 0 } : { top: `${Math.max(0, topOffset)}px`, bottom: `calc(100% - ${Math.max(0, rect?.top ?? 0)}px)` };
|
|
9
|
+
}
|
|
10
|
+
export function DropMenu({ zIndex = 12, direction = 'down', topOffset = 0, modal = true, closeOnClickModal = true, duration = 200, className = '', style, children }) {
|
|
11
|
+
const node = useRef(null);
|
|
12
|
+
const [active, setActive] = useState();
|
|
13
|
+
const [rect, setRect] = useState();
|
|
14
|
+
const activeRef = useRef();
|
|
15
|
+
const lastPortal = useRef(false);
|
|
16
|
+
const generation = useRef(0);
|
|
17
|
+
const measure = () => {
|
|
18
|
+
'background only';
|
|
19
|
+
return new Promise(resolve => {
|
|
20
|
+
if (!node.current) {
|
|
21
|
+
resolve(undefined);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
node.current.invoke({ method: 'boundingClientRect', params: { androidEnableTransformProps: true, iosEnableTransformProps: true }, success: (result) => {
|
|
25
|
+
'background only';
|
|
26
|
+
const value = result;
|
|
27
|
+
resolve(value && typeof value.top === 'number' && typeof value.bottom === 'number' && Number.isFinite(value.top) && Number.isFinite(value.bottom) ? { top: value.top, bottom: value.bottom } : undefined);
|
|
28
|
+
}, fail: () => resolve(undefined) }).exec();
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
const close = (id) => {
|
|
32
|
+
'background only';
|
|
33
|
+
if (activeRef.current?.id === id) {
|
|
34
|
+
activeRef.current = undefined;
|
|
35
|
+
setActive(undefined);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
useEffect(() => () => { generation.current++; activeRef.current = undefined; }, []);
|
|
39
|
+
const context = {
|
|
40
|
+
active: active?.id, rect, direction, topOffset, duration, zIndex,
|
|
41
|
+
claim: () => {
|
|
42
|
+
'background only';
|
|
43
|
+
return ++generation.current;
|
|
44
|
+
},
|
|
45
|
+
isCurrent: ticket => {
|
|
46
|
+
'background only';
|
|
47
|
+
return ticket === generation.current;
|
|
48
|
+
},
|
|
49
|
+
measure,
|
|
50
|
+
activate: (item, nextRect) => {
|
|
51
|
+
'background only';
|
|
52
|
+
lastPortal.current = item.portal;
|
|
53
|
+
activeRef.current = item;
|
|
54
|
+
setRect(nextRect);
|
|
55
|
+
setActive(item);
|
|
56
|
+
},
|
|
57
|
+
close,
|
|
58
|
+
};
|
|
59
|
+
return <MenuContext.Provider value={context}>
|
|
60
|
+
<view ref={node} flatten={false} className={`ui-drop-menu ${className}`} style={style} bindlayoutchange={() => {
|
|
61
|
+
'background only';
|
|
62
|
+
const current = activeRef.current;
|
|
63
|
+
if (current)
|
|
64
|
+
void measure().then(next => {
|
|
65
|
+
'background only';
|
|
66
|
+
if (next && current === activeRef.current)
|
|
67
|
+
setRect(next);
|
|
68
|
+
});
|
|
69
|
+
}}>{children}</view>
|
|
70
|
+
{modal ? <Overlay show={!!active} rootPortal={lastPortal.current} zIndex={zIndex} duration={duration} style={anchorStyle(rect, direction, topOffset)} onTap={() => {
|
|
71
|
+
'background only';
|
|
72
|
+
if (closeOnClickModal)
|
|
73
|
+
activeRef.current?.close();
|
|
74
|
+
}}/> : null}
|
|
75
|
+
</MenuContext.Provider>;
|
|
76
|
+
}
|
|
77
|
+
function SelectedIcon({ name, size, color }) {
|
|
78
|
+
return color ? <Icon name={name} size={size} color={color}/> : <><Icon name={name} size={size} color="#f86100" className="ui-drop-menu-primary-light"/><Icon name={name} size={size} color="#ff812e" className="ui-drop-menu-primary-dark"/></>;
|
|
79
|
+
}
|
|
80
|
+
export const DropMenuItem = forwardRef(function DropMenuItem({ value, defaultValue, onChange, options = [], disabled = false, title, icon = 'caret-down', iconSize = 16, iconName = 'check', activeColor, beforeToggle, valueKey = 'value', labelKey = 'label', tipKey = 'tip', popupClassName = '', popupStyle, popupHeight, rootPortal = false, className = '', style, children, onOpen, onOpened, onClose, onClosed }, ref) {
|
|
81
|
+
const menu = useContext(MenuContext);
|
|
82
|
+
if (!menu)
|
|
83
|
+
throw new Error('DropMenuItem requires a DropMenu parent.');
|
|
84
|
+
const id = useRef({}).current;
|
|
85
|
+
const [inner, setInner] = useState(defaultValue);
|
|
86
|
+
const [present, setPresent] = useState(false);
|
|
87
|
+
const [hidden, setHidden] = useState(true);
|
|
88
|
+
const [height, setHeight] = useState(0);
|
|
89
|
+
const show = menu.active === id;
|
|
90
|
+
const current = value === undefined ? inner : value;
|
|
91
|
+
const selected = options.find(item => item[valueKey] === current);
|
|
92
|
+
const label = title ?? String(selected?.[labelKey] ?? '');
|
|
93
|
+
const requestId = useRef(0);
|
|
94
|
+
const pending = useRef(undefined);
|
|
95
|
+
const latest = useRef({ menu, disabled, show, beforeToggle, rootPortal });
|
|
96
|
+
latest.current = { menu, disabled, show, beforeToggle, rootPortal };
|
|
97
|
+
const requestRef = useRef(() => { });
|
|
98
|
+
const request = (status) => {
|
|
99
|
+
'background only';
|
|
100
|
+
const state = latest.current;
|
|
101
|
+
if (state.disabled || pending.current === status)
|
|
102
|
+
return;
|
|
103
|
+
if (state.show === status) {
|
|
104
|
+
requestId.current++;
|
|
105
|
+
pending.current = undefined;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const sequence = ++requestId.current;
|
|
109
|
+
pending.current = status;
|
|
110
|
+
const ticket = status ? state.menu.claim() : undefined;
|
|
111
|
+
const valid = () => sequence === requestId.current && !latest.current.disabled && (ticket === undefined || latest.current.menu.isCurrent(ticket));
|
|
112
|
+
void (async () => {
|
|
113
|
+
try {
|
|
114
|
+
if (state.beforeToggle && !await state.beforeToggle({ status }))
|
|
115
|
+
return;
|
|
116
|
+
if (!valid())
|
|
117
|
+
return;
|
|
118
|
+
if (status) {
|
|
119
|
+
const nextRect = await latest.current.menu.measure();
|
|
120
|
+
if (!nextRect || !valid())
|
|
121
|
+
return;
|
|
122
|
+
setPresent(true);
|
|
123
|
+
setHidden(false);
|
|
124
|
+
latest.current.menu.activate({ id, portal: latest.current.rootPortal, close: () => {
|
|
125
|
+
'background only';
|
|
126
|
+
requestRef.current(false);
|
|
127
|
+
} }, nextRect);
|
|
128
|
+
}
|
|
129
|
+
else
|
|
130
|
+
latest.current.menu.close(id);
|
|
131
|
+
}
|
|
132
|
+
catch { /* A rejected guard cancels only this item's request. */ }
|
|
133
|
+
finally {
|
|
134
|
+
if (sequence === requestId.current)
|
|
135
|
+
pending.current = undefined;
|
|
136
|
+
}
|
|
137
|
+
})();
|
|
138
|
+
};
|
|
139
|
+
requestRef.current = request;
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
if (disabled) {
|
|
142
|
+
requestId.current++;
|
|
143
|
+
pending.current = undefined;
|
|
144
|
+
menu.close(id);
|
|
145
|
+
}
|
|
146
|
+
}, [disabled]);
|
|
147
|
+
useEffect(() => () => { requestId.current++; latest.current.menu.close(id); }, []);
|
|
148
|
+
useImperativeHandle(ref, () => ({
|
|
149
|
+
getShowPop: () => {
|
|
150
|
+
'background only';
|
|
151
|
+
return latest.current.show;
|
|
152
|
+
},
|
|
153
|
+
open: () => {
|
|
154
|
+
'background only';
|
|
155
|
+
requestRef.current(true);
|
|
156
|
+
},
|
|
157
|
+
close: () => {
|
|
158
|
+
'background only';
|
|
159
|
+
requestRef.current(false);
|
|
160
|
+
},
|
|
161
|
+
toggle: () => {
|
|
162
|
+
'background only';
|
|
163
|
+
requestRef.current(!(pending.current ?? latest.current.show));
|
|
164
|
+
},
|
|
165
|
+
}), []);
|
|
166
|
+
const select = (option) => {
|
|
167
|
+
'background only';
|
|
168
|
+
const next = option[valueKey];
|
|
169
|
+
if (!latest.current.show || disabled || typeof next !== 'string' && typeof next !== 'number')
|
|
170
|
+
return;
|
|
171
|
+
if (next !== current) {
|
|
172
|
+
if (value === undefined)
|
|
173
|
+
setInner(next);
|
|
174
|
+
onChange?.({ value: next, selectedItem: option });
|
|
175
|
+
}
|
|
176
|
+
request(false);
|
|
177
|
+
};
|
|
178
|
+
const layer = present ? <view className={`ui-drop-menu-layer ui-drop-menu-layer-${menu.direction}`} style={{ ...anchorStyle(menu.rect, menu.direction, menu.topOffset), zIndex: menu.zIndex + 1, display: hidden ? 'none' : 'flex' }} event-through>
|
|
179
|
+
<Transition show={show} name={menu.direction === 'down' ? 'slide-down' : 'slide-up'} duration={menu.duration} lazyRender destroy={false} interactiveDuringLeave className={`ui-drop-menu-popup ${popupClassName}`} style={popupStyle} onBeforeEnter={onOpen} onAfterEnter={onOpened} onBeforeLeave={onClose} onAfterLeave={() => {
|
|
180
|
+
'background only';
|
|
181
|
+
setHidden(true);
|
|
182
|
+
onClosed?.();
|
|
183
|
+
}}>
|
|
184
|
+
<scroll-view className="ui-drop-menu-scroll" scroll-orientation="vertical" scroll-y scroll-bar-enable={false} style={{ height: popupHeight === undefined ? `${height}px` : typeof popupHeight === 'number' ? `${Math.max(0, popupHeight)}px` : popupHeight }}>
|
|
185
|
+
<view className="ui-drop-menu-content" flatten={false} bindlayoutchange={event => {
|
|
186
|
+
'background only';
|
|
187
|
+
const next = event.detail.height;
|
|
188
|
+
if (Number.isFinite(next) && next !== height)
|
|
189
|
+
setHeight(next);
|
|
190
|
+
}} catchtap={() => { }}>
|
|
191
|
+
{children ?? <view className="ui-drop-menu-options">
|
|
192
|
+
{options.map((option, index) => {
|
|
193
|
+
const active = option[valueKey] === current;
|
|
194
|
+
return <view key={`${typeof option[valueKey]}:${String(option[valueKey])}:${index}`} className={`ui-drop-menu-option ${active ? 'ui-drop-menu-option-selected' : ''}`} bindtap={() => select(option)} accessibility-element accessibility-traits="button" accessibility-label={`${String(option[labelKey] ?? '')}${active ? ',已选中' : ''}`}>
|
|
195
|
+
<view className="ui-drop-menu-option-copy"><text className="ui-drop-menu-option-label" style={active ? { color: activeColor } : undefined} text-maxline="1" text-overflow="ellipsis">{String(option[labelKey] ?? '')}</text>{option[tipKey] ? <text className="ui-drop-menu-option-tip" style={active ? { color: activeColor } : undefined} text-maxline="1" text-overflow="ellipsis">{String(option[tipKey])}</text> : null}</view>
|
|
196
|
+
{active && iconName ? <SelectedIcon name={iconName} size={20} color={activeColor}/> : null}
|
|
197
|
+
</view>;
|
|
198
|
+
})}
|
|
199
|
+
</view>}
|
|
200
|
+
</view>
|
|
201
|
+
</scroll-view>
|
|
202
|
+
</Transition>
|
|
203
|
+
</view> : null;
|
|
204
|
+
return <>
|
|
205
|
+
<view className={`ui-drop-menu-item ${show ? 'ui-drop-menu-item-open' : ''} ${disabled ? 'ui-drop-menu-item-disabled' : ''} ${className}`} style={style} catchtap={() => request(!(pending.current ?? show))} accessibility-element accessibility-traits="button" accessibility-label={`${label}${disabled ? ',已禁用' : show ? ',已展开' : ',已折叠'}`}>
|
|
206
|
+
<view className="ui-drop-menu-title"><text className="ui-drop-menu-title-text" style={show ? { color: activeColor } : undefined} text-maxline="1" text-overflow="ellipsis">{label}</text>{icon ? <view className="ui-drop-menu-arrow" style={{ transform: `rotate(${show ? 180 : 0}deg)`, transitionDuration: `${menu.duration}ms` }}>{show ? <SelectedIcon name={icon} size={iconSize} color={activeColor}/> : <><Icon name={icon} size={iconSize} color="#868a9c" className="ui-drop-menu-primary-light"/><Icon name={icon} size={iconSize} color="#a9acb8" className="ui-drop-menu-primary-dark"/></>}</view> : null}</view>
|
|
207
|
+
</view>
|
|
208
|
+
{rootPortal ? <RootPortal>{layer}</RootPortal> : layer}
|
|
209
|
+
</>;
|
|
210
|
+
});
|
package/dist/Empty.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
3
|
+
export type EmptyProps = {
|
|
4
|
+
icon?: string;
|
|
5
|
+
iconSize?: number | string;
|
|
6
|
+
iconColor?: string;
|
|
7
|
+
tip?: ReactNode;
|
|
8
|
+
image?: ReactNode;
|
|
9
|
+
bottom?: ReactNode;
|
|
10
|
+
className?: string;
|
|
11
|
+
style?: CSSProperties;
|
|
12
|
+
};
|
|
13
|
+
/** Empty uses SVG glyphs; the business EmptyState remains independent. */
|
|
14
|
+
export declare function Empty({ icon, iconSize, iconColor, tip, image, bottom, className, style }: EmptyProps): import("@lynx-js/react").JSX.Element;
|
package/dist/Empty.jsx
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Icon } from "./Icon.jsx";
|
|
2
|
+
import { imgDimension } from './imgModel.js';
|
|
3
|
+
/** Empty uses SVG glyphs; the business EmptyState remains independent. */
|
|
4
|
+
export function Empty({ icon = 'empty', iconSize = 98, iconColor, tip, image, bottom, className = '', style }) {
|
|
5
|
+
const dimension = imgDimension(iconSize, 98);
|
|
6
|
+
const customImage = image !== undefined && image !== null;
|
|
7
|
+
return <view className={`ui-empty ${className}`} style={style}>
|
|
8
|
+
{customImage ? typeof image === 'string' || typeof image === 'number' ? <text>{image}</text> : image : <view className="ui-empty-icon" style={{ width: dimension, height: dimension }}>
|
|
9
|
+
{iconColor ? <Icon name={icon} size={1} color={iconColor} className="ui-empty-glyph"/> : <><Icon name={icon} size={1} color="#c9cbd4" className="ui-empty-glyph ui-empty-glyph-light"/><Icon name={icon} size={1} color="#4e5369" className="ui-empty-glyph ui-empty-glyph-dark"/></>}
|
|
10
|
+
</view>}
|
|
11
|
+
{tip !== undefined && tip !== null && tip !== false && tip !== '' ? typeof tip === 'string' || typeof tip === 'number' ? <text className="ui-empty-tip">{tip}</text> : <view className="ui-empty-tip">{tip}</view> : null}
|
|
12
|
+
{bottom !== undefined && bottom !== null && bottom !== false ? typeof bottom === 'string' || typeof bottom === 'number' ? <text>{bottom}</text> : bottom : null}
|
|
13
|
+
</view>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Button } from "./Button.jsx";
|
|
2
|
+
export function EmptyState({ title = '暂无数据', description, actionLabel, onAction }) {
|
|
3
|
+
return <view className="ui-empty-state">
|
|
4
|
+
<view className="ui-empty-mark"><view className="ui-empty-mark-line"/></view>
|
|
5
|
+
<text className="ui-empty-title">{title}</text>
|
|
6
|
+
{description ? <text className="ui-empty-description">{description}</text> : null}
|
|
7
|
+
{actionLabel ? <view className="ui-empty-action"><Button label={actionLabel} variant="plain" size="small" onTap={onAction}/></view> : null}
|
|
8
|
+
</view>;
|
|
9
|
+
}
|
package/dist/Fab.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { ButtonTone } from "./Button.jsx";
|
|
3
|
+
import type { FabDirection, FabGap, FabPosition } from './fabModel.js';
|
|
4
|
+
export type FabProps = {
|
|
5
|
+
active?: boolean;
|
|
6
|
+
defaultActive?: boolean;
|
|
7
|
+
onActiveChange?: (active: boolean) => void;
|
|
8
|
+
type?: ButtonTone | 'default' | 'error';
|
|
9
|
+
position?: FabPosition;
|
|
10
|
+
direction?: FabDirection;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
draggable?: boolean;
|
|
13
|
+
expandable?: boolean;
|
|
14
|
+
inactiveIcon?: string;
|
|
15
|
+
activeIcon?: string;
|
|
16
|
+
zIndex?: number;
|
|
17
|
+
gap?: FabGap;
|
|
18
|
+
className?: string;
|
|
19
|
+
children?: ReactNode;
|
|
20
|
+
trigger?: ReactNode | ((state: {
|
|
21
|
+
active: boolean;
|
|
22
|
+
disabled: boolean;
|
|
23
|
+
}) => ReactNode);
|
|
24
|
+
onTap?: () => void;
|
|
25
|
+
};
|
|
26
|
+
export type FabRef = {
|
|
27
|
+
open: () => void;
|
|
28
|
+
close: () => void;
|
|
29
|
+
};
|
|
30
|
+
export declare const Fab: (props: FabProps & import("react").RefAttributes<FabRef>) => React.ReactElement | null;
|
package/dist/Fab.jsx
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from '@lynx-js/react';
|
|
2
|
+
import { Button } from "./Button.jsx";
|
|
3
|
+
import { Icon } from "./Icon.jsx";
|
|
4
|
+
import { Transition } from "./Transition.jsx";
|
|
5
|
+
import { clampFab, fabBounds, fabPosition, snapFab } from './fabModel.js';
|
|
6
|
+
const pointOf = (event, end = false) => {
|
|
7
|
+
const p = (end ? event.changedTouches?.[0] : event.touches?.[0]) ?? event;
|
|
8
|
+
const x = p.clientX ?? p.x, y = p.clientY ?? p.y;
|
|
9
|
+
return Number.isFinite(x) && Number.isFinite(y) ? { x: x, y: y } : null;
|
|
10
|
+
};
|
|
11
|
+
export const Fab = forwardRef(function Fab({ active, defaultActive = false, onActiveChange, type = 'primary', position = 'right-bottom', direction = 'top', disabled = false, draggable = false, expandable = true, inactiveIcon = 'add', activeIcon = 'close', zIndex = 99, gap = {}, className = '', children, trigger, onTap }, ref) {
|
|
12
|
+
const [inner, setInner] = useState(defaultActive);
|
|
13
|
+
const expanded = active ?? inner;
|
|
14
|
+
const [viewport, setViewport] = useState({ width: 0, height: 0 });
|
|
15
|
+
const [size, setSize] = useState({ width: 60, height: 60 });
|
|
16
|
+
const [location, setLocation] = useState({ x: 0, y: 0 });
|
|
17
|
+
const [dragDirection, setDragDirection] = useState(null);
|
|
18
|
+
const [attract, setAttract] = useState(false);
|
|
19
|
+
const drag = useRef(null);
|
|
20
|
+
const suppressTap = useRef(false);
|
|
21
|
+
const bounds = fabBounds(viewport.width, viewport.height, size.width, size.height, gap);
|
|
22
|
+
useEffect(() => { setLocation(fabPosition(position, bounds)); setDragDirection(null); setAttract(false); drag.current = null; }, [position, viewport.width, viewport.height, size.width, size.height, gap.top, gap.left, gap.right, gap.bottom]);
|
|
23
|
+
useEffect(() => { if (disabled || !draggable)
|
|
24
|
+
drag.current = null; }, [disabled, draggable]);
|
|
25
|
+
const update = (next) => {
|
|
26
|
+
'background only';
|
|
27
|
+
if (next && (disabled || !expandable))
|
|
28
|
+
return;
|
|
29
|
+
if (next === expanded)
|
|
30
|
+
return;
|
|
31
|
+
if (active === undefined)
|
|
32
|
+
setInner(next);
|
|
33
|
+
onActiveChange?.(next);
|
|
34
|
+
};
|
|
35
|
+
useImperativeHandle(ref, () => ({ open: () => {
|
|
36
|
+
'background only';
|
|
37
|
+
update(true);
|
|
38
|
+
}, close: () => {
|
|
39
|
+
'background only';
|
|
40
|
+
update(false);
|
|
41
|
+
} }), [active, expanded, disabled, expandable, onActiveChange]);
|
|
42
|
+
const start = (event) => {
|
|
43
|
+
'background only';
|
|
44
|
+
suppressTap.current = false;
|
|
45
|
+
const point = pointOf(event);
|
|
46
|
+
if (!draggable || disabled || !point)
|
|
47
|
+
return;
|
|
48
|
+
drag.current = { start: point, origin: location, last: location, moved: false };
|
|
49
|
+
setAttract(false);
|
|
50
|
+
};
|
|
51
|
+
const move = (event, end = false) => {
|
|
52
|
+
'background only';
|
|
53
|
+
const state = drag.current, point = pointOf(event, end);
|
|
54
|
+
if (!state || !point)
|
|
55
|
+
return;
|
|
56
|
+
if (Math.abs(point.x - state.start.x) + Math.abs(point.y - state.start.y) > 5)
|
|
57
|
+
state.moved = true;
|
|
58
|
+
if (!state.moved)
|
|
59
|
+
return;
|
|
60
|
+
suppressTap.current = true;
|
|
61
|
+
state.last = clampFab({ x: state.origin.x + point.x - state.start.x, y: state.origin.y + point.y - state.start.y }, bounds);
|
|
62
|
+
setLocation(state.last);
|
|
63
|
+
};
|
|
64
|
+
const finish = (event, cancel = false) => {
|
|
65
|
+
'background only';
|
|
66
|
+
if (!cancel)
|
|
67
|
+
move(event, true);
|
|
68
|
+
const state = drag.current;
|
|
69
|
+
drag.current = null;
|
|
70
|
+
if (!state?.moved)
|
|
71
|
+
return;
|
|
72
|
+
const snap = snapFab(state.last, bounds);
|
|
73
|
+
setAttract(true);
|
|
74
|
+
setLocation({ x: snap.x, y: snap.y });
|
|
75
|
+
setDragDirection(snap.direction);
|
|
76
|
+
};
|
|
77
|
+
const toggle = () => {
|
|
78
|
+
'background only';
|
|
79
|
+
if (disabled || suppressTap.current)
|
|
80
|
+
return;
|
|
81
|
+
if (expandable)
|
|
82
|
+
update(!expanded);
|
|
83
|
+
else
|
|
84
|
+
onTap?.();
|
|
85
|
+
};
|
|
86
|
+
const menuDirection = draggable && dragDirection ? dragDirection : direction;
|
|
87
|
+
const tone = type === 'error' ? 'danger' : type === 'default' ? 'neutral' : type;
|
|
88
|
+
return <>
|
|
89
|
+
<view className="ui-fab-viewport" flatten={false} user-interaction-enabled={false} bindlayoutchange={event => {
|
|
90
|
+
'background only';
|
|
91
|
+
const { width } = event.detail;
|
|
92
|
+
setViewport(old => old.width === width ? old : { ...old, width });
|
|
93
|
+
}}/>
|
|
94
|
+
<view className="ui-fab-viewport ui-fab-viewport-vertical" flatten={false} user-interaction-enabled={false} bindlayoutchange={event => {
|
|
95
|
+
'background only';
|
|
96
|
+
const { height } = event.detail;
|
|
97
|
+
setViewport(old => old.height === height ? old : { ...old, height });
|
|
98
|
+
}}/>
|
|
99
|
+
<view className={`ui-fab ${draggable ? 'ui-fab-draggable' : ''} ${disabled ? 'ui-fab-disabled' : ''} ${className}`} style={{ left: `${location.x}px`, top: `${location.y}px`, zIndex, visibility: viewport.width && viewport.height ? 'visible' : 'hidden', transitionDuration: attract ? '300ms' : '0ms' }} catchtap={() => {
|
|
100
|
+
'background only';
|
|
101
|
+
}}>
|
|
102
|
+
<view className="ui-fab-trigger" flatten={false} bindlayoutchange={event => {
|
|
103
|
+
'background only';
|
|
104
|
+
const { width, height } = event.detail;
|
|
105
|
+
setSize(old => old.width === width && old.height === height ? old : { width, height });
|
|
106
|
+
}} bindtap={toggle} bindtouchstart={start} catchtouchmove={event => {
|
|
107
|
+
'background only';
|
|
108
|
+
move(event);
|
|
109
|
+
}} bindtouchend={event => {
|
|
110
|
+
'background only';
|
|
111
|
+
finish(event);
|
|
112
|
+
}} bindtouchcancel={event => {
|
|
113
|
+
'background only';
|
|
114
|
+
finish(event, true);
|
|
115
|
+
}} bindmousedown={start} global-bindmousemove={draggable ? event => {
|
|
116
|
+
'background only';
|
|
117
|
+
move(event);
|
|
118
|
+
} : undefined} global-bindmouseup={draggable ? event => {
|
|
119
|
+
'background only';
|
|
120
|
+
finish(event);
|
|
121
|
+
} : undefined} consume-slide-event={draggable ? [[0, 360]] : undefined}>
|
|
122
|
+
{trigger ? typeof trigger === 'function' ? trigger({ active: expanded, disabled }) : trigger : <Button className="ui-fab-default-trigger" tone={tone} round disabled={disabled} icon={<Icon name={expanded ? activeIcon : inactiveIcon === 'add' ? 'plus' : inactiveIcon} size={32} color={tone === 'neutral' ? '#4e5369' : '#fff'}/>} accessibilityLabel={expanded ? '收起动作菜单' : '展开动作菜单'}/>}
|
|
123
|
+
</view>
|
|
124
|
+
{expandable ? <Transition show={expanded} name={[]} className={`ui-fab-actions ui-fab-actions-${menuDirection}`} enterClassName={`ui-fab-offset-${menuDirection}`} leaveToClassName={`ui-fab-offset-${menuDirection}`} enterActiveClassName="ui-fab-actions-animating" leaveActiveClassName="ui-fab-actions-animating"><view className="ui-fab-action-content" user-interaction-enabled={!disabled}>{children}</view></Transition> : null}
|
|
125
|
+
</view>
|
|
126
|
+
</>;
|
|
127
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
3
|
+
export type FloatingPanelProps = {
|
|
4
|
+
height?: number;
|
|
5
|
+
defaultHeight?: number;
|
|
6
|
+
anchors?: readonly number[];
|
|
7
|
+
duration?: number;
|
|
8
|
+
contentDraggable?: boolean;
|
|
9
|
+
safeAreaInsetBottom?: boolean;
|
|
10
|
+
safeAreaBottom?: number;
|
|
11
|
+
showScrollbar?: boolean;
|
|
12
|
+
zIndex?: number;
|
|
13
|
+
rootPortal?: boolean;
|
|
14
|
+
onHeightChange?: (event: {
|
|
15
|
+
height: number;
|
|
16
|
+
}) => void;
|
|
17
|
+
className?: string;
|
|
18
|
+
style?: CSSProperties;
|
|
19
|
+
children?: ReactNode;
|
|
20
|
+
};
|
|
21
|
+
export declare function FloatingPanel({ height, defaultHeight, anchors: anchorProps, duration, contentDraggable, safeAreaInsetBottom, safeAreaBottom, showScrollbar, zIndex, rootPortal, onHeightChange, className, style, children }: FloatingPanelProps): import("@lynx-js/react").JSX.Element;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from '@lynx-js/react';
|
|
2
|
+
import { RootPortal } from "./RootPortal.jsx";
|
|
3
|
+
import { nearestPanelAnchor, panelAnchors, panelHeight } from './floatingPanelModel.js';
|
|
4
|
+
function point(event) {
|
|
5
|
+
'background only';
|
|
6
|
+
const touch = event.touches?.[0] ?? event.changedTouches?.[0] ?? event.detail ?? event;
|
|
7
|
+
const x = touch.clientX ?? touch.pageX ?? touch.x, y = touch.clientY ?? touch.pageY ?? touch.y;
|
|
8
|
+
return Number.isFinite(x) && Number.isFinite(y) ? { x: x, y: y } : undefined;
|
|
9
|
+
}
|
|
10
|
+
export function FloatingPanel({ height, defaultHeight = 0, anchors: anchorProps, duration = 300, contentDraggable = true, safeAreaInsetBottom = false, safeAreaBottom = 0, showScrollbar = true, zIndex = 10, rootPortal = false, onHeightChange, className = '', style, children }) {
|
|
11
|
+
const viewport = useRef(null);
|
|
12
|
+
const scroll = useRef(null);
|
|
13
|
+
const scrollTop = useRef(0);
|
|
14
|
+
const [viewportHeight, setViewportHeight] = useState(0);
|
|
15
|
+
const [inner, setInner] = useState(defaultHeight);
|
|
16
|
+
const [dragHeight, setDragHeight] = useState();
|
|
17
|
+
const [dragging, setDragging] = useState(false);
|
|
18
|
+
const anchors = panelAnchors(anchorProps, viewportHeight);
|
|
19
|
+
const key = anchors.join(',');
|
|
20
|
+
const max = anchors[anchors.length - 1];
|
|
21
|
+
const current = panelHeight(height ?? inner, anchors);
|
|
22
|
+
const shownHeight = dragHeight ?? current;
|
|
23
|
+
const atMax = shownHeight >= max - .5;
|
|
24
|
+
const drag = useRef();
|
|
25
|
+
const measured = (value) => {
|
|
26
|
+
'background only';
|
|
27
|
+
if (Number.isFinite(value) && value > 0)
|
|
28
|
+
setViewportHeight(value);
|
|
29
|
+
};
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
let cancelled = false;
|
|
32
|
+
const timer = setTimeout(() => viewport.current?.invoke({ method: 'boundingClientRect', success: (value) => {
|
|
33
|
+
'background only';
|
|
34
|
+
if (!cancelled)
|
|
35
|
+
measured(value.height);
|
|
36
|
+
} }).exec(), 32);
|
|
37
|
+
return () => { cancelled = true; clearTimeout(timer); };
|
|
38
|
+
}, []);
|
|
39
|
+
useEffect(() => { drag.current = undefined; setDragging(false); setDragHeight(undefined); }, [height, key, contentDraggable]);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (!atMax && scrollTop.current > 0) {
|
|
42
|
+
scrollTop.current = 0;
|
|
43
|
+
scroll.current?.invoke({ method: 'scrollTo', params: { offset: 0, smooth: false } }).exec();
|
|
44
|
+
}
|
|
45
|
+
}, [atMax]);
|
|
46
|
+
const start = (event, source) => {
|
|
47
|
+
'background only';
|
|
48
|
+
const p = point(event);
|
|
49
|
+
if (!p || source === 'content' && !contentDraggable || drag.current)
|
|
50
|
+
return;
|
|
51
|
+
drag.current = { ...p, height: current, next: current, source, active: false };
|
|
52
|
+
};
|
|
53
|
+
const move = (event) => {
|
|
54
|
+
'background only';
|
|
55
|
+
const state = drag.current, p = point(event);
|
|
56
|
+
if (!state || !p)
|
|
57
|
+
return;
|
|
58
|
+
const dy = p.y - state.y, dx = p.x - state.x;
|
|
59
|
+
if (!state.active) {
|
|
60
|
+
if (Math.max(Math.abs(dy), Math.abs(dx)) < 5)
|
|
61
|
+
return;
|
|
62
|
+
if (Math.abs(dx) >= Math.abs(dy) || state.source === 'content' && (scrollTop.current > 0 || state.height >= max - .5 && dy < 0)) {
|
|
63
|
+
drag.current = undefined;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
state.active = true;
|
|
67
|
+
setDragging(true);
|
|
68
|
+
}
|
|
69
|
+
state.next = panelHeight(state.height - dy, anchors);
|
|
70
|
+
setDragHeight(state.next);
|
|
71
|
+
};
|
|
72
|
+
const finish = (cancelled = false) => {
|
|
73
|
+
'background only';
|
|
74
|
+
const state = drag.current;
|
|
75
|
+
if (!state)
|
|
76
|
+
return;
|
|
77
|
+
drag.current = undefined;
|
|
78
|
+
setDragging(false);
|
|
79
|
+
setDragHeight(undefined);
|
|
80
|
+
if (!state.active || cancelled)
|
|
81
|
+
return;
|
|
82
|
+
const next = nearestPanelAnchor(state.next, anchors);
|
|
83
|
+
if (height === undefined)
|
|
84
|
+
setInner(next);
|
|
85
|
+
if (next !== current)
|
|
86
|
+
onHeightChange?.({ height: next });
|
|
87
|
+
};
|
|
88
|
+
const inset = safeAreaInsetBottom && Number.isFinite(safeAreaBottom) ? Math.max(0, safeAreaBottom) : 0;
|
|
89
|
+
const layer = <>
|
|
90
|
+
<view ref={viewport} flatten={false} className="ui-floating-panel-viewport" bindlayoutchange={event => measured(event.detail.height)}/>
|
|
91
|
+
<view className={`ui-floating-panel ${className}`} style={{ ...style, height: `${max}px`, transform: `translateY(${max - shownHeight}px)`, transitionDuration: `${dragging ? 0 : Math.max(0, Number.isFinite(duration) ? duration : 300)}ms`, paddingBottom: `${inset}px`, zIndex }}>
|
|
92
|
+
<view className="ui-floating-panel-header" consume-slide-event={[[-180, 180]]} catchtouchstart={event => start(event, 'header')} catchtouchmove={move} catchtouchend={() => finish()} catchtouchcancel={() => finish(true)} catchmousedown={event => start(event, 'header')} global-bindmousemove={move} global-bindmouseup={() => finish()} global-bindtouchmove={move} global-bindtouchend={() => finish()} global-bindtouchcancel={() => finish(true)} accessibility-element accessibility-traits="adjustable" accessibility-label={`浮动面板,高度${Math.round(shownHeight)}`}><view className="ui-floating-panel-bar"/></view>
|
|
93
|
+
<scroll-view ref={scroll} className="ui-floating-panel-scroll" scroll-orientation="vertical" scroll-bar-enable={showScrollbar} enable-scroll={!contentDraggable || atMax && !dragging} bounces={false} bindscroll={event => {
|
|
94
|
+
'background only';
|
|
95
|
+
scrollTop.current = Math.max(0, event.detail.scrollTop);
|
|
96
|
+
}}>
|
|
97
|
+
<view className="ui-floating-panel-content" consume-slide-event={contentDraggable && !atMax ? [[-180, 180]] : undefined} bindtouchstart={event => start(event, 'content')} bindtouchmove={move} bindtouchend={() => finish()} bindtouchcancel={() => finish(true)} bindmousedown={event => start(event, 'content')}>{children}</view>
|
|
98
|
+
</scroll-view>
|
|
99
|
+
</view>
|
|
100
|
+
</>;
|
|
101
|
+
return rootPortal ? <RootPortal>{layer}</RootPortal> : layer;
|
|
102
|
+
}
|