bj-web-components 0.2.27 → 0.2.28
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/index.js +51 -1
- package/dist/index.mjs +49 -49
- package/dist/style.css +3744 -1
- package/dist/web/BasicInput/BInput.js +208 -1
- package/dist/web/BasicInput/BInput.mjs +164 -132
- package/dist/web/BasicInput/utils.js +47 -1
- package/dist/web/BasicInput/utils.mjs +38 -28
- package/dist/web/CategoryDropdown/CategoryDropdown.js +307 -1
- package/dist/web/CategoryDropdown/CategoryDropdown.mjs +218 -170
- package/dist/web/CheckBox/BCheckBox.js +116 -1
- package/dist/web/CheckBox/BCheckBox.mjs +86 -70
- package/dist/web/CheckBox/Group.js +73 -1
- package/dist/web/CheckBox/Group.mjs +63 -56
- package/dist/web/CheckBox/context.js +5 -1
- package/dist/web/CheckBox/context.mjs +3 -3
- package/dist/web/CheckBox/index.js +8 -1
- package/dist/web/CheckBox/index.mjs +6 -6
- package/dist/web/Dropdown/BDropdown.js +186 -1
- package/dist/web/Dropdown/BDropdown.mjs +132 -106
- package/dist/web/EmptyInputBox/EmptyInputBox.js +77 -1
- package/dist/web/EmptyInputBox/EmptyInputBox.mjs +52 -48
- package/dist/web/FileCard/FileCard.js +157 -1
- package/dist/web/FileCard/FileCard.mjs +112 -82
- package/dist/web/Icon/Icon.js +9 -1
- package/dist/web/Icon/Icon.mjs +6 -6
- package/dist/web/Input/Input.js +181 -1
- package/dist/web/Input/Input.mjs +122 -113
- package/dist/web/InputNumber/BInputNumber.js +311 -1
- package/dist/web/InputNumber/BInputNumber.mjs +275 -167
- package/dist/web/InputNumber/StepHandler.js +69 -1
- package/dist/web/InputNumber/StepHandler.mjs +38 -32
- package/dist/web/InputNumber/hooks/useCursor.js +40 -1
- package/dist/web/InputNumber/hooks/useCursor.mjs +35 -33
- package/dist/web/InputNumber/hooks/useFrame.js +12 -1
- package/dist/web/InputNumber/hooks/useFrame.mjs +9 -6
- package/dist/web/InputNumber/utils/decimal.js +147 -1
- package/dist/web/InputNumber/utils/decimal.mjs +109 -81
- package/dist/web/Modal/Modal.js +84 -1
- package/dist/web/Modal/Modal.mjs +52 -49
- package/dist/web/OverlayScrollbar/BOverlayScrollbar.js +232 -1
- package/dist/web/OverlayScrollbar/BOverlayScrollbar.mjs +206 -125
- package/dist/web/Pagination/Pagination.js +328 -1
- package/dist/web/Pagination/Pagination.mjs +254 -178
- package/dist/web/ProductField/ProductField.js +272 -1
- package/dist/web/ProductField/ProductField.mjs +190 -143
- package/dist/web/ProductField/arrow-up.svg.js +3 -1
- package/dist/web/ProductField/arrow-up.svg.mjs +2 -2
- package/dist/web/ProductField/checkbox-no.svg.js +3 -1
- package/dist/web/ProductField/checkbox-no.svg.mjs +2 -2
- package/dist/web/ProductField/checkbox-ok.svg.js +3 -1
- package/dist/web/ProductField/checkbox-ok.svg.mjs +2 -2
- package/dist/web/ProductField/no_data_light.svg.js +3 -1
- package/dist/web/ProductField/no_data_light.svg.mjs +2 -2
- package/dist/web/ProductField/search.svg.js +3 -1
- package/dist/web/ProductField/search.svg.mjs +2 -2
- package/dist/web/ProductField/sort.svg.js +3 -1
- package/dist/web/ProductField/sort.svg.mjs +2 -2
- package/dist/web/SkuInputCard/SkuInputCard.js +276 -1
- package/dist/web/SkuInputCard/SkuInputCard.mjs +188 -149
- package/dist/web/SkuInputCard/spin_loading_red.gif.js +3 -1
- package/dist/web/SkuInputCard/spin_loading_red.gif.mjs +2 -2
- package/dist/web/Switch/Switch.js +70 -1
- package/dist/web/Switch/Switch.mjs +47 -37
- package/dist/web/Table/BTable.js +950 -1
- package/dist/web/Table/BTable.mjs +771 -519
- package/dist/web/Table/Column.js +5 -1
- package/dist/web/Table/Column.mjs +2 -2
- package/dist/web/Table/ColumnGroup.js +5 -1
- package/dist/web/Table/ColumnGroup.mjs +2 -2
- package/dist/web/Table/utils/columns.js +48 -1
- package/dist/web/Table/utils/columns.mjs +35 -30
- package/dist/web/Table/utils/sortFilter.js +84 -1
- package/dist/web/Table/utils/sortFilter.mjs +73 -52
- package/dist/web/Tabs/BTabs.js +150 -1
- package/dist/web/Tabs/BTabs.mjs +118 -98
- package/dist/web/Tabs/TabPane.js +8 -1
- package/dist/web/Tabs/TabPane.mjs +4 -4
- package/dist/web/Tooltip/ConfirmTooltip.js +26 -1
- package/dist/web/Tooltip/ConfirmTooltip.mjs +20 -19
- package/dist/web/Tooltip/ContentTooltip.js +94 -1
- package/dist/web/Tooltip/ContentTooltip.mjs +72 -62
- package/dist/web/Tooltip/ProgressTooltip.js +36 -1
- package/dist/web/Tooltip/ProgressTooltip.mjs +22 -20
- package/dist/web/Tooltip/TooltipWrapper.js +12 -1
- package/dist/web/Tooltip/TooltipWrapper.mjs +8 -8
- package/dist/web/Tooltip/useAutoPlacement.js +41 -1
- package/dist/web/Tooltip/useAutoPlacement.mjs +34 -25
- package/dist/web.js +51 -1
- package/dist/web.mjs +49 -49
- package/package.json +1 -1
package/dist/web/Modal/Modal.js
CHANGED
|
@@ -1 +1,84 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
+
;/* empty css */
|
|
4
|
+
function BuModal({
|
|
5
|
+
open = false,
|
|
6
|
+
title = "标题",
|
|
7
|
+
mode = "standard",
|
|
8
|
+
children,
|
|
9
|
+
okText = "确认",
|
|
10
|
+
cancelText = "取消",
|
|
11
|
+
onOk,
|
|
12
|
+
onCancel,
|
|
13
|
+
onClose,
|
|
14
|
+
activeLang = "zh",
|
|
15
|
+
onLangChange,
|
|
16
|
+
labels,
|
|
17
|
+
hint,
|
|
18
|
+
confirmLoading = false,
|
|
19
|
+
width,
|
|
20
|
+
className,
|
|
21
|
+
style
|
|
22
|
+
}) {
|
|
23
|
+
const zhLabel = (labels == null ? void 0 : labels.zh) ?? "中文";
|
|
24
|
+
const enLabel = (labels == null ? void 0 : labels.en) ?? "EN";
|
|
25
|
+
if (!open) return null;
|
|
26
|
+
const isBilingual = mode === "bilingual";
|
|
27
|
+
const isSingle = mode === "single";
|
|
28
|
+
const containerStyle = width != null ? { width, ...style } : style;
|
|
29
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: ["bu-modal__overlay", className].filter(Boolean).join(" "), onClick: onClose, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
30
|
+
"div",
|
|
31
|
+
{
|
|
32
|
+
className: "bu-modal__container",
|
|
33
|
+
style: containerStyle,
|
|
34
|
+
onClick: (e) => e.stopPropagation(),
|
|
35
|
+
children: [
|
|
36
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bu-modal__header", children: [
|
|
37
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "bu-modal__title", children: title }),
|
|
38
|
+
isBilingual && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bu-modal__lang-toggle", children: [
|
|
39
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
40
|
+
"button",
|
|
41
|
+
{
|
|
42
|
+
type: "button",
|
|
43
|
+
className: `bu-modal__lang-btn${activeLang === "zh" ? " bu-modal__lang-btn--active" : ""}`,
|
|
44
|
+
onClick: () => onLangChange == null ? void 0 : onLangChange("zh"),
|
|
45
|
+
children: zhLabel
|
|
46
|
+
}
|
|
47
|
+
),
|
|
48
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
49
|
+
"button",
|
|
50
|
+
{
|
|
51
|
+
type: "button",
|
|
52
|
+
className: `bu-modal__lang-btn${activeLang === "en" ? " bu-modal__lang-btn--active" : ""}`,
|
|
53
|
+
onClick: () => onLangChange == null ? void 0 : onLangChange("en"),
|
|
54
|
+
children: enLabel
|
|
55
|
+
}
|
|
56
|
+
)
|
|
57
|
+
] }),
|
|
58
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "bu-modal__close", onClick: onClose, children: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M16.5613 6.73027C16.7558 6.53571 17.0723 6.53442 17.2684 6.72736C17.4644 6.92032 17.4657 7.23444 17.2713 7.42901L12.7036 12.0002L17.2713 16.5714C17.4657 16.766 17.4644 17.0801 17.2684 17.273C17.0723 17.4659 16.7558 17.4646 16.5613 17.2701L11.9996 12.7047L7.43794 17.2701C7.24352 17.4647 6.92699 17.4659 6.73091 17.273C6.53485 17.0801 6.53355 16.7659 6.72798 16.5714L11.2955 12.0002L6.72798 7.42901C6.53355 7.23442 6.53485 6.92032 6.73091 6.72736C6.92698 6.53442 7.2435 6.53571 7.43794 6.73027L11.9996 11.2955L16.5613 6.73027Z", fill: "currentColor" }) }) })
|
|
59
|
+
] }),
|
|
60
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bu-modal__body", children }),
|
|
61
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bu-modal__footer", children: [
|
|
62
|
+
hint && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "bu-modal__hint", children: hint }),
|
|
63
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bu-modal__btn-row", children: [
|
|
64
|
+
!isSingle && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "bu-modal__btn-cancel", onClick: onCancel ?? onClose, children: cancelText }),
|
|
65
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
66
|
+
"button",
|
|
67
|
+
{
|
|
68
|
+
type: "button",
|
|
69
|
+
className: ["bu-modal__btn-ok", confirmLoading ? "bu-modal__btn-ok--loading" : ""].filter(Boolean).join(" "),
|
|
70
|
+
disabled: confirmLoading,
|
|
71
|
+
onClick: confirmLoading ? void 0 : onOk,
|
|
72
|
+
children: [
|
|
73
|
+
confirmLoading && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "bu-modal__btn-ok-spinner" }),
|
|
74
|
+
okText
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
)
|
|
78
|
+
] })
|
|
79
|
+
] })
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
) });
|
|
83
|
+
}
|
|
84
|
+
module.exports = BuModal;
|
package/dist/web/Modal/Modal.mjs
CHANGED
|
@@ -1,73 +1,76 @@
|
|
|
1
|
-
import { jsx
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
/* empty css */
|
|
3
|
-
function
|
|
4
|
-
open
|
|
5
|
-
title
|
|
6
|
-
mode
|
|
7
|
-
children
|
|
8
|
-
okText
|
|
9
|
-
cancelText
|
|
10
|
-
onOk
|
|
11
|
-
onCancel
|
|
12
|
-
onClose
|
|
13
|
-
activeLang
|
|
14
|
-
onLangChange
|
|
15
|
-
labels
|
|
16
|
-
hint
|
|
17
|
-
confirmLoading
|
|
18
|
-
width
|
|
19
|
-
className
|
|
20
|
-
style
|
|
3
|
+
function BuModal({
|
|
4
|
+
open = false,
|
|
5
|
+
title = "标题",
|
|
6
|
+
mode = "standard",
|
|
7
|
+
children,
|
|
8
|
+
okText = "确认",
|
|
9
|
+
cancelText = "取消",
|
|
10
|
+
onOk,
|
|
11
|
+
onCancel,
|
|
12
|
+
onClose,
|
|
13
|
+
activeLang = "zh",
|
|
14
|
+
onLangChange,
|
|
15
|
+
labels,
|
|
16
|
+
hint,
|
|
17
|
+
confirmLoading = false,
|
|
18
|
+
width,
|
|
19
|
+
className,
|
|
20
|
+
style
|
|
21
21
|
}) {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
const zhLabel = (labels == null ? void 0 : labels.zh) ?? "中文";
|
|
23
|
+
const enLabel = (labels == null ? void 0 : labels.en) ?? "EN";
|
|
24
|
+
if (!open) return null;
|
|
25
|
+
const isBilingual = mode === "bilingual";
|
|
26
|
+
const isSingle = mode === "single";
|
|
27
|
+
const containerStyle = width != null ? { width, ...style } : style;
|
|
28
|
+
return /* @__PURE__ */ jsx("div", { className: ["bu-modal__overlay", className].filter(Boolean).join(" "), onClick: onClose, children: /* @__PURE__ */ jsxs(
|
|
26
29
|
"div",
|
|
27
30
|
{
|
|
28
31
|
className: "bu-modal__container",
|
|
29
|
-
style:
|
|
30
|
-
onClick: (
|
|
32
|
+
style: containerStyle,
|
|
33
|
+
onClick: (e) => e.stopPropagation(),
|
|
31
34
|
children: [
|
|
32
|
-
/* @__PURE__ */
|
|
33
|
-
/* @__PURE__ */
|
|
34
|
-
|
|
35
|
-
/* @__PURE__ */
|
|
35
|
+
/* @__PURE__ */ jsxs("div", { className: "bu-modal__header", children: [
|
|
36
|
+
/* @__PURE__ */ jsx("p", { className: "bu-modal__title", children: title }),
|
|
37
|
+
isBilingual && /* @__PURE__ */ jsxs("div", { className: "bu-modal__lang-toggle", children: [
|
|
38
|
+
/* @__PURE__ */ jsx(
|
|
36
39
|
"button",
|
|
37
40
|
{
|
|
38
41
|
type: "button",
|
|
39
|
-
className: `bu-modal__lang-btn${
|
|
40
|
-
onClick: () =>
|
|
41
|
-
children:
|
|
42
|
+
className: `bu-modal__lang-btn${activeLang === "zh" ? " bu-modal__lang-btn--active" : ""}`,
|
|
43
|
+
onClick: () => onLangChange == null ? void 0 : onLangChange("zh"),
|
|
44
|
+
children: zhLabel
|
|
42
45
|
}
|
|
43
46
|
),
|
|
44
|
-
/* @__PURE__ */
|
|
47
|
+
/* @__PURE__ */ jsx(
|
|
45
48
|
"button",
|
|
46
49
|
{
|
|
47
50
|
type: "button",
|
|
48
|
-
className: `bu-modal__lang-btn${
|
|
49
|
-
onClick: () =>
|
|
50
|
-
children:
|
|
51
|
+
className: `bu-modal__lang-btn${activeLang === "en" ? " bu-modal__lang-btn--active" : ""}`,
|
|
52
|
+
onClick: () => onLangChange == null ? void 0 : onLangChange("en"),
|
|
53
|
+
children: enLabel
|
|
51
54
|
}
|
|
52
55
|
)
|
|
53
56
|
] }),
|
|
54
|
-
/* @__PURE__ */
|
|
57
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "bu-modal__close", onClick: onClose, children: /* @__PURE__ */ jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsx("path", { d: "M16.5613 6.73027C16.7558 6.53571 17.0723 6.53442 17.2684 6.72736C17.4644 6.92032 17.4657 7.23444 17.2713 7.42901L12.7036 12.0002L17.2713 16.5714C17.4657 16.766 17.4644 17.0801 17.2684 17.273C17.0723 17.4659 16.7558 17.4646 16.5613 17.2701L11.9996 12.7047L7.43794 17.2701C7.24352 17.4647 6.92699 17.4659 6.73091 17.273C6.53485 17.0801 6.53355 16.7659 6.72798 16.5714L11.2955 12.0002L6.72798 7.42901C6.53355 7.23442 6.53485 6.92032 6.73091 6.72736C6.92698 6.53442 7.2435 6.53571 7.43794 6.73027L11.9996 11.2955L16.5613 6.73027Z", fill: "currentColor" }) }) })
|
|
55
58
|
] }),
|
|
56
|
-
/* @__PURE__ */
|
|
57
|
-
/* @__PURE__ */
|
|
58
|
-
|
|
59
|
-
/* @__PURE__ */
|
|
60
|
-
!
|
|
61
|
-
/* @__PURE__ */
|
|
59
|
+
/* @__PURE__ */ jsx("div", { className: "bu-modal__body", children }),
|
|
60
|
+
/* @__PURE__ */ jsxs("div", { className: "bu-modal__footer", children: [
|
|
61
|
+
hint && /* @__PURE__ */ jsx("p", { className: "bu-modal__hint", children: hint }),
|
|
62
|
+
/* @__PURE__ */ jsxs("div", { className: "bu-modal__btn-row", children: [
|
|
63
|
+
!isSingle && /* @__PURE__ */ jsx("button", { type: "button", className: "bu-modal__btn-cancel", onClick: onCancel ?? onClose, children: cancelText }),
|
|
64
|
+
/* @__PURE__ */ jsxs(
|
|
62
65
|
"button",
|
|
63
66
|
{
|
|
64
67
|
type: "button",
|
|
65
|
-
className: ["bu-modal__btn-ok",
|
|
66
|
-
disabled:
|
|
67
|
-
onClick:
|
|
68
|
+
className: ["bu-modal__btn-ok", confirmLoading ? "bu-modal__btn-ok--loading" : ""].filter(Boolean).join(" "),
|
|
69
|
+
disabled: confirmLoading,
|
|
70
|
+
onClick: confirmLoading ? void 0 : onOk,
|
|
68
71
|
children: [
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
confirmLoading && /* @__PURE__ */ jsx("span", { className: "bu-modal__btn-ok-spinner" }),
|
|
73
|
+
okText
|
|
71
74
|
]
|
|
72
75
|
}
|
|
73
76
|
)
|
|
@@ -78,5 +81,5 @@ function j({
|
|
|
78
81
|
) });
|
|
79
82
|
}
|
|
80
83
|
export {
|
|
81
|
-
|
|
84
|
+
BuModal as default
|
|
82
85
|
};
|
|
@@ -1 +1,232 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
+
const react = require("react");
|
|
4
|
+
;/* empty css */
|
|
5
|
+
const MIN_THUMB_SIZE = 24;
|
|
6
|
+
const HIDE_DELAY = 800;
|
|
7
|
+
const EMPTY_THUMB = { visible: false, offset: 0, length: 0, cross: 0 };
|
|
8
|
+
function BOverlayScrollbar({
|
|
9
|
+
containerRef,
|
|
10
|
+
targetRef,
|
|
11
|
+
selector,
|
|
12
|
+
direction = "vertical",
|
|
13
|
+
size = 4,
|
|
14
|
+
gap = 0,
|
|
15
|
+
background,
|
|
16
|
+
showOnHover = true,
|
|
17
|
+
showOnScroll = true,
|
|
18
|
+
hoverSelector,
|
|
19
|
+
horizontalInsetStart = 0,
|
|
20
|
+
horizontalInsetEnd = 0,
|
|
21
|
+
horizontalThumbLength,
|
|
22
|
+
className = ""
|
|
23
|
+
}) {
|
|
24
|
+
const showVertical = direction === "vertical" || direction === "both";
|
|
25
|
+
const showHorizontal = direction === "horizontal" || direction === "both";
|
|
26
|
+
const scrollElementRef = react.useRef(null);
|
|
27
|
+
const dragRef = react.useRef(null);
|
|
28
|
+
const hideTimerRef = react.useRef(null);
|
|
29
|
+
const hoverTargetRef = react.useRef(false);
|
|
30
|
+
const thumbHoverRef = react.useRef(false);
|
|
31
|
+
const [verticalThumb, setVerticalThumb] = react.useState(EMPTY_THUMB);
|
|
32
|
+
const [horizontalThumb, setHorizontalThumb] = react.useState(EMPTY_THUMB);
|
|
33
|
+
const [active, setActive] = react.useState(!showOnHover);
|
|
34
|
+
react.useEffect(() => {
|
|
35
|
+
if (!showOnHover) setActive(true);
|
|
36
|
+
}, [showOnHover]);
|
|
37
|
+
const sync = react.useCallback(() => {
|
|
38
|
+
const element = scrollElementRef.current;
|
|
39
|
+
const container = containerRef.current;
|
|
40
|
+
if (!element || !container) return;
|
|
41
|
+
const { scrollTop, scrollHeight, clientHeight, scrollLeft, scrollWidth, clientWidth } = element;
|
|
42
|
+
const elementRect = element.getBoundingClientRect();
|
|
43
|
+
const containerRect = container.getBoundingClientRect();
|
|
44
|
+
const offsetTop = elementRect.top - containerRect.top;
|
|
45
|
+
const offsetLeft = elementRect.left - containerRect.left;
|
|
46
|
+
if (showVertical) {
|
|
47
|
+
const maxScroll = scrollHeight - clientHeight;
|
|
48
|
+
if (maxScroll <= 1) {
|
|
49
|
+
setVerticalThumb((previous) => previous.visible ? EMPTY_THUMB : previous);
|
|
50
|
+
} else {
|
|
51
|
+
const length = Math.max(clientHeight / scrollHeight * clientHeight, MIN_THUMB_SIZE);
|
|
52
|
+
setVerticalThumb({
|
|
53
|
+
visible: true,
|
|
54
|
+
offset: offsetTop + scrollTop / maxScroll * (clientHeight - length),
|
|
55
|
+
length,
|
|
56
|
+
cross: offsetLeft + clientWidth - size - gap
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (showHorizontal) {
|
|
61
|
+
const maxScroll = scrollWidth - clientWidth;
|
|
62
|
+
const trackLength = Math.max(clientWidth - horizontalInsetStart - horizontalInsetEnd, 0);
|
|
63
|
+
if (maxScroll <= 1 || trackLength <= 0) {
|
|
64
|
+
setHorizontalThumb((previous) => previous.visible ? EMPTY_THUMB : previous);
|
|
65
|
+
} else {
|
|
66
|
+
const proportionalLength = clientWidth / scrollWidth * trackLength;
|
|
67
|
+
const length = Math.min(trackLength, Math.max(horizontalThumbLength ?? proportionalLength, MIN_THUMB_SIZE));
|
|
68
|
+
setHorizontalThumb({
|
|
69
|
+
visible: true,
|
|
70
|
+
offset: offsetLeft + horizontalInsetStart + scrollLeft / maxScroll * (trackLength - length),
|
|
71
|
+
length,
|
|
72
|
+
cross: offsetTop + clientHeight - size - gap
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}, [containerRef, gap, horizontalInsetEnd, horizontalInsetStart, horizontalThumbLength, showHorizontal, showVertical, size]);
|
|
77
|
+
const wakeUp = react.useCallback(() => {
|
|
78
|
+
if (!showOnHover) return;
|
|
79
|
+
const interacting = hoverTargetRef.current || thumbHoverRef.current || dragRef.current;
|
|
80
|
+
if (!showOnScroll && !interacting) {
|
|
81
|
+
setActive(false);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
setActive(true);
|
|
85
|
+
if (hideTimerRef.current) clearTimeout(hideTimerRef.current);
|
|
86
|
+
hideTimerRef.current = setTimeout(() => {
|
|
87
|
+
if (!dragRef.current && !hoverTargetRef.current && !thumbHoverRef.current) setActive(false);
|
|
88
|
+
}, HIDE_DELAY);
|
|
89
|
+
}, [showOnHover, showOnScroll]);
|
|
90
|
+
const onScroll = react.useCallback(() => {
|
|
91
|
+
sync();
|
|
92
|
+
wakeUp();
|
|
93
|
+
}, [sync, wakeUp]);
|
|
94
|
+
react.useEffect(() => {
|
|
95
|
+
const container = containerRef.current;
|
|
96
|
+
if (!container) return;
|
|
97
|
+
if (window.getComputedStyle(container).position === "static") container.style.position = "relative";
|
|
98
|
+
let detach;
|
|
99
|
+
let hoverElement = null;
|
|
100
|
+
const attach = () => {
|
|
101
|
+
const element = (targetRef == null ? void 0 : targetRef.current) ?? (selector ? container.querySelector(selector) : container.firstElementChild);
|
|
102
|
+
if (!element || element === scrollElementRef.current) return;
|
|
103
|
+
detach == null ? void 0 : detach();
|
|
104
|
+
scrollElementRef.current = element;
|
|
105
|
+
element.addEventListener("scroll", onScroll, { passive: true });
|
|
106
|
+
const observer = new ResizeObserver(sync);
|
|
107
|
+
observer.observe(element);
|
|
108
|
+
if (element.firstElementChild) observer.observe(element.firstElementChild);
|
|
109
|
+
detach = () => {
|
|
110
|
+
element.removeEventListener("scroll", onScroll);
|
|
111
|
+
observer.disconnect();
|
|
112
|
+
};
|
|
113
|
+
sync();
|
|
114
|
+
};
|
|
115
|
+
const onEnter = () => {
|
|
116
|
+
hoverTargetRef.current = true;
|
|
117
|
+
if (showOnHover) setActive(true);
|
|
118
|
+
};
|
|
119
|
+
const onLeave = () => {
|
|
120
|
+
hoverTargetRef.current = false;
|
|
121
|
+
if (showOnHover && !thumbHoverRef.current && !dragRef.current) setActive(false);
|
|
122
|
+
};
|
|
123
|
+
const detachHover = () => {
|
|
124
|
+
hoverElement == null ? void 0 : hoverElement.removeEventListener("mouseenter", onEnter);
|
|
125
|
+
hoverElement == null ? void 0 : hoverElement.removeEventListener("mouseleave", onLeave);
|
|
126
|
+
hoverElement = null;
|
|
127
|
+
hoverTargetRef.current = false;
|
|
128
|
+
};
|
|
129
|
+
const attachHover = () => {
|
|
130
|
+
const next = hoverSelector ? container.querySelector(hoverSelector) : container;
|
|
131
|
+
if (!next || next === hoverElement) return;
|
|
132
|
+
detachHover();
|
|
133
|
+
hoverElement = next;
|
|
134
|
+
hoverElement.addEventListener("mouseenter", onEnter);
|
|
135
|
+
hoverElement.addEventListener("mouseleave", onLeave);
|
|
136
|
+
};
|
|
137
|
+
attach();
|
|
138
|
+
attachHover();
|
|
139
|
+
const mutation = new MutationObserver(() => {
|
|
140
|
+
if (!scrollElementRef.current || !container.contains(scrollElementRef.current)) attach();
|
|
141
|
+
if (hoverElement && !container.contains(hoverElement)) detachHover();
|
|
142
|
+
if (!hoverElement) attachHover();
|
|
143
|
+
sync();
|
|
144
|
+
});
|
|
145
|
+
mutation.observe(container, { childList: true, subtree: true });
|
|
146
|
+
return () => {
|
|
147
|
+
mutation.disconnect();
|
|
148
|
+
detach == null ? void 0 : detach();
|
|
149
|
+
detachHover();
|
|
150
|
+
scrollElementRef.current = null;
|
|
151
|
+
if (hideTimerRef.current) clearTimeout(hideTimerRef.current);
|
|
152
|
+
};
|
|
153
|
+
}, [containerRef, hoverSelector, onScroll, selector, showOnHover, sync, targetRef]);
|
|
154
|
+
const onDragMove = react.useCallback((event) => {
|
|
155
|
+
const element = scrollElementRef.current;
|
|
156
|
+
const start = dragRef.current;
|
|
157
|
+
if (!element || !start) return;
|
|
158
|
+
const vertical = start.axis === "vertical";
|
|
159
|
+
const clientSize = vertical ? element.clientHeight : element.clientWidth;
|
|
160
|
+
const scrollSize = vertical ? element.scrollHeight : element.scrollWidth;
|
|
161
|
+
const trackLength = vertical ? clientSize : Math.max(clientSize - horizontalInsetStart - horizontalInsetEnd, 0);
|
|
162
|
+
const proportionalLength = clientSize / scrollSize * trackLength;
|
|
163
|
+
const thumbLength = Math.min(trackLength, Math.max(vertical ? proportionalLength : horizontalThumbLength ?? proportionalLength, MIN_THUMB_SIZE));
|
|
164
|
+
const trackRange = trackLength - thumbLength;
|
|
165
|
+
if (trackRange <= 0) return;
|
|
166
|
+
const delta = (vertical ? event.clientY : event.clientX) - start.client;
|
|
167
|
+
const moved = start.scroll + delta * ((scrollSize - clientSize) / trackRange);
|
|
168
|
+
if (vertical) element.scrollTop = moved;
|
|
169
|
+
else element.scrollLeft = moved;
|
|
170
|
+
}, [horizontalInsetEnd, horizontalInsetStart, horizontalThumbLength]);
|
|
171
|
+
const onDragEnd = react.useCallback(() => {
|
|
172
|
+
const wasDragging = Boolean(dragRef.current);
|
|
173
|
+
dragRef.current = null;
|
|
174
|
+
document.body.style.userSelect = "";
|
|
175
|
+
document.removeEventListener("mousemove", onDragMove);
|
|
176
|
+
document.removeEventListener("mouseup", onDragEnd);
|
|
177
|
+
if (wasDragging) wakeUp();
|
|
178
|
+
}, [onDragMove, wakeUp]);
|
|
179
|
+
const startDrag = (axis) => (event) => {
|
|
180
|
+
const element = scrollElementRef.current;
|
|
181
|
+
if (!element) return;
|
|
182
|
+
event.preventDefault();
|
|
183
|
+
event.stopPropagation();
|
|
184
|
+
dragRef.current = {
|
|
185
|
+
axis,
|
|
186
|
+
client: axis === "vertical" ? event.clientY : event.clientX,
|
|
187
|
+
scroll: axis === "vertical" ? element.scrollTop : element.scrollLeft
|
|
188
|
+
};
|
|
189
|
+
document.body.style.userSelect = "none";
|
|
190
|
+
document.addEventListener("mousemove", onDragMove);
|
|
191
|
+
document.addEventListener("mouseup", onDragEnd);
|
|
192
|
+
};
|
|
193
|
+
react.useEffect(() => () => {
|
|
194
|
+
dragRef.current = null;
|
|
195
|
+
document.body.style.userSelect = "";
|
|
196
|
+
document.removeEventListener("mousemove", onDragMove);
|
|
197
|
+
document.removeEventListener("mouseup", onDragEnd);
|
|
198
|
+
}, [onDragEnd, onDragMove]);
|
|
199
|
+
const thumbClassName = ["bj-overlay-scrollbar__thumb", active && "bj-overlay-scrollbar__thumb--active", className].filter(Boolean).join(" ");
|
|
200
|
+
const colorStyle = background ? { "--bj-overlay-scrollbar-bg": background } : void 0;
|
|
201
|
+
const onThumbEnter = () => {
|
|
202
|
+
thumbHoverRef.current = true;
|
|
203
|
+
if (showOnHover) setActive(true);
|
|
204
|
+
};
|
|
205
|
+
const onThumbLeave = () => {
|
|
206
|
+
thumbHoverRef.current = false;
|
|
207
|
+
if (showOnHover && !hoverTargetRef.current && !dragRef.current) setActive(false);
|
|
208
|
+
};
|
|
209
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
210
|
+
showVertical && verticalThumb.visible && /* @__PURE__ */ jsxRuntime.jsx(
|
|
211
|
+
"div",
|
|
212
|
+
{
|
|
213
|
+
className: `${thumbClassName} bj-overlay-scrollbar__thumb--vertical`,
|
|
214
|
+
onMouseDown: startDrag("vertical"),
|
|
215
|
+
onMouseEnter: onThumbEnter,
|
|
216
|
+
onMouseLeave: onThumbLeave,
|
|
217
|
+
style: { ...colorStyle, top: verticalThumb.offset, left: verticalThumb.cross, height: verticalThumb.length, width: size }
|
|
218
|
+
}
|
|
219
|
+
),
|
|
220
|
+
showHorizontal && horizontalThumb.visible && /* @__PURE__ */ jsxRuntime.jsx(
|
|
221
|
+
"div",
|
|
222
|
+
{
|
|
223
|
+
className: `${thumbClassName} bj-overlay-scrollbar__thumb--horizontal`,
|
|
224
|
+
onMouseDown: startDrag("horizontal"),
|
|
225
|
+
onMouseEnter: onThumbEnter,
|
|
226
|
+
onMouseLeave: onThumbLeave,
|
|
227
|
+
style: { ...colorStyle, left: horizontalThumb.offset, top: horizontalThumb.cross, width: horizontalThumb.length, height: size }
|
|
228
|
+
}
|
|
229
|
+
)
|
|
230
|
+
] });
|
|
231
|
+
}
|
|
232
|
+
module.exports = BOverlayScrollbar;
|