@bifrostui/react 2.0.0-alpha.13 → 2.0.0-alpha.15

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.
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
2
  import { DatePickerProps } from './DatePicker.types';
3
- declare const DatePicker: React.ForwardRefExoticComponent<Omit<DatePickerProps<"div", Omit<import("../Picker").PickerProps<"div", import("..").DrawerProps>, "value" | "defaultValue" | "onChange" | "onClose" | "onConfirm">>, "ref"> & React.RefAttributes<HTMLDivElement>>;
3
+ declare const DatePicker: React.ForwardRefExoticComponent<Omit<DatePickerProps<"div", Omit<import("../Picker").PickerProps<"div", import("..").DrawerProps>, "defaultValue" | "onChange" | "value" | "onClose" | "onConfirm">>, "ref"> & React.RefAttributes<HTMLDivElement>>;
4
4
  export default DatePicker;
@@ -12,5 +12,5 @@ declare const Modal: React.ForwardRefExoticComponent<Omit<ViewProps & {
12
12
  keepMounted?: boolean;
13
13
  } & import("@bifrostui/types").ICommonProps & Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
14
14
  ref?: React.Ref<HTMLDivElement>;
15
- }, "open" | "container" | keyof import("@bifrostui/types").ICommonProps | "disablePortal" | "hideBackdrop" | "BackdropProps" | "onClose" | "disableScrollLock" | "keepMounted">, "ref"> & React.RefAttributes<HTMLDivElement>>;
15
+ }, keyof import("@bifrostui/types").ICommonProps | "open" | "container" | "disablePortal" | "onClose" | "hideBackdrop" | "BackdropProps" | "disableScrollLock" | "keepMounted">, "ref"> & React.RefAttributes<HTMLDivElement>>;
16
16
  export default Modal;
@@ -32,7 +32,6 @@ __export(Tab_exports, {
32
32
  module.exports = __toCommonJS(Tab_exports);
33
33
  var import_react = __toESM(require("react"));
34
34
  var import_clsx = __toESM(require("clsx"));
35
- var import_components = require("@tarojs/components");
36
35
  var import_utils = require("@bifrostui/utils");
37
36
  var import_TabsContext = __toESM(require("./TabsContext"));
38
37
  var import_classes = require("../classes");
@@ -83,7 +82,7 @@ const Tab = (props) => {
83
82
  );
84
83
  const tabId = tabsContainerId ? `${tabsContainerId}-tab-${index}` : void 0;
85
84
  return /* @__PURE__ */ import_react.default.createElement(
86
- import_components.View,
85
+ "div",
87
86
  {
88
87
  id: tabId,
89
88
  className: rootCls,
@@ -53,7 +53,6 @@ module.exports = __toCommonJS(TabIndicator_exports);
53
53
  var import_react = __toESM(require("react"));
54
54
  var import_clsx = __toESM(require("clsx"));
55
55
  var import_taro = __toESM(require("@tarojs/taro"));
56
- var import_components = require("@tarojs/components");
57
56
  var import_utils = require("@bifrostui/utils");
58
57
  var import_classes = require("../classes");
59
58
  var import_queryBatch = require("./utils/queryBatch");
@@ -191,7 +190,7 @@ const TabIndicator = ({
191
190
  };
192
191
  }, [initializePositions]);
193
192
  return /* @__PURE__ */ import_react.default.createElement(
194
- import_components.View,
193
+ "div",
195
194
  {
196
195
  id: `${wrapperId}-indicator`,
197
196
  className: (0, import_clsx.default)(import_classes.tabIndicatorClass),
@@ -32,7 +32,6 @@ __export(TabMask_exports, {
32
32
  module.exports = __toCommonJS(TabMask_exports);
33
33
  var import_react = __toESM(require("react"));
34
34
  var import_clsx = __toESM(require("clsx"));
35
- var import_components = require("@tarojs/components");
36
35
  var import_classes = require("../classes");
37
36
  const TabMask = ({
38
37
  position,
@@ -48,7 +47,7 @@ const TabMask = ({
48
47
  return rightRange > 1;
49
48
  }, [position, scrollLeft, containerWidth, scrollWidth]);
50
49
  return /* @__PURE__ */ import_react.default.createElement(
51
- import_components.View,
50
+ "div",
52
51
  {
53
52
  className: (0, import_clsx.default)(
54
53
  import_classes.tabMaskClass,
@@ -126,8 +126,8 @@ const Tabs = (props) => {
126
126
  });
127
127
  const handleClick = (0, import_utils.useEventCallback)(
128
128
  (e, item) => {
129
- const { index, disabled: isDisabled = false } = item;
130
- if (isDisabled || [void 0, null].includes(index))
129
+ const { index, disabled = false } = item;
130
+ if (disabled || [void 0, null].includes(index))
131
131
  return;
132
132
  if (index !== currentValue) {
133
133
  triggerValueChange(e, index);
@@ -164,33 +164,47 @@ const Tabs = (props) => {
164
164
  }
165
165
  }));
166
166
  }, [scrollViewId, registrationVersion, registeredTabValues.length]);
167
+ const centerActiveTab = (0, import_utils.useEventCallback)(() => __async(void 0, null, function* () {
168
+ if (!currentValue || registeredTabValues.length === 0) {
169
+ return;
170
+ }
171
+ const { scrollView, scrollFields, wrapper, currentTab } = yield (0, import_queryBatch.batchQueryForScroll)({
172
+ scrollViewId,
173
+ wrapperId,
174
+ currentTabValue: currentValue
175
+ });
176
+ if (!scrollView || !scrollFields || !wrapper || !currentTab || currentTab.width === 0) {
177
+ return;
178
+ }
179
+ const tabLeftRelativeToWrapper = currentTab.left - wrapper.left;
180
+ const tabWidth = currentTab.width;
181
+ const containerViewWidth = scrollView.width;
182
+ const currentScrollWidth = scrollFields.scrollWidth || scrollView.width;
183
+ const targetScrollLeft = tabLeftRelativeToWrapper - (containerViewWidth - tabWidth) / 2;
184
+ const maxScrollDistance = currentScrollWidth - containerViewWidth;
185
+ const finalScrollLeft = Math.max(
186
+ 0,
187
+ Math.min(targetScrollLeft, maxScrollDistance)
188
+ );
189
+ setScrollLeft(finalScrollLeft);
190
+ lastScrollLeftRef.current = finalScrollLeft;
191
+ }));
167
192
  import_react.default.useEffect(() => {
168
193
  if (!currentValue || registeredTabValues.length === 0) {
169
194
  return;
170
195
  }
171
- import_taro.default.nextTick(() => __async(void 0, null, function* () {
172
- const { scrollView, scrollFields, wrapper, currentTab } = yield (0, import_queryBatch.batchQueryForScroll)({
173
- scrollViewId,
174
- wrapperId,
175
- currentTabValue: currentValue
176
- });
177
- if (!scrollView || !scrollFields || !wrapper || !currentTab || currentTab.width === 0) {
178
- return;
179
- }
180
- const tabLeftRelativeToWrapper = currentTab.left - wrapper.left;
181
- const tabWidth = currentTab.width;
182
- const containerViewWidth = scrollView.width;
183
- const currentScrollWidth = scrollFields.scrollWidth || scrollView.width;
184
- const targetScrollLeft = tabLeftRelativeToWrapper - (containerViewWidth - tabWidth) / 2;
185
- const maxScrollDistance = currentScrollWidth - containerViewWidth;
186
- const finalScrollLeft = Math.max(
187
- 0,
188
- Math.min(targetScrollLeft, maxScrollDistance)
189
- );
190
- setScrollLeft(finalScrollLeft);
191
- lastScrollLeftRef.current = finalScrollLeft;
192
- }));
193
- }, [currentValue, scrollViewId, wrapperId]);
196
+ import_taro.default.nextTick(() => {
197
+ centerActiveTab();
198
+ });
199
+ }, [currentValue, centerActiveTab]);
200
+ import_react.default.useEffect(() => {
201
+ if (!currentValue || registeredTabValues.length === 0) {
202
+ return;
203
+ }
204
+ import_taro.default.nextTick(() => {
205
+ centerActiveTab();
206
+ });
207
+ }, [registrationVersion, centerActiveTab]);
194
208
  const contextValue = (0, import_react.useMemo)(
195
209
  () => ({
196
210
  value: currentValue,
@@ -214,7 +228,7 @@ const Tabs = (props) => {
214
228
  }
215
229
  };
216
230
  }, []);
217
- return /* @__PURE__ */ import_react.default.createElement(import_components.View, { className: (0, import_clsx.default)(import_classes.tabsRootClass, className), style }, /* @__PURE__ */ import_react.default.createElement(
231
+ return /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_clsx.default)(import_classes.tabsRootClass, className), style }, /* @__PURE__ */ import_react.default.createElement(
218
232
  import_TabMask.default,
219
233
  {
220
234
  position: "left",
@@ -245,7 +259,7 @@ const Tabs = (props) => {
245
259
  enablePassive: true,
246
260
  enableFlex: true
247
261
  },
248
- /* @__PURE__ */ import_react.default.createElement(import_components.View, { id: wrapperId, className: import_classes.tabsScrollWrapperClass }, /* @__PURE__ */ import_react.default.createElement(
262
+ /* @__PURE__ */ import_react.default.createElement("div", { id: wrapperId, className: import_classes.tabsScrollWrapperClass }, /* @__PURE__ */ import_react.default.createElement(
249
263
  import_TabIndicator.default,
250
264
  {
251
265
  currentValue,
@@ -1,6 +1,5 @@
1
1
  import React, { useEffect } from "react";
2
2
  import clsx from "clsx";
3
- import { View } from "@tarojs/components";
4
3
  import { useContextSelector } from "@bifrostui/utils";
5
4
  import TabsContext from "./TabsContext";
6
5
  import { tabRootClass, tabActiveClass, tabDisabledClass } from "../classes";
@@ -51,7 +50,7 @@ const Tab = (props) => {
51
50
  );
52
51
  const tabId = tabsContainerId ? `${tabsContainerId}-tab-${index}` : void 0;
53
52
  return /* @__PURE__ */ React.createElement(
54
- View,
53
+ "div",
55
54
  {
56
55
  id: tabId,
57
56
  className: rootCls,
@@ -21,7 +21,6 @@ var __async = (__this, __arguments, generator) => {
21
21
  import React, { useEffect, useRef, useState } from "react";
22
22
  import clsx from "clsx";
23
23
  import Taro from "@tarojs/taro";
24
- import { View } from "@tarojs/components";
25
24
  import { useEventCallback } from "@bifrostui/utils";
26
25
  import { tabIndicatorClass } from "../classes";
27
26
  import { batchQueryTabs } from "./utils/queryBatch";
@@ -159,7 +158,7 @@ const TabIndicator = ({
159
158
  };
160
159
  }, [initializePositions]);
161
160
  return /* @__PURE__ */ React.createElement(
162
- View,
161
+ "div",
163
162
  {
164
163
  id: `${wrapperId}-indicator`,
165
164
  className: clsx(tabIndicatorClass),
@@ -1,6 +1,5 @@
1
1
  import React from "react";
2
2
  import clsx from "clsx";
3
- import { View } from "@tarojs/components";
4
3
  import { tabMaskClass, tabMaskLeftClass, tabMaskRightClass } from "../classes";
5
4
  const TabMask = ({
6
5
  position,
@@ -16,7 +15,7 @@ const TabMask = ({
16
15
  return rightRange > 1;
17
16
  }, [position, scrollLeft, containerWidth, scrollWidth]);
18
17
  return /* @__PURE__ */ React.createElement(
19
- View,
18
+ "div",
20
19
  {
21
20
  className: clsx(
22
21
  tabMaskClass,
@@ -21,7 +21,7 @@ var __async = (__this, __arguments, generator) => {
21
21
  import React, { useMemo, useState } from "react";
22
22
  import clsx from "clsx";
23
23
  import Taro from "@tarojs/taro";
24
- import { View, ScrollView } from "@tarojs/components";
24
+ import { ScrollView } from "@tarojs/components";
25
25
  import { useValue, useEventCallback } from "@bifrostui/utils";
26
26
  import Tab from "./Tab";
27
27
  import TabIndicator from "./TabIndicator";
@@ -101,8 +101,8 @@ const Tabs = (props) => {
101
101
  });
102
102
  const handleClick = useEventCallback(
103
103
  (e, item) => {
104
- const { index, disabled: isDisabled = false } = item;
105
- if (isDisabled || [void 0, null].includes(index))
104
+ const { index, disabled = false } = item;
105
+ if (disabled || [void 0, null].includes(index))
106
106
  return;
107
107
  if (index !== currentValue) {
108
108
  triggerValueChange(e, index);
@@ -139,33 +139,47 @@ const Tabs = (props) => {
139
139
  }
140
140
  }));
141
141
  }, [scrollViewId, registrationVersion, registeredTabValues.length]);
142
+ const centerActiveTab = useEventCallback(() => __async(void 0, null, function* () {
143
+ if (!currentValue || registeredTabValues.length === 0) {
144
+ return;
145
+ }
146
+ const { scrollView, scrollFields, wrapper, currentTab } = yield batchQueryForScroll({
147
+ scrollViewId,
148
+ wrapperId,
149
+ currentTabValue: currentValue
150
+ });
151
+ if (!scrollView || !scrollFields || !wrapper || !currentTab || currentTab.width === 0) {
152
+ return;
153
+ }
154
+ const tabLeftRelativeToWrapper = currentTab.left - wrapper.left;
155
+ const tabWidth = currentTab.width;
156
+ const containerViewWidth = scrollView.width;
157
+ const currentScrollWidth = scrollFields.scrollWidth || scrollView.width;
158
+ const targetScrollLeft = tabLeftRelativeToWrapper - (containerViewWidth - tabWidth) / 2;
159
+ const maxScrollDistance = currentScrollWidth - containerViewWidth;
160
+ const finalScrollLeft = Math.max(
161
+ 0,
162
+ Math.min(targetScrollLeft, maxScrollDistance)
163
+ );
164
+ setScrollLeft(finalScrollLeft);
165
+ lastScrollLeftRef.current = finalScrollLeft;
166
+ }));
142
167
  React.useEffect(() => {
143
168
  if (!currentValue || registeredTabValues.length === 0) {
144
169
  return;
145
170
  }
146
- Taro.nextTick(() => __async(void 0, null, function* () {
147
- const { scrollView, scrollFields, wrapper, currentTab } = yield batchQueryForScroll({
148
- scrollViewId,
149
- wrapperId,
150
- currentTabValue: currentValue
151
- });
152
- if (!scrollView || !scrollFields || !wrapper || !currentTab || currentTab.width === 0) {
153
- return;
154
- }
155
- const tabLeftRelativeToWrapper = currentTab.left - wrapper.left;
156
- const tabWidth = currentTab.width;
157
- const containerViewWidth = scrollView.width;
158
- const currentScrollWidth = scrollFields.scrollWidth || scrollView.width;
159
- const targetScrollLeft = tabLeftRelativeToWrapper - (containerViewWidth - tabWidth) / 2;
160
- const maxScrollDistance = currentScrollWidth - containerViewWidth;
161
- const finalScrollLeft = Math.max(
162
- 0,
163
- Math.min(targetScrollLeft, maxScrollDistance)
164
- );
165
- setScrollLeft(finalScrollLeft);
166
- lastScrollLeftRef.current = finalScrollLeft;
167
- }));
168
- }, [currentValue, scrollViewId, wrapperId]);
171
+ Taro.nextTick(() => {
172
+ centerActiveTab();
173
+ });
174
+ }, [currentValue, centerActiveTab]);
175
+ React.useEffect(() => {
176
+ if (!currentValue || registeredTabValues.length === 0) {
177
+ return;
178
+ }
179
+ Taro.nextTick(() => {
180
+ centerActiveTab();
181
+ });
182
+ }, [registrationVersion, centerActiveTab]);
169
183
  const contextValue = useMemo(
170
184
  () => ({
171
185
  value: currentValue,
@@ -189,7 +203,7 @@ const Tabs = (props) => {
189
203
  }
190
204
  };
191
205
  }, []);
192
- return /* @__PURE__ */ React.createElement(View, { className: clsx(tabsRootClass, className), style }, /* @__PURE__ */ React.createElement(
206
+ return /* @__PURE__ */ React.createElement("div", { className: clsx(tabsRootClass, className), style }, /* @__PURE__ */ React.createElement(
193
207
  TabMask,
194
208
  {
195
209
  position: "left",
@@ -220,7 +234,7 @@ const Tabs = (props) => {
220
234
  enablePassive: true,
221
235
  enableFlex: true
222
236
  },
223
- /* @__PURE__ */ React.createElement(View, { id: wrapperId, className: tabsScrollWrapperClass }, /* @__PURE__ */ React.createElement(
237
+ /* @__PURE__ */ React.createElement("div", { id: wrapperId, className: tabsScrollWrapperClass }, /* @__PURE__ */ React.createElement(
224
238
  TabIndicator,
225
239
  {
226
240
  currentValue,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bifrostui/react",
3
- "version": "2.0.0-alpha.13",
3
+ "version": "2.0.0-alpha.15",
4
4
  "description": "React components for building mobile application",
5
5
  "homepage": "http://bui.taopiaopiao.com",
6
6
  "license": "MIT",
@@ -43,10 +43,10 @@
43
43
  "clsx": "^2.1.1",
44
44
  "dayjs": "^1.11.7",
45
45
  "swiper": "^8.1.5",
46
- "@bifrostui/styles": "2.0.0-alpha.13",
47
- "@bifrostui/icons": "2.0.0-alpha.13",
48
- "@bifrostui/types": "2.0.0-alpha.13",
49
- "@bifrostui/utils": "2.0.0-alpha.13"
46
+ "@bifrostui/icons": "2.0.0-alpha.15",
47
+ "@bifrostui/styles": "2.0.0-alpha.15",
48
+ "@bifrostui/types": "2.0.0-alpha.15",
49
+ "@bifrostui/utils": "2.0.0-alpha.15"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "@tarojs/components": "^3.0.0",