@x-plat/design-system 0.8.0 → 0.8.1
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/components/DatePicker/index.cjs +388 -400
- package/dist/components/DatePicker/index.css +3 -0
- package/dist/components/DatePicker/index.js +375 -387
- package/dist/components/Dropdown/index.cjs +21 -26
- package/dist/components/Dropdown/index.js +20 -25
- package/dist/components/Modal/index.cjs +18 -28
- package/dist/components/Modal/index.css +3 -0
- package/dist/components/Modal/index.js +17 -27
- package/dist/components/PopOver/index.cjs +18 -23
- package/dist/components/PopOver/index.js +17 -22
- package/dist/components/Select/index.cjs +337 -342
- package/dist/components/Select/index.js +336 -341
- package/dist/components/Tooltip/index.cjs +27 -32
- package/dist/components/Tooltip/index.js +26 -31
- package/dist/components/index.cjs +467 -471
- package/dist/components/index.css +3 -0
- package/dist/components/index.js +418 -422
- package/dist/index.cjs +491 -495
- package/dist/index.css +3 -0
- package/dist/index.js +440 -444
- package/package.json +1 -1
|
@@ -35,18 +35,13 @@ __export(Tooltip_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(Tooltip_exports);
|
|
36
36
|
|
|
37
37
|
// src/components/Tooltip/Tooltip.tsx
|
|
38
|
-
var
|
|
38
|
+
var import_react = __toESM(require("react"), 1);
|
|
39
39
|
|
|
40
40
|
// src/tokens/hooks/Portal.tsx
|
|
41
|
-
var import_react = __toESM(require("react"), 1);
|
|
42
41
|
var import_react_dom = __toESM(require("react-dom"), 1);
|
|
43
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
44
|
-
var PortalContainerContext = import_react.default.createContext(null);
|
|
45
42
|
var Portal = ({ children }) => {
|
|
46
|
-
const contextContainer = import_react.default.useContext(PortalContainerContext);
|
|
47
43
|
if (typeof document === "undefined") return null;
|
|
48
|
-
|
|
49
|
-
return import_react_dom.default.createPortal(children, container);
|
|
44
|
+
return import_react_dom.default.createPortal(children, document.body);
|
|
50
45
|
};
|
|
51
46
|
Portal.displayName = "Portal";
|
|
52
47
|
var Portal_default = Portal;
|
|
@@ -68,7 +63,7 @@ function clsx() {
|
|
|
68
63
|
var clsx_default = clsx;
|
|
69
64
|
|
|
70
65
|
// src/components/Tooltip/Tooltip.tsx
|
|
71
|
-
var
|
|
66
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
72
67
|
var OFFSET = 12;
|
|
73
68
|
var GAP = 8;
|
|
74
69
|
var SHOW_DELAY = 300;
|
|
@@ -81,14 +76,14 @@ var Tooltip = (props) => {
|
|
|
81
76
|
follow = false,
|
|
82
77
|
disabled = false
|
|
83
78
|
} = props;
|
|
84
|
-
const triggerRef =
|
|
85
|
-
const tooltipRef =
|
|
86
|
-
const [visible, setVisible] =
|
|
87
|
-
const [pos, setPos] =
|
|
88
|
-
const delayTimer =
|
|
89
|
-
const rafRef =
|
|
90
|
-
const cursor =
|
|
91
|
-
const clamp =
|
|
79
|
+
const triggerRef = import_react.default.useRef(null);
|
|
80
|
+
const tooltipRef = import_react.default.useRef(null);
|
|
81
|
+
const [visible, setVisible] = import_react.default.useState(false);
|
|
82
|
+
const [pos, setPos] = import_react.default.useState({ left: 0, top: 0 });
|
|
83
|
+
const delayTimer = import_react.default.useRef(0);
|
|
84
|
+
const rafRef = import_react.default.useRef(0);
|
|
85
|
+
const cursor = import_react.default.useRef(null);
|
|
86
|
+
const clamp = import_react.default.useCallback((left, top, w, h) => {
|
|
92
87
|
const vw = window.innerWidth;
|
|
93
88
|
const vh = window.innerHeight;
|
|
94
89
|
return {
|
|
@@ -96,7 +91,7 @@ var Tooltip = (props) => {
|
|
|
96
91
|
top: Math.min(Math.max(GAP, top), Math.max(GAP, vh - h - GAP))
|
|
97
92
|
};
|
|
98
93
|
}, []);
|
|
99
|
-
const placeAtCursor =
|
|
94
|
+
const placeAtCursor = import_react.default.useCallback((x, y) => {
|
|
100
95
|
const el = tooltipRef.current;
|
|
101
96
|
if (!el) return;
|
|
102
97
|
const w = el.offsetWidth;
|
|
@@ -107,7 +102,7 @@ var Tooltip = (props) => {
|
|
|
107
102
|
if (top < GAP) top = y + OFFSET;
|
|
108
103
|
setPos(clamp(left, top, w, h));
|
|
109
104
|
}, [clamp]);
|
|
110
|
-
const placeAtTrigger =
|
|
105
|
+
const placeAtTrigger = import_react.default.useCallback(() => {
|
|
111
106
|
const el = tooltipRef.current;
|
|
112
107
|
const trigger = triggerRef.current;
|
|
113
108
|
if (!el || !trigger) return;
|
|
@@ -119,19 +114,19 @@ var Tooltip = (props) => {
|
|
|
119
114
|
const left = rect.left + rect.width / 2 - w / 2;
|
|
120
115
|
setPos(clamp(left, top, w, h));
|
|
121
116
|
}, [clamp]);
|
|
122
|
-
const reposition =
|
|
117
|
+
const reposition = import_react.default.useCallback(() => {
|
|
123
118
|
if (follow && cursor.current) {
|
|
124
119
|
placeAtCursor(cursor.current.x, cursor.current.y);
|
|
125
120
|
} else {
|
|
126
121
|
placeAtTrigger();
|
|
127
122
|
}
|
|
128
123
|
}, [follow, placeAtCursor, placeAtTrigger]);
|
|
129
|
-
const handleMouseEnter =
|
|
124
|
+
const handleMouseEnter = import_react.default.useCallback((e) => {
|
|
130
125
|
if (disabled) return;
|
|
131
126
|
cursor.current = { x: e.clientX, y: e.clientY };
|
|
132
127
|
delayTimer.current = window.setTimeout(() => setVisible(true), SHOW_DELAY);
|
|
133
128
|
}, [disabled]);
|
|
134
|
-
const handleMouseMove =
|
|
129
|
+
const handleMouseMove = import_react.default.useCallback((e) => {
|
|
135
130
|
cursor.current = { x: e.clientX, y: e.clientY };
|
|
136
131
|
if (!visible || !follow) return;
|
|
137
132
|
cancelAnimationFrame(rafRef.current);
|
|
@@ -139,25 +134,25 @@ var Tooltip = (props) => {
|
|
|
139
134
|
if (cursor.current) placeAtCursor(cursor.current.x, cursor.current.y);
|
|
140
135
|
});
|
|
141
136
|
}, [visible, follow, placeAtCursor]);
|
|
142
|
-
const close =
|
|
137
|
+
const close = import_react.default.useCallback(() => {
|
|
143
138
|
window.clearTimeout(delayTimer.current);
|
|
144
139
|
cancelAnimationFrame(rafRef.current);
|
|
145
140
|
setVisible(false);
|
|
146
141
|
}, []);
|
|
147
|
-
const handleMouseLeave =
|
|
142
|
+
const handleMouseLeave = import_react.default.useCallback(() => {
|
|
148
143
|
cursor.current = null;
|
|
149
144
|
close();
|
|
150
145
|
}, [close]);
|
|
151
|
-
const handleFocus =
|
|
146
|
+
const handleFocus = import_react.default.useCallback(() => {
|
|
152
147
|
if (disabled) return;
|
|
153
148
|
cursor.current = null;
|
|
154
149
|
setVisible(true);
|
|
155
150
|
}, [disabled]);
|
|
156
|
-
|
|
151
|
+
import_react.default.useLayoutEffect(() => {
|
|
157
152
|
if (!visible) return;
|
|
158
153
|
reposition();
|
|
159
154
|
}, [visible, reposition]);
|
|
160
|
-
|
|
155
|
+
import_react.default.useEffect(() => {
|
|
161
156
|
if (!visible || follow) return;
|
|
162
157
|
const onChange = () => placeAtTrigger();
|
|
163
158
|
window.addEventListener("scroll", onChange, true);
|
|
@@ -167,12 +162,12 @@ var Tooltip = (props) => {
|
|
|
167
162
|
window.removeEventListener("resize", onChange);
|
|
168
163
|
};
|
|
169
164
|
}, [visible, follow, placeAtTrigger]);
|
|
170
|
-
|
|
165
|
+
import_react.default.useEffect(() => () => {
|
|
171
166
|
window.clearTimeout(delayTimer.current);
|
|
172
167
|
cancelAnimationFrame(rafRef.current);
|
|
173
168
|
}, []);
|
|
174
|
-
if (!title && !description) return /* @__PURE__ */ (0,
|
|
175
|
-
return /* @__PURE__ */ (0,
|
|
169
|
+
if (!title && !description) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
|
|
170
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
176
171
|
"div",
|
|
177
172
|
{
|
|
178
173
|
ref: triggerRef,
|
|
@@ -185,7 +180,7 @@ var Tooltip = (props) => {
|
|
|
185
180
|
onBlur: close,
|
|
186
181
|
children: [
|
|
187
182
|
children,
|
|
188
|
-
visible && /* @__PURE__ */ (0,
|
|
183
|
+
visible && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Portal_default, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
189
184
|
"div",
|
|
190
185
|
{
|
|
191
186
|
ref: tooltipRef,
|
|
@@ -193,8 +188,8 @@ var Tooltip = (props) => {
|
|
|
193
188
|
className: clsx_default("lib-xplat-tooltip", type),
|
|
194
189
|
style: { position: "fixed", left: pos.left, top: pos.top },
|
|
195
190
|
children: [
|
|
196
|
-
title && /* @__PURE__ */ (0,
|
|
197
|
-
description && /* @__PURE__ */ (0,
|
|
191
|
+
title && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "tooltip-title", children: title }),
|
|
192
|
+
description && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "tooltip-desc", children: description })
|
|
198
193
|
]
|
|
199
194
|
}
|
|
200
195
|
) })
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
// src/components/Tooltip/Tooltip.tsx
|
|
2
|
-
import
|
|
2
|
+
import React from "react";
|
|
3
3
|
|
|
4
4
|
// src/tokens/hooks/Portal.tsx
|
|
5
|
-
import React from "react";
|
|
6
5
|
import ReactDOM from "react-dom";
|
|
7
|
-
import { jsx } from "react/jsx-runtime";
|
|
8
|
-
var PortalContainerContext = React.createContext(null);
|
|
9
6
|
var Portal = ({ children }) => {
|
|
10
|
-
const contextContainer = React.useContext(PortalContainerContext);
|
|
11
7
|
if (typeof document === "undefined") return null;
|
|
12
|
-
|
|
13
|
-
return ReactDOM.createPortal(children, container);
|
|
8
|
+
return ReactDOM.createPortal(children, document.body);
|
|
14
9
|
};
|
|
15
10
|
Portal.displayName = "Portal";
|
|
16
11
|
var Portal_default = Portal;
|
|
@@ -32,7 +27,7 @@ function clsx() {
|
|
|
32
27
|
var clsx_default = clsx;
|
|
33
28
|
|
|
34
29
|
// src/components/Tooltip/Tooltip.tsx
|
|
35
|
-
import { Fragment, jsx
|
|
30
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
36
31
|
var OFFSET = 12;
|
|
37
32
|
var GAP = 8;
|
|
38
33
|
var SHOW_DELAY = 300;
|
|
@@ -45,14 +40,14 @@ var Tooltip = (props) => {
|
|
|
45
40
|
follow = false,
|
|
46
41
|
disabled = false
|
|
47
42
|
} = props;
|
|
48
|
-
const triggerRef =
|
|
49
|
-
const tooltipRef =
|
|
50
|
-
const [visible, setVisible] =
|
|
51
|
-
const [pos, setPos] =
|
|
52
|
-
const delayTimer =
|
|
53
|
-
const rafRef =
|
|
54
|
-
const cursor =
|
|
55
|
-
const clamp =
|
|
43
|
+
const triggerRef = React.useRef(null);
|
|
44
|
+
const tooltipRef = React.useRef(null);
|
|
45
|
+
const [visible, setVisible] = React.useState(false);
|
|
46
|
+
const [pos, setPos] = React.useState({ left: 0, top: 0 });
|
|
47
|
+
const delayTimer = React.useRef(0);
|
|
48
|
+
const rafRef = React.useRef(0);
|
|
49
|
+
const cursor = React.useRef(null);
|
|
50
|
+
const clamp = React.useCallback((left, top, w, h) => {
|
|
56
51
|
const vw = window.innerWidth;
|
|
57
52
|
const vh = window.innerHeight;
|
|
58
53
|
return {
|
|
@@ -60,7 +55,7 @@ var Tooltip = (props) => {
|
|
|
60
55
|
top: Math.min(Math.max(GAP, top), Math.max(GAP, vh - h - GAP))
|
|
61
56
|
};
|
|
62
57
|
}, []);
|
|
63
|
-
const placeAtCursor =
|
|
58
|
+
const placeAtCursor = React.useCallback((x, y) => {
|
|
64
59
|
const el = tooltipRef.current;
|
|
65
60
|
if (!el) return;
|
|
66
61
|
const w = el.offsetWidth;
|
|
@@ -71,7 +66,7 @@ var Tooltip = (props) => {
|
|
|
71
66
|
if (top < GAP) top = y + OFFSET;
|
|
72
67
|
setPos(clamp(left, top, w, h));
|
|
73
68
|
}, [clamp]);
|
|
74
|
-
const placeAtTrigger =
|
|
69
|
+
const placeAtTrigger = React.useCallback(() => {
|
|
75
70
|
const el = tooltipRef.current;
|
|
76
71
|
const trigger = triggerRef.current;
|
|
77
72
|
if (!el || !trigger) return;
|
|
@@ -83,19 +78,19 @@ var Tooltip = (props) => {
|
|
|
83
78
|
const left = rect.left + rect.width / 2 - w / 2;
|
|
84
79
|
setPos(clamp(left, top, w, h));
|
|
85
80
|
}, [clamp]);
|
|
86
|
-
const reposition =
|
|
81
|
+
const reposition = React.useCallback(() => {
|
|
87
82
|
if (follow && cursor.current) {
|
|
88
83
|
placeAtCursor(cursor.current.x, cursor.current.y);
|
|
89
84
|
} else {
|
|
90
85
|
placeAtTrigger();
|
|
91
86
|
}
|
|
92
87
|
}, [follow, placeAtCursor, placeAtTrigger]);
|
|
93
|
-
const handleMouseEnter =
|
|
88
|
+
const handleMouseEnter = React.useCallback((e) => {
|
|
94
89
|
if (disabled) return;
|
|
95
90
|
cursor.current = { x: e.clientX, y: e.clientY };
|
|
96
91
|
delayTimer.current = window.setTimeout(() => setVisible(true), SHOW_DELAY);
|
|
97
92
|
}, [disabled]);
|
|
98
|
-
const handleMouseMove =
|
|
93
|
+
const handleMouseMove = React.useCallback((e) => {
|
|
99
94
|
cursor.current = { x: e.clientX, y: e.clientY };
|
|
100
95
|
if (!visible || !follow) return;
|
|
101
96
|
cancelAnimationFrame(rafRef.current);
|
|
@@ -103,25 +98,25 @@ var Tooltip = (props) => {
|
|
|
103
98
|
if (cursor.current) placeAtCursor(cursor.current.x, cursor.current.y);
|
|
104
99
|
});
|
|
105
100
|
}, [visible, follow, placeAtCursor]);
|
|
106
|
-
const close =
|
|
101
|
+
const close = React.useCallback(() => {
|
|
107
102
|
window.clearTimeout(delayTimer.current);
|
|
108
103
|
cancelAnimationFrame(rafRef.current);
|
|
109
104
|
setVisible(false);
|
|
110
105
|
}, []);
|
|
111
|
-
const handleMouseLeave =
|
|
106
|
+
const handleMouseLeave = React.useCallback(() => {
|
|
112
107
|
cursor.current = null;
|
|
113
108
|
close();
|
|
114
109
|
}, [close]);
|
|
115
|
-
const handleFocus =
|
|
110
|
+
const handleFocus = React.useCallback(() => {
|
|
116
111
|
if (disabled) return;
|
|
117
112
|
cursor.current = null;
|
|
118
113
|
setVisible(true);
|
|
119
114
|
}, [disabled]);
|
|
120
|
-
|
|
115
|
+
React.useLayoutEffect(() => {
|
|
121
116
|
if (!visible) return;
|
|
122
117
|
reposition();
|
|
123
118
|
}, [visible, reposition]);
|
|
124
|
-
|
|
119
|
+
React.useEffect(() => {
|
|
125
120
|
if (!visible || follow) return;
|
|
126
121
|
const onChange = () => placeAtTrigger();
|
|
127
122
|
window.addEventListener("scroll", onChange, true);
|
|
@@ -131,11 +126,11 @@ var Tooltip = (props) => {
|
|
|
131
126
|
window.removeEventListener("resize", onChange);
|
|
132
127
|
};
|
|
133
128
|
}, [visible, follow, placeAtTrigger]);
|
|
134
|
-
|
|
129
|
+
React.useEffect(() => () => {
|
|
135
130
|
window.clearTimeout(delayTimer.current);
|
|
136
131
|
cancelAnimationFrame(rafRef.current);
|
|
137
132
|
}, []);
|
|
138
|
-
if (!title && !description) return /* @__PURE__ */
|
|
133
|
+
if (!title && !description) return /* @__PURE__ */ jsx(Fragment, { children });
|
|
139
134
|
return /* @__PURE__ */ jsxs(
|
|
140
135
|
"div",
|
|
141
136
|
{
|
|
@@ -149,7 +144,7 @@ var Tooltip = (props) => {
|
|
|
149
144
|
onBlur: close,
|
|
150
145
|
children: [
|
|
151
146
|
children,
|
|
152
|
-
visible && /* @__PURE__ */
|
|
147
|
+
visible && /* @__PURE__ */ jsx(Portal_default, { children: /* @__PURE__ */ jsxs(
|
|
153
148
|
"div",
|
|
154
149
|
{
|
|
155
150
|
ref: tooltipRef,
|
|
@@ -157,8 +152,8 @@ var Tooltip = (props) => {
|
|
|
157
152
|
className: clsx_default("lib-xplat-tooltip", type),
|
|
158
153
|
style: { position: "fixed", left: pos.left, top: pos.top },
|
|
159
154
|
children: [
|
|
160
|
-
title && /* @__PURE__ */
|
|
161
|
-
description && /* @__PURE__ */
|
|
155
|
+
title && /* @__PURE__ */ jsx("div", { className: "tooltip-title", children: title }),
|
|
156
|
+
description && /* @__PURE__ */ jsx("div", { className: "tooltip-desc", children: description })
|
|
162
157
|
]
|
|
163
158
|
}
|
|
164
159
|
) })
|