@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,454 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
addUtcDays,
|
|
5
|
+
formatUtcDateKey,
|
|
6
|
+
getUtcWeekdayIndex,
|
|
7
|
+
parseUtcDateInput,
|
|
8
|
+
} from "@musecat/functionkit";
|
|
9
|
+
import clsx from "clsx";
|
|
10
|
+
import {
|
|
11
|
+
type PointerEvent as ReactPointerEvent,
|
|
12
|
+
useMemo,
|
|
13
|
+
useRef,
|
|
14
|
+
useState,
|
|
15
|
+
} from "react";
|
|
16
|
+
import { Word } from "@/i18n/shared";
|
|
17
|
+
import Box from "@/packages/Components/Box/Box";
|
|
18
|
+
import styles from "@/packages/Components/ContributionGraph/ContributionGraph.module.scss";
|
|
19
|
+
import type { ContributionGraphProps } from "@/packages/Components/ContributionGraph/ContributionGraph.types";
|
|
20
|
+
import Text from "@/packages/Components/Text/Text";
|
|
21
|
+
import View from "@/packages/Frameworks/View/View";
|
|
22
|
+
|
|
23
|
+
const DAY_LABEL_KEYS = [
|
|
24
|
+
"sun",
|
|
25
|
+
"mon",
|
|
26
|
+
"tue",
|
|
27
|
+
"wed",
|
|
28
|
+
"thu",
|
|
29
|
+
"fri",
|
|
30
|
+
"sat",
|
|
31
|
+
] as const;
|
|
32
|
+
const VISIBLE_DAY_INDICES = [1, 3, 5] as const;
|
|
33
|
+
|
|
34
|
+
function normalizeLocale(locale?: string) {
|
|
35
|
+
if (!locale) return "en";
|
|
36
|
+
if (locale === "kr") return "ko-KR";
|
|
37
|
+
if (locale === "jp") return "ja-JP";
|
|
38
|
+
return locale;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function parseGraphDate(value?: string | Date) {
|
|
42
|
+
return parseUtcDateInput(value, new Date()) ?? new Date();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getRollingYearVisibleDays(endDate: Date) {
|
|
46
|
+
const end = parseUtcDateInput(endDate, new Date()) ?? new Date();
|
|
47
|
+
const start = addUtcDays(end, 1);
|
|
48
|
+
start.setUTCFullYear(start.getUTCFullYear() - 1);
|
|
49
|
+
|
|
50
|
+
const diffMs = end.getTime() - start.getTime();
|
|
51
|
+
return Math.floor(diffMs / 86400000) + 1;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function buildCellTitle(cell: {
|
|
55
|
+
date: string;
|
|
56
|
+
total_count?: number;
|
|
57
|
+
changelog_count?: number;
|
|
58
|
+
flag_count?: number;
|
|
59
|
+
legacy_ticket_count?: number;
|
|
60
|
+
}) {
|
|
61
|
+
return [
|
|
62
|
+
cell.date,
|
|
63
|
+
`total_count: ${cell.total_count ?? 0}`,
|
|
64
|
+
`changelog_count: ${cell.changelog_count ?? 0}`,
|
|
65
|
+
`flag_count: ${cell.flag_count ?? 0}`,
|
|
66
|
+
`legacy_ticket_count: ${cell.legacy_ticket_count ?? 0}`,
|
|
67
|
+
].join("\n");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function GraphCell({
|
|
71
|
+
date,
|
|
72
|
+
level,
|
|
73
|
+
total_count,
|
|
74
|
+
changelog_count,
|
|
75
|
+
flag_count,
|
|
76
|
+
legacy_ticket_count,
|
|
77
|
+
inRange,
|
|
78
|
+
weekIndex,
|
|
79
|
+
dayIndex,
|
|
80
|
+
}: {
|
|
81
|
+
date: string;
|
|
82
|
+
level: number;
|
|
83
|
+
total_count?: number;
|
|
84
|
+
changelog_count?: number;
|
|
85
|
+
flag_count?: number;
|
|
86
|
+
legacy_ticket_count?: number;
|
|
87
|
+
inRange: boolean;
|
|
88
|
+
weekIndex: number;
|
|
89
|
+
dayIndex: number;
|
|
90
|
+
}) {
|
|
91
|
+
return (
|
|
92
|
+
<View
|
|
93
|
+
border={["Base6TP2", "Regular"]}
|
|
94
|
+
radius={4}
|
|
95
|
+
className={styles.Cell}
|
|
96
|
+
data-level={level}
|
|
97
|
+
data-in-range={inRange ? "true" : "false"}
|
|
98
|
+
title={buildCellTitle({ date, total_count, changelog_count, flag_count, legacy_ticket_count })}
|
|
99
|
+
style={{
|
|
100
|
+
gridColumn: `${weekIndex + 1}`,
|
|
101
|
+
gridRow: `${dayIndex + 1}`,
|
|
102
|
+
}}
|
|
103
|
+
/>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function MonthLabel({ title, colIndex }: { title: string; colIndex: number }) {
|
|
108
|
+
return (
|
|
109
|
+
<Text
|
|
110
|
+
verticalTrim
|
|
111
|
+
type="Caption1"
|
|
112
|
+
weight={400}
|
|
113
|
+
style={{
|
|
114
|
+
position: "absolute",
|
|
115
|
+
top: 0,
|
|
116
|
+
left: `calc(${colIndex} * (var(--contribution-cell-size) + var(--contribution-cell-gap)))`,
|
|
117
|
+
}}
|
|
118
|
+
>
|
|
119
|
+
{title}
|
|
120
|
+
</Text>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export default function ContributionGraph({
|
|
125
|
+
data = [],
|
|
126
|
+
endDate,
|
|
127
|
+
visibleDays,
|
|
128
|
+
locale,
|
|
129
|
+
className,
|
|
130
|
+
style,
|
|
131
|
+
"data-color-mode": dataTheme,
|
|
132
|
+
themePreset,
|
|
133
|
+
background,
|
|
134
|
+
color,
|
|
135
|
+
border,
|
|
136
|
+
shadow,
|
|
137
|
+
radius,
|
|
138
|
+
themeInteractive,
|
|
139
|
+
selected,
|
|
140
|
+
disabled,
|
|
141
|
+
readOnly,
|
|
142
|
+
backgroundBlur,
|
|
143
|
+
}: ContributionGraphProps) {
|
|
144
|
+
const t = Word();
|
|
145
|
+
const scrollAreaRef = useRef<HTMLDivElement | null>(null);
|
|
146
|
+
const dragStateRef = useRef<{
|
|
147
|
+
pointerId: number;
|
|
148
|
+
startX: number;
|
|
149
|
+
startScrollLeft: number;
|
|
150
|
+
} | null>(null);
|
|
151
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
152
|
+
const resolvedLocale = useMemo(() => normalizeLocale(locale), [locale]);
|
|
153
|
+
const monthFormatter = useMemo(
|
|
154
|
+
() =>
|
|
155
|
+
new Intl.DateTimeFormat(resolvedLocale, {
|
|
156
|
+
month: "short",
|
|
157
|
+
timeZone: "UTC",
|
|
158
|
+
}),
|
|
159
|
+
[resolvedLocale],
|
|
160
|
+
);
|
|
161
|
+
const weekdayFormatter = useMemo(
|
|
162
|
+
() =>
|
|
163
|
+
new Intl.DateTimeFormat(resolvedLocale, {
|
|
164
|
+
weekday: "short",
|
|
165
|
+
timeZone: "UTC",
|
|
166
|
+
}),
|
|
167
|
+
[resolvedLocale],
|
|
168
|
+
);
|
|
169
|
+
const dayLabels = useMemo(
|
|
170
|
+
() =>
|
|
171
|
+
DAY_LABEL_KEYS.map((key, index) => {
|
|
172
|
+
if (
|
|
173
|
+
!VISIBLE_DAY_INDICES.includes(
|
|
174
|
+
index as (typeof VISIBLE_DAY_INDICES)[number],
|
|
175
|
+
)
|
|
176
|
+
) {
|
|
177
|
+
return { key, label: "" };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const sampleDate = new Date(Date.UTC(2024, 0, 7 + index));
|
|
181
|
+
return {
|
|
182
|
+
key,
|
|
183
|
+
label: weekdayFormatter.format(sampleDate).replace(/\.$/, ""),
|
|
184
|
+
};
|
|
185
|
+
}),
|
|
186
|
+
[weekdayFormatter],
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
const graphData = useMemo(() => {
|
|
190
|
+
const resolvedEndDate = parseGraphDate(endDate);
|
|
191
|
+
|
|
192
|
+
const resolvedVisibleDays =
|
|
193
|
+
visibleDays !== undefined
|
|
194
|
+
? Math.max(1, Math.floor(visibleDays))
|
|
195
|
+
: getRollingYearVisibleDays(resolvedEndDate);
|
|
196
|
+
const end = new Date(resolvedEndDate);
|
|
197
|
+
|
|
198
|
+
const visibleStart = addUtcDays(end, -(resolvedVisibleDays - 1));
|
|
199
|
+
|
|
200
|
+
const start = addUtcDays(visibleStart, -getUtcWeekdayIndex(visibleStart));
|
|
201
|
+
|
|
202
|
+
const alignedEnd = new Date(end);
|
|
203
|
+
alignedEnd.setUTCDate(
|
|
204
|
+
alignedEnd.getUTCDate() + (6 - getUtcWeekdayIndex(alignedEnd)),
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
const actMap = new Map<
|
|
208
|
+
string,
|
|
209
|
+
{
|
|
210
|
+
level: number;
|
|
211
|
+
total_count?: number;
|
|
212
|
+
changelog_count?: number;
|
|
213
|
+
flag_count?: number;
|
|
214
|
+
legacy_ticket_count?: number;
|
|
215
|
+
}
|
|
216
|
+
>();
|
|
217
|
+
for (const item of data) {
|
|
218
|
+
const d = parseGraphDate(item.date);
|
|
219
|
+
const dateStr = formatUtcDateKey(d);
|
|
220
|
+
actMap.set(dateStr, {
|
|
221
|
+
level: item.level,
|
|
222
|
+
total_count: item.total_count,
|
|
223
|
+
changelog_count: item.changelog_count,
|
|
224
|
+
flag_count: item.flag_count,
|
|
225
|
+
legacy_ticket_count: item.legacy_ticket_count,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const cells: Array<{
|
|
230
|
+
date: string;
|
|
231
|
+
level: number;
|
|
232
|
+
total_count?: number;
|
|
233
|
+
changelog_count?: number;
|
|
234
|
+
flag_count?: number;
|
|
235
|
+
legacy_ticket_count?: number;
|
|
236
|
+
inRange: boolean;
|
|
237
|
+
weekIndex: number;
|
|
238
|
+
dayIndex: number;
|
|
239
|
+
}> = [];
|
|
240
|
+
const months: Array<{ title: string; colIndex: number }> = [];
|
|
241
|
+
const current = new Date(start);
|
|
242
|
+
let dayIndex = 0;
|
|
243
|
+
|
|
244
|
+
while (current <= alignedEnd) {
|
|
245
|
+
const weekIndex = Math.floor(dayIndex / 7);
|
|
246
|
+
|
|
247
|
+
if (current.getUTCDate() === 1) {
|
|
248
|
+
months.push({
|
|
249
|
+
title: monthFormatter.format(
|
|
250
|
+
new Date(
|
|
251
|
+
Date.UTC(current.getUTCFullYear(), current.getUTCMonth(), 1),
|
|
252
|
+
),
|
|
253
|
+
),
|
|
254
|
+
colIndex: weekIndex,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const dateStr = formatUtcDateKey(current);
|
|
259
|
+
const activity = actMap.get(dateStr);
|
|
260
|
+
const level = activity?.level ?? 0;
|
|
261
|
+
const inRange = current >= visibleStart && current <= end;
|
|
262
|
+
cells.push({
|
|
263
|
+
date: dateStr,
|
|
264
|
+
level,
|
|
265
|
+
total_count: activity?.total_count,
|
|
266
|
+
changelog_count: activity?.changelog_count,
|
|
267
|
+
flag_count: activity?.flag_count,
|
|
268
|
+
legacy_ticket_count: activity?.legacy_ticket_count,
|
|
269
|
+
inRange,
|
|
270
|
+
weekIndex,
|
|
271
|
+
dayIndex: getUtcWeekdayIndex(current),
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
current.setUTCDate(current.getUTCDate() + 1);
|
|
275
|
+
dayIndex += 1;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return {
|
|
279
|
+
cells,
|
|
280
|
+
months,
|
|
281
|
+
weekCount: Math.ceil(cells.length / 7),
|
|
282
|
+
};
|
|
283
|
+
}, [data, endDate, monthFormatter, visibleDays]);
|
|
284
|
+
|
|
285
|
+
const boxStyle = useMemo(
|
|
286
|
+
() =>
|
|
287
|
+
({
|
|
288
|
+
"--contribution-cell-size": "1.2rem",
|
|
289
|
+
"--contribution-cell-gap": "0.4rem",
|
|
290
|
+
width: "100%",
|
|
291
|
+
minWidth: 0,
|
|
292
|
+
maxWidth: "100%",
|
|
293
|
+
padding: 0,
|
|
294
|
+
overflow: "hidden",
|
|
295
|
+
...style,
|
|
296
|
+
}) as React.CSSProperties,
|
|
297
|
+
[style],
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
const finishDrag = (pointerId: number) => {
|
|
301
|
+
const scrollArea = scrollAreaRef.current;
|
|
302
|
+
if (scrollArea?.hasPointerCapture(pointerId)) {
|
|
303
|
+
scrollArea.releasePointerCapture(pointerId);
|
|
304
|
+
}
|
|
305
|
+
dragStateRef.current = null;
|
|
306
|
+
setIsDragging(false);
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
const handlePointerDown = (event: ReactPointerEvent<HTMLDivElement>) => {
|
|
310
|
+
if (event.pointerType !== "mouse" && event.pointerType !== "pen") return;
|
|
311
|
+
|
|
312
|
+
const scrollArea = scrollAreaRef.current;
|
|
313
|
+
if (!scrollArea || scrollArea.scrollWidth <= scrollArea.clientWidth) return;
|
|
314
|
+
|
|
315
|
+
dragStateRef.current = {
|
|
316
|
+
pointerId: event.pointerId,
|
|
317
|
+
startX: event.clientX,
|
|
318
|
+
startScrollLeft: scrollArea.scrollLeft,
|
|
319
|
+
};
|
|
320
|
+
setIsDragging(true);
|
|
321
|
+
scrollArea.setPointerCapture(event.pointerId);
|
|
322
|
+
event.preventDefault();
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
const handlePointerMove = (event: ReactPointerEvent<HTMLDivElement>) => {
|
|
326
|
+
const dragState = dragStateRef.current;
|
|
327
|
+
const scrollArea = scrollAreaRef.current;
|
|
328
|
+
if (!dragState || !scrollArea || dragState.pointerId !== event.pointerId) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const deltaX = event.clientX - dragState.startX;
|
|
333
|
+
scrollArea.scrollLeft = dragState.startScrollLeft - deltaX;
|
|
334
|
+
event.preventDefault();
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
const handlePointerUp = (event: ReactPointerEvent<HTMLDivElement>) => {
|
|
338
|
+
if (dragStateRef.current?.pointerId !== event.pointerId) return;
|
|
339
|
+
finishDrag(event.pointerId);
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const handlePointerCancel = (event: ReactPointerEvent<HTMLDivElement>) => {
|
|
343
|
+
if (dragStateRef.current?.pointerId !== event.pointerId) return;
|
|
344
|
+
finishDrag(event.pointerId);
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
return (
|
|
348
|
+
<Box
|
|
349
|
+
className={className}
|
|
350
|
+
style={boxStyle}
|
|
351
|
+
data-color-mode={dataTheme}
|
|
352
|
+
themePreset={themePreset}
|
|
353
|
+
background={background}
|
|
354
|
+
color={color}
|
|
355
|
+
border={border}
|
|
356
|
+
shadow={shadow}
|
|
357
|
+
radius={radius}
|
|
358
|
+
themeInteractive={themeInteractive}
|
|
359
|
+
selected={selected}
|
|
360
|
+
disabled={disabled}
|
|
361
|
+
readOnly={readOnly}
|
|
362
|
+
backgroundBlur={backgroundBlur}
|
|
363
|
+
>
|
|
364
|
+
<View column gap={12}>
|
|
365
|
+
<View
|
|
366
|
+
ref={scrollAreaRef}
|
|
367
|
+
className={styles.ScrollArea}
|
|
368
|
+
data-dragging={isDragging ? "true" : "false"}
|
|
369
|
+
onPointerDown={handlePointerDown}
|
|
370
|
+
onPointerMove={handlePointerMove}
|
|
371
|
+
onPointerUp={handlePointerUp}
|
|
372
|
+
onPointerCancel={handlePointerCancel}
|
|
373
|
+
>
|
|
374
|
+
<View
|
|
375
|
+
column
|
|
376
|
+
gap={10}
|
|
377
|
+
style={
|
|
378
|
+
{
|
|
379
|
+
"--contribution-weeks": String(graphData.weekCount),
|
|
380
|
+
} as React.CSSProperties
|
|
381
|
+
}
|
|
382
|
+
>
|
|
383
|
+
{}
|
|
384
|
+
<View
|
|
385
|
+
opacity={0.6}
|
|
386
|
+
height="var(--font-footnote-size)"
|
|
387
|
+
style={{ position: "relative", marginLeft: "3.6rem" }}
|
|
388
|
+
>
|
|
389
|
+
{graphData.months.map((m) => (
|
|
390
|
+
<MonthLabel key={`${m.title}-${m.colIndex}`} title={m.title} colIndex={m.colIndex} />
|
|
391
|
+
))}
|
|
392
|
+
</View>
|
|
393
|
+
|
|
394
|
+
{}
|
|
395
|
+
<View gap={10}>
|
|
396
|
+
{}
|
|
397
|
+
<View
|
|
398
|
+
column
|
|
399
|
+
opacity={0.6}
|
|
400
|
+
width="2.8rem"
|
|
401
|
+
style={{ textAlign: "right" }}
|
|
402
|
+
gridTemplateRows="repeat(7, var(--contribution-cell-size))"
|
|
403
|
+
gap={4}
|
|
404
|
+
>
|
|
405
|
+
{dayLabels.map((day) => (
|
|
406
|
+
<Text key={day.key} verticalTrim type="Caption1" weight={400}>
|
|
407
|
+
{day.label}
|
|
408
|
+
</Text>
|
|
409
|
+
))}
|
|
410
|
+
</View>
|
|
411
|
+
|
|
412
|
+
<View
|
|
413
|
+
className={styles.Grid}
|
|
414
|
+
gridTemplateColumns="repeat(var(--contribution-weeks), var(--contribution-cell-size))"
|
|
415
|
+
gridTemplateRows="repeat(7, var(--contribution-cell-size))"
|
|
416
|
+
gap={4}
|
|
417
|
+
>
|
|
418
|
+
{graphData.cells.map((cell) => (
|
|
419
|
+
<GraphCell key={cell.date} {...cell} />
|
|
420
|
+
))}
|
|
421
|
+
</View>
|
|
422
|
+
</View>
|
|
423
|
+
</View>
|
|
424
|
+
</View>
|
|
425
|
+
|
|
426
|
+
{}
|
|
427
|
+
<View
|
|
428
|
+
padding={[0, 12, 12, 12]}
|
|
429
|
+
justifyContent="flex-end"
|
|
430
|
+
alignItems="center"
|
|
431
|
+
gap={8}
|
|
432
|
+
>
|
|
433
|
+
<Text type="Caption1" opacity={0.6}>
|
|
434
|
+
{t.UIKit.ui.less}
|
|
435
|
+
</Text>
|
|
436
|
+
<View gap={4} aria-hidden="true">
|
|
437
|
+
{[0, 1, 2, 3, 4].map((level) => (
|
|
438
|
+
<View
|
|
439
|
+
border={["Base6TP2", "Regular"]}
|
|
440
|
+
radius={4}
|
|
441
|
+
key={level}
|
|
442
|
+
className={styles.LegendCell}
|
|
443
|
+
data-level={level}
|
|
444
|
+
/>
|
|
445
|
+
))}
|
|
446
|
+
</View>
|
|
447
|
+
<Text type="Caption1" opacity={0.6}>
|
|
448
|
+
{t.UIKit.ui.more}
|
|
449
|
+
</Text>
|
|
450
|
+
</View>
|
|
451
|
+
</View>
|
|
452
|
+
</Box>
|
|
453
|
+
);
|
|
454
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { RadiusProps } from "@/packages/Frameworks/Theme/Radius.types";
|
|
2
|
+
import type {
|
|
3
|
+
BorderProps,
|
|
4
|
+
ThemeSystemProps,
|
|
5
|
+
} from "@/packages/Frameworks/Theme/Theme.types";
|
|
6
|
+
|
|
7
|
+
export interface ContributionActivity {
|
|
8
|
+
date: string | Date;
|
|
9
|
+
level: 0 | 1 | 2 | 3 | 4;
|
|
10
|
+
total_count?: number;
|
|
11
|
+
changelog_count?: number;
|
|
12
|
+
flag_count?: number;
|
|
13
|
+
legacy_ticket_count?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ContributionGraphProps
|
|
17
|
+
extends ThemeSystemProps,
|
|
18
|
+
RadiusProps,
|
|
19
|
+
BorderProps {
|
|
20
|
+
"data-color-mode"?: string;
|
|
21
|
+
className?: string;
|
|
22
|
+
style?: React.CSSProperties;
|
|
23
|
+
data?: ContributionActivity[];
|
|
24
|
+
endDate?: string | Date;
|
|
25
|
+
visibleDays?: number;
|
|
26
|
+
locale?: string;
|
|
27
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import styles from "@/packages/Components/DatePicker/DatePicker.module.scss";
|
|
4
|
+
import {
|
|
5
|
+
isDateDisabled,
|
|
6
|
+
isSameDay,
|
|
7
|
+
toYMD,
|
|
8
|
+
} from "@/packages/Components/DatePicker/DatePicker.utils";
|
|
9
|
+
import Icon from "@/packages/Components/Icon/Icon";
|
|
10
|
+
import Text from "@/packages/Components/Text/Text";
|
|
11
|
+
import Pressable from "@/packages/Frameworks/Pressable/Pressable";
|
|
12
|
+
import View from "@/packages/Frameworks/View/View";
|
|
13
|
+
|
|
14
|
+
function NavBtn({
|
|
15
|
+
onClick,
|
|
16
|
+
direction,
|
|
17
|
+
}: {
|
|
18
|
+
onClick: () => void;
|
|
19
|
+
direction: "prev" | "next";
|
|
20
|
+
}) {
|
|
21
|
+
return (
|
|
22
|
+
<Icon
|
|
23
|
+
icon={direction === "prev" ? "iArrowKeyLeft" : "iArrowKeyRight"}
|
|
24
|
+
size={20}
|
|
25
|
+
box
|
|
26
|
+
boxOptions={{ padding: ".8rem" }}
|
|
27
|
+
pressable={{ onClick }}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface CalendarProps {
|
|
33
|
+
currentLocale: {
|
|
34
|
+
weekdays: readonly string[];
|
|
35
|
+
title: (y: number, m: number) => string;
|
|
36
|
+
};
|
|
37
|
+
viewYear: number;
|
|
38
|
+
viewMonth: number;
|
|
39
|
+
prevMonth: () => void;
|
|
40
|
+
nextMonth: () => void;
|
|
41
|
+
days: Date[];
|
|
42
|
+
mode: "single" | "range";
|
|
43
|
+
minDate?: string;
|
|
44
|
+
maxDate?: string;
|
|
45
|
+
disabledDaysOfWeek?: number[];
|
|
46
|
+
selected?: Date | null;
|
|
47
|
+
rangeStart?: Date | null;
|
|
48
|
+
rangeEnd?: Date | null;
|
|
49
|
+
today: Date;
|
|
50
|
+
setHoverDay: (d: Date | null) => void;
|
|
51
|
+
handleDayClick: (d: Date) => void;
|
|
52
|
+
isInRange: (d: Date) => boolean;
|
|
53
|
+
isRangeStart: (d: Date) => boolean;
|
|
54
|
+
isRangeEnd: (d: Date) => boolean;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function Calendar({
|
|
58
|
+
currentLocale,
|
|
59
|
+
viewYear,
|
|
60
|
+
viewMonth,
|
|
61
|
+
prevMonth,
|
|
62
|
+
nextMonth,
|
|
63
|
+
days,
|
|
64
|
+
mode,
|
|
65
|
+
minDate,
|
|
66
|
+
maxDate,
|
|
67
|
+
disabledDaysOfWeek,
|
|
68
|
+
selected,
|
|
69
|
+
rangeStart,
|
|
70
|
+
rangeEnd,
|
|
71
|
+
today,
|
|
72
|
+
setHoverDay,
|
|
73
|
+
handleDayClick,
|
|
74
|
+
isInRange,
|
|
75
|
+
isRangeStart,
|
|
76
|
+
isRangeEnd,
|
|
77
|
+
}: CalendarProps) {
|
|
78
|
+
return (
|
|
79
|
+
<View column gap={16} fullWidth>
|
|
80
|
+
<View alignItems="center" justifyContent="space-between">
|
|
81
|
+
<NavBtn direction="prev" onClick={prevMonth} />
|
|
82
|
+
<Text type="Subheadline" weight={500} opacity={0.8}>
|
|
83
|
+
{currentLocale.title(viewYear, viewMonth)}
|
|
84
|
+
</Text>
|
|
85
|
+
<NavBtn direction="next" onClick={nextMonth} />
|
|
86
|
+
</View>
|
|
87
|
+
|
|
88
|
+
<View
|
|
89
|
+
className={styles.WeekRow}
|
|
90
|
+
gridTemplateColumns="repeat(7, minmax(0, 1fr))"
|
|
91
|
+
gap={2}
|
|
92
|
+
>
|
|
93
|
+
{currentLocale.weekdays.map((w) => (
|
|
94
|
+
<View key={w} justifyContent="center">
|
|
95
|
+
<Text
|
|
96
|
+
type="Footnote"
|
|
97
|
+
weight={400}
|
|
98
|
+
opacity={0.8}
|
|
99
|
+
textAlign="center"
|
|
100
|
+
verticalTrim
|
|
101
|
+
>
|
|
102
|
+
{w}
|
|
103
|
+
</Text>
|
|
104
|
+
</View>
|
|
105
|
+
))}
|
|
106
|
+
</View>
|
|
107
|
+
|
|
108
|
+
<View gridTemplateColumns="repeat(7, minmax(0, 1fr))" gap={2}>
|
|
109
|
+
{days.map((day) => {
|
|
110
|
+
const isCurrentMonth = day.getMonth() === viewMonth;
|
|
111
|
+
const isDisabledDay = isDateDisabled(
|
|
112
|
+
day,
|
|
113
|
+
minDate,
|
|
114
|
+
maxDate,
|
|
115
|
+
disabledDaysOfWeek,
|
|
116
|
+
);
|
|
117
|
+
const isSel = mode === "single" && isSameDay(day, selected ?? null);
|
|
118
|
+
const isStart = mode === "range" && isRangeStart(day);
|
|
119
|
+
const isEnd = mode === "range" && isRangeEnd(day);
|
|
120
|
+
const inRange = isInRange(day);
|
|
121
|
+
const isToday = isSameDay(day, today);
|
|
122
|
+
const isUnselectable = isDisabledDay;
|
|
123
|
+
return (
|
|
124
|
+
<Pressable
|
|
125
|
+
key={toYMD(day)}
|
|
126
|
+
radius="Circle"
|
|
127
|
+
alignItems="center"
|
|
128
|
+
justifyContent="center"
|
|
129
|
+
opacity={!isCurrentMonth || isDisabledDay ? 0.2 : undefined}
|
|
130
|
+
themePreset={
|
|
131
|
+
isSel || isStart || isEnd
|
|
132
|
+
? "ReversedUIPrimary"
|
|
133
|
+
: inRange
|
|
134
|
+
? "UISecondary"
|
|
135
|
+
: isToday && !isUnselectable
|
|
136
|
+
? "BaseFull"
|
|
137
|
+
: undefined
|
|
138
|
+
}
|
|
139
|
+
style={{
|
|
140
|
+
aspectRatio: 1,
|
|
141
|
+
position: "relative",
|
|
142
|
+
cursor:
|
|
143
|
+
!isCurrentMonth || isDisabledDay ? "default" : "pointer",
|
|
144
|
+
}}
|
|
145
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
146
|
+
onClick={() => !isUnselectable && handleDayClick(day)}
|
|
147
|
+
onMouseEnter={() =>
|
|
148
|
+
mode === "range" && rangeStart && !rangeEnd && setHoverDay(day)
|
|
149
|
+
}
|
|
150
|
+
onMouseLeave={() => mode === "range" && setHoverDay(null)}
|
|
151
|
+
>
|
|
152
|
+
<Text type="Body" weight={isSel || isStart || isEnd ? 500 : 400}>
|
|
153
|
+
{day.getDate()}
|
|
154
|
+
</Text>
|
|
155
|
+
</Pressable>
|
|
156
|
+
);
|
|
157
|
+
})}
|
|
158
|
+
</View>
|
|
159
|
+
</View>
|
|
160
|
+
);
|
|
161
|
+
}
|