@bifrostui/react 1.4.6 → 1.4.7-beta.0
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/dist/Calendar/Calendar.js +5 -1
- package/dist/Calendar/Calendar.types.d.ts +5 -0
- package/dist/CitySelector/CitySelectorCore.js +3 -3
- package/dist/Collapse/Collapse.css +0 -1
- package/dist/Collapse/Collapse.d.ts +1 -1
- package/dist/Collapse/Collapse.js +11 -8
- package/dist/Collapse/Collapse.miniapp.d.ts +5 -0
- package/dist/Collapse/Collapse.miniapp.js +177 -0
- package/dist/CollapsePanel/CollapsePanel.css +4 -2
- package/dist/DatePicker/DatePicker.d.ts +4 -0
- package/dist/DatePicker/DatePicker.js +335 -0
- package/dist/DatePicker/DatePicker.types.d.ts +43 -0
- package/dist/DatePicker/DatePicker.types.js +35 -0
- package/dist/DatePicker/index.d.ts +2 -0
- package/dist/DatePicker/index.js +41 -0
- package/dist/DesktopDatePicker/DesktopDatePicker.d.ts +5 -0
- package/dist/DesktopDatePicker/DesktopDatePicker.js +280 -0
- package/dist/DesktopDatePicker/DesktopDatePicker.types.d.ts +163 -0
- package/dist/DesktopDatePicker/DesktopDatePicker.types.js +15 -0
- package/dist/DesktopDatePicker/deskTopPickerContainer.css +100 -0
- package/dist/DesktopDatePicker/index.css +61 -0
- package/dist/DesktopDatePicker/index.d.ts +2 -0
- package/dist/DesktopDatePicker/index.js +41 -0
- package/dist/DesktopDatePicker/useGetDatePickerContent.d.ts +6 -0
- package/dist/DesktopDatePicker/useGetDatePickerContent.js +343 -0
- package/dist/DesktopDateTimePicker/DesktopDateTimePicker.d.ts +5 -0
- package/dist/DesktopDateTimePicker/DesktopDateTimePicker.js +322 -0
- package/dist/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +163 -0
- package/dist/DesktopDateTimePicker/DesktopDateTimePicker.types.js +15 -0
- package/dist/DesktopDateTimePicker/index.css +66 -0
- package/dist/DesktopDateTimePicker/index.d.ts +2 -0
- package/dist/DesktopDateTimePicker/index.js +41 -0
- package/dist/DesktopPicker/DesktopPicker.d.ts +5 -0
- package/dist/DesktopPicker/DesktopPicker.js +238 -0
- package/dist/DesktopPicker/DesktopPicker.types.d.ts +57 -0
- package/dist/DesktopPicker/DesktopPicker.types.js +15 -0
- package/dist/DesktopPicker/index.css +37 -0
- package/dist/DesktopPicker/index.d.ts +2 -0
- package/dist/DesktopPicker/index.js +41 -0
- package/dist/DesktopPicker/utils/calcAfterMounted.d.ts +2 -0
- package/dist/{Tabs/utils/bound.js → DesktopPicker/utils/calcAfterMounted.js} +7 -14
- package/dist/DesktopPicker/utils/calcAfterMounted.miniapp.d.ts +2 -0
- package/dist/DesktopPicker/utils/calcAfterMounted.miniapp.js +38 -0
- package/dist/DesktopTimePicker/DesktopTimePicker.d.ts +5 -0
- package/dist/DesktopTimePicker/DesktopTimePicker.js +288 -0
- package/dist/DesktopTimePicker/DesktopTimePicker.types.d.ts +182 -0
- package/dist/DesktopTimePicker/DesktopTimePicker.types.js +15 -0
- package/dist/DesktopTimePicker/DesktopTimePickerList.d.ts +4 -0
- package/dist/DesktopTimePicker/DesktopTimePickerList.js +111 -0
- package/dist/DesktopTimePicker/index.css +170 -0
- package/dist/DesktopTimePicker/index.d.ts +2 -0
- package/dist/DesktopTimePicker/index.js +41 -0
- package/dist/DesktopTimePicker/useGetTimePickerContent.d.ts +6 -0
- package/dist/DesktopTimePicker/useGetTimePickerContent.js +246 -0
- package/dist/DesktopTimePicker/utils/scrollUtil.d.ts +2 -0
- package/dist/DesktopTimePicker/utils/scrollUtil.js +27 -0
- package/dist/DesktopTimePicker/utils/scrollUtil.miniapp.d.ts +2 -0
- package/dist/DesktopTimePicker/utils/scrollUtil.miniapp.js +51 -0
- package/dist/DesktopTimePicker/utils/utils.d.ts +28 -0
- package/dist/DesktopTimePicker/utils/utils.js +408 -0
- package/dist/Dialog/FunctionalDialog.js +1 -1
- package/dist/ItemSelector/ItemSelector.css +120 -0
- package/dist/ItemSelector/ItemSelector.d.ts +4 -0
- package/dist/ItemSelector/ItemSelector.js +84 -0
- package/dist/ItemSelector/ItemSelector.miniapp.d.ts +5 -0
- package/dist/ItemSelector/ItemSelector.miniapp.js +125 -0
- package/dist/ItemSelector/ItemSelector.types.d.ts +40 -0
- package/dist/ItemSelector/ItemSelector.types.js +15 -0
- package/dist/ItemSelector/ItemSelectorCore.d.ts +5 -0
- package/dist/ItemSelector/ItemSelectorCore.js +217 -0
- package/dist/ItemSelector/Selector/index.css +11 -0
- package/dist/ItemSelector/Selector/index.d.ts +9 -0
- package/dist/ItemSelector/Selector/index.js +48 -0
- package/dist/ItemSelector/index.d.ts +2 -0
- package/dist/ItemSelector/index.js +41 -0
- package/dist/ItemSelector/miniapp.css +4 -0
- package/dist/Modal/Modal.miniapp.d.ts +1 -1
- package/dist/Picker/Picker.css +5 -0
- package/dist/Picker/Picker.js +27 -5
- package/dist/Picker/Picker.types.d.ts +15 -2
- package/dist/Picker/PickerPanel.css +4 -0
- package/dist/Picker/PickerPanel.js +7 -6
- package/dist/Popover/Popover.js +70 -27
- package/dist/Portal/Portal.miniapp.js +7 -4
- package/dist/ScrollView/ScrollView.js +24 -11
- package/dist/ScrollView/ScrollView.types.d.ts +0 -1
- package/dist/Select/Select.css +1 -4
- package/dist/Select/Select.js +63 -40
- package/dist/Slider/Slider.js +13 -5
- package/dist/SwipeAction/SwipeAction.css +79 -0
- package/dist/SwipeAction/SwipeAction.d.ts +5 -0
- package/dist/SwipeAction/SwipeAction.js +349 -0
- package/dist/SwipeAction/SwipeAction.types.d.ts +83 -0
- package/dist/SwipeAction/SwipeAction.types.js +39 -0
- package/dist/SwipeAction/SwipeActionContext.d.ts +4 -0
- package/dist/SwipeAction/SwipeActionContext.js +30 -0
- package/dist/SwipeAction/SwipeActionItem.css +31 -0
- package/dist/SwipeAction/SwipeActionItem.d.ts +5 -0
- package/dist/SwipeAction/SwipeActionItem.js +105 -0
- package/dist/SwipeAction/index.d.ts +4 -0
- package/dist/SwipeAction/index.js +45 -0
- package/dist/Tabs/Tab.js +13 -4
- package/dist/Tabs/Tabs.js +30 -15
- package/dist/Tabs/utils/scroll.d.ts +2 -0
- package/dist/Tabs/utils/scroll.js +55 -0
- package/dist/Toast/FunctionalToast.js +1 -1
- package/dist/Toast/Toast.css +0 -1
- package/dist/Tooltip/Tooltip.js +70 -27
- package/dist/index.d.ts +7 -0
- package/dist/index.js +15 -1
- package/dist/locales/base.d.ts +11 -0
- package/dist/locales/en-US.js +24 -0
- package/dist/locales/zh-CN.js +24 -0
- package/dist/locales/zh-TW.js +24 -0
- package/es/Calendar/Calendar.js +5 -1
- package/es/Calendar/Calendar.types.d.ts +5 -0
- package/es/CitySelector/CitySelectorCore.js +3 -3
- package/es/Collapse/Collapse.css +0 -1
- package/es/Collapse/Collapse.d.ts +1 -1
- package/es/Collapse/Collapse.js +11 -8
- package/es/Collapse/Collapse.miniapp.d.ts +5 -0
- package/es/Collapse/Collapse.miniapp.js +157 -0
- package/es/CollapsePanel/CollapsePanel.css +4 -2
- package/es/DatePicker/DatePicker.d.ts +4 -0
- package/es/DatePicker/DatePicker.js +310 -0
- package/es/DatePicker/DatePicker.types.d.ts +43 -0
- package/es/DatePicker/DatePicker.types.js +1 -0
- package/es/DatePicker/index.d.ts +2 -0
- package/es/DatePicker/index.js +6 -0
- package/es/DesktopDatePicker/DesktopDatePicker.d.ts +5 -0
- package/es/DesktopDatePicker/DesktopDatePicker.js +253 -0
- package/es/DesktopDatePicker/DesktopDatePicker.types.d.ts +163 -0
- package/es/DesktopDatePicker/DesktopDatePicker.types.js +1 -0
- package/es/DesktopDatePicker/deskTopPickerContainer.css +100 -0
- package/es/DesktopDatePicker/index.css +61 -0
- package/es/DesktopDatePicker/index.d.ts +2 -0
- package/es/DesktopDatePicker/index.js +6 -0
- package/es/DesktopDatePicker/useGetDatePickerContent.d.ts +6 -0
- package/es/DesktopDatePicker/useGetDatePickerContent.js +316 -0
- package/es/DesktopDateTimePicker/DesktopDateTimePicker.d.ts +5 -0
- package/es/DesktopDateTimePicker/DesktopDateTimePicker.js +295 -0
- package/es/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +163 -0
- package/es/DesktopDateTimePicker/DesktopDateTimePicker.types.js +1 -0
- package/es/DesktopDateTimePicker/index.css +66 -0
- package/es/DesktopDateTimePicker/index.d.ts +2 -0
- package/es/DesktopDateTimePicker/index.js +9 -0
- package/es/DesktopPicker/DesktopPicker.d.ts +5 -0
- package/es/DesktopPicker/DesktopPicker.js +221 -0
- package/es/DesktopPicker/DesktopPicker.types.d.ts +57 -0
- package/es/DesktopPicker/DesktopPicker.types.js +1 -0
- package/es/DesktopPicker/index.css +37 -0
- package/es/DesktopPicker/index.d.ts +2 -0
- package/es/DesktopPicker/index.js +6 -0
- package/es/DesktopPicker/utils/calcAfterMounted.d.ts +2 -0
- package/es/DesktopPicker/utils/calcAfterMounted.js +6 -0
- package/es/DesktopPicker/utils/calcAfterMounted.miniapp.d.ts +2 -0
- package/es/DesktopPicker/utils/calcAfterMounted.miniapp.js +9 -0
- package/es/DesktopTimePicker/DesktopTimePicker.d.ts +5 -0
- package/es/DesktopTimePicker/DesktopTimePicker.js +261 -0
- package/es/DesktopTimePicker/DesktopTimePicker.types.d.ts +182 -0
- package/es/DesktopTimePicker/DesktopTimePicker.types.js +1 -0
- package/es/DesktopTimePicker/DesktopTimePickerList.d.ts +4 -0
- package/es/DesktopTimePicker/DesktopTimePickerList.js +84 -0
- package/es/DesktopTimePicker/index.css +170 -0
- package/es/DesktopTimePicker/index.d.ts +2 -0
- package/es/DesktopTimePicker/index.js +6 -0
- package/es/DesktopTimePicker/useGetTimePickerContent.d.ts +6 -0
- package/es/DesktopTimePicker/useGetTimePickerContent.js +223 -0
- package/es/DesktopTimePicker/utils/scrollUtil.d.ts +2 -0
- package/es/DesktopTimePicker/utils/scrollUtil.js +8 -0
- package/es/DesktopTimePicker/utils/scrollUtil.miniapp.d.ts +2 -0
- package/es/DesktopTimePicker/utils/scrollUtil.miniapp.js +22 -0
- package/es/DesktopTimePicker/utils/utils.d.ts +28 -0
- package/es/DesktopTimePicker/utils/utils.js +365 -0
- package/es/Dialog/FunctionalDialog.js +2 -2
- package/es/ItemSelector/ItemSelector.css +120 -0
- package/es/ItemSelector/ItemSelector.d.ts +4 -0
- package/es/ItemSelector/ItemSelector.js +57 -0
- package/es/ItemSelector/ItemSelector.miniapp.d.ts +5 -0
- package/es/ItemSelector/ItemSelector.miniapp.js +98 -0
- package/es/ItemSelector/ItemSelector.types.d.ts +40 -0
- package/es/ItemSelector/ItemSelector.types.js +1 -0
- package/es/ItemSelector/ItemSelectorCore.d.ts +5 -0
- package/es/ItemSelector/ItemSelectorCore.js +190 -0
- package/es/ItemSelector/Selector/index.css +11 -0
- package/es/ItemSelector/Selector/index.d.ts +9 -0
- package/es/ItemSelector/Selector/index.js +19 -0
- package/es/ItemSelector/index.d.ts +2 -0
- package/es/ItemSelector/index.js +6 -0
- package/es/ItemSelector/miniapp.css +4 -0
- package/es/Modal/Modal.miniapp.d.ts +1 -1
- package/es/Picker/Picker.css +5 -0
- package/es/Picker/Picker.js +27 -5
- package/es/Picker/Picker.types.d.ts +15 -2
- package/es/Picker/PickerPanel.css +4 -0
- package/es/Picker/PickerPanel.js +7 -6
- package/es/Popover/Popover.js +73 -29
- package/es/Portal/Portal.miniapp.js +8 -5
- package/es/ScrollView/ScrollView.js +24 -11
- package/es/ScrollView/ScrollView.types.d.ts +0 -1
- package/es/Select/Select.css +1 -4
- package/es/Select/Select.js +63 -41
- package/es/Slider/Slider.js +16 -6
- package/es/SwipeAction/SwipeAction.css +79 -0
- package/es/SwipeAction/SwipeAction.d.ts +5 -0
- package/es/SwipeAction/SwipeAction.js +337 -0
- package/es/SwipeAction/SwipeAction.types.d.ts +83 -0
- package/es/SwipeAction/SwipeAction.types.js +1 -0
- package/es/SwipeAction/SwipeActionContext.d.ts +4 -0
- package/es/SwipeAction/SwipeActionContext.js +11 -0
- package/es/SwipeAction/SwipeActionItem.css +31 -0
- package/es/SwipeAction/SwipeActionItem.d.ts +5 -0
- package/es/SwipeAction/SwipeActionItem.js +78 -0
- package/es/SwipeAction/index.d.ts +4 -0
- package/es/SwipeAction/index.js +9 -0
- package/es/Tabs/Tab.js +13 -4
- package/es/Tabs/Tabs.js +30 -15
- package/es/Tabs/utils/scroll.d.ts +2 -0
- package/es/Tabs/utils/scroll.js +36 -0
- package/es/Toast/FunctionalToast.js +2 -2
- package/es/Toast/Toast.css +0 -1
- package/es/Tooltip/Tooltip.js +73 -29
- package/es/index.d.ts +7 -0
- package/es/index.js +7 -0
- package/es/locales/base.d.ts +11 -0
- package/es/locales/en-US.js +24 -0
- package/es/locales/zh-CN.js +24 -0
- package/es/locales/zh-TW.js +24 -0
- package/package.json +5 -5
- package/dist/Tabs/utils/bound.d.ts +0 -1
- package/es/Tabs/utils/bound.d.ts +0 -1
- package/es/Tabs/utils/bound.js +0 -13
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __objRest = (source, exclude) => {
|
|
18
|
+
var target = {};
|
|
19
|
+
for (var prop in source)
|
|
20
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
21
|
+
target[prop] = source[prop];
|
|
22
|
+
if (source != null && __getOwnPropSymbols)
|
|
23
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
24
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
};
|
|
29
|
+
var __async = (__this, __arguments, generator) => {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
var fulfilled = (value) => {
|
|
32
|
+
try {
|
|
33
|
+
step(generator.next(value));
|
|
34
|
+
} catch (e) {
|
|
35
|
+
reject(e);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var rejected = (value) => {
|
|
39
|
+
try {
|
|
40
|
+
step(generator.throw(value));
|
|
41
|
+
} catch (e) {
|
|
42
|
+
reject(e);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
46
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
import React, {
|
|
50
|
+
useImperativeHandle,
|
|
51
|
+
useRef,
|
|
52
|
+
useState,
|
|
53
|
+
useEffect,
|
|
54
|
+
useMemo
|
|
55
|
+
} from "react";
|
|
56
|
+
import clsx from "clsx";
|
|
57
|
+
import {
|
|
58
|
+
useTouch,
|
|
59
|
+
touchEmulator,
|
|
60
|
+
isMini,
|
|
61
|
+
getBoundingClientRect,
|
|
62
|
+
throttle
|
|
63
|
+
} from "@bifrostui/utils";
|
|
64
|
+
import BuiSwipeActionContext from "./SwipeActionContext";
|
|
65
|
+
import {
|
|
66
|
+
SideTypeEnum,
|
|
67
|
+
DragPhaseEnum
|
|
68
|
+
} from "./SwipeAction.types";
|
|
69
|
+
import "./SwipeAction.css";
|
|
70
|
+
const classPrefix = "bui-swipe-action";
|
|
71
|
+
const SwipeAction = /* @__PURE__ */ React.forwardRef(
|
|
72
|
+
(props, ref) => {
|
|
73
|
+
const _a = props, {
|
|
74
|
+
className,
|
|
75
|
+
children,
|
|
76
|
+
rightActions,
|
|
77
|
+
leftActions,
|
|
78
|
+
disabled,
|
|
79
|
+
closeOnClickActionItem = true,
|
|
80
|
+
closeOnClickContainer = false,
|
|
81
|
+
onActionsReveal
|
|
82
|
+
} = _a, others = __objRest(_a, [
|
|
83
|
+
"className",
|
|
84
|
+
"children",
|
|
85
|
+
"rightActions",
|
|
86
|
+
"leftActions",
|
|
87
|
+
"disabled",
|
|
88
|
+
"closeOnClickActionItem",
|
|
89
|
+
"closeOnClickContainer",
|
|
90
|
+
"onActionsReveal"
|
|
91
|
+
]);
|
|
92
|
+
const touch = useTouch();
|
|
93
|
+
const rootRef = useRef(null);
|
|
94
|
+
const leftRef = useRef(null);
|
|
95
|
+
const rightRef = useRef(null);
|
|
96
|
+
const contentRef = useRef(null);
|
|
97
|
+
const [translateX, setTranslateX] = useState(0);
|
|
98
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
99
|
+
const startingX = useRef(0);
|
|
100
|
+
const currentX = useRef(0);
|
|
101
|
+
const isDragging = useRef(false);
|
|
102
|
+
let pretranslateX = 0;
|
|
103
|
+
let dragPhase = DragPhaseEnum.START;
|
|
104
|
+
const dragThreshold = 5;
|
|
105
|
+
const leftWidthCache = useRef(0);
|
|
106
|
+
const rightWidthCache = useRef(0);
|
|
107
|
+
const getWidth = (_ref) => {
|
|
108
|
+
if (!_ref.current)
|
|
109
|
+
return Promise.resolve(0);
|
|
110
|
+
return new Promise((resolve) => {
|
|
111
|
+
if (isMini) {
|
|
112
|
+
getBoundingClientRect(_ref.current).then((rect) => {
|
|
113
|
+
if (rect) {
|
|
114
|
+
resolve(rect.width || 0);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
} else {
|
|
118
|
+
resolve(_ref.current.offsetWidth);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
const getLefRefWidth = () => __async(void 0, null, function* () {
|
|
123
|
+
if (leftRef.current && leftActions && !leftWidthCache.current) {
|
|
124
|
+
leftWidthCache.current = yield getWidth(leftRef);
|
|
125
|
+
}
|
|
126
|
+
return leftWidthCache.current;
|
|
127
|
+
});
|
|
128
|
+
const getRightRefWidth = () => __async(void 0, null, function* () {
|
|
129
|
+
if (rightRef.current && rightActions && !rightWidthCache.current) {
|
|
130
|
+
rightWidthCache.current = yield getWidth(rightRef);
|
|
131
|
+
}
|
|
132
|
+
return rightWidthCache.current;
|
|
133
|
+
});
|
|
134
|
+
const initRefWidth = () => {
|
|
135
|
+
getLefRefWidth();
|
|
136
|
+
getRightRefWidth();
|
|
137
|
+
};
|
|
138
|
+
const handleTouchStart = (e) => {
|
|
139
|
+
dragPhase = DragPhaseEnum.START;
|
|
140
|
+
const isMaskEle = e.target.id === "content-mask";
|
|
141
|
+
if (isDragging.current || disabled || isMaskEle)
|
|
142
|
+
return;
|
|
143
|
+
touch.start(e);
|
|
144
|
+
isDragging.current = true;
|
|
145
|
+
startingX.current = touch.deltaX.current - translateX;
|
|
146
|
+
};
|
|
147
|
+
const handleTouchMove = throttle(
|
|
148
|
+
(e) => __async(void 0, null, function* () {
|
|
149
|
+
if (!isDragging.current || disabled)
|
|
150
|
+
return;
|
|
151
|
+
if (dragPhase === DragPhaseEnum.START) {
|
|
152
|
+
dragPhase = DragPhaseEnum.MOVE;
|
|
153
|
+
}
|
|
154
|
+
touch.move(e);
|
|
155
|
+
currentX.current = touch.deltaX.current - startingX.current;
|
|
156
|
+
if (Math.abs(currentX.current) < dragThreshold)
|
|
157
|
+
return;
|
|
158
|
+
const leftWidth = yield getLefRefWidth();
|
|
159
|
+
const rightWidth = yield getRightRefWidth();
|
|
160
|
+
currentX.current = Math.max(
|
|
161
|
+
-rightWidth,
|
|
162
|
+
Math.min(leftWidth, currentX.current)
|
|
163
|
+
);
|
|
164
|
+
setTranslateX(currentX.current);
|
|
165
|
+
}),
|
|
166
|
+
100
|
|
167
|
+
);
|
|
168
|
+
const emitActionsReveal = (targetX, stop = false) => {
|
|
169
|
+
const isSpecial = targetX === pretranslateX && targetX !== 0;
|
|
170
|
+
if (targetX === pretranslateX && !isSpecial || stop)
|
|
171
|
+
return;
|
|
172
|
+
let resStr = null;
|
|
173
|
+
const shouldOpen = targetX > 0 && pretranslateX <= 0 || targetX < 0 && pretranslateX >= 0 || isSpecial;
|
|
174
|
+
if (shouldOpen) {
|
|
175
|
+
if (targetX > 0) {
|
|
176
|
+
resStr = SideTypeEnum.LEFT;
|
|
177
|
+
} else if (targetX < 0) {
|
|
178
|
+
resStr = SideTypeEnum.RIGHT;
|
|
179
|
+
}
|
|
180
|
+
setIsOpen(true);
|
|
181
|
+
} else {
|
|
182
|
+
setIsOpen(false);
|
|
183
|
+
}
|
|
184
|
+
if (resStr) {
|
|
185
|
+
onActionsReveal == null ? void 0 : onActionsReveal({ side: resStr });
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
const handleTouchEnd = (e) => __async(void 0, null, function* () {
|
|
189
|
+
if (!isDragging.current)
|
|
190
|
+
return;
|
|
191
|
+
if (dragPhase === DragPhaseEnum.MOVE) {
|
|
192
|
+
dragPhase = DragPhaseEnum.END;
|
|
193
|
+
}
|
|
194
|
+
const leftWidth = yield getLefRefWidth();
|
|
195
|
+
const rightWidth = yield getRightRefWidth();
|
|
196
|
+
const threshold = 0.5;
|
|
197
|
+
let targetX = 0;
|
|
198
|
+
isDragging.current = false;
|
|
199
|
+
if (Math.abs(currentX.current) < dragThreshold)
|
|
200
|
+
return;
|
|
201
|
+
if (currentX.current > leftWidth * threshold) {
|
|
202
|
+
targetX = leftWidth;
|
|
203
|
+
} else if (currentX.current < -rightWidth * threshold) {
|
|
204
|
+
targetX = -rightWidth;
|
|
205
|
+
}
|
|
206
|
+
if (dragPhase === DragPhaseEnum.END || isMini) {
|
|
207
|
+
emitActionsReveal(targetX);
|
|
208
|
+
console.log("handleTouchEnd\uFF1A", targetX, e);
|
|
209
|
+
setTranslateX(targetX);
|
|
210
|
+
pretranslateX = targetX;
|
|
211
|
+
}
|
|
212
|
+
currentX.current = 0;
|
|
213
|
+
});
|
|
214
|
+
const close = () => {
|
|
215
|
+
setTranslateX(0);
|
|
216
|
+
pretranslateX = 0;
|
|
217
|
+
setIsOpen(false);
|
|
218
|
+
};
|
|
219
|
+
useEffect(() => {
|
|
220
|
+
initRefWidth();
|
|
221
|
+
if (!contentRef.current)
|
|
222
|
+
return;
|
|
223
|
+
const removeTouchEmulator = touchEmulator(contentRef.current);
|
|
224
|
+
return () => {
|
|
225
|
+
removeTouchEmulator();
|
|
226
|
+
};
|
|
227
|
+
}, []);
|
|
228
|
+
useEffect(() => {
|
|
229
|
+
var _a2, _b, _c, _d;
|
|
230
|
+
(_a2 = contentRef == null ? void 0 : contentRef.current) == null ? void 0 : _a2.addEventListener("touchstart", handleTouchStart);
|
|
231
|
+
(_b = contentRef == null ? void 0 : contentRef.current) == null ? void 0 : _b.addEventListener("touchmove", handleTouchMove);
|
|
232
|
+
(_c = contentRef == null ? void 0 : contentRef.current) == null ? void 0 : _c.addEventListener("touchend", handleTouchEnd);
|
|
233
|
+
(_d = contentRef == null ? void 0 : contentRef.current) == null ? void 0 : _d.addEventListener("touchcancel", handleTouchEnd);
|
|
234
|
+
if (!isMini && document) {
|
|
235
|
+
document.addEventListener("mouseup", handleTouchEnd);
|
|
236
|
+
}
|
|
237
|
+
return () => {
|
|
238
|
+
var _a3, _b2, _c2, _d2;
|
|
239
|
+
(_a3 = contentRef == null ? void 0 : contentRef.current) == null ? void 0 : _a3.removeEventListener(
|
|
240
|
+
"touchstart",
|
|
241
|
+
handleTouchStart
|
|
242
|
+
);
|
|
243
|
+
(_b2 = contentRef == null ? void 0 : contentRef.current) == null ? void 0 : _b2.removeEventListener("touchmove", handleTouchMove);
|
|
244
|
+
(_c2 = contentRef == null ? void 0 : contentRef.current) == null ? void 0 : _c2.removeEventListener("touchend", handleTouchEnd);
|
|
245
|
+
(_d2 = contentRef == null ? void 0 : contentRef.current) == null ? void 0 : _d2.removeEventListener("touchcancel", handleTouchEnd);
|
|
246
|
+
if (!isMini && document) {
|
|
247
|
+
document.removeEventListener("mouseup", handleTouchEnd);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
}, []);
|
|
251
|
+
useImperativeHandle(ref, () => ({
|
|
252
|
+
show: (params) => __async(void 0, null, function* () {
|
|
253
|
+
let targetX = 0;
|
|
254
|
+
if (params && params.side === SideTypeEnum.RIGHT) {
|
|
255
|
+
targetX = -(yield getRightRefWidth());
|
|
256
|
+
} else {
|
|
257
|
+
targetX = yield getLefRefWidth();
|
|
258
|
+
}
|
|
259
|
+
setTranslateX(targetX);
|
|
260
|
+
pretranslateX = targetX;
|
|
261
|
+
emitActionsReveal(targetX);
|
|
262
|
+
}),
|
|
263
|
+
close,
|
|
264
|
+
// 获取当前是否打开
|
|
265
|
+
open: isOpen,
|
|
266
|
+
ref: rootRef.current
|
|
267
|
+
}));
|
|
268
|
+
const outClickHandle = (e) => {
|
|
269
|
+
e.preventDefault();
|
|
270
|
+
e.stopPropagation();
|
|
271
|
+
if (translateX !== 0 && closeOnClickContainer) {
|
|
272
|
+
close();
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
const SwipeActionContext = useMemo(
|
|
276
|
+
() => ({ closeOnClickActionItem, close }),
|
|
277
|
+
[closeOnClickActionItem]
|
|
278
|
+
);
|
|
279
|
+
return /* @__PURE__ */ React.createElement(BuiSwipeActionContext.Provider, { value: SwipeActionContext }, /* @__PURE__ */ React.createElement(
|
|
280
|
+
"div",
|
|
281
|
+
__spreadValues({
|
|
282
|
+
className: clsx(`${classPrefix}`, className),
|
|
283
|
+
ref: rootRef
|
|
284
|
+
}, others),
|
|
285
|
+
/* @__PURE__ */ React.createElement(
|
|
286
|
+
"div",
|
|
287
|
+
{
|
|
288
|
+
className: `${classPrefix}-track`,
|
|
289
|
+
style: {
|
|
290
|
+
transform: `translate3d(${translateX}px, 0, 0)`
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
/* @__PURE__ */ React.createElement(
|
|
294
|
+
"div",
|
|
295
|
+
{
|
|
296
|
+
className: `${classPrefix}-actions ${classPrefix}-actions-left`,
|
|
297
|
+
ref: leftRef
|
|
298
|
+
},
|
|
299
|
+
leftActions
|
|
300
|
+
),
|
|
301
|
+
/* @__PURE__ */ React.createElement(
|
|
302
|
+
"div",
|
|
303
|
+
{
|
|
304
|
+
className: `${classPrefix}-content-container`,
|
|
305
|
+
ref: contentRef,
|
|
306
|
+
onTouchStart: handleTouchStart,
|
|
307
|
+
onTouchMove: handleTouchMove,
|
|
308
|
+
onTouchEnd: handleTouchEnd,
|
|
309
|
+
onTouchCancel: handleTouchEnd
|
|
310
|
+
},
|
|
311
|
+
isOpen && closeOnClickContainer && /* @__PURE__ */ React.createElement(
|
|
312
|
+
"div",
|
|
313
|
+
{
|
|
314
|
+
className: `${classPrefix}-content-mask`,
|
|
315
|
+
id: "content-mask",
|
|
316
|
+
onClick: outClickHandle
|
|
317
|
+
}
|
|
318
|
+
),
|
|
319
|
+
children
|
|
320
|
+
),
|
|
321
|
+
/* @__PURE__ */ React.createElement(
|
|
322
|
+
"div",
|
|
323
|
+
{
|
|
324
|
+
className: `${classPrefix}-actions ${classPrefix}-actions-right`,
|
|
325
|
+
ref: rightRef
|
|
326
|
+
},
|
|
327
|
+
rightActions
|
|
328
|
+
)
|
|
329
|
+
)
|
|
330
|
+
));
|
|
331
|
+
}
|
|
332
|
+
);
|
|
333
|
+
SwipeAction.displayName = "BuiSwipeAction";
|
|
334
|
+
var SwipeAction_default = SwipeAction;
|
|
335
|
+
export {
|
|
336
|
+
SwipeAction_default as default
|
|
337
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { OverrideProps, ThemeColor } from '@bifrostui/types';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export type SwipeActionProps<D extends React.ElementType = 'div', P = {}> = OverrideProps<{
|
|
4
|
+
props: P & {
|
|
5
|
+
/**
|
|
6
|
+
* 右侧的操作按钮列表区域
|
|
7
|
+
*/
|
|
8
|
+
rightActions?: React.ReactNode;
|
|
9
|
+
/**
|
|
10
|
+
* 左侧的操作按钮列表区域
|
|
11
|
+
*/
|
|
12
|
+
leftActions?: React.ReactNode;
|
|
13
|
+
/**
|
|
14
|
+
* 是否在点击按钮区自动归位
|
|
15
|
+
*/
|
|
16
|
+
closeOnClickActionItem?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* 是否在点击其他区域时自动归位
|
|
19
|
+
*/
|
|
20
|
+
closeOnClickContainer?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* 操作按钮展开时触发
|
|
23
|
+
*/
|
|
24
|
+
onActionsReveal?: (params: RevealParams) => void;
|
|
25
|
+
/**
|
|
26
|
+
* 是否禁用拖动
|
|
27
|
+
*/
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
};
|
|
30
|
+
defaultComponent: D;
|
|
31
|
+
}, D>;
|
|
32
|
+
interface RevealParams {
|
|
33
|
+
side: SideTypeEnum | '';
|
|
34
|
+
}
|
|
35
|
+
export type SwipeActionItemProps<D extends React.ElementType = 'div', P = {}> = OverrideProps<{
|
|
36
|
+
props: P & {
|
|
37
|
+
/**
|
|
38
|
+
* 颜色风格
|
|
39
|
+
*/
|
|
40
|
+
color?: ThemeColor | 'vip';
|
|
41
|
+
/**
|
|
42
|
+
* id
|
|
43
|
+
*/
|
|
44
|
+
id?: string | number;
|
|
45
|
+
/**
|
|
46
|
+
* 点击事件
|
|
47
|
+
*/
|
|
48
|
+
onClick?: (e: React.SyntheticEvent, item: {
|
|
49
|
+
id: string | number;
|
|
50
|
+
color: ThemeColor | 'vip';
|
|
51
|
+
text: React.ReactNode;
|
|
52
|
+
}) => void;
|
|
53
|
+
};
|
|
54
|
+
defaultComponent: D;
|
|
55
|
+
}, D>;
|
|
56
|
+
export interface BuiSwipeActionContextProps {
|
|
57
|
+
/**
|
|
58
|
+
* 是否在点击操作按钮时自动归位
|
|
59
|
+
*/
|
|
60
|
+
closeOnClickActionItem?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* 关闭函数
|
|
63
|
+
*/
|
|
64
|
+
close: () => void;
|
|
65
|
+
}
|
|
66
|
+
export type SwipeActionRef = {
|
|
67
|
+
close: () => void;
|
|
68
|
+
show: (params?: {
|
|
69
|
+
side: SideTypeEnum;
|
|
70
|
+
}) => void;
|
|
71
|
+
open: boolean;
|
|
72
|
+
ref?: HTMLDivElement;
|
|
73
|
+
};
|
|
74
|
+
export declare enum SideTypeEnum {
|
|
75
|
+
LEFT = "left",
|
|
76
|
+
RIGHT = "right"
|
|
77
|
+
}
|
|
78
|
+
export declare enum DragPhaseEnum {
|
|
79
|
+
START = 1,
|
|
80
|
+
MOVE = 2,
|
|
81
|
+
END = 3
|
|
82
|
+
}
|
|
83
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
const BuiSwipeActionContext = createContext({
|
|
3
|
+
closeOnClickActionItem: true,
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
5
|
+
close: () => {
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
var SwipeActionContext_default = BuiSwipeActionContext;
|
|
9
|
+
export {
|
|
10
|
+
SwipeActionContext_default as default
|
|
11
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
.bui-swipe-action-item {
|
|
2
|
+
padding: 0 15px;
|
|
3
|
+
display: flex;
|
|
4
|
+
align-items: center;
|
|
5
|
+
justify-content: center;
|
|
6
|
+
height: 100%;
|
|
7
|
+
width: 100%;
|
|
8
|
+
background: var(--background-button-color);
|
|
9
|
+
color: #fff;
|
|
10
|
+
box-sizing: content-box;
|
|
11
|
+
white-space: nowrap;
|
|
12
|
+
font-family: var(--bui-font-family);
|
|
13
|
+
}
|
|
14
|
+
.bui-swipe-action-item-primary {
|
|
15
|
+
background-color: var(--bui-color-primary);
|
|
16
|
+
}
|
|
17
|
+
.bui-swipe-action-item-vip {
|
|
18
|
+
background-color: var(--bui-color-vip);
|
|
19
|
+
}
|
|
20
|
+
.bui-swipe-action-item-success {
|
|
21
|
+
background-color: var(--bui-color-success);
|
|
22
|
+
}
|
|
23
|
+
.bui-swipe-action-item-info {
|
|
24
|
+
background-color: var(--bui-color-info);
|
|
25
|
+
}
|
|
26
|
+
.bui-swipe-action-item-warning {
|
|
27
|
+
background-color: var(--bui-color-warning);
|
|
28
|
+
}
|
|
29
|
+
.bui-swipe-action-item-danger {
|
|
30
|
+
background-color: var(--bui-color-danger);
|
|
31
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SwipeActionItemProps } from './SwipeAction.types';
|
|
3
|
+
import './SwipeActionItem.less';
|
|
4
|
+
declare const SwipeActionItem: React.ForwardRefExoticComponent<Omit<SwipeActionItemProps<"div", {}>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
5
|
+
export default SwipeActionItem;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __objRest = (source, exclude) => {
|
|
18
|
+
var target = {};
|
|
19
|
+
for (var prop in source)
|
|
20
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
21
|
+
target[prop] = source[prop];
|
|
22
|
+
if (source != null && __getOwnPropSymbols)
|
|
23
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
24
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
};
|
|
29
|
+
import React, { useContext } from "react";
|
|
30
|
+
import clsx from "clsx";
|
|
31
|
+
import BuiSwipeActionContext from "./SwipeActionContext";
|
|
32
|
+
import "./SwipeActionItem.css";
|
|
33
|
+
const prefixCls = "bui-swipe-action-item";
|
|
34
|
+
const SwipeActionItem = /* @__PURE__ */ React.forwardRef(
|
|
35
|
+
(props, ref) => {
|
|
36
|
+
const _a = props, {
|
|
37
|
+
className,
|
|
38
|
+
children,
|
|
39
|
+
onClick,
|
|
40
|
+
color = "primary",
|
|
41
|
+
id = ""
|
|
42
|
+
} = _a, others = __objRest(_a, [
|
|
43
|
+
"className",
|
|
44
|
+
"children",
|
|
45
|
+
"onClick",
|
|
46
|
+
"color",
|
|
47
|
+
"id"
|
|
48
|
+
]);
|
|
49
|
+
const { closeOnClickActionItem, close } = useContext(BuiSwipeActionContext);
|
|
50
|
+
const onClickHandle = (e) => {
|
|
51
|
+
e.stopPropagation();
|
|
52
|
+
if (closeOnClickActionItem) {
|
|
53
|
+
close == null ? void 0 : close();
|
|
54
|
+
}
|
|
55
|
+
onClick == null ? void 0 : onClick(e, {
|
|
56
|
+
color,
|
|
57
|
+
id,
|
|
58
|
+
text: children
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
return /* @__PURE__ */ React.createElement(
|
|
62
|
+
"div",
|
|
63
|
+
__spreadValues({
|
|
64
|
+
className: clsx(prefixCls, className, {
|
|
65
|
+
[`${prefixCls}-${color}`]: color
|
|
66
|
+
}),
|
|
67
|
+
ref,
|
|
68
|
+
onClick: onClickHandle
|
|
69
|
+
}, others),
|
|
70
|
+
children
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
SwipeActionItem.displayName = "SwipeActionItem";
|
|
75
|
+
var SwipeActionItem_default = SwipeActionItem;
|
|
76
|
+
export {
|
|
77
|
+
SwipeActionItem_default as default
|
|
78
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./SwipeAction.types";
|
|
2
|
+
import { default as default2 } from "./SwipeAction";
|
|
3
|
+
import { default as default3 } from "./SwipeAction";
|
|
4
|
+
import { default as default4 } from "./SwipeActionItem";
|
|
5
|
+
export {
|
|
6
|
+
default3 as SwipeAction,
|
|
7
|
+
default4 as SwipeActionItem,
|
|
8
|
+
default2 as default
|
|
9
|
+
};
|
package/es/Tabs/Tab.js
CHANGED
|
@@ -36,7 +36,19 @@ import TabsContext from "./TabsContext";
|
|
|
36
36
|
import "./Tab.css";
|
|
37
37
|
const prefixCls = "bui-tab";
|
|
38
38
|
const Tab = /* @__PURE__ */ React.forwardRef((props, ref) => {
|
|
39
|
-
const _a = props, {
|
|
39
|
+
const _a = props, {
|
|
40
|
+
className,
|
|
41
|
+
children,
|
|
42
|
+
index,
|
|
43
|
+
disabled = false,
|
|
44
|
+
onClick
|
|
45
|
+
} = _a, others = __objRest(_a, [
|
|
46
|
+
"className",
|
|
47
|
+
"children",
|
|
48
|
+
"index",
|
|
49
|
+
"disabled",
|
|
50
|
+
"onClick"
|
|
51
|
+
]);
|
|
40
52
|
const tabsContext = React.useContext(TabsContext);
|
|
41
53
|
const { value, align, triggerChange } = tabsContext;
|
|
42
54
|
return /* @__PURE__ */ React.createElement(
|
|
@@ -74,9 +86,6 @@ const Tab = /* @__PURE__ */ React.forwardRef((props, ref) => {
|
|
|
74
86
|
);
|
|
75
87
|
});
|
|
76
88
|
Tab.displayName = "BuiTab";
|
|
77
|
-
Tab.defaultProps = {
|
|
78
|
-
disabled: false
|
|
79
|
-
};
|
|
80
89
|
var Tab_default = Tab;
|
|
81
90
|
export {
|
|
82
91
|
Tab_default as default
|
package/es/Tabs/Tabs.js
CHANGED
|
@@ -42,9 +42,10 @@ import React, {
|
|
|
42
42
|
} from "react";
|
|
43
43
|
import Tab from "./Tab";
|
|
44
44
|
import { TabsContextProvider } from "./TabsContext";
|
|
45
|
-
import
|
|
45
|
+
import scrollLeftTo from "./utils/scroll";
|
|
46
46
|
import "./Tabs.css";
|
|
47
47
|
const prefixCls = "bui-tabs";
|
|
48
|
+
const duration = 300;
|
|
48
49
|
const Tabs = /* @__PURE__ */ React.forwardRef((props, ref) => {
|
|
49
50
|
const _a = props, { children, className, value, tabs, align, onChange } = _a, others = __objRest(_a, ["children", "className", "value", "tabs", "align", "onChange"]);
|
|
50
51
|
const [active, setActive] = useState("");
|
|
@@ -59,14 +60,11 @@ const Tabs = /* @__PURE__ */ React.forwardRef((props, ref) => {
|
|
|
59
60
|
leftMaskOpacity: 0,
|
|
60
61
|
rightMaskOpacity: 0
|
|
61
62
|
});
|
|
62
|
-
const
|
|
63
|
+
const getActiveTabElement = () => {
|
|
63
64
|
const container = tabsRef.current;
|
|
64
65
|
if (!container)
|
|
65
|
-
return;
|
|
66
|
+
return void 0;
|
|
66
67
|
const activeIndex = !!tabs.length && tabs.findIndex((item) => item.index === active);
|
|
67
|
-
const activeLine = activeLineRef.current;
|
|
68
|
-
if (!activeLine)
|
|
69
|
-
return;
|
|
70
68
|
let activeTab;
|
|
71
69
|
if (tabs.length) {
|
|
72
70
|
activeTab = activeIndex > -1 ? container.childNodes[activeIndex + 1] : void 0;
|
|
@@ -80,6 +78,25 @@ const Tabs = /* @__PURE__ */ React.forwardRef((props, ref) => {
|
|
|
80
78
|
return [...child.classList].includes("bui-tab-active");
|
|
81
79
|
});
|
|
82
80
|
}
|
|
81
|
+
return activeTab;
|
|
82
|
+
};
|
|
83
|
+
const scrollIntoView = () => {
|
|
84
|
+
const tabsContainer = tabsRef.current;
|
|
85
|
+
const activeTab = getActiveTabElement();
|
|
86
|
+
if (!tabsContainer || !activeTab) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const to = activeTab.offsetLeft - (tabsContainer.offsetWidth - activeTab.offsetWidth) / 2;
|
|
90
|
+
scrollLeftTo(tabsContainer, to, duration);
|
|
91
|
+
};
|
|
92
|
+
const animate = ({ transitionInUse }) => {
|
|
93
|
+
const container = tabsRef.current;
|
|
94
|
+
if (!container)
|
|
95
|
+
return;
|
|
96
|
+
const activeLine = activeLineRef.current;
|
|
97
|
+
if (!activeLine)
|
|
98
|
+
return;
|
|
99
|
+
const activeTab = getActiveTabElement();
|
|
83
100
|
let activeTabLeft = 0;
|
|
84
101
|
let activeTabWidth = 0;
|
|
85
102
|
let containerWidth = 0;
|
|
@@ -102,13 +119,8 @@ const Tabs = /* @__PURE__ */ React.forwardRef((props, ref) => {
|
|
|
102
119
|
const maxScrollDistance = containerScrollWidth - containerWidth;
|
|
103
120
|
if (maxScrollDistance <= 0 || !activeTab)
|
|
104
121
|
return;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
0,
|
|
108
|
-
containerScrollWidth - containerWidth
|
|
109
|
-
);
|
|
110
|
-
if (tabsRef.current) {
|
|
111
|
-
tabsRef.current.scrollLeft = nextScrollLeft;
|
|
122
|
+
if (!isMini) {
|
|
123
|
+
scrollIntoView();
|
|
112
124
|
}
|
|
113
125
|
};
|
|
114
126
|
useEffect(() => {
|
|
@@ -138,7 +150,10 @@ const Tabs = /* @__PURE__ */ React.forwardRef((props, ref) => {
|
|
|
138
150
|
return;
|
|
139
151
|
const scrollLeft = container == null ? void 0 : container.scrollLeft;
|
|
140
152
|
const showLeftMask = scrollLeft > 0;
|
|
141
|
-
const
|
|
153
|
+
const rightRange = Math.abs(
|
|
154
|
+
container.scrollWidth - (scrollLeft + container.offsetWidth)
|
|
155
|
+
);
|
|
156
|
+
const showRightMask = rightRange > 1;
|
|
142
157
|
setMaskData({
|
|
143
158
|
leftMaskOpacity: showLeftMask ? 1 : 0,
|
|
144
159
|
rightMaskOpacity: showRightMask ? 1 : 0
|
|
@@ -196,7 +211,7 @@ const Tabs = /* @__PURE__ */ React.forwardRef((props, ref) => {
|
|
|
196
211
|
"bui-tabline-invisible": isMini || !lineData.hasActiveTab
|
|
197
212
|
}),
|
|
198
213
|
style: {
|
|
199
|
-
transition: lineData.transitionInUse ?
|
|
214
|
+
transition: lineData.transitionInUse ? `transform ${duration / 1e3}s ease` : void 0,
|
|
200
215
|
transform: `translate3d(${lineData.x}px, 0px, 0px)`
|
|
201
216
|
}
|
|
202
217
|
}
|