@musecat/uikit 0.1.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/LICENSE +9 -0
- package/README.md +51 -0
- package/index.ts +78 -0
- package/package.json +103 -0
- package/packages/Components/Box/Box.tsx +173 -0
- package/packages/Components/Box/Box.types.ts +48 -0
- package/packages/Components/Button/Button.tsx +275 -0
- package/packages/Components/Button/Button.types.ts +44 -0
- package/packages/Components/Card/Card.default.tsx +180 -0
- package/packages/Components/Card/Card.foldable.tsx +383 -0
- package/packages/Components/Card/Card.module.scss +23 -0
- package/packages/Components/Card/Card.tsx +8 -0
- package/packages/Components/Card/Card.types.ts +91 -0
- package/packages/Components/Card/Card.utils.ts +66 -0
- package/packages/Components/Checkbox/Checkbox.module.scss +11 -0
- package/packages/Components/Checkbox/Checkbox.tsx +104 -0
- package/packages/Components/Checkbox/Checkbox.types.ts +24 -0
- package/packages/Components/CodeBox/CodeBox.copy.tsx +43 -0
- package/packages/Components/CodeBox/CodeBox.module.scss +72 -0
- package/packages/Components/CodeBox/CodeBox.tsx +91 -0
- package/packages/Components/CodeBox/CodeBox.types.ts +17 -0
- package/packages/Components/ContextMenu/ContextMenu.module.scss +8 -0
- package/packages/Components/ContextMenu/ContextMenu.options.tsx +126 -0
- package/packages/Components/ContextMenu/ContextMenu.tsx +381 -0
- package/packages/Components/ContextMenu/ContextMenu.types.ts +46 -0
- package/packages/Components/ContributionGraph/ContributionGraph.module.scss +42 -0
- package/packages/Components/ContributionGraph/ContributionGraph.tsx +454 -0
- package/packages/Components/ContributionGraph/ContributionGraph.types.ts +27 -0
- package/packages/Components/DatePicker/DatePicker.calendar.tsx +161 -0
- package/packages/Components/DatePicker/DatePicker.core.tsx +582 -0
- package/packages/Components/DatePicker/DatePicker.module.scss +26 -0
- package/packages/Components/DatePicker/DatePicker.tsx +786 -0
- package/packages/Components/DatePicker/DatePicker.types.ts +36 -0
- package/packages/Components/DatePicker/DatePicker.utils.ts +80 -0
- package/packages/Components/DatePicker/hooks/useCalendar.ts +61 -0
- package/packages/Components/DatePicker/hooks/useSelection.ts +208 -0
- package/packages/Components/Divider/Divider.tsx +46 -0
- package/packages/Components/Divider/Divider.types.ts +12 -0
- package/packages/Components/Header/Header.module.scss +74 -0
- package/packages/Components/Header/Header.tsx +47 -0
- package/packages/Components/Header/Header.types.ts +8 -0
- package/packages/Components/Icon/Icon.group.tsx +122 -0
- package/packages/Components/Icon/Icon.group.types.ts +20 -0
- package/packages/Components/Icon/Icon.tsx +341 -0
- package/packages/Components/Icon/Icon.types.ts +59 -0
- package/packages/Components/Icon/SVG/data.tsx +232 -0
- package/packages/Components/Input/Input.module.scss +5 -0
- package/packages/Components/Input/Input.tsx +87 -0
- package/packages/Components/Input/Input.types.ts +14 -0
- package/packages/Components/Label/Label.module.scss +19 -0
- package/packages/Components/Label/Label.tsx +115 -0
- package/packages/Components/Label/Label.types.ts +28 -0
- package/packages/Components/Layout/Layout.docs.module.scss +42 -0
- package/packages/Components/Layout/Layout.docs.tsx +150 -0
- package/packages/Components/Layout/Layout.docs.types.ts +18 -0
- package/packages/Components/Layout/Layout.module.scss +91 -0
- package/packages/Components/Layout/Layout.tsx +306 -0
- package/packages/Components/Layout/Layout.types.ts +71 -0
- package/packages/Components/Maps/OSM/MapOSM.module.scss +11 -0
- package/packages/Components/Maps/OSM/MapOSM.shared.ts +121 -0
- package/packages/Components/Maps/OSM/MapOSM.tsx +279 -0
- package/packages/Components/Maps/OSM/MapOSM.types.ts +18 -0
- package/packages/Components/Nav/Nav.module.scss +137 -0
- package/packages/Components/Nav/Nav.tsx +304 -0
- package/packages/Components/Nav/Nav.types.ts +32 -0
- package/packages/Components/Nav/hooks/useNavDrag.ts +374 -0
- package/packages/Components/Nav/hooks/useNavIndicator.ts +137 -0
- package/packages/Components/Pagination/Pagination.tsx +254 -0
- package/packages/Components/Pagination/Pagination.types.ts +18 -0
- package/packages/Components/Pill/Pill.tsx +127 -0
- package/packages/Components/Pill/Pill.types.ts +33 -0
- package/packages/Components/Profile/Profile.shared.ts +74 -0
- package/packages/Components/Profile/Profile.tsx +382 -0
- package/packages/Components/Profile/Profile.types.ts +55 -0
- package/packages/Components/Progress/Progress.module.scss +15 -0
- package/packages/Components/Progress/Progress.tsx +88 -0
- package/packages/Components/Progress/Progress.types.ts +22 -0
- package/packages/Components/Radio/Radio.module.scss +11 -0
- package/packages/Components/Radio/Radio.tsx +121 -0
- package/packages/Components/Radio/Radio.types.ts +20 -0
- package/packages/Components/Select/Select.keyboard.tsx +76 -0
- package/packages/Components/Select/Select.trigger.tsx +88 -0
- package/packages/Components/Select/Select.tsx +11 -0
- package/packages/Components/Select/Select.types.ts +38 -0
- package/packages/Components/Select/Select.utils.ts +84 -0
- package/packages/Components/Select/hooks/useSelectNavigation.ts +461 -0
- package/packages/Components/Select/hooks/useSelectSelection.ts +142 -0
- package/packages/Components/Select/hooks/useSelectState.ts +314 -0
- package/packages/Components/Select/select.control.tsx +228 -0
- package/packages/Components/Select/select.inner.tsx +312 -0
- package/packages/Components/Skeleton/Skeleton.tsx +30 -0
- package/packages/Components/Skeleton/Skeleton.types.ts +12 -0
- package/packages/Components/Spinner/Spinner.module.scss +78 -0
- package/packages/Components/Spinner/Spinner.tsx +125 -0
- package/packages/Components/Spinner/Spinner.types.ts +19 -0
- package/packages/Components/Text/Text.module.scss +7 -0
- package/packages/Components/Text/Text.tsx +49 -0
- package/packages/Components/Text/Text.types.ts +33 -0
- package/packages/Components/TimePicker/TimePicker.core.tsx +448 -0
- package/packages/Components/TimePicker/TimePicker.module.scss +30 -0
- package/packages/Components/TimePicker/TimePicker.tsx +511 -0
- package/packages/Components/TimePicker/TimePicker.types.ts +22 -0
- package/packages/Components/Timeline/Timeline.tsx +111 -0
- package/packages/Components/Timeline/Timeline.types.ts +23 -0
- package/packages/Components/Title/Title.tsx +305 -0
- package/packages/Components/Title/Title.types.ts +64 -0
- package/packages/Components/Toggle/Toggle.module.scss +32 -0
- package/packages/Components/Toggle/Toggle.tsx +272 -0
- package/packages/Components/Toggle/Toggle.types.ts +17 -0
- package/packages/Components/Tooltip/Tooltip.module.scss +44 -0
- package/packages/Components/Tooltip/Tooltip.tsx +340 -0
- package/packages/Components/Tooltip/Tooltip.types.ts +38 -0
- package/packages/Frameworks/Dialog/Dialog.background.tsx +88 -0
- package/packages/Frameworks/Dialog/Dialog.boot.tsx +32 -0
- package/packages/Frameworks/Dialog/Dialog.store.ts +199 -0
- package/packages/Frameworks/Dialog/Dialog.tsx +185 -0
- package/packages/Frameworks/Dialog/Dialog.types.ts +264 -0
- package/packages/Frameworks/Dialog/Dialog.utils.ts +22 -0
- package/packages/Frameworks/Dialog/contents/Dialog.footer.tsx +79 -0
- package/packages/Frameworks/Dialog/contents/Dialog.funnel.tsx +260 -0
- package/packages/Frameworks/Dialog/contents/Dialog.header.tsx +137 -0
- package/packages/Frameworks/Dialog/hooks/useDialogPosition.ts +298 -0
- package/packages/Frameworks/Dialog/hooks/useSheetDrag.ts +325 -0
- package/packages/Frameworks/Dialog/hooks/useSheetGeometry.ts +201 -0
- package/packages/Frameworks/Dialog/hooks/useSheetProgressive.ts +98 -0
- package/packages/Frameworks/Dialog/renderers/renderModal.tsx +228 -0
- package/packages/Frameworks/Dialog/renderers/renderPopover.tsx +220 -0
- package/packages/Frameworks/Dialog/renderers/renderSheet.tsx +571 -0
- package/packages/Frameworks/EdgeEffect/EdgeEffect.tsx +52 -0
- package/packages/Frameworks/EdgeEffect/EdgeEffect.types.ts +5 -0
- package/packages/Frameworks/Motion/Motion.presets.ts +49 -0
- package/packages/Frameworks/Pressable/Pressable.module.scss +19 -0
- package/packages/Frameworks/Pressable/Pressable.tsx +651 -0
- package/packages/Frameworks/Pressable/Pressable.types.ts +73 -0
- package/packages/Frameworks/Squircle/Squircle.tsx +263 -0
- package/packages/Frameworks/Squircle/Squircle.types.ts +15 -0
- package/packages/Frameworks/Theme/Radius.types.ts +55 -0
- package/packages/Frameworks/Theme/Theme.types.ts +325 -0
- package/packages/Frameworks/Toaster/Toaster.boot.tsx +47 -0
- package/packages/Frameworks/Toaster/Toaster.module.scss +168 -0
- package/packages/Frameworks/Toaster/Toaster.types.ts +13 -0
- package/packages/Frameworks/View/DNDView/DNDView.module.scss +8 -0
- package/packages/Frameworks/View/DNDView/DNDView.tsx +470 -0
- package/packages/Frameworks/View/DNDView/DNDView.types.ts +61 -0
- package/packages/Frameworks/View/HScrollView/HScrollView.module.scss +59 -0
- package/packages/Frameworks/View/HScrollView/HScrollView.tsx +386 -0
- package/packages/Frameworks/View/HScrollView/HScrollView.types.ts +46 -0
- package/packages/Frameworks/View/ImageView/Dialog/ImageDialog.counter.tsx +27 -0
- package/packages/Frameworks/View/ImageView/Dialog/ImageDialog.footer.tsx +76 -0
- package/packages/Frameworks/View/ImageView/Dialog/ImageDialog.header.tsx +49 -0
- package/packages/Frameworks/View/ImageView/Dialog/ImageDialog.list.tsx +74 -0
- package/packages/Frameworks/View/ImageView/Dialog/ImageDialog.slide.tsx +71 -0
- package/packages/Frameworks/View/ImageView/Dialog/ImageDialog.tsx +175 -0
- package/packages/Frameworks/View/ImageView/Image.controls.tsx +39 -0
- package/packages/Frameworks/View/ImageView/Image.hooks.ts +82 -0
- package/packages/Frameworks/View/ImageView/Image.module.scss +7 -0
- package/packages/Frameworks/View/ImageView/Image.tsx +375 -0
- package/packages/Frameworks/View/ImageView/Image.types.ts +71 -0
- package/packages/Frameworks/View/ImageView/Image.utils.ts +79 -0
- package/packages/Frameworks/View/View.module.scss +34 -0
- package/packages/Frameworks/View/View.tsx +200 -0
- package/packages/Frameworks/View/View.types.ts +36 -0
- package/packages/Frameworks/_shared/Padding.types.ts +52 -0
- package/packages/Frameworks/_shared/StopParentInteraction.tsx +45 -0
- package/packages/Frameworks/_shared/Wind.types.ts +17 -0
- package/packages/Frameworks/_shared/bodyScrollLock.ts +127 -0
- package/packages/Frameworks/_shared/layer.constants.ts +8 -0
- package/packages/Frameworks/_shared/normalize.ts +39 -0
- package/packages/Frameworks/_shared/sizing.ts +55 -0
- package/packages/Frameworks/_shared/useControllableState.ts +29 -0
- package/packages/Styles/_animation.scss +42 -0
- package/packages/Styles/_color.scss +131 -0
- package/packages/Styles/_font.scss +30 -0
- package/packages/Styles/_icon.scss +782 -0
- package/packages/Styles/_importer.scss +9 -0
- package/packages/Styles/_system.scss +69 -0
- package/packages/Styles/_textstyle.scss +111 -0
- package/packages/Styles/_theme.scss +452 -0
- package/packages/Styles/_viewport-global.scss +99 -0
- package/packages/Styles/_viewport.scss +108 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
.Wrapper {
|
|
2
|
+
position: relative;
|
|
3
|
+
display: inline-flex;
|
|
4
|
+
width: fit-content;
|
|
5
|
+
|
|
6
|
+
&:focus-visible {
|
|
7
|
+
outline: 2px solid
|
|
8
|
+
color-mix(in srgb, var(--color-base-light-3) 70%, transparent);
|
|
9
|
+
outline-offset: 2px;
|
|
10
|
+
border-radius: var(--radius-system-light);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.Bubble {
|
|
15
|
+
position: absolute;
|
|
16
|
+
max-width: 100%;
|
|
17
|
+
opacity: 1;
|
|
18
|
+
visibility: visible;
|
|
19
|
+
transform-origin: center;
|
|
20
|
+
transition:
|
|
21
|
+
opacity 120ms ease-out,
|
|
22
|
+
visibility 120ms ease-out;
|
|
23
|
+
filter: drop-shadow(
|
|
24
|
+
0 6px 24px color-mix(in srgb, var(--color-base-dark-6) 18%, transparent)
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
&.BubbleClosed {
|
|
28
|
+
opacity: 0;
|
|
29
|
+
visibility: hidden;
|
|
30
|
+
pointer-events: none;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.Arrow {
|
|
35
|
+
position: absolute;
|
|
36
|
+
width: 10px;
|
|
37
|
+
height: 10px;
|
|
38
|
+
background: inherit;
|
|
39
|
+
border: inherit;
|
|
40
|
+
border-top: none;
|
|
41
|
+
border-left: none;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import {
|
|
5
|
+
type CSSProperties,
|
|
6
|
+
isValidElement,
|
|
7
|
+
memo,
|
|
8
|
+
useCallback,
|
|
9
|
+
useEffect,
|
|
10
|
+
useId,
|
|
11
|
+
useLayoutEffect,
|
|
12
|
+
useRef,
|
|
13
|
+
useState,
|
|
14
|
+
} from "react";
|
|
15
|
+
import styles from "@/packages/Components/Tooltip/Tooltip.module.scss";
|
|
16
|
+
import type {
|
|
17
|
+
TooltipPlacement,
|
|
18
|
+
TooltipProps,
|
|
19
|
+
} from "@/packages/Components/Tooltip/Tooltip.types";
|
|
20
|
+
import View from "@/packages/Frameworks/View/View";
|
|
21
|
+
|
|
22
|
+
const TOOLTIP_GAP = 8;
|
|
23
|
+
const TOOLTIP_MARGIN = 4;
|
|
24
|
+
|
|
25
|
+
function getOppositePlacement(placement: TooltipPlacement): TooltipPlacement {
|
|
26
|
+
const side = getBaseSide(placement);
|
|
27
|
+
const align = placement.includes("-")
|
|
28
|
+
? (`-${placement.split("-")[1]}` as string)
|
|
29
|
+
: "";
|
|
30
|
+
const opposite = side === "top" ? "bottom" : "top";
|
|
31
|
+
return `${opposite}${align}` as TooltipPlacement;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface ClampShift {
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function computeClampShift(
|
|
40
|
+
placement: TooltipPlacement,
|
|
41
|
+
wrapperRect: DOMRect,
|
|
42
|
+
bubbleW: number,
|
|
43
|
+
bubbleH: number,
|
|
44
|
+
vw: number,
|
|
45
|
+
vh: number,
|
|
46
|
+
): ClampShift {
|
|
47
|
+
const side = getBaseSide(placement);
|
|
48
|
+
const start = placement.endsWith("-start");
|
|
49
|
+
const end = placement.endsWith("-end");
|
|
50
|
+
|
|
51
|
+
let idealLeft: number;
|
|
52
|
+
const idealTop =
|
|
53
|
+
side === "top"
|
|
54
|
+
? wrapperRect.top - TOOLTIP_GAP - bubbleH
|
|
55
|
+
: wrapperRect.bottom + TOOLTIP_GAP;
|
|
56
|
+
|
|
57
|
+
if (start) idealLeft = wrapperRect.left;
|
|
58
|
+
else if (end) idealLeft = wrapperRect.right - bubbleW;
|
|
59
|
+
else idealLeft = wrapperRect.left + wrapperRect.width / 2 - bubbleW / 2;
|
|
60
|
+
|
|
61
|
+
const minLeft = TOOLTIP_MARGIN;
|
|
62
|
+
const maxLeft = vw - TOOLTIP_MARGIN - bubbleW;
|
|
63
|
+
const minTop = TOOLTIP_MARGIN;
|
|
64
|
+
const maxTop = vh - TOOLTIP_MARGIN - bubbleH;
|
|
65
|
+
|
|
66
|
+
const clampedLeft = Math.max(minLeft, Math.min(maxLeft, idealLeft));
|
|
67
|
+
const clampedTop = Math.max(minTop, Math.min(maxTop, idealTop));
|
|
68
|
+
|
|
69
|
+
return { x: clampedLeft - idealLeft, y: clampedTop - idealTop };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const FOCUSABLE_TAGS = new Set([
|
|
73
|
+
"button",
|
|
74
|
+
"a",
|
|
75
|
+
"input",
|
|
76
|
+
"select",
|
|
77
|
+
"textarea",
|
|
78
|
+
"summary",
|
|
79
|
+
]);
|
|
80
|
+
|
|
81
|
+
function isTriggerFocusable(trigger: React.ReactNode): boolean {
|
|
82
|
+
if (!isValidElement(trigger)) return false;
|
|
83
|
+
const tag = trigger.type;
|
|
84
|
+
if (typeof tag === "string" && FOCUSABLE_TAGS.has(tag)) return true;
|
|
85
|
+
const props = trigger.props as {
|
|
86
|
+
tabIndex?: number;
|
|
87
|
+
onClick?: unknown;
|
|
88
|
+
} | null;
|
|
89
|
+
if (props && (props.tabIndex !== undefined || props.onClick !== undefined)) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function getBaseSide(placement: TooltipPlacement): "top" | "bottom" {
|
|
96
|
+
return placement.split("-")[0] as "top" | "bottom";
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function computePlacementStyle(placement: TooltipPlacement): CSSProperties {
|
|
100
|
+
const offset = `calc(100% + ${TOOLTIP_GAP}px)`;
|
|
101
|
+
const start = placement.endsWith("-start");
|
|
102
|
+
const end = placement.endsWith("-end");
|
|
103
|
+
|
|
104
|
+
if (getBaseSide(placement) === "top") {
|
|
105
|
+
return {
|
|
106
|
+
bottom: offset,
|
|
107
|
+
left: start ? 0 : end ? undefined : "50%",
|
|
108
|
+
right: end ? 0 : undefined,
|
|
109
|
+
transform: start || end ? undefined : "translateX(-50%)",
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
top: offset,
|
|
114
|
+
left: start ? 0 : end ? undefined : "50%",
|
|
115
|
+
right: end ? 0 : undefined,
|
|
116
|
+
transform: start || end ? undefined : "translateX(-50%)",
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const Tooltip = memo(function Tooltip({
|
|
121
|
+
trigger,
|
|
122
|
+
content,
|
|
123
|
+
placement = "top",
|
|
124
|
+
open,
|
|
125
|
+
defaultOpen = false,
|
|
126
|
+
onOpenChange,
|
|
127
|
+
delay = 200,
|
|
128
|
+
disabled = false,
|
|
129
|
+
interactive = false,
|
|
130
|
+
flip = true,
|
|
131
|
+
className,
|
|
132
|
+
contentClassName,
|
|
133
|
+
maxWidth = 280,
|
|
134
|
+
themePreset,
|
|
135
|
+
background = "Base1",
|
|
136
|
+
color = "Base6",
|
|
137
|
+
radius = "Regular",
|
|
138
|
+
border = "None",
|
|
139
|
+
"data-color-mode": dataColorMode,
|
|
140
|
+
}: TooltipProps) {
|
|
141
|
+
const contentId = useId();
|
|
142
|
+
const isControlled = open !== undefined;
|
|
143
|
+
const [internalOpen, setInternalOpen] = useState(defaultOpen);
|
|
144
|
+
const isOpen = isControlled ? Boolean(open) : internalOpen;
|
|
145
|
+
|
|
146
|
+
const wrapperRef = useRef<HTMLDivElement>(null);
|
|
147
|
+
const bubbleRef = useRef<HTMLDivElement>(null);
|
|
148
|
+
const [effectivePlacement, setEffectivePlacement] =
|
|
149
|
+
useState<TooltipPlacement>(placement);
|
|
150
|
+
const [clampShift, setClampShift] = useState<ClampShift>({ x: 0, y: 0 });
|
|
151
|
+
|
|
152
|
+
const openTimer = useRef<number | null>(null);
|
|
153
|
+
const closeTimer = useRef<number | null>(null);
|
|
154
|
+
|
|
155
|
+
const setOpen = useCallback(
|
|
156
|
+
(next: boolean) => {
|
|
157
|
+
if ((isControlled ? Boolean(open) : internalOpen) === next) return;
|
|
158
|
+
if (!isControlled) setInternalOpen(next);
|
|
159
|
+
onOpenChange?.(next);
|
|
160
|
+
},
|
|
161
|
+
[isControlled, open, internalOpen, onOpenChange],
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
useEffect(() => {
|
|
165
|
+
return () => {
|
|
166
|
+
clearTimeout(openTimer.current ?? undefined);
|
|
167
|
+
clearTimeout(closeTimer.current ?? undefined);
|
|
168
|
+
};
|
|
169
|
+
}, []);
|
|
170
|
+
|
|
171
|
+
const scheduleOpen = useCallback(() => {
|
|
172
|
+
if (disabled) return;
|
|
173
|
+
clearTimeout(closeTimer.current ?? undefined);
|
|
174
|
+
openTimer.current = window.setTimeout(() => setOpen(true), delay);
|
|
175
|
+
}, [disabled, delay, setOpen]);
|
|
176
|
+
|
|
177
|
+
const scheduleClose = useCallback(() => {
|
|
178
|
+
clearTimeout(openTimer.current ?? undefined);
|
|
179
|
+
if (interactive) {
|
|
180
|
+
closeTimer.current = window.setTimeout(() => setOpen(false), 120);
|
|
181
|
+
} else {
|
|
182
|
+
setOpen(false);
|
|
183
|
+
}
|
|
184
|
+
}, [interactive, setOpen]);
|
|
185
|
+
|
|
186
|
+
const toggle = useCallback(() => {
|
|
187
|
+
if (disabled) return;
|
|
188
|
+
setOpen(!isOpen);
|
|
189
|
+
}, [disabled, isOpen, setOpen]);
|
|
190
|
+
|
|
191
|
+
const resolvePlacement = useCallback(() => {
|
|
192
|
+
const wrapperEl = wrapperRef.current;
|
|
193
|
+
const bubbleEl = bubbleRef.current;
|
|
194
|
+
if (!wrapperEl || !bubbleEl) return placement;
|
|
195
|
+
|
|
196
|
+
const rect = wrapperEl.getBoundingClientRect();
|
|
197
|
+
const bubbleHeight = bubbleEl.offsetHeight;
|
|
198
|
+
const _bubbleWidth = bubbleEl.offsetWidth;
|
|
199
|
+
const vh = window.visualViewport?.height ?? window.innerHeight;
|
|
200
|
+
const _vw = window.visualViewport?.width ?? window.innerWidth;
|
|
201
|
+
|
|
202
|
+
const fits = (side: "top" | "bottom") => {
|
|
203
|
+
if (side === "top")
|
|
204
|
+
return rect.top - TOOLTIP_GAP - bubbleHeight >= TOOLTIP_MARGIN;
|
|
205
|
+
return rect.bottom + TOOLTIP_GAP + bubbleHeight <= vh - TOOLTIP_MARGIN;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const preferred = placement;
|
|
209
|
+
if (flip && !fits(getBaseSide(preferred))) {
|
|
210
|
+
const flipped = getOppositePlacement(preferred);
|
|
211
|
+
if (fits(getBaseSide(flipped))) return flipped;
|
|
212
|
+
return flipped;
|
|
213
|
+
}
|
|
214
|
+
return preferred;
|
|
215
|
+
}, [placement, flip]);
|
|
216
|
+
|
|
217
|
+
useLayoutEffect(() => {
|
|
218
|
+
if (!isOpen) return;
|
|
219
|
+
const apply = () => setEffectivePlacement(resolvePlacement());
|
|
220
|
+
apply();
|
|
221
|
+
|
|
222
|
+
window.addEventListener("resize", apply);
|
|
223
|
+
window.addEventListener("scroll", apply, true);
|
|
224
|
+
return () => {
|
|
225
|
+
window.removeEventListener("resize", apply);
|
|
226
|
+
window.removeEventListener("scroll", apply, true);
|
|
227
|
+
};
|
|
228
|
+
}, [isOpen, resolvePlacement]);
|
|
229
|
+
|
|
230
|
+
useLayoutEffect(() => {
|
|
231
|
+
if (!isOpen) return;
|
|
232
|
+
const wrapperEl = wrapperRef.current;
|
|
233
|
+
const bubbleEl = bubbleRef.current;
|
|
234
|
+
if (!wrapperEl || !bubbleEl) return;
|
|
235
|
+
|
|
236
|
+
const rect = wrapperEl.getBoundingClientRect();
|
|
237
|
+
const vh = window.visualViewport?.height ?? window.innerHeight;
|
|
238
|
+
const vw = window.visualViewport?.width ?? window.innerWidth;
|
|
239
|
+
setClampShift(
|
|
240
|
+
computeClampShift(
|
|
241
|
+
effectivePlacement,
|
|
242
|
+
rect,
|
|
243
|
+
bubbleEl.offsetWidth,
|
|
244
|
+
bubbleEl.offsetHeight,
|
|
245
|
+
vw,
|
|
246
|
+
vh,
|
|
247
|
+
),
|
|
248
|
+
);
|
|
249
|
+
}, [isOpen, effectivePlacement]);
|
|
250
|
+
|
|
251
|
+
const handleKeyDown = useCallback(
|
|
252
|
+
(event: React.KeyboardEvent) => {
|
|
253
|
+
if (event.key === "Escape" && isOpen) {
|
|
254
|
+
setOpen(false);
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
[isOpen, setOpen],
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
const bubbleFocusable = isTriggerFocusable(trigger);
|
|
261
|
+
|
|
262
|
+
const placementStyle = computePlacementStyle(effectivePlacement);
|
|
263
|
+
const arrowClass =
|
|
264
|
+
styles[`Arrow_${getBaseSide(effectivePlacement)}` as keyof typeof styles];
|
|
265
|
+
|
|
266
|
+
const clampTransform =
|
|
267
|
+
clampShift.x === 0 && clampShift.y === 0
|
|
268
|
+
? undefined
|
|
269
|
+
: `translate(${clampShift.x}px, ${clampShift.y}px)`;
|
|
270
|
+
|
|
271
|
+
const bubbleStyle: CSSProperties = {
|
|
272
|
+
...placementStyle,
|
|
273
|
+
...(clampTransform
|
|
274
|
+
? {
|
|
275
|
+
transform: placementStyle.transform
|
|
276
|
+
? `${placementStyle.transform} ${clampTransform}`
|
|
277
|
+
: clampTransform,
|
|
278
|
+
}
|
|
279
|
+
: null),
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
return (
|
|
283
|
+
<View
|
|
284
|
+
ref={wrapperRef}
|
|
285
|
+
className={clsx(styles.Wrapper, className)}
|
|
286
|
+
data-color-mode={dataColorMode}
|
|
287
|
+
data-tooltip-open={isOpen ? "" : undefined}
|
|
288
|
+
tabIndex={bubbleFocusable ? undefined : 0}
|
|
289
|
+
onMouseEnter={scheduleOpen}
|
|
290
|
+
onMouseLeave={scheduleClose}
|
|
291
|
+
onFocus={scheduleOpen}
|
|
292
|
+
onBlur={scheduleClose}
|
|
293
|
+
onClick={toggle}
|
|
294
|
+
onKeyDown={handleKeyDown}
|
|
295
|
+
aria-describedby={isOpen ? contentId : undefined}
|
|
296
|
+
>
|
|
297
|
+
{trigger}
|
|
298
|
+
<View
|
|
299
|
+
ref={bubbleRef}
|
|
300
|
+
id={contentId}
|
|
301
|
+
role="tooltip"
|
|
302
|
+
radius={radius}
|
|
303
|
+
noSquircle
|
|
304
|
+
themePreset={themePreset}
|
|
305
|
+
background={background}
|
|
306
|
+
color={color}
|
|
307
|
+
border={border}
|
|
308
|
+
className={clsx(
|
|
309
|
+
styles.Bubble,
|
|
310
|
+
!isOpen && styles.BubbleClosed,
|
|
311
|
+
contentClassName,
|
|
312
|
+
)}
|
|
313
|
+
padding={[6, 8]}
|
|
314
|
+
style={{
|
|
315
|
+
width: "max-content",
|
|
316
|
+
...bubbleStyle,
|
|
317
|
+
maxWidth,
|
|
318
|
+
zIndex: 1300,
|
|
319
|
+
}}
|
|
320
|
+
onMouseEnter={() => clearTimeout(closeTimer.current ?? undefined)}
|
|
321
|
+
onMouseLeave={scheduleClose}
|
|
322
|
+
onClick={(e) => e.stopPropagation()}
|
|
323
|
+
>
|
|
324
|
+
{content}
|
|
325
|
+
<span
|
|
326
|
+
className={clsx(styles.Arrow, arrowClass)}
|
|
327
|
+
aria-hidden
|
|
328
|
+
style={{
|
|
329
|
+
["--tooltip-clamp-x" as string]: `${clampShift.x}px`,
|
|
330
|
+
["--tooltip-clamp-y" as string]: `${clampShift.y}px`,
|
|
331
|
+
}}
|
|
332
|
+
/>
|
|
333
|
+
</View>
|
|
334
|
+
</View>
|
|
335
|
+
);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
Tooltip.displayName = "Tooltip";
|
|
339
|
+
|
|
340
|
+
export default Tooltip;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { RadiusValue } from "@/packages/Frameworks/Theme/Radius.types";
|
|
2
|
+
import type {
|
|
3
|
+
BorderProps,
|
|
4
|
+
ThemeBackgroundPaint,
|
|
5
|
+
ThemePaint,
|
|
6
|
+
ThemePreset,
|
|
7
|
+
} from "@/packages/Frameworks/Theme/Theme.types";
|
|
8
|
+
|
|
9
|
+
export type TooltipPlacement =
|
|
10
|
+
| "top"
|
|
11
|
+
| "top-start"
|
|
12
|
+
| "top-end"
|
|
13
|
+
| "bottom"
|
|
14
|
+
| "bottom-start"
|
|
15
|
+
| "bottom-end";
|
|
16
|
+
|
|
17
|
+
export interface TooltipProps extends BorderProps {
|
|
18
|
+
trigger: React.ReactNode;
|
|
19
|
+
content: React.ReactNode;
|
|
20
|
+
placement?: TooltipPlacement;
|
|
21
|
+
open?: boolean;
|
|
22
|
+
defaultOpen?: boolean;
|
|
23
|
+
onOpenChange?: (open: boolean) => void;
|
|
24
|
+
delay?: number;
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
interactive?: boolean;
|
|
27
|
+
flip?: boolean;
|
|
28
|
+
className?: string;
|
|
29
|
+
contentClassName?: string;
|
|
30
|
+
maxWidth?: number | string;
|
|
31
|
+
|
|
32
|
+
themePreset?: ThemePreset;
|
|
33
|
+
background?: ThemeBackgroundPaint;
|
|
34
|
+
color?: ThemePaint;
|
|
35
|
+
radius?: RadiusValue;
|
|
36
|
+
|
|
37
|
+
"data-color-mode"?: string;
|
|
38
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import type { MotionValue } from "motion/react";
|
|
5
|
+
import { useEffect, useState } from "react";
|
|
6
|
+
import { motionPresets } from "@/packages/Frameworks/Motion/Motion.presets";
|
|
7
|
+
import type {
|
|
8
|
+
BackgroundBlurValue,
|
|
9
|
+
ThemeBackgroundPaint,
|
|
10
|
+
} from "@/packages/Frameworks/Theme/Theme.types";
|
|
11
|
+
import { BackgroundBlur } from "@/packages/Frameworks/Theme/Theme.types";
|
|
12
|
+
import View from "@/packages/Frameworks/View/View";
|
|
13
|
+
|
|
14
|
+
interface BackgroundWrapperProps {
|
|
15
|
+
open: boolean;
|
|
16
|
+
showBackdrop: boolean;
|
|
17
|
+
background?: ThemeBackgroundPaint;
|
|
18
|
+
backgroundBlur?: BackgroundBlurValue;
|
|
19
|
+
className?: string;
|
|
20
|
+
style?: React.CSSProperties;
|
|
21
|
+
onClick?: () => void;
|
|
22
|
+
zIndex: number;
|
|
23
|
+
overlayOpacity?: MotionValue<number>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default function BackgroundWrapper({
|
|
27
|
+
open,
|
|
28
|
+
showBackdrop,
|
|
29
|
+
background: backgroundProp,
|
|
30
|
+
backgroundBlur,
|
|
31
|
+
className,
|
|
32
|
+
style,
|
|
33
|
+
onClick,
|
|
34
|
+
zIndex,
|
|
35
|
+
overlayOpacity,
|
|
36
|
+
}: BackgroundWrapperProps) {
|
|
37
|
+
const [pointerEvents, setPointerEvents] = useState<"auto" | "none">("none");
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (open) {
|
|
41
|
+
setPointerEvents("auto");
|
|
42
|
+
} else {
|
|
43
|
+
const timer = setTimeout(() => {
|
|
44
|
+
setPointerEvents("none");
|
|
45
|
+
}, 50);
|
|
46
|
+
return () => clearTimeout(timer);
|
|
47
|
+
}
|
|
48
|
+
}, [open]);
|
|
49
|
+
|
|
50
|
+
if (!showBackdrop) return null;
|
|
51
|
+
|
|
52
|
+
const backdropBg = backgroundProp ?? "BaseDark3TP6";
|
|
53
|
+
const blurClass = BackgroundBlur(backgroundBlur ?? "None");
|
|
54
|
+
|
|
55
|
+
const handlePointerDown = (e: React.PointerEvent) => {
|
|
56
|
+
e.preventDefault();
|
|
57
|
+
e.stopPropagation();
|
|
58
|
+
onClick?.();
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<View
|
|
63
|
+
className={clsx(blurClass, className)}
|
|
64
|
+
background={backdropBg}
|
|
65
|
+
style={{
|
|
66
|
+
position: "fixed",
|
|
67
|
+
top: 0,
|
|
68
|
+
left: 0,
|
|
69
|
+
right: 0,
|
|
70
|
+
height: "100%",
|
|
71
|
+
bottom: "-8rem",
|
|
72
|
+
zIndex,
|
|
73
|
+
pointerEvents,
|
|
74
|
+
...style,
|
|
75
|
+
}}
|
|
76
|
+
motion={
|
|
77
|
+
overlayOpacity
|
|
78
|
+
? { style: { opacity: overlayOpacity } }
|
|
79
|
+
: motionPresets.backdrop(open)
|
|
80
|
+
}
|
|
81
|
+
onPointerDown={handlePointerDown}
|
|
82
|
+
onClick={(e: any) => {
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
e.stopPropagation();
|
|
85
|
+
}}
|
|
86
|
+
/>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import Dialog from "@/packages/Frameworks/Dialog/Dialog";
|
|
5
|
+
import {
|
|
6
|
+
type DialogInstance,
|
|
7
|
+
DialogStore,
|
|
8
|
+
} from "@/packages/Frameworks/Dialog/Dialog.store";
|
|
9
|
+
|
|
10
|
+
interface DialogBootstrapProps {
|
|
11
|
+
"data-color-mode"?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default function DialogBootstrap(props: DialogBootstrapProps) {
|
|
15
|
+
const [stack, setStack] = useState<DialogInstance[]>([]);
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
return DialogStore.subscribe((nextStack) => {
|
|
19
|
+
setStack(nextStack);
|
|
20
|
+
});
|
|
21
|
+
}, []);
|
|
22
|
+
|
|
23
|
+
return stack.map((item) => (
|
|
24
|
+
<Dialog
|
|
25
|
+
key={item.instanceId}
|
|
26
|
+
data-color-mode={
|
|
27
|
+
props["data-color-mode"] ?? item.props["data-color-mode"]
|
|
28
|
+
}
|
|
29
|
+
{...item.props}
|
|
30
|
+
/>
|
|
31
|
+
));
|
|
32
|
+
}
|