@bifrostui/react 1.4.2 → 1.4.3-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.
@@ -30,6 +30,7 @@
30
30
  }
31
31
  .bui-input-input {
32
32
  flex: 1;
33
+ min-width: 0;
33
34
  display: flex;
34
35
  align-items: center;
35
36
  padding: 0;
@@ -39,16 +40,11 @@
39
40
  outline: none;
40
41
  background-color: var(--background-color);
41
42
  font-size: var(--bui-text-size-2);
42
- width: auto;
43
- overflow: hidden;
44
- text-overflow: ellipsis;
45
- white-space: nowrap;
46
43
  }
47
44
  .bui-input-input::placeholder {
48
45
  color: var(--bui-color-fg-subtle);
49
46
  }
50
47
  .bui-input-disabled {
51
- pointer-events: none;
52
48
  background-color: var(--disabled-background-color);
53
49
  }
54
50
  .bui-input-disabled .bui-input-input {
@@ -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" | keyof import("@bifrostui/types").ICommonProps | "container" | "disablePortal" | "hideBackdrop" | "BackdropProps" | "onClose" | "disableScrollLock" | "keepMounted">, "ref"> & React.RefAttributes<HTMLDivElement>>;
15
+ }, "open" | "container" | "disablePortal" | keyof import("@bifrostui/types").ICommonProps | "onClose" | "keepMounted" | "BackdropProps" | "hideBackdrop" | "disableScrollLock">, "ref"> & React.RefAttributes<HTMLDivElement>>;
16
16
  export default Modal;
@@ -3,7 +3,7 @@
3
3
  --localtion-position: var(--bui-popover-localtion-position, 8PX);
4
4
  --max-width: var(--bui-popover-max-width, 350px);
5
5
  --content-min-width: var(--bui-popover-content-min-width, 30px);
6
- --content-padding: var(--bui-popover-content-padding, 0);
6
+ --content-padding: var(--bui-popover-content-padding, 6px 8px);
7
7
  max-width: var(--max-width);
8
8
  font-size: var(--bui-text-size-1);
9
9
  position: absolute;
@@ -70,6 +70,7 @@ const Popover = /* @__PURE__ */ import_react.default.forwardRef((props, ref) =>
70
70
  title,
71
71
  content,
72
72
  defaultOpen,
73
+ offsetSpacing = 0,
73
74
  placement = "top",
74
75
  trigger = "click",
75
76
  onOpenChange,
@@ -82,6 +83,7 @@ const Popover = /* @__PURE__ */ import_react.default.forwardRef((props, ref) =>
82
83
  "title",
83
84
  "content",
84
85
  "defaultOpen",
86
+ "offsetSpacing",
85
87
  "placement",
86
88
  "trigger",
87
89
  "onOpenChange",
@@ -89,15 +91,7 @@ const Popover = /* @__PURE__ */ import_react.default.forwardRef((props, ref) =>
89
91
  "hideArrow"
90
92
  ]);
91
93
  const controlByUser = typeof open !== "undefined";
92
- const positionArr = placement.split(/([A-Z])/);
93
- const direction = positionArr[0];
94
- let location;
95
- if (positionArr.length > 1) {
96
- positionArr.splice(0, 1);
97
- location = positionArr.join("").toLowerCase();
98
- } else {
99
- location = "center";
100
- }
94
+ const { direction, location = "center" } = (0, import_utils.parsePlacement)(placement);
101
95
  const childrenRef = (0, import_react.useRef)();
102
96
  const [openStatus, setOpenStatus] = (0, import_react.useState)(defaultOpen);
103
97
  const [arrowDirection, setArrowDirection] = (0, import_react.useState)(direction);
@@ -132,10 +126,15 @@ const Popover = /* @__PURE__ */ import_react.default.forwardRef((props, ref) =>
132
126
  hidePopover(event);
133
127
  };
134
128
  const onRootElementMouted = (0, import_utils.throttle)(() => {
129
+ const {
130
+ direction: newParsedDirection,
131
+ location: newParsedLocation = "center"
132
+ } = (0, import_utils.parsePlacement)(placement);
135
133
  const result = (0, import_utils.getStylesAndLocation)({
136
134
  childrenRef,
137
- arrowDirection,
138
- arrowLocation,
135
+ arrowDirection: newParsedDirection,
136
+ arrowLocation: newParsedLocation,
137
+ offsetSpacing,
139
138
  selector: `[data-id="tt_${ttId}"]`
140
139
  });
141
140
  if (!result)
@@ -25,6 +25,10 @@ export type PopoverProps<D extends React.ElementType = 'div', P = {}> = Override
25
25
  * @default false
26
26
  */
27
27
  hideArrow?: boolean;
28
+ /**
29
+ * 用于控制浮层和目标元素偏移量
30
+ */
31
+ offsetSpacing?: number;
28
32
  /**
29
33
  * 气泡框位置
30
34
  * @default 'top'
@@ -61,7 +61,19 @@ var import_react = __toESM(require("react"));
61
61
  var import_TabPanel = require("./TabPanel.css");
62
62
  const prefixCls = "bui-tabpanel";
63
63
  const TabPanel = (0, import_react.forwardRef)((props, ref) => {
64
- const _a = props, { className, children, value, index, keepMounted } = _a, others = __objRest(_a, ["className", "children", "value", "index", "keepMounted"]);
64
+ const _a = props, {
65
+ className,
66
+ children,
67
+ value,
68
+ index,
69
+ keepMounted = false
70
+ } = _a, others = __objRest(_a, [
71
+ "className",
72
+ "children",
73
+ "value",
74
+ "index",
75
+ "keepMounted"
76
+ ]);
65
77
  const keepActiveDom = keepMounted ? children : null;
66
78
  return /* @__PURE__ */ import_react.default.createElement(
67
79
  "div",
@@ -76,7 +88,4 @@ const TabPanel = (0, import_react.forwardRef)((props, ref) => {
76
88
  );
77
89
  });
78
90
  TabPanel.displayName = "BuiTabPanel";
79
- TabPanel.defaultProps = {
80
- keepMounted: false
81
- };
82
91
  var TabPanel_default = TabPanel;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import './Tabs.less';
3
2
  import { TabsProps } from './Tabs.types';
3
+ import './Tabs.less';
4
4
  declare const Tabs: React.ForwardRefExoticComponent<Omit<TabsProps<"div", {}>, "ref"> & React.RefAttributes<HTMLDivElement>>;
5
5
  export default Tabs;
package/dist/Tabs/Tabs.js CHANGED
@@ -60,9 +60,9 @@ var import_utils = require("@bifrostui/utils");
60
60
  var import_clsx = __toESM(require("clsx"));
61
61
  var import_react = __toESM(require("react"));
62
62
  var import_Tab = __toESM(require("./Tab"));
63
- var import_Tabs = require("./Tabs.css");
64
63
  var import_TabsContext = require("./TabsContext");
65
64
  var import_bound = __toESM(require("./utils/bound"));
65
+ var import_Tabs2 = require("./Tabs.css");
66
66
  const prefixCls = "bui-tabs";
67
67
  const Tabs = /* @__PURE__ */ import_react.default.forwardRef((props, ref) => {
68
68
  const _a = props, { children, className, value, tabs, align, onChange } = _a, others = __objRest(_a, ["children", "className", "value", "tabs", "align", "onChange"]);
@@ -81,16 +81,13 @@ const Tabs = /* @__PURE__ */ import_react.default.forwardRef((props, ref) => {
81
81
  const container = tabsRef.current;
82
82
  if (!container)
83
83
  return;
84
- const activeIndex = !!tabs.length && tabs.findIndex((item) => {
85
- var _a2;
86
- return item.index === (active || ((_a2 = tabs[0]) == null ? void 0 : _a2.index));
87
- });
84
+ const activeIndex = !!tabs.length && tabs.findIndex((item) => item.index === active);
88
85
  const activeLine = activeLineRef.current;
89
86
  if (!activeLine)
90
87
  return;
91
88
  let activeTab;
92
89
  if (tabs.length) {
93
- activeTab = container.childNodes[activeIndex + 1];
90
+ activeTab = activeIndex > -1 ? container.childNodes[activeIndex + 1] : void 0;
94
91
  } else {
95
92
  activeTab = [...container.childNodes].find((child) => {
96
93
  if (import_utils.isMini) {
@@ -101,20 +98,26 @@ const Tabs = /* @__PURE__ */ import_react.default.forwardRef((props, ref) => {
101
98
  return [...child.classList].includes("bui-tab-active");
102
99
  });
103
100
  }
104
- if (!activeTab)
105
- return;
106
- const activeTabLeft = activeTab.offsetLeft;
107
- const activeTabWidth = activeTab.offsetWidth;
108
- const containerWidth = container.offsetWidth;
109
- const containerScrollWidth = container.scrollWidth;
110
- const activeLineWidth = activeLine.offsetWidth;
111
- const x = activeTabLeft + (activeTabWidth - activeLineWidth) / 2;
101
+ let activeTabLeft = 0;
102
+ let activeTabWidth = 0;
103
+ let containerWidth = 0;
104
+ let containerScrollWidth = 0;
105
+ let activeLineWidth = 0;
106
+ let x = 0;
107
+ if (activeTab) {
108
+ activeTabLeft = activeTab.offsetLeft;
109
+ activeTabWidth = activeTab.offsetWidth;
110
+ containerWidth = container.offsetWidth;
111
+ containerScrollWidth = container.scrollWidth;
112
+ activeLineWidth = activeLine.offsetWidth;
113
+ x = activeTabLeft + (activeTabWidth - activeLineWidth) / 2;
114
+ }
112
115
  setLineData({
113
116
  x,
114
117
  transitionInUse
115
118
  });
116
119
  const maxScrollDistance = containerScrollWidth - containerWidth;
117
- if (maxScrollDistance <= 0)
120
+ if (maxScrollDistance <= 0 || !activeTab)
118
121
  return;
119
122
  const nextScrollLeft = (0, import_bound.default)(
120
123
  activeTabLeft - (containerWidth - activeTabWidth) / 2,
@@ -126,8 +129,7 @@ const Tabs = /* @__PURE__ */ import_react.default.forwardRef((props, ref) => {
126
129
  }
127
130
  };
128
131
  (0, import_react.useEffect)(() => {
129
- const defaultIndex = safeValue();
130
- setActive(defaultIndex);
132
+ setActive(value);
131
133
  }, [value]);
132
134
  (0, import_react.useLayoutEffect)(() => {
133
135
  animate({ transitionInUse: false });
@@ -145,26 +147,6 @@ const Tabs = /* @__PURE__ */ import_react.default.forwardRef((props, ref) => {
145
147
  (0, import_utils.useDidMountEffect)(() => {
146
148
  animate({ transitionInUse: true });
147
149
  }, [active, tabs, children]);
148
- const safeValue = () => {
149
- var _a2;
150
- let defaultIndex = value;
151
- const childs = import_react.default.Children.toArray(children);
152
- const hasSameChild = !!childs.length && childs.some(
153
- (child) => {
154
- var _a3;
155
- return import_react.default.isValidElement(child) && ((_a3 = child == null ? void 0 : child.props) == null ? void 0 : _a3.index) === value;
156
- }
157
- );
158
- if (!!tabs.length && !tabs.some((item) => item.index === value)) {
159
- defaultIndex = (_a2 = tabs[0]) == null ? void 0 : _a2.index;
160
- } else if (children && !hasSameChild) {
161
- const childNode = childs[0];
162
- if (import_react.default.isValidElement(childNode)) {
163
- defaultIndex = childNode.props.index;
164
- }
165
- }
166
- return defaultIndex;
167
- };
168
150
  const updateMask = (0, import_react.useMemo)(
169
151
  () => (0, import_utils.throttle)(
170
152
  () => {
@@ -205,8 +187,7 @@ const Tabs = /* @__PURE__ */ import_react.default.forwardRef((props, ref) => {
205
187
  }
206
188
  };
207
189
  const providerValue = (0, import_react.useMemo)(() => {
208
- const v = safeValue();
209
- return { value: v, align, triggerChange: handleClick };
190
+ return { value, align, triggerChange: handleClick };
210
191
  }, [value, align, children, handleClick]);
211
192
  return /* @__PURE__ */ import_react.default.createElement("div", __spreadValues({ ref, className: (0, import_clsx.default)(prefixCls, className) }, others), /* @__PURE__ */ import_react.default.createElement(
212
193
  "div",
@@ -229,7 +210,7 @@ const Tabs = /* @__PURE__ */ import_react.default.forwardRef((props, ref) => {
229
210
  {
230
211
  ref: activeLineRef,
231
212
  className: (0, import_clsx.default)(`${prefixCls}-tabline`, {
232
- "bui-tabline-invisible": import_utils.isMini
213
+ "bui-tabline-invisible": import_utils.isMini || !lineData.x
233
214
  }),
234
215
  style: {
235
216
  transition: lineData.transitionInUse ? "transform 0.25s ease-in-out" : void 0,
@@ -69,6 +69,7 @@ const Tooltip = /* @__PURE__ */ import_react.default.forwardRef((props, ref) =>
69
69
  children,
70
70
  title,
71
71
  defaultOpen,
72
+ offsetSpacing = 0,
72
73
  placement = "top",
73
74
  trigger = "click",
74
75
  onOpenChange,
@@ -79,21 +80,14 @@ const Tooltip = /* @__PURE__ */ import_react.default.forwardRef((props, ref) =>
79
80
  "children",
80
81
  "title",
81
82
  "defaultOpen",
83
+ "offsetSpacing",
82
84
  "placement",
83
85
  "trigger",
84
86
  "onOpenChange",
85
87
  "open"
86
88
  ]);
87
89
  const controlByUser = typeof open !== "undefined";
88
- const positionArr = placement.split(/([A-Z])/);
89
- const direction = positionArr[0];
90
- let location;
91
- if (positionArr.length > 1) {
92
- positionArr.splice(0, 1);
93
- location = positionArr.join("").toLowerCase();
94
- } else {
95
- location = "center";
96
- }
90
+ const { direction, location = "center" } = (0, import_utils.parsePlacement)(placement);
97
91
  const childrenRef = (0, import_react.useRef)();
98
92
  const [openStatus, setOpenStatus] = (0, import_react.useState)(defaultOpen);
99
93
  const [arrowDirection, setArrowDirection] = (0, import_react.useState)(direction);
@@ -128,10 +122,15 @@ const Tooltip = /* @__PURE__ */ import_react.default.forwardRef((props, ref) =>
128
122
  hideTooltip(event);
129
123
  };
130
124
  const onRootElementMouted = (0, import_utils.throttle)(() => {
125
+ const {
126
+ direction: newParsedDirection,
127
+ location: newParsedLocation = "center"
128
+ } = (0, import_utils.parsePlacement)(placement);
131
129
  const result = (0, import_utils.getStylesAndLocation)({
132
130
  childrenRef,
133
- arrowDirection,
134
- arrowLocation,
131
+ arrowDirection: newParsedDirection,
132
+ arrowLocation: newParsedLocation,
133
+ offsetSpacing,
135
134
  selector: `[data-id="tt_${ttId}"]`
136
135
  });
137
136
  if (!result)
@@ -16,6 +16,10 @@ export type TooltipProps<D extends React.ElementType = 'div', P = {}> = Override
16
16
  * 用于手动控制气泡浮层显隐
17
17
  */
18
18
  open?: boolean;
19
+ /**
20
+ * 用于控制气泡浮层和目标元素偏移量
21
+ */
22
+ offsetSpacing?: number;
19
23
  /**
20
24
  * 气泡框位置
21
25
  * @default 'top'
@@ -30,6 +30,7 @@
30
30
  }
31
31
  .bui-input-input {
32
32
  flex: 1;
33
+ min-width: 0;
33
34
  display: flex;
34
35
  align-items: center;
35
36
  padding: 0;
@@ -39,16 +40,11 @@
39
40
  outline: none;
40
41
  background-color: var(--background-color);
41
42
  font-size: var(--bui-text-size-2);
42
- width: auto;
43
- overflow: hidden;
44
- text-overflow: ellipsis;
45
- white-space: nowrap;
46
43
  }
47
44
  .bui-input-input::placeholder {
48
45
  color: var(--bui-color-fg-subtle);
49
46
  }
50
47
  .bui-input-disabled {
51
- pointer-events: none;
52
48
  background-color: var(--disabled-background-color);
53
49
  }
54
50
  .bui-input-disabled .bui-input-input {
@@ -3,7 +3,7 @@
3
3
  --localtion-position: var(--bui-popover-localtion-position, 8PX);
4
4
  --max-width: var(--bui-popover-max-width, 350px);
5
5
  --content-min-width: var(--bui-popover-content-min-width, 30px);
6
- --content-padding: var(--bui-popover-content-padding, 0);
6
+ --content-padding: var(--bui-popover-content-padding, 6px 8px);
7
7
  max-width: var(--max-width);
8
8
  font-size: var(--bui-text-size-1);
9
9
  position: absolute;
@@ -31,6 +31,7 @@ import React, { useState, useRef, useEffect } from "react";
31
31
  import {
32
32
  getStylesAndLocation,
33
33
  triggerEventTransform,
34
+ parsePlacement,
34
35
  useUniqueId,
35
36
  throttle
36
37
  } from "@bifrostui/utils";
@@ -45,6 +46,7 @@ const Popover = /* @__PURE__ */ React.forwardRef((props, ref) => {
45
46
  title,
46
47
  content,
47
48
  defaultOpen,
49
+ offsetSpacing = 0,
48
50
  placement = "top",
49
51
  trigger = "click",
50
52
  onOpenChange,
@@ -57,6 +59,7 @@ const Popover = /* @__PURE__ */ React.forwardRef((props, ref) => {
57
59
  "title",
58
60
  "content",
59
61
  "defaultOpen",
62
+ "offsetSpacing",
60
63
  "placement",
61
64
  "trigger",
62
65
  "onOpenChange",
@@ -64,15 +67,7 @@ const Popover = /* @__PURE__ */ React.forwardRef((props, ref) => {
64
67
  "hideArrow"
65
68
  ]);
66
69
  const controlByUser = typeof open !== "undefined";
67
- const positionArr = placement.split(/([A-Z])/);
68
- const direction = positionArr[0];
69
- let location;
70
- if (positionArr.length > 1) {
71
- positionArr.splice(0, 1);
72
- location = positionArr.join("").toLowerCase();
73
- } else {
74
- location = "center";
75
- }
70
+ const { direction, location = "center" } = parsePlacement(placement);
76
71
  const childrenRef = useRef();
77
72
  const [openStatus, setOpenStatus] = useState(defaultOpen);
78
73
  const [arrowDirection, setArrowDirection] = useState(direction);
@@ -107,10 +102,15 @@ const Popover = /* @__PURE__ */ React.forwardRef((props, ref) => {
107
102
  hidePopover(event);
108
103
  };
109
104
  const onRootElementMouted = throttle(() => {
105
+ const {
106
+ direction: newParsedDirection,
107
+ location: newParsedLocation = "center"
108
+ } = parsePlacement(placement);
110
109
  const result = getStylesAndLocation({
111
110
  childrenRef,
112
- arrowDirection,
113
- arrowLocation,
111
+ arrowDirection: newParsedDirection,
112
+ arrowLocation: newParsedLocation,
113
+ offsetSpacing,
114
114
  selector: `[data-id="tt_${ttId}"]`
115
115
  });
116
116
  if (!result)
@@ -25,6 +25,10 @@ export type PopoverProps<D extends React.ElementType = 'div', P = {}> = Override
25
25
  * @default false
26
26
  */
27
27
  hideArrow?: boolean;
28
+ /**
29
+ * 用于控制浮层和目标元素偏移量
30
+ */
31
+ offsetSpacing?: number;
28
32
  /**
29
33
  * 气泡框位置
30
34
  * @default 'top'
@@ -31,7 +31,19 @@ import React, { forwardRef } from "react";
31
31
  import "./TabPanel.css";
32
32
  const prefixCls = "bui-tabpanel";
33
33
  const TabPanel = forwardRef((props, ref) => {
34
- const _a = props, { className, children, value, index, keepMounted } = _a, others = __objRest(_a, ["className", "children", "value", "index", "keepMounted"]);
34
+ const _a = props, {
35
+ className,
36
+ children,
37
+ value,
38
+ index,
39
+ keepMounted = false
40
+ } = _a, others = __objRest(_a, [
41
+ "className",
42
+ "children",
43
+ "value",
44
+ "index",
45
+ "keepMounted"
46
+ ]);
35
47
  const keepActiveDom = keepMounted ? children : null;
36
48
  return /* @__PURE__ */ React.createElement(
37
49
  "div",
@@ -46,9 +58,6 @@ const TabPanel = forwardRef((props, ref) => {
46
58
  );
47
59
  });
48
60
  TabPanel.displayName = "BuiTabPanel";
49
- TabPanel.defaultProps = {
50
- keepMounted: false
51
- };
52
61
  var TabPanel_default = TabPanel;
53
62
  export {
54
63
  TabPanel_default as default
package/es/Tabs/Tabs.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import './Tabs.less';
3
2
  import { TabsProps } from './Tabs.types';
3
+ import './Tabs.less';
4
4
  declare const Tabs: React.ForwardRefExoticComponent<Omit<TabsProps<"div", {}>, "ref"> & React.RefAttributes<HTMLDivElement>>;
5
5
  export default Tabs;
package/es/Tabs/Tabs.js CHANGED
@@ -41,9 +41,9 @@ import React, {
41
41
  useState
42
42
  } from "react";
43
43
  import Tab from "./Tab";
44
- import "./Tabs.css";
45
44
  import { TabsContextProvider } from "./TabsContext";
46
45
  import bound from "./utils/bound";
46
+ import "./Tabs.css";
47
47
  const prefixCls = "bui-tabs";
48
48
  const Tabs = /* @__PURE__ */ React.forwardRef((props, ref) => {
49
49
  const _a = props, { children, className, value, tabs, align, onChange } = _a, others = __objRest(_a, ["children", "className", "value", "tabs", "align", "onChange"]);
@@ -62,16 +62,13 @@ const Tabs = /* @__PURE__ */ React.forwardRef((props, ref) => {
62
62
  const container = tabsRef.current;
63
63
  if (!container)
64
64
  return;
65
- const activeIndex = !!tabs.length && tabs.findIndex((item) => {
66
- var _a2;
67
- return item.index === (active || ((_a2 = tabs[0]) == null ? void 0 : _a2.index));
68
- });
65
+ const activeIndex = !!tabs.length && tabs.findIndex((item) => item.index === active);
69
66
  const activeLine = activeLineRef.current;
70
67
  if (!activeLine)
71
68
  return;
72
69
  let activeTab;
73
70
  if (tabs.length) {
74
- activeTab = container.childNodes[activeIndex + 1];
71
+ activeTab = activeIndex > -1 ? container.childNodes[activeIndex + 1] : void 0;
75
72
  } else {
76
73
  activeTab = [...container.childNodes].find((child) => {
77
74
  if (isMini) {
@@ -82,20 +79,26 @@ const Tabs = /* @__PURE__ */ React.forwardRef((props, ref) => {
82
79
  return [...child.classList].includes("bui-tab-active");
83
80
  });
84
81
  }
85
- if (!activeTab)
86
- return;
87
- const activeTabLeft = activeTab.offsetLeft;
88
- const activeTabWidth = activeTab.offsetWidth;
89
- const containerWidth = container.offsetWidth;
90
- const containerScrollWidth = container.scrollWidth;
91
- const activeLineWidth = activeLine.offsetWidth;
92
- const x = activeTabLeft + (activeTabWidth - activeLineWidth) / 2;
82
+ let activeTabLeft = 0;
83
+ let activeTabWidth = 0;
84
+ let containerWidth = 0;
85
+ let containerScrollWidth = 0;
86
+ let activeLineWidth = 0;
87
+ let x = 0;
88
+ if (activeTab) {
89
+ activeTabLeft = activeTab.offsetLeft;
90
+ activeTabWidth = activeTab.offsetWidth;
91
+ containerWidth = container.offsetWidth;
92
+ containerScrollWidth = container.scrollWidth;
93
+ activeLineWidth = activeLine.offsetWidth;
94
+ x = activeTabLeft + (activeTabWidth - activeLineWidth) / 2;
95
+ }
93
96
  setLineData({
94
97
  x,
95
98
  transitionInUse
96
99
  });
97
100
  const maxScrollDistance = containerScrollWidth - containerWidth;
98
- if (maxScrollDistance <= 0)
101
+ if (maxScrollDistance <= 0 || !activeTab)
99
102
  return;
100
103
  const nextScrollLeft = bound(
101
104
  activeTabLeft - (containerWidth - activeTabWidth) / 2,
@@ -107,8 +110,7 @@ const Tabs = /* @__PURE__ */ React.forwardRef((props, ref) => {
107
110
  }
108
111
  };
109
112
  useEffect(() => {
110
- const defaultIndex = safeValue();
111
- setActive(defaultIndex);
113
+ setActive(value);
112
114
  }, [value]);
113
115
  useLayoutEffect(() => {
114
116
  animate({ transitionInUse: false });
@@ -126,26 +128,6 @@ const Tabs = /* @__PURE__ */ React.forwardRef((props, ref) => {
126
128
  useDidMountEffect(() => {
127
129
  animate({ transitionInUse: true });
128
130
  }, [active, tabs, children]);
129
- const safeValue = () => {
130
- var _a2;
131
- let defaultIndex = value;
132
- const childs = React.Children.toArray(children);
133
- const hasSameChild = !!childs.length && childs.some(
134
- (child) => {
135
- var _a3;
136
- return React.isValidElement(child) && ((_a3 = child == null ? void 0 : child.props) == null ? void 0 : _a3.index) === value;
137
- }
138
- );
139
- if (!!tabs.length && !tabs.some((item) => item.index === value)) {
140
- defaultIndex = (_a2 = tabs[0]) == null ? void 0 : _a2.index;
141
- } else if (children && !hasSameChild) {
142
- const childNode = childs[0];
143
- if (React.isValidElement(childNode)) {
144
- defaultIndex = childNode.props.index;
145
- }
146
- }
147
- return defaultIndex;
148
- };
149
131
  const updateMask = useMemo(
150
132
  () => throttle(
151
133
  () => {
@@ -186,8 +168,7 @@ const Tabs = /* @__PURE__ */ React.forwardRef((props, ref) => {
186
168
  }
187
169
  };
188
170
  const providerValue = useMemo(() => {
189
- const v = safeValue();
190
- return { value: v, align, triggerChange: handleClick };
171
+ return { value, align, triggerChange: handleClick };
191
172
  }, [value, align, children, handleClick]);
192
173
  return /* @__PURE__ */ React.createElement("div", __spreadValues({ ref, className: clsx(prefixCls, className) }, others), /* @__PURE__ */ React.createElement(
193
174
  "div",
@@ -210,7 +191,7 @@ const Tabs = /* @__PURE__ */ React.forwardRef((props, ref) => {
210
191
  {
211
192
  ref: activeLineRef,
212
193
  className: clsx(`${prefixCls}-tabline`, {
213
- "bui-tabline-invisible": isMini
194
+ "bui-tabline-invisible": isMini || !lineData.x
214
195
  }),
215
196
  style: {
216
197
  transition: lineData.transitionInUse ? "transform 0.25s ease-in-out" : void 0,
@@ -31,6 +31,7 @@ import React, { useState, useRef, useEffect } from "react";
31
31
  import {
32
32
  getStylesAndLocation,
33
33
  triggerEventTransform,
34
+ parsePlacement,
34
35
  useUniqueId,
35
36
  throttle
36
37
  } from "@bifrostui/utils";
@@ -44,6 +45,7 @@ const Tooltip = /* @__PURE__ */ React.forwardRef((props, ref) => {
44
45
  children,
45
46
  title,
46
47
  defaultOpen,
48
+ offsetSpacing = 0,
47
49
  placement = "top",
48
50
  trigger = "click",
49
51
  onOpenChange,
@@ -54,21 +56,14 @@ const Tooltip = /* @__PURE__ */ React.forwardRef((props, ref) => {
54
56
  "children",
55
57
  "title",
56
58
  "defaultOpen",
59
+ "offsetSpacing",
57
60
  "placement",
58
61
  "trigger",
59
62
  "onOpenChange",
60
63
  "open"
61
64
  ]);
62
65
  const controlByUser = typeof open !== "undefined";
63
- const positionArr = placement.split(/([A-Z])/);
64
- const direction = positionArr[0];
65
- let location;
66
- if (positionArr.length > 1) {
67
- positionArr.splice(0, 1);
68
- location = positionArr.join("").toLowerCase();
69
- } else {
70
- location = "center";
71
- }
66
+ const { direction, location = "center" } = parsePlacement(placement);
72
67
  const childrenRef = useRef();
73
68
  const [openStatus, setOpenStatus] = useState(defaultOpen);
74
69
  const [arrowDirection, setArrowDirection] = useState(direction);
@@ -103,10 +98,15 @@ const Tooltip = /* @__PURE__ */ React.forwardRef((props, ref) => {
103
98
  hideTooltip(event);
104
99
  };
105
100
  const onRootElementMouted = throttle(() => {
101
+ const {
102
+ direction: newParsedDirection,
103
+ location: newParsedLocation = "center"
104
+ } = parsePlacement(placement);
106
105
  const result = getStylesAndLocation({
107
106
  childrenRef,
108
- arrowDirection,
109
- arrowLocation,
107
+ arrowDirection: newParsedDirection,
108
+ arrowLocation: newParsedLocation,
109
+ offsetSpacing,
110
110
  selector: `[data-id="tt_${ttId}"]`
111
111
  });
112
112
  if (!result)
@@ -16,6 +16,10 @@ export type TooltipProps<D extends React.ElementType = 'div', P = {}> = Override
16
16
  * 用于手动控制气泡浮层显隐
17
17
  */
18
18
  open?: boolean;
19
+ /**
20
+ * 用于控制气泡浮层和目标元素偏移量
21
+ */
22
+ offsetSpacing?: number;
19
23
  /**
20
24
  * 气泡框位置
21
25
  * @default 'top'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bifrostui/react",
3
- "version": "1.4.2",
3
+ "version": "1.4.3-beta.0",
4
4
  "description": "React components for building mobile application",
5
5
  "homepage": "http://bui.taopiaopiao.com",
6
6
  "license": "MIT",
@@ -33,10 +33,10 @@
33
33
  "clsx": "^1.2.1",
34
34
  "dayjs": "^1.11.7",
35
35
  "swiper": "^8.1.5",
36
- "@bifrostui/icons": "1.4.2",
37
- "@bifrostui/styles": "1.4.2",
38
- "@bifrostui/types": "1.4.2",
39
- "@bifrostui/utils": "1.4.2"
36
+ "@bifrostui/icons": "1.4.3-beta.0",
37
+ "@bifrostui/styles": "1.4.3-beta.0",
38
+ "@bifrostui/types": "1.4.3-beta.0",
39
+ "@bifrostui/utils": "1.4.3-beta.0"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@tarojs/components": "^3.0.0",