@duskmoon-dev/components 0.3.3 → 0.4.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/README.md +61 -2
- package/dist/classes/chat.d.ts +9 -1
- package/dist/classes/console-page.d.ts +16 -0
- package/dist/classes/dropdown.d.ts +5 -5
- package/dist/classes/fab.d.ts +11 -0
- package/dist/classes/index.d.ts +5 -0
- package/dist/classes/index.js +180 -34
- package/dist/classes/megamenu.d.ts +10 -0
- package/dist/classes/otp-input.d.ts +12 -0
- package/dist/classes/popover.d.ts +1 -3
- package/dist/classes/swap.d.ts +12 -0
- package/dist/classes/tree-select.d.ts +6 -6
- package/dist/components/app/index.js +128 -68
- package/dist/components/avatar/Avatar.types.d.ts +1 -1
- package/dist/components/avatar/index.js +2 -1
- package/dist/components/badge/index.js +1 -1
- package/dist/components/button/Button.d.ts +1 -1
- package/dist/components/button/Button.types.d.ts +8 -0
- package/dist/components/button/index.js +253 -24
- package/dist/components/calendar/index.js +44 -19
- package/dist/components/chat/Chat.d.ts +9 -1
- package/dist/components/chat/Chat.types.d.ts +26 -0
- package/dist/components/chat/index.js +92 -3
- package/dist/components/color-picker/ColorPicker.types.d.ts +2 -1
- package/dist/components/color-picker/index.js +206 -9
- package/dist/components/console-page/ConsolePage.d.ts +2 -0
- package/dist/components/console-page/ConsolePage.types.d.ts +29 -0
- package/dist/components/console-page/index.d.ts +2 -0
- package/dist/components/console-page/index.js +205 -0
- package/dist/components/date-picker/DatePicker.types.d.ts +1 -0
- package/dist/components/date-picker/index.js +537 -35
- package/dist/components/date-picker/usePickerDropdown.d.ts +17 -0
- package/dist/components/dm-date-picker/index.js +545 -43
- package/dist/components/dm-drawer/index.js +253 -24
- package/dist/components/dm-layout/index.js +391 -24
- package/dist/components/dm-menu/index.js +380 -13
- package/dist/components/dm-page-header/index.js +404 -114
- package/dist/components/dm-pro-table/index.js +1183 -368
- package/dist/components/dm-query/DmQuery.types.d.ts +1 -1
- package/dist/components/dm-query/index.js +931 -188
- package/dist/components/dm-search/DmSearch.types.d.ts +4 -0
- package/dist/components/dm-search/index.js +917 -163
- package/dist/components/dm-table/index.js +1001 -247
- package/dist/components/dm-toolbar/index.js +400 -110
- package/dist/components/dm-truncate/index.js +115 -35
- package/dist/components/dropdown/Dropdown.types.d.ts +1 -1
- package/dist/components/dropdown/index.js +400 -110
- package/dist/components/fab/Fab.d.ts +4 -0
- package/dist/components/fab/Fab.types.d.ts +25 -0
- package/dist/components/fab/index.d.ts +2 -0
- package/dist/components/fab/index.js +480 -0
- package/dist/components/form/Form.types.d.ts +1 -0
- package/dist/components/form/index.js +14 -3
- package/dist/components/megamenu/Megamenu.d.ts +2 -0
- package/dist/components/megamenu/Megamenu.types.d.ts +32 -0
- package/dist/components/megamenu/index.d.ts +2 -0
- package/dist/components/megamenu/index.js +214 -0
- package/dist/components/modal/index.js +128 -68
- package/dist/components/otp-input/OtpInput.d.ts +2 -0
- package/dist/components/otp-input/OtpInput.types.d.ts +16 -0
- package/dist/components/otp-input/index.d.ts +2 -0
- package/dist/components/otp-input/index.js +112 -0
- package/dist/components/popconfirm/index.js +255 -26
- package/dist/components/popover/index.js +24 -4
- package/dist/components/swap/Swap.d.ts +3 -0
- package/dist/components/swap/Swap.types.d.ts +22 -0
- package/dist/components/swap/index.d.ts +2 -0
- package/dist/components/swap/index.js +109 -0
- package/dist/components/time-picker/TimePicker.types.d.ts +1 -0
- package/dist/components/time-picker/index.js +167 -29
- package/dist/components/tooltip/Tooltip.types.d.ts +4 -0
- package/dist/components/tooltip/index.js +107 -27
- package/dist/components/tour/index.js +253 -24
- package/dist/components/tree-select/index.js +8 -8
- package/dist/components/upload/Upload.types.d.ts +1 -0
- package/dist/components/upload/index.js +2 -0
- package/dist/generated/version.d.ts +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +3330 -1632
- package/dist/infrastructure.js +1 -1
- package/dist/styles.css +1190 -906
- package/package.json +23 -3
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
import {
|
|
5
5
|
forwardRef as forwardRef2,
|
|
6
6
|
useCallback,
|
|
7
|
-
useEffect,
|
|
7
|
+
useEffect as useEffect2,
|
|
8
8
|
useLayoutEffect,
|
|
9
9
|
useMemo,
|
|
10
|
-
useRef,
|
|
10
|
+
useRef as useRef2,
|
|
11
11
|
useState as useState2
|
|
12
12
|
} from "react";
|
|
13
13
|
|
|
@@ -57,13 +57,12 @@ function getDmTruncateTextClasses({
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// src/components/tooltip/Tooltip.tsx
|
|
60
|
-
import { forwardRef, useState } from "react";
|
|
60
|
+
import React, { forwardRef, useEffect, useId, useRef, useState } from "react";
|
|
61
61
|
|
|
62
62
|
// src/classes/tooltip.ts
|
|
63
63
|
var tooltipWrapperClass = "tooltip-wrapper";
|
|
64
64
|
var tooltipBaseClass = "tooltip";
|
|
65
65
|
var tooltipShowClass = "tooltip-show";
|
|
66
|
-
var tooltipArrowClass = "tooltip-arrow";
|
|
67
66
|
var tooltipNoArrowClass = "tooltip-no-arrow";
|
|
68
67
|
var tooltipPlacementClasses = {
|
|
69
68
|
top: "tooltip-top",
|
|
@@ -93,10 +92,12 @@ var Tooltip = forwardRef(({
|
|
|
93
92
|
placement = "top",
|
|
94
93
|
open,
|
|
95
94
|
defaultOpen,
|
|
95
|
+
onOpenChange,
|
|
96
96
|
arrow = true,
|
|
97
97
|
size = "md",
|
|
98
98
|
className,
|
|
99
99
|
children,
|
|
100
|
+
style,
|
|
100
101
|
onBlur,
|
|
101
102
|
onFocus,
|
|
102
103
|
onMouseEnter,
|
|
@@ -106,54 +107,133 @@ var Tooltip = forwardRef(({
|
|
|
106
107
|
const [internalOpen, setInternalOpen] = useState(Boolean(defaultOpen));
|
|
107
108
|
const isControlled = open !== undefined;
|
|
108
109
|
const visible = isControlled ? open : internalOpen;
|
|
109
|
-
const
|
|
110
|
+
const reactId = useId();
|
|
111
|
+
const tooltipId = props.id !== undefined ? `${props.id}-tooltip` : `${reactId}-tooltip`;
|
|
112
|
+
const anchor = `--tooltip-${reactId.replace(/[^a-zA-Z0-9_-]/g, "")}`;
|
|
113
|
+
const surfaceRef = useRef(null);
|
|
114
|
+
const hoveredRef = useRef(false);
|
|
115
|
+
const focusedRef = useRef(false);
|
|
116
|
+
const interactionOpenRef = useRef(false);
|
|
117
|
+
const visibleRef = useRef(visible);
|
|
118
|
+
const controlledRef = useRef(isControlled);
|
|
119
|
+
const onOpenChangeRef = useRef(onOpenChange);
|
|
120
|
+
visibleRef.current = visible;
|
|
121
|
+
controlledRef.current = isControlled;
|
|
122
|
+
onOpenChangeRef.current = onOpenChange;
|
|
123
|
+
const hasTitle = Boolean(title);
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
const surface = surfaceRef.current;
|
|
126
|
+
if (!surface)
|
|
127
|
+
return;
|
|
128
|
+
const tooltipSurface = surface;
|
|
129
|
+
function handleToggle(event) {
|
|
130
|
+
if (event.newState !== "closed" || !visibleRef.current || isControlled || isControlled !== controlledRef.current || tooltipSurface.matches(":popover-open")) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
hoveredRef.current = false;
|
|
134
|
+
focusedRef.current = false;
|
|
135
|
+
interactionOpenRef.current = false;
|
|
136
|
+
onOpenChangeRef.current?.(false);
|
|
137
|
+
setInternalOpen(false);
|
|
138
|
+
}
|
|
139
|
+
surface.addEventListener("toggle", handleToggle);
|
|
140
|
+
return () => surface.removeEventListener("toggle", handleToggle);
|
|
141
|
+
}, [hasTitle, isControlled]);
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
const surface = surfaceRef.current;
|
|
144
|
+
if (!surface)
|
|
145
|
+
return;
|
|
146
|
+
if (visible && !surface.matches(":popover-open")) {
|
|
147
|
+
surface.showPopover();
|
|
148
|
+
} else if (!visible && surface.matches(":popover-open")) {
|
|
149
|
+
surface.hidePopover();
|
|
150
|
+
}
|
|
151
|
+
}, [visible, hasTitle, isControlled]);
|
|
152
|
+
useEffect(() => {
|
|
153
|
+
if (!isControlled || !visible || !hasTitle)
|
|
154
|
+
return;
|
|
155
|
+
const wrapper = surfaceRef.current?.parentElement;
|
|
156
|
+
if (!wrapper)
|
|
157
|
+
return;
|
|
158
|
+
const tooltipWrapper = wrapper;
|
|
159
|
+
function requestDismiss() {
|
|
160
|
+
hoveredRef.current = false;
|
|
161
|
+
focusedRef.current = false;
|
|
162
|
+
interactionOpenRef.current = false;
|
|
163
|
+
onOpenChangeRef.current?.(false);
|
|
164
|
+
}
|
|
165
|
+
function handlePointerDown(event) {
|
|
166
|
+
if (!tooltipWrapper.contains(event.target))
|
|
167
|
+
requestDismiss();
|
|
168
|
+
}
|
|
169
|
+
function handleKeyDown(event) {
|
|
170
|
+
if (event.key === "Escape")
|
|
171
|
+
requestDismiss();
|
|
172
|
+
}
|
|
173
|
+
document.addEventListener("pointerdown", handlePointerDown, true);
|
|
174
|
+
document.addEventListener("keydown", handleKeyDown, true);
|
|
175
|
+
return () => {
|
|
176
|
+
document.removeEventListener("pointerdown", handlePointerDown, true);
|
|
177
|
+
document.removeEventListener("keydown", handleKeyDown, true);
|
|
178
|
+
};
|
|
179
|
+
}, [isControlled, visible, hasTitle]);
|
|
180
|
+
function updateInteraction() {
|
|
181
|
+
const next = hoveredRef.current || focusedRef.current;
|
|
182
|
+
if (next === interactionOpenRef.current)
|
|
183
|
+
return;
|
|
184
|
+
interactionOpenRef.current = next;
|
|
185
|
+
onOpenChange?.(next);
|
|
186
|
+
if (!isControlled)
|
|
187
|
+
setInternalOpen(next);
|
|
188
|
+
}
|
|
110
189
|
function showTooltip(event) {
|
|
111
190
|
onMouseEnter?.(event);
|
|
112
|
-
|
|
113
|
-
|
|
191
|
+
hoveredRef.current = true;
|
|
192
|
+
updateInteraction();
|
|
114
193
|
}
|
|
115
194
|
function hideTooltip(event) {
|
|
116
195
|
onMouseLeave?.(event);
|
|
117
|
-
|
|
118
|
-
|
|
196
|
+
hoveredRef.current = false;
|
|
197
|
+
updateInteraction();
|
|
119
198
|
}
|
|
120
199
|
function focusTooltip(event) {
|
|
121
200
|
onFocus?.(event);
|
|
122
|
-
|
|
123
|
-
|
|
201
|
+
focusedRef.current = true;
|
|
202
|
+
updateInteraction();
|
|
124
203
|
}
|
|
125
204
|
function blurTooltip(event) {
|
|
126
205
|
onBlur?.(event);
|
|
127
|
-
if (
|
|
128
|
-
|
|
206
|
+
if (event.currentTarget.contains(event.relatedTarget))
|
|
207
|
+
return;
|
|
208
|
+
focusedRef.current = false;
|
|
209
|
+
updateInteraction();
|
|
210
|
+
}
|
|
211
|
+
let trigger = children;
|
|
212
|
+
if (hasTitle && React.isValidElement(children) && children.type !== React.Fragment) {
|
|
213
|
+
trigger = React.cloneElement(children, {
|
|
214
|
+
"aria-describedby": [children.props["aria-describedby"], tooltipId].filter(Boolean).join(" ")
|
|
215
|
+
});
|
|
129
216
|
}
|
|
130
217
|
return /* @__PURE__ */ jsxs("span", {
|
|
131
218
|
...props,
|
|
132
219
|
ref,
|
|
133
220
|
className: tooltipWrapperClass,
|
|
134
|
-
|
|
221
|
+
style: { ...style, anchorName: anchor },
|
|
222
|
+
"aria-describedby": hasTitle && trigger === children ? [props["aria-describedby"], tooltipId].filter(Boolean).join(" ") : props["aria-describedby"],
|
|
135
223
|
onMouseEnter: showTooltip,
|
|
136
224
|
onMouseLeave: hideTooltip,
|
|
137
225
|
onFocus: focusTooltip,
|
|
138
226
|
onBlur: blurTooltip,
|
|
139
227
|
children: [
|
|
140
|
-
|
|
141
|
-
|
|
228
|
+
trigger,
|
|
229
|
+
hasTitle ? /* @__PURE__ */ jsx("span", {
|
|
230
|
+
ref: surfaceRef,
|
|
142
231
|
id: tooltipId,
|
|
143
232
|
role: "tooltip",
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
arrow,
|
|
149
|
-
className
|
|
150
|
-
}),
|
|
151
|
-
children: [
|
|
152
|
-
title,
|
|
153
|
-
arrow ? /* @__PURE__ */ jsx("span", {
|
|
154
|
-
className: tooltipArrowClass
|
|
155
|
-
}) : null
|
|
156
|
-
]
|
|
233
|
+
popover: isControlled ? "manual" : "hint",
|
|
234
|
+
style: { positionAnchor: anchor },
|
|
235
|
+
className: getTooltipClasses({ placement, size, arrow, className }),
|
|
236
|
+
children: title
|
|
157
237
|
}) : null
|
|
158
238
|
]
|
|
159
239
|
});
|
|
@@ -217,10 +297,10 @@ var DmTruncate = forwardRef2(({
|
|
|
217
297
|
onCopy,
|
|
218
298
|
...props
|
|
219
299
|
}, ref) => {
|
|
220
|
-
const wrapperRef =
|
|
221
|
-
const textRef =
|
|
222
|
-
const measureRef =
|
|
223
|
-
const copyTimerRef =
|
|
300
|
+
const wrapperRef = useRef2(null);
|
|
301
|
+
const textRef = useRef2(null);
|
|
302
|
+
const measureRef = useRef2(null);
|
|
303
|
+
const copyTimerRef = useRef2(null);
|
|
224
304
|
const [overflow, setOverflow] = useState2(false);
|
|
225
305
|
const [copied, setCopied] = useState2(false);
|
|
226
306
|
const textValue = toPlainText(children);
|
|
@@ -276,14 +356,14 @@ var DmTruncate = forwardRef2(({
|
|
|
276
356
|
useLayoutEffect(() => {
|
|
277
357
|
measure();
|
|
278
358
|
}, [measure, textValue]);
|
|
279
|
-
|
|
359
|
+
useEffect2(() => {
|
|
280
360
|
if (typeof window === "undefined") {
|
|
281
361
|
return;
|
|
282
362
|
}
|
|
283
363
|
window.addEventListener("resize", measure);
|
|
284
364
|
return () => window.removeEventListener("resize", measure);
|
|
285
365
|
}, [measure]);
|
|
286
|
-
|
|
366
|
+
useEffect2(() => {
|
|
287
367
|
return () => {
|
|
288
368
|
if (copyTimerRef.current) {
|
|
289
369
|
window.clearTimeout(copyTimerRef.current);
|
|
@@ -34,7 +34,7 @@ export interface DropdownProps extends Omit<ComponentProps<"span">, "menu"> {
|
|
|
34
34
|
onOpenChange?: (open: boolean) => void;
|
|
35
35
|
children: ReactNode;
|
|
36
36
|
}
|
|
37
|
-
export type DropdownButtonProps = Omit<DropdownProps, "children" | "onClick" | keyof ButtonProps> & Omit<ButtonProps, "children" | "onClick"> & {
|
|
37
|
+
export type DropdownButtonProps = Omit<DropdownProps, "children" | "onClick" | keyof ButtonProps> & Omit<ButtonProps, "children" | "onClick" | "ref"> & {
|
|
38
38
|
buttonsRender?: (buttons: ReactNode[]) => ReactNode[];
|
|
39
39
|
children?: ReactNode;
|
|
40
40
|
onClick?: ButtonProps["onClick"];
|