@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,381 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useViewportMatch } from "@musecat/functionkit";
|
|
4
|
+
import {
|
|
5
|
+
type ReactElement,
|
|
6
|
+
useCallback,
|
|
7
|
+
useEffect,
|
|
8
|
+
useLayoutEffect,
|
|
9
|
+
useRef,
|
|
10
|
+
useState,
|
|
11
|
+
} from "react";
|
|
12
|
+
import { Word } from "@/i18n/shared";
|
|
13
|
+
import ContextMenuOption from "@/packages/Components/ContextMenu/ContextMenu.options";
|
|
14
|
+
import type {
|
|
15
|
+
ContentItem,
|
|
16
|
+
ContextMenuProps,
|
|
17
|
+
} from "@/packages/Components/ContextMenu/ContextMenu.types";
|
|
18
|
+
import {
|
|
19
|
+
handleEndKey,
|
|
20
|
+
handleHomeKey,
|
|
21
|
+
} from "@/packages/Components/Select/Select.keyboard";
|
|
22
|
+
import Text from "@/packages/Components/Text/Text";
|
|
23
|
+
import Dialog from "@/packages/Frameworks/Dialog/Dialog";
|
|
24
|
+
import View from "@/packages/Frameworks/View/View";
|
|
25
|
+
|
|
26
|
+
const clampScrollTop = (element: HTMLElement, nextScrollTop: number) => {
|
|
27
|
+
const maxScrollTop = Math.max(0, element.scrollHeight - element.clientHeight);
|
|
28
|
+
return Math.max(0, Math.min(maxScrollTop, nextScrollTop));
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const isItemDisabled = (item: ContentItem) => item.disabled ?? false;
|
|
32
|
+
|
|
33
|
+
export default function ContextMenu(props: ContextMenuProps): ReactElement {
|
|
34
|
+
const t = Word();
|
|
35
|
+
const {
|
|
36
|
+
open,
|
|
37
|
+
onOpenChange,
|
|
38
|
+
anchorRef,
|
|
39
|
+
popoverOwnerId,
|
|
40
|
+
listId,
|
|
41
|
+
listLabelId,
|
|
42
|
+
role,
|
|
43
|
+
isInteractionDisabled,
|
|
44
|
+
contents,
|
|
45
|
+
recalcKey,
|
|
46
|
+
popoverConfig,
|
|
47
|
+
sheetConfig,
|
|
48
|
+
exit,
|
|
49
|
+
mobileMode,
|
|
50
|
+
children,
|
|
51
|
+
showCheck,
|
|
52
|
+
activeIndex: activeIndexProp,
|
|
53
|
+
onActiveIndexChange,
|
|
54
|
+
openSource: openSourceProp,
|
|
55
|
+
onOpenSourceChange,
|
|
56
|
+
} = props;
|
|
57
|
+
|
|
58
|
+
const isMobile = useViewportMatch("(max-width: 549.98px)");
|
|
59
|
+
const isSheetMode = mobileMode === "sheet" && isMobile;
|
|
60
|
+
|
|
61
|
+
const isActiveIndexControlled = activeIndexProp !== undefined;
|
|
62
|
+
const [activeIndexState, setActiveIndexState] = useState(-1);
|
|
63
|
+
const activeIndex = isActiveIndexControlled
|
|
64
|
+
? activeIndexProp
|
|
65
|
+
: activeIndexState;
|
|
66
|
+
const setActiveIndex = isActiveIndexControlled
|
|
67
|
+
? (onActiveIndexChange ?? setActiveIndexState)
|
|
68
|
+
: setActiveIndexState;
|
|
69
|
+
|
|
70
|
+
const isOpenSourceControlled = openSourceProp !== undefined;
|
|
71
|
+
const [openSourceState, setOpenSourceState] = useState<"mouse" | "keyboard">(
|
|
72
|
+
"mouse",
|
|
73
|
+
);
|
|
74
|
+
const openSource = isOpenSourceControlled ? openSourceProp : openSourceState;
|
|
75
|
+
const setOpenSource = isOpenSourceControlled
|
|
76
|
+
? (onOpenSourceChange ?? setOpenSourceState)
|
|
77
|
+
: setOpenSourceState;
|
|
78
|
+
|
|
79
|
+
const getFirstEnabledIndex = useCallback(
|
|
80
|
+
(items: ContentItem[]) => items.findIndex((item) => !isItemDisabled(item)),
|
|
81
|
+
[],
|
|
82
|
+
);
|
|
83
|
+
const getNextEnabledIndex = useCallback(
|
|
84
|
+
(items: ContentItem[], start: number, direction: 1 | -1) => {
|
|
85
|
+
if (!items.length) return -1;
|
|
86
|
+
let idx = start;
|
|
87
|
+
for (let i = 0; i < items.length; i += 1) {
|
|
88
|
+
idx += direction;
|
|
89
|
+
if (idx < 0) idx = items.length - 1;
|
|
90
|
+
if (idx >= items.length) idx = 0;
|
|
91
|
+
if (items[idx] && !isItemDisabled(items[idx])) return idx;
|
|
92
|
+
}
|
|
93
|
+
return -1;
|
|
94
|
+
},
|
|
95
|
+
[],
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const activeIndexRef = useRef(activeIndex);
|
|
99
|
+
activeIndexRef.current = activeIndex;
|
|
100
|
+
const openRef = useRef(open);
|
|
101
|
+
openRef.current = open;
|
|
102
|
+
|
|
103
|
+
const ensureActiveOptionVisible = useCallback(() => {
|
|
104
|
+
if (!openRef.current || activeIndexRef.current < 0) return;
|
|
105
|
+
const listEl = document.getElementById(listId) as HTMLElement | null;
|
|
106
|
+
const activeEl = document.getElementById(
|
|
107
|
+
`${listId}-${activeIndexRef.current}`,
|
|
108
|
+
) as HTMLElement | null;
|
|
109
|
+
if (!listEl || !activeEl || listEl.scrollHeight <= listEl.clientHeight) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const computedStyle = window.getComputedStyle(listEl);
|
|
113
|
+
const paddingTop = Number.parseFloat(computedStyle.paddingTop) || 0;
|
|
114
|
+
const paddingBottom = Number.parseFloat(computedStyle.paddingBottom) || 0;
|
|
115
|
+
const listRect = listEl.getBoundingClientRect();
|
|
116
|
+
const safeTop = listRect.top + paddingTop;
|
|
117
|
+
const safeBottom = listRect.bottom - paddingBottom;
|
|
118
|
+
const activeRect = activeEl.getBoundingClientRect();
|
|
119
|
+
if (openSource !== "keyboard") {
|
|
120
|
+
if (activeRect.top < safeTop) {
|
|
121
|
+
listEl.scrollTop = clampScrollTop(
|
|
122
|
+
listEl,
|
|
123
|
+
listEl.scrollTop - (safeTop - activeRect.top),
|
|
124
|
+
);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (activeRect.bottom > safeBottom) {
|
|
128
|
+
listEl.scrollTop = clampScrollTop(
|
|
129
|
+
listEl,
|
|
130
|
+
listEl.scrollTop + (activeRect.bottom - safeBottom),
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const activeHalfHeight = activeRect.height / 2;
|
|
136
|
+
const desiredCenterY = Math.min(
|
|
137
|
+
safeBottom - activeHalfHeight,
|
|
138
|
+
Math.max(safeTop + activeHalfHeight, listRect.top + listRect.height / 2),
|
|
139
|
+
);
|
|
140
|
+
const currentCenterY = activeRect.top + activeHalfHeight;
|
|
141
|
+
const nextScrollTop = clampScrollTop(
|
|
142
|
+
listEl,
|
|
143
|
+
listEl.scrollTop + (currentCenterY - desiredCenterY),
|
|
144
|
+
);
|
|
145
|
+
if (nextScrollTop !== listEl.scrollTop) {
|
|
146
|
+
listEl.scrollTop = nextScrollTop;
|
|
147
|
+
}
|
|
148
|
+
}, [listId, openSource]);
|
|
149
|
+
|
|
150
|
+
const ensureVisibleRafRef = useRef<number | null>(null);
|
|
151
|
+
const ensureActiveOptionVisibleRafRef = useRef<number | null>(null);
|
|
152
|
+
const ensureControlVisible = useCallback(() => {
|
|
153
|
+
const controlEl = anchorRef.current;
|
|
154
|
+
if (!controlEl) return;
|
|
155
|
+
controlEl.scrollIntoView({ block: "nearest", inline: "nearest" });
|
|
156
|
+
}, [anchorRef]);
|
|
157
|
+
const scheduleEnsureControlVisible = useCallback(() => {
|
|
158
|
+
if (ensureVisibleRafRef.current !== null) {
|
|
159
|
+
cancelAnimationFrame(ensureVisibleRafRef.current);
|
|
160
|
+
}
|
|
161
|
+
const outerRafId = requestAnimationFrame(() => {
|
|
162
|
+
ensureVisibleRafRef.current = requestAnimationFrame(() => {
|
|
163
|
+
ensureControlVisible();
|
|
164
|
+
ensureVisibleRafRef.current = null;
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
ensureVisibleRafRef.current = outerRafId;
|
|
168
|
+
}, [ensureControlVisible]);
|
|
169
|
+
const scheduleEnsureActiveOptionVisible = useCallback(() => {
|
|
170
|
+
if (ensureActiveOptionVisibleRafRef.current !== null) {
|
|
171
|
+
cancelAnimationFrame(ensureActiveOptionVisibleRafRef.current);
|
|
172
|
+
}
|
|
173
|
+
const outerRafId = requestAnimationFrame(() => {
|
|
174
|
+
ensureActiveOptionVisibleRafRef.current = requestAnimationFrame(() => {
|
|
175
|
+
ensureActiveOptionVisible();
|
|
176
|
+
ensureActiveOptionVisibleRafRef.current = null;
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
ensureActiveOptionVisibleRafRef.current = outerRafId;
|
|
180
|
+
}, [ensureActiveOptionVisible]);
|
|
181
|
+
|
|
182
|
+
useLayoutEffect(() => {
|
|
183
|
+
if (!open || activeIndex < 0 || openSource !== "keyboard") return;
|
|
184
|
+
ensureActiveOptionVisible();
|
|
185
|
+
scheduleEnsureActiveOptionVisible();
|
|
186
|
+
}, [
|
|
187
|
+
activeIndex,
|
|
188
|
+
ensureActiveOptionVisible,
|
|
189
|
+
open,
|
|
190
|
+
openSource,
|
|
191
|
+
scheduleEnsureActiveOptionVisible,
|
|
192
|
+
]);
|
|
193
|
+
|
|
194
|
+
useEffect(() => {
|
|
195
|
+
return () => {
|
|
196
|
+
if (ensureVisibleRafRef.current !== null) {
|
|
197
|
+
cancelAnimationFrame(ensureVisibleRafRef.current);
|
|
198
|
+
}
|
|
199
|
+
if (ensureActiveOptionVisibleRafRef.current !== null) {
|
|
200
|
+
cancelAnimationFrame(ensureActiveOptionVisibleRafRef.current);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
}, []);
|
|
204
|
+
|
|
205
|
+
useEffect(() => {
|
|
206
|
+
const handleViewportShift = () => {
|
|
207
|
+
const active = document.activeElement as Node | null;
|
|
208
|
+
if (!active || !anchorRef.current?.contains(active)) return;
|
|
209
|
+
scheduleEnsureControlVisible();
|
|
210
|
+
scheduleEnsureActiveOptionVisible();
|
|
211
|
+
};
|
|
212
|
+
window.addEventListener("resize", handleViewportShift);
|
|
213
|
+
window.visualViewport?.addEventListener("resize", handleViewportShift);
|
|
214
|
+
window.visualViewport?.addEventListener("scroll", handleViewportShift);
|
|
215
|
+
return () => {
|
|
216
|
+
window.removeEventListener("resize", handleViewportShift);
|
|
217
|
+
window.visualViewport?.removeEventListener("resize", handleViewportShift);
|
|
218
|
+
window.visualViewport?.removeEventListener("scroll", handleViewportShift);
|
|
219
|
+
};
|
|
220
|
+
}, [
|
|
221
|
+
anchorRef,
|
|
222
|
+
scheduleEnsureActiveOptionVisible,
|
|
223
|
+
scheduleEnsureControlVisible,
|
|
224
|
+
]);
|
|
225
|
+
|
|
226
|
+
useEffect(() => {
|
|
227
|
+
if (!open || isInteractionDisabled) return;
|
|
228
|
+
const handler = (e: globalThis.KeyboardEvent) => {
|
|
229
|
+
if (e.isComposing) return;
|
|
230
|
+
const target = e.target as HTMLElement | null;
|
|
231
|
+
const within =
|
|
232
|
+
anchorRef.current?.contains(target) ||
|
|
233
|
+
!!target?.closest(`[data-popover-owner="${popoverOwnerId}"]`);
|
|
234
|
+
if (!within) return;
|
|
235
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
236
|
+
e.preventDefault();
|
|
237
|
+
e.stopPropagation();
|
|
238
|
+
setOpenSource("keyboard");
|
|
239
|
+
setActiveIndex((prev) =>
|
|
240
|
+
e.key === "ArrowDown"
|
|
241
|
+
? getNextEnabledIndex(contents, prev < 0 ? -1 : prev, 1)
|
|
242
|
+
: getNextEnabledIndex(contents, prev < 0 ? 0 : prev, -1),
|
|
243
|
+
);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (e.key === "Home") {
|
|
247
|
+
e.preventDefault();
|
|
248
|
+
e.stopPropagation();
|
|
249
|
+
const idx = handleHomeKey(contents, isItemDisabled);
|
|
250
|
+
if (idx >= 0) setActiveIndex(idx);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (e.key === "End") {
|
|
254
|
+
e.preventDefault();
|
|
255
|
+
e.stopPropagation();
|
|
256
|
+
const idx = handleEndKey(contents, isItemDisabled);
|
|
257
|
+
if (idx >= 0) setActiveIndex(idx);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const isInput =
|
|
261
|
+
target?.tagName === "INPUT" ||
|
|
262
|
+
target?.tagName === "TEXTAREA" ||
|
|
263
|
+
target?.isContentEditable;
|
|
264
|
+
const isSelectionKey = e.key === "Enter" || (!isInput && e.key === " ");
|
|
265
|
+
if (isSelectionKey) {
|
|
266
|
+
e.preventDefault();
|
|
267
|
+
e.stopPropagation();
|
|
268
|
+
const fallbackIndex = getFirstEnabledIndex(contents);
|
|
269
|
+
const indexToPick =
|
|
270
|
+
activeIndexRef.current >= 0 ? activeIndexRef.current : fallbackIndex;
|
|
271
|
+
const picked = indexToPick >= 0 ? contents[indexToPick] : undefined;
|
|
272
|
+
if (picked && !isItemDisabled(picked)) {
|
|
273
|
+
picked.onClick?.();
|
|
274
|
+
}
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (e.key === "Escape") {
|
|
278
|
+
e.preventDefault();
|
|
279
|
+
e.stopPropagation();
|
|
280
|
+
onOpenChange(false);
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
document.addEventListener("keydown", handler, true);
|
|
284
|
+
return () => document.removeEventListener("keydown", handler, true);
|
|
285
|
+
}, [
|
|
286
|
+
anchorRef,
|
|
287
|
+
getFirstEnabledIndex,
|
|
288
|
+
getNextEnabledIndex,
|
|
289
|
+
isInteractionDisabled,
|
|
290
|
+
onOpenChange,
|
|
291
|
+
open,
|
|
292
|
+
contents,
|
|
293
|
+
popoverOwnerId,
|
|
294
|
+
setActiveIndex,
|
|
295
|
+
setOpenSource,
|
|
296
|
+
]);
|
|
297
|
+
|
|
298
|
+
return (
|
|
299
|
+
<Dialog
|
|
300
|
+
mode="popover"
|
|
301
|
+
open={!isInteractionDisabled && open}
|
|
302
|
+
onOpenChange={onOpenChange}
|
|
303
|
+
mobileMode={mobileMode}
|
|
304
|
+
sheet={{
|
|
305
|
+
snapPoints: sheetConfig?.header ? [0.7, 1.0] : [0.3, 1.0],
|
|
306
|
+
defaultSnap: sheetConfig?.header ? 0.7 : 0.3,
|
|
307
|
+
...sheetConfig,
|
|
308
|
+
exit,
|
|
309
|
+
}}
|
|
310
|
+
role={role}
|
|
311
|
+
popover={{
|
|
312
|
+
anchorRef: anchorRef as React.RefObject<HTMLElement>,
|
|
313
|
+
recalcKey: recalcKey,
|
|
314
|
+
popoverOwnerId: popoverOwnerId,
|
|
315
|
+
style: { padding: ".4rem" },
|
|
316
|
+
stopInteractionPropagation: true,
|
|
317
|
+
exit: exit,
|
|
318
|
+
...popoverConfig,
|
|
319
|
+
}}
|
|
320
|
+
>
|
|
321
|
+
<View
|
|
322
|
+
gap={popoverConfig?.gap ?? 0}
|
|
323
|
+
column
|
|
324
|
+
style={{
|
|
325
|
+
maxHeight: isSheetMode ? "none" : "inherit",
|
|
326
|
+
overflow: isSheetMode ? "visible" : "hidden",
|
|
327
|
+
}}
|
|
328
|
+
fullWidth
|
|
329
|
+
>
|
|
330
|
+
{children}
|
|
331
|
+
<View
|
|
332
|
+
id={listId}
|
|
333
|
+
role="listbox"
|
|
334
|
+
aria-labelledby={listLabelId}
|
|
335
|
+
fullWidth
|
|
336
|
+
style={{
|
|
337
|
+
overflowY: isSheetMode ? "visible" : "auto",
|
|
338
|
+
maxHeight: isSheetMode ? "none" : undefined,
|
|
339
|
+
}}
|
|
340
|
+
padding={isSheetMode ? [0, 6, 6, 6] : undefined}
|
|
341
|
+
>
|
|
342
|
+
<View
|
|
343
|
+
column
|
|
344
|
+
gap={2}
|
|
345
|
+
padding={isSheetMode ? [6, 4] : undefined}
|
|
346
|
+
themePreset={isSheetMode ? "BaseFull" : undefined}
|
|
347
|
+
radius={isSheetMode ? "Regular" : undefined}
|
|
348
|
+
>
|
|
349
|
+
{contents.length === 0 ? (
|
|
350
|
+
<Text
|
|
351
|
+
type="Subheadline"
|
|
352
|
+
opacity={0.6}
|
|
353
|
+
style={{ padding: "0.6rem 1.6rem" }}
|
|
354
|
+
>
|
|
355
|
+
{t.UIKit.ui.noResults}
|
|
356
|
+
</Text>
|
|
357
|
+
) : (
|
|
358
|
+
contents.map((item, index) => (
|
|
359
|
+
<ContextMenuOption
|
|
360
|
+
key={`${item.value}-${index}`}
|
|
361
|
+
item={item}
|
|
362
|
+
index={index}
|
|
363
|
+
listId={listId}
|
|
364
|
+
openSource={openSource}
|
|
365
|
+
activeIndex={activeIndex}
|
|
366
|
+
isInteractionDisabled={isInteractionDisabled}
|
|
367
|
+
isOptionDisabled={isItemDisabled}
|
|
368
|
+
setOpenSource={setOpenSource}
|
|
369
|
+
setActiveIndex={setActiveIndex}
|
|
370
|
+
selectOption={item.onClick ?? (() => {})}
|
|
371
|
+
isSheetMode={isSheetMode}
|
|
372
|
+
showCheck={showCheck}
|
|
373
|
+
/>
|
|
374
|
+
))
|
|
375
|
+
)}
|
|
376
|
+
</View>
|
|
377
|
+
</View>
|
|
378
|
+
</View>
|
|
379
|
+
</Dialog>
|
|
380
|
+
);
|
|
381
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type {
|
|
3
|
+
DialogMobileMode,
|
|
4
|
+
ExitConfig,
|
|
5
|
+
PopoverConfig,
|
|
6
|
+
SheetConfig,
|
|
7
|
+
} from "@/packages/Frameworks/Dialog/Dialog.types";
|
|
8
|
+
|
|
9
|
+
export interface ContentItem {
|
|
10
|
+
type: "option";
|
|
11
|
+
value: string | number;
|
|
12
|
+
label: ReactNode;
|
|
13
|
+
icon?: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
selected?: boolean;
|
|
17
|
+
onClick?: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type Contents = ContentItem[];
|
|
21
|
+
|
|
22
|
+
export interface ContextMenuProps {
|
|
23
|
+
open: boolean;
|
|
24
|
+
onOpenChange: (open: boolean) => void;
|
|
25
|
+
anchorRef: React.RefObject<HTMLElement | null>;
|
|
26
|
+
popoverOwnerId: string;
|
|
27
|
+
listId: string;
|
|
28
|
+
listLabelId?: string;
|
|
29
|
+
role?: string;
|
|
30
|
+
isInteractionDisabled: boolean;
|
|
31
|
+
contents: Contents;
|
|
32
|
+
|
|
33
|
+
recalcKey: string;
|
|
34
|
+
popoverConfig?: Partial<PopoverConfig>;
|
|
35
|
+
sheetConfig?: SheetConfig;
|
|
36
|
+
exit?: ExitConfig;
|
|
37
|
+
mobileMode?: DialogMobileMode;
|
|
38
|
+
children?: React.ReactNode;
|
|
39
|
+
|
|
40
|
+
showCheck?: boolean;
|
|
41
|
+
|
|
42
|
+
activeIndex?: number;
|
|
43
|
+
onActiveIndexChange?: (index: number | ((prev: number) => number)) => void;
|
|
44
|
+
openSource?: "mouse" | "keyboard";
|
|
45
|
+
onOpenSourceChange?: (source: "mouse" | "keyboard") => void;
|
|
46
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
.ScrollArea {
|
|
2
|
+
width: 100%;
|
|
3
|
+
overflow: auto hidden;
|
|
4
|
+
overscroll-behavior-x: contain;
|
|
5
|
+
padding: 1.2rem 1.2rem 0 !important;
|
|
6
|
+
|
|
7
|
+
@media (pointer: fine) {
|
|
8
|
+
cursor: grab;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.Grid {
|
|
13
|
+
.Cell[data-in-range="false"] {
|
|
14
|
+
opacity: 0;
|
|
15
|
+
pointer-events: none;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.Cell,
|
|
20
|
+
.LegendCell {
|
|
21
|
+
width: var(--contribution-cell-size);
|
|
22
|
+
height: var(--contribution-cell-size);
|
|
23
|
+
|
|
24
|
+
&[data-level="1"] {
|
|
25
|
+
background: var(--color-green-2);
|
|
26
|
+
opacity: 0.4;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&[data-level="2"] {
|
|
30
|
+
background: var(--color-green-3);
|
|
31
|
+
opacity: 0.6;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
&[data-level="3"] {
|
|
35
|
+
background: var(--color-green-4);
|
|
36
|
+
opacity: 0.8;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
&[data-level="4"] {
|
|
40
|
+
background: var(--color-green-5);
|
|
41
|
+
}
|
|
42
|
+
}
|