@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,201 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
4
|
+
import type { SheetConfig } from "@/packages/Frameworks/Dialog/Dialog.types";
|
|
5
|
+
|
|
6
|
+
function toPx(
|
|
7
|
+
value: number | string | undefined,
|
|
8
|
+
viewportHeight: number,
|
|
9
|
+
fallback: number,
|
|
10
|
+
): number {
|
|
11
|
+
if (value === undefined) return fallback;
|
|
12
|
+
if (typeof value === "number") {
|
|
13
|
+
if (value > 0 && value <= 1) return viewportHeight * value;
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
const normalized = value.trim().toLowerCase();
|
|
17
|
+
const numeric = parseFloat(normalized);
|
|
18
|
+
if (Number.isNaN(numeric)) return fallback;
|
|
19
|
+
|
|
20
|
+
if (normalized.endsWith("rem")) {
|
|
21
|
+
if (typeof window !== "undefined") {
|
|
22
|
+
const rootFontSize =
|
|
23
|
+
parseFloat(
|
|
24
|
+
window.getComputedStyle(document.documentElement).fontSize,
|
|
25
|
+
) || 16;
|
|
26
|
+
return numeric * rootFontSize;
|
|
27
|
+
}
|
|
28
|
+
return numeric * 16;
|
|
29
|
+
}
|
|
30
|
+
if (normalized.endsWith("px")) return numeric;
|
|
31
|
+
if (normalized.endsWith("vh")) return viewportHeight * (numeric / 100);
|
|
32
|
+
if (normalized.endsWith("%")) return viewportHeight * (numeric / 100);
|
|
33
|
+
|
|
34
|
+
if (numeric > 0 && numeric <= 1) return viewportHeight * numeric;
|
|
35
|
+
return numeric;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function normalizeSnapPoints(points?: number[]) {
|
|
39
|
+
const source = points?.length ? points : [0.5, 1];
|
|
40
|
+
return Array.from(
|
|
41
|
+
new Set(source.map((point) => Math.max(0.1, Math.min(1, point)))),
|
|
42
|
+
).sort((a, b) => a - b);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function resolveInitialSnapIndex(points: number[], defaultSnap?: number) {
|
|
46
|
+
if (defaultSnap === undefined) return points.length - 1;
|
|
47
|
+
if (
|
|
48
|
+
Number.isInteger(defaultSnap) &&
|
|
49
|
+
defaultSnap >= 0 &&
|
|
50
|
+
defaultSnap < points.length
|
|
51
|
+
) {
|
|
52
|
+
return defaultSnap;
|
|
53
|
+
}
|
|
54
|
+
const exactIndex = points.indexOf(defaultSnap);
|
|
55
|
+
if (exactIndex >= 0) return exactIndex;
|
|
56
|
+
return points.length - 1;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { resolveInitialSnapIndex, toPx };
|
|
60
|
+
|
|
61
|
+
export interface SheetGeometryInput {
|
|
62
|
+
config?: SheetConfig;
|
|
63
|
+
height?: string | number;
|
|
64
|
+
sheetHeightPx: number;
|
|
65
|
+
open: boolean;
|
|
66
|
+
rendered: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface SheetGeometryOutput {
|
|
70
|
+
viewportHeight: number;
|
|
71
|
+
getViewportHeight: () => number;
|
|
72
|
+
minPx: number;
|
|
73
|
+
maxPx: number;
|
|
74
|
+
maxSnap: number;
|
|
75
|
+
normalizedSnapPoints: number[];
|
|
76
|
+
resolvedFreeDragHeightPx: number;
|
|
77
|
+
getTargetYForSnap: (snap: number) => number;
|
|
78
|
+
getGapHiddenY: (
|
|
79
|
+
currentSnap: number,
|
|
80
|
+
isFreeDrag: boolean,
|
|
81
|
+
getTargetYForSnap: (snap: number) => number,
|
|
82
|
+
) => number;
|
|
83
|
+
isFreeDrag: boolean;
|
|
84
|
+
isMinDefault: boolean;
|
|
85
|
+
snapHeightRatio: number;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const DEFAULT_MIN_REM = 7.2;
|
|
89
|
+
const DEFAULT_MIN_PX_FALLBACK = 115.2;
|
|
90
|
+
|
|
91
|
+
export function useSheetGeometry({
|
|
92
|
+
config,
|
|
93
|
+
height,
|
|
94
|
+
sheetHeightPx,
|
|
95
|
+
open,
|
|
96
|
+
rendered,
|
|
97
|
+
}: SheetGeometryInput): SheetGeometryOutput {
|
|
98
|
+
const [viewportHeight, setViewportHeight] = useState(0);
|
|
99
|
+
|
|
100
|
+
const getViewportHeight = useCallback(
|
|
101
|
+
() => window.visualViewport?.height ?? window.innerHeight,
|
|
102
|
+
[],
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (!open && !rendered) return;
|
|
107
|
+
const update = () => {
|
|
108
|
+
setViewportHeight(getViewportHeight());
|
|
109
|
+
};
|
|
110
|
+
update();
|
|
111
|
+
window.visualViewport?.addEventListener("resize", update);
|
|
112
|
+
window.addEventListener("resize", update);
|
|
113
|
+
window.addEventListener("orientationchange", update);
|
|
114
|
+
return () => {
|
|
115
|
+
window.visualViewport?.removeEventListener("resize", update);
|
|
116
|
+
window.removeEventListener("resize", update);
|
|
117
|
+
window.removeEventListener("orientationchange", update);
|
|
118
|
+
};
|
|
119
|
+
}, [open, rendered, getViewportHeight]);
|
|
120
|
+
|
|
121
|
+
const isFreeDrag = config?.freeDrag === true;
|
|
122
|
+
const isMinDefault = isFreeDrag && config?.min === undefined;
|
|
123
|
+
|
|
124
|
+
const minPx = useMemo(() => {
|
|
125
|
+
const vh = viewportHeight || 800;
|
|
126
|
+
return toPx(
|
|
127
|
+
config?.min,
|
|
128
|
+
vh,
|
|
129
|
+
toPx(`${DEFAULT_MIN_REM}rem`, vh, DEFAULT_MIN_PX_FALLBACK),
|
|
130
|
+
);
|
|
131
|
+
}, [config?.min, viewportHeight]);
|
|
132
|
+
|
|
133
|
+
const maxPx = useMemo(() => {
|
|
134
|
+
const vh = viewportHeight || 800;
|
|
135
|
+
const isMaxContent = height === undefined && !config?.snapPoints?.length;
|
|
136
|
+
const baseHeight = isMaxContent && sheetHeightPx > 0 ? sheetHeightPx : vh;
|
|
137
|
+
return toPx(config?.max, baseHeight, baseHeight);
|
|
138
|
+
}, [config?.max, viewportHeight, height, config?.snapPoints, sheetHeightPx]);
|
|
139
|
+
|
|
140
|
+
const resolvedFreeDragHeightPx = useMemo(
|
|
141
|
+
() => Math.max(maxPx, minPx),
|
|
142
|
+
[maxPx, minPx],
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
const _snapPointsStr = JSON.stringify(config?.snapPoints);
|
|
146
|
+
const normalizedSnapPoints = useMemo(
|
|
147
|
+
() =>
|
|
148
|
+
config?.snapPoints?.length ? normalizeSnapPoints(config.snapPoints) : [1],
|
|
149
|
+
[config?.snapPoints?.length, config.snapPoints],
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
const maxSnap = useMemo(
|
|
153
|
+
() =>
|
|
154
|
+
isFreeDrag
|
|
155
|
+
? maxPx / (viewportHeight || 800)
|
|
156
|
+
: (normalizedSnapPoints.at(-1) ?? 1),
|
|
157
|
+
[isFreeDrag, normalizedSnapPoints, maxPx, viewportHeight],
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
const snapHeightRatio = useMemo(
|
|
161
|
+
() => maxSnap / (normalizedSnapPoints.at(-1) ?? 1),
|
|
162
|
+
[maxSnap, normalizedSnapPoints],
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
const getTargetYForSnap = useCallback(
|
|
166
|
+
(snap: number) => {
|
|
167
|
+
const vh = viewportHeight || getViewportHeight();
|
|
168
|
+
if (isFreeDrag) return 0;
|
|
169
|
+
return vh * (maxSnap - snap);
|
|
170
|
+
},
|
|
171
|
+
[viewportHeight, maxSnap, getViewportHeight, isFreeDrag],
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
const getGapHiddenY = useCallback(
|
|
175
|
+
(
|
|
176
|
+
currentSnap: number,
|
|
177
|
+
isFreeDrag: boolean,
|
|
178
|
+
getTargetYForSnap: (snap: number) => number,
|
|
179
|
+
) => {
|
|
180
|
+
const h = viewportHeight || getViewportHeight() || 800;
|
|
181
|
+
const restY = isFreeDrag ? 0 : getTargetYForSnap(currentSnap);
|
|
182
|
+
return restY + h;
|
|
183
|
+
},
|
|
184
|
+
[viewportHeight, getViewportHeight],
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
return {
|
|
188
|
+
viewportHeight,
|
|
189
|
+
getViewportHeight,
|
|
190
|
+
minPx,
|
|
191
|
+
maxPx,
|
|
192
|
+
maxSnap,
|
|
193
|
+
normalizedSnapPoints,
|
|
194
|
+
resolvedFreeDragHeightPx,
|
|
195
|
+
getTargetYForSnap,
|
|
196
|
+
getGapHiddenY,
|
|
197
|
+
isFreeDrag,
|
|
198
|
+
isMinDefault,
|
|
199
|
+
snapHeightRatio,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { MotionValue } from "motion/react";
|
|
4
|
+
import { useEffect, useMemo, useState } from "react";
|
|
5
|
+
import type { RadiusValue } from "@/packages/Frameworks/Theme/Radius.types";
|
|
6
|
+
|
|
7
|
+
const EDGE_INSET_MAX_PX = 8;
|
|
8
|
+
const BOTTOM_GAP_PX = 8;
|
|
9
|
+
const BOTTOM_RADIUS_MAX_PX = 24;
|
|
10
|
+
const BOTTOM_RADIUS_THRESHOLD = 1;
|
|
11
|
+
|
|
12
|
+
export interface UseSheetProgressiveInput {
|
|
13
|
+
y: MotionValue<number>;
|
|
14
|
+
normalizedSnapPoints: number[];
|
|
15
|
+
viewportHeight: number;
|
|
16
|
+
maxSnap: number;
|
|
17
|
+
isFreeDrag: boolean;
|
|
18
|
+
hasExplicitSnapPoints: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface UseSheetProgressiveOutput {
|
|
22
|
+
inset: number;
|
|
23
|
+
bottomGap: number;
|
|
24
|
+
radiusArr: RadiusValue;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function computeProgress(
|
|
28
|
+
latestY: number,
|
|
29
|
+
maxSnap: number,
|
|
30
|
+
firstSnap: number,
|
|
31
|
+
lastSnap: number,
|
|
32
|
+
vh: number,
|
|
33
|
+
) {
|
|
34
|
+
if (!vh) return 0;
|
|
35
|
+
const snap = maxSnap - latestY / vh;
|
|
36
|
+
return Math.max(0, Math.min(1, (snap - firstSnap) / (lastSnap - firstSnap)));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function useSheetProgressive({
|
|
40
|
+
y,
|
|
41
|
+
normalizedSnapPoints,
|
|
42
|
+
viewportHeight,
|
|
43
|
+
maxSnap,
|
|
44
|
+
isFreeDrag,
|
|
45
|
+
hasExplicitSnapPoints,
|
|
46
|
+
}: UseSheetProgressiveInput): UseSheetProgressiveOutput {
|
|
47
|
+
const firstSnap = normalizedSnapPoints[0];
|
|
48
|
+
const lastSnap = normalizedSnapPoints.at(-1)!;
|
|
49
|
+
const hasProgression =
|
|
50
|
+
hasExplicitSnapPoints && normalizedSnapPoints.length > 1 && !isFreeDrag;
|
|
51
|
+
|
|
52
|
+
const [inset, setInset] = useState(0);
|
|
53
|
+
const [bottomGap, setBottomGap] = useState(0);
|
|
54
|
+
const [bottomRadius, setBottomRadius] = useState(BOTTOM_RADIUS_MAX_PX);
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (!hasProgression) {
|
|
58
|
+
setInset(0);
|
|
59
|
+
setBottomGap(0);
|
|
60
|
+
setBottomRadius(BOTTOM_RADIUS_MAX_PX);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const update = (latestY: number) => {
|
|
65
|
+
const vh = viewportHeight || 800;
|
|
66
|
+
const p = computeProgress(latestY, maxSnap, firstSnap, lastSnap, vh);
|
|
67
|
+
setInset(Math.round(EDGE_INSET_MAX_PX * (1 - p)));
|
|
68
|
+
setBottomGap(Math.round(BOTTOM_GAP_PX * (1 - p)));
|
|
69
|
+
setBottomRadius(Math.round(BOTTOM_RADIUS_MAX_PX * (1 - p)));
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
update(y.get());
|
|
73
|
+
return y.on("change", update);
|
|
74
|
+
}, [y, hasProgression, viewportHeight, maxSnap, firstSnap, lastSnap]);
|
|
75
|
+
|
|
76
|
+
const radiusArr: RadiusValue = useMemo(() => {
|
|
77
|
+
if (
|
|
78
|
+
!hasProgression ||
|
|
79
|
+
bottomRadius >= BOTTOM_RADIUS_MAX_PX - BOTTOM_RADIUS_THRESHOLD
|
|
80
|
+
) {
|
|
81
|
+
return ["ExtraBold", "ExtraBold", "ExtraBold", "ExtraBold"] as const;
|
|
82
|
+
}
|
|
83
|
+
if (bottomRadius <= BOTTOM_RADIUS_THRESHOLD) {
|
|
84
|
+
return ["ExtraBold", "ExtraBold", "None", "None"] as const;
|
|
85
|
+
}
|
|
86
|
+
return bottomRadius <= 6
|
|
87
|
+
? (["ExtraBold", "ExtraBold", "ExtraLight", "ExtraLight"] as const)
|
|
88
|
+
: bottomRadius <= 12
|
|
89
|
+
? (["ExtraBold", "ExtraBold", "Light", "Light"] as const)
|
|
90
|
+
: bottomRadius <= 16
|
|
91
|
+
? (["ExtraBold", "ExtraBold", "Regular", "Regular"] as const)
|
|
92
|
+
: bottomRadius <= 20
|
|
93
|
+
? (["ExtraBold", "ExtraBold", "Bold", "Bold"] as const)
|
|
94
|
+
: (["ExtraBold", "ExtraBold", "ExtraBold", "ExtraBold"] as const);
|
|
95
|
+
}, [hasProgression, bottomRadius]);
|
|
96
|
+
|
|
97
|
+
return { inset, bottomGap, radiusArr };
|
|
98
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { AnimatePresence } from "motion/react";
|
|
4
|
+
import type { ReactNode } from "react";
|
|
5
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
6
|
+
import { useScrollLock } from "@/packages/Frameworks/_shared/bodyScrollLock";
|
|
7
|
+
import { LAYER_Z_INDEX } from "@/packages/Frameworks/_shared/layer.constants";
|
|
8
|
+
import DialogFooter from "@/packages/Frameworks/Dialog/contents/Dialog.footer";
|
|
9
|
+
import DialogHeader from "@/packages/Frameworks/Dialog/contents/Dialog.header";
|
|
10
|
+
import BackgroundWrapper from "@/packages/Frameworks/Dialog/Dialog.background";
|
|
11
|
+
import type {
|
|
12
|
+
DialogOutsideOptions,
|
|
13
|
+
ModalConfig,
|
|
14
|
+
} from "@/packages/Frameworks/Dialog/Dialog.types";
|
|
15
|
+
import {
|
|
16
|
+
DialogPortal,
|
|
17
|
+
useEscapeClose,
|
|
18
|
+
} from "@/packages/Frameworks/Dialog/Dialog.utils";
|
|
19
|
+
import { motionPresets } from "@/packages/Frameworks/Motion/Motion.presets";
|
|
20
|
+
import View from "@/packages/Frameworks/View/View";
|
|
21
|
+
|
|
22
|
+
interface RenderModalProps {
|
|
23
|
+
open: boolean;
|
|
24
|
+
onOpenChange: (open: boolean) => void;
|
|
25
|
+
config?: ModalConfig;
|
|
26
|
+
id?: string;
|
|
27
|
+
zIndex?: number;
|
|
28
|
+
width?: string | number;
|
|
29
|
+
height?: string | number;
|
|
30
|
+
children?: ReactNode;
|
|
31
|
+
role?: string;
|
|
32
|
+
"data-color-mode"?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default function RenderModal({
|
|
36
|
+
open,
|
|
37
|
+
onOpenChange,
|
|
38
|
+
config,
|
|
39
|
+
id,
|
|
40
|
+
zIndex,
|
|
41
|
+
width,
|
|
42
|
+
height,
|
|
43
|
+
children,
|
|
44
|
+
role = "dialog",
|
|
45
|
+
"data-color-mode": dataColorMode,
|
|
46
|
+
}: RenderModalProps) {
|
|
47
|
+
const modalRef = useRef<HTMLDivElement>(null);
|
|
48
|
+
const resolvedZIndex = zIndex ?? LAYER_Z_INDEX.modal;
|
|
49
|
+
|
|
50
|
+
const isOutsideConfig = config?.outside !== false;
|
|
51
|
+
const outsideOptions: DialogOutsideOptions =
|
|
52
|
+
config?.outside && typeof config.outside === "object" ? config.outside : {};
|
|
53
|
+
const lockBodyScroll = outsideOptions.lockBodyScroll !== false;
|
|
54
|
+
|
|
55
|
+
useScrollLock(open && lockBodyScroll);
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (!open) return;
|
|
59
|
+
|
|
60
|
+
const modalEl = modalRef.current;
|
|
61
|
+
if (!modalEl) return;
|
|
62
|
+
|
|
63
|
+
const focusableElements = modalEl.querySelectorAll(
|
|
64
|
+
'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])',
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const firstElement = focusableElements[0] as HTMLElement | undefined;
|
|
68
|
+
const lastElement = focusableElements[focusableElements.length - 1] as
|
|
69
|
+
| HTMLElement
|
|
70
|
+
| undefined;
|
|
71
|
+
|
|
72
|
+
firstElement?.focus();
|
|
73
|
+
|
|
74
|
+
const handleTab = (e: KeyboardEvent) => {
|
|
75
|
+
if (e.key !== "Tab") return;
|
|
76
|
+
|
|
77
|
+
if (e.shiftKey) {
|
|
78
|
+
if (document.activeElement === firstElement) {
|
|
79
|
+
lastElement?.focus();
|
|
80
|
+
e.preventDefault();
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
if (document.activeElement === lastElement) {
|
|
84
|
+
firstElement?.focus();
|
|
85
|
+
e.preventDefault();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
modalEl.addEventListener("keydown", handleTab);
|
|
91
|
+
return () => modalEl.removeEventListener("keydown", handleTab);
|
|
92
|
+
}, [open]);
|
|
93
|
+
|
|
94
|
+
const closeWithConfirm = useCallback(() => {
|
|
95
|
+
if (config?.exit?.confirm) {
|
|
96
|
+
const { title, caption } = config.exit.confirm;
|
|
97
|
+
const isConfirmed = window.confirm(
|
|
98
|
+
`${title ?? "확인"}\n\n${caption ?? "작업을 중단하시겠습니까?"}`,
|
|
99
|
+
);
|
|
100
|
+
if (!isConfirmed) return;
|
|
101
|
+
}
|
|
102
|
+
onOpenChange(false);
|
|
103
|
+
}, [config?.exit?.confirm, onOpenChange]);
|
|
104
|
+
|
|
105
|
+
useEscapeClose(open && config?.exit?.escape !== false, closeWithConfirm);
|
|
106
|
+
|
|
107
|
+
const modalNode = (
|
|
108
|
+
<AnimatePresence>
|
|
109
|
+
{open ? (
|
|
110
|
+
<View
|
|
111
|
+
data-open="true"
|
|
112
|
+
data-color-mode={dataColorMode}
|
|
113
|
+
style={{
|
|
114
|
+
position: "fixed",
|
|
115
|
+
inset: 0,
|
|
116
|
+
zIndex: resolvedZIndex,
|
|
117
|
+
pointerEvents: "none",
|
|
118
|
+
}}
|
|
119
|
+
>
|
|
120
|
+
<BackgroundWrapper
|
|
121
|
+
open={open}
|
|
122
|
+
showBackdrop={isOutsideConfig}
|
|
123
|
+
background={outsideOptions.background}
|
|
124
|
+
backgroundBlur={outsideOptions.backgroundBlur}
|
|
125
|
+
className={outsideOptions.className}
|
|
126
|
+
style={outsideOptions.style}
|
|
127
|
+
zIndex={resolvedZIndex - 1}
|
|
128
|
+
onClick={
|
|
129
|
+
config?.exit?.overlay !== false ? closeWithConfirm : undefined
|
|
130
|
+
}
|
|
131
|
+
/>
|
|
132
|
+
<View
|
|
133
|
+
row
|
|
134
|
+
alignItems="center"
|
|
135
|
+
justifyContent="center"
|
|
136
|
+
style={{
|
|
137
|
+
position: "fixed",
|
|
138
|
+
inset: 0,
|
|
139
|
+
pointerEvents: "none",
|
|
140
|
+
zIndex: resolvedZIndex,
|
|
141
|
+
}}
|
|
142
|
+
>
|
|
143
|
+
<View
|
|
144
|
+
id={id}
|
|
145
|
+
ref={modalRef}
|
|
146
|
+
data-popover-owner={config?.popoverOwnerId}
|
|
147
|
+
className={config?.className}
|
|
148
|
+
role={role}
|
|
149
|
+
aria-modal="true"
|
|
150
|
+
tabIndex={-1}
|
|
151
|
+
motion={motionPresets.modal}
|
|
152
|
+
themePreset={
|
|
153
|
+
config?.immersive ? "UISecondary" : config?.themePreset
|
|
154
|
+
}
|
|
155
|
+
background={
|
|
156
|
+
config?.immersive
|
|
157
|
+
? undefined
|
|
158
|
+
: (config?.background ??
|
|
159
|
+
(config?.themePreset ? undefined : "Base1TP1"))
|
|
160
|
+
}
|
|
161
|
+
color={config?.color}
|
|
162
|
+
border={config?.immersive ? "None" : config?.border}
|
|
163
|
+
radius={
|
|
164
|
+
config?.immersive ? "None" : (config?.radius ?? "ExtraBold")
|
|
165
|
+
}
|
|
166
|
+
shadow={
|
|
167
|
+
config?.immersive ? "None" : (config?.shadow ?? "Regular")
|
|
168
|
+
}
|
|
169
|
+
backgroundBlur={
|
|
170
|
+
config?.immersive ? "None" : (config?.backgroundBlur ?? "Light")
|
|
171
|
+
}
|
|
172
|
+
width={
|
|
173
|
+
config?.immersive
|
|
174
|
+
? "100vw"
|
|
175
|
+
: (width ?? "min(100% - 3.2rem, 48rem)")
|
|
176
|
+
}
|
|
177
|
+
height={config?.immersive ? "100vh" : height}
|
|
178
|
+
column
|
|
179
|
+
style={{
|
|
180
|
+
maxHeight: config?.immersive ? "100vh" : "calc(100% - 3.2rem)",
|
|
181
|
+
pointerEvents: "auto",
|
|
182
|
+
overflow: "hidden",
|
|
183
|
+
margin: config?.immersive ? 0 : undefined,
|
|
184
|
+
...config?.style,
|
|
185
|
+
}}
|
|
186
|
+
>
|
|
187
|
+
{config?.custom ? (
|
|
188
|
+
config.custom
|
|
189
|
+
) : (
|
|
190
|
+
<>
|
|
191
|
+
<View padding={16}>
|
|
192
|
+
<DialogHeader
|
|
193
|
+
config={config?.header}
|
|
194
|
+
exitIcon={config?.exit?.icon}
|
|
195
|
+
onExit={closeWithConfirm}
|
|
196
|
+
/>
|
|
197
|
+
</View>
|
|
198
|
+
|
|
199
|
+
<View
|
|
200
|
+
padding={16}
|
|
201
|
+
column
|
|
202
|
+
style={{
|
|
203
|
+
flex: "1 1 auto",
|
|
204
|
+
overflowY: "auto",
|
|
205
|
+
minHeight: 0,
|
|
206
|
+
}}
|
|
207
|
+
>
|
|
208
|
+
{children}
|
|
209
|
+
</View>
|
|
210
|
+
|
|
211
|
+
<View padding={16}>
|
|
212
|
+
<DialogFooter
|
|
213
|
+
config={config?.footer}
|
|
214
|
+
exitButton={config?.exit?.footerButton}
|
|
215
|
+
onExit={closeWithConfirm}
|
|
216
|
+
/>
|
|
217
|
+
</View>
|
|
218
|
+
</>
|
|
219
|
+
)}
|
|
220
|
+
</View>
|
|
221
|
+
</View>
|
|
222
|
+
</View>
|
|
223
|
+
) : null}
|
|
224
|
+
</AnimatePresence>
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
return <DialogPortal>{modalNode}</DialogPortal>;
|
|
228
|
+
}
|