@typescript-calendar-lib/react 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/package.json +25 -0
- package/src/calendar.css +296 -0
- package/src/cell-classes.ts +22 -0
- package/src/global.d.ts +1 -0
- package/src/hooks.ts +107 -0
- package/src/index.test.tsx +217 -0
- package/src/index.tsx +174 -0
- package/src/size.ts +32 -0
- package/src/themes.ts +143 -0
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@typescript-calendar-lib/react",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "src/index.tsx",
|
|
6
|
+
"types": "src/index.tsx",
|
|
7
|
+
"files": [
|
|
8
|
+
"src"
|
|
9
|
+
],
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@typescript-calendar/core": "workspace:*",
|
|
12
|
+
"@typescript-calendar/tui": "workspace:*"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@testing-library/react": "^16",
|
|
16
|
+
"@types/react": "^19",
|
|
17
|
+
"jsdom": "^26",
|
|
18
|
+
"react-dom": "19.2.8",
|
|
19
|
+
"vitest": "^5"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"typescript": "^5",
|
|
23
|
+
"react": "^19"
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/calendar.css
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
/* ─── Base ─────────────────────────────────────────────── */
|
|
2
|
+
|
|
3
|
+
.calendar {
|
|
4
|
+
--cal-bg: #ffffff;
|
|
5
|
+
--cal-fg: #1e293b;
|
|
6
|
+
--cal-accent: #dc2626;
|
|
7
|
+
--cal-weekend-fg: #94a3b8;
|
|
8
|
+
--cal-border: #e2e8f0;
|
|
9
|
+
--cal-header-bg: #f8fafc;
|
|
10
|
+
--cal-highlight-bg: #dc2626;
|
|
11
|
+
--cal-highlight-fg: #ffffff;
|
|
12
|
+
--cal-range-bg: #fef3c7;
|
|
13
|
+
--cal-today-bg: #fff7ed;
|
|
14
|
+
--cal-today-fg: #c2410c;
|
|
15
|
+
|
|
16
|
+
/* セルサイズ(size propや style の CSS 変数で上書きできる) */
|
|
17
|
+
--cal-cell-w: 2.25rem;
|
|
18
|
+
--cal-cell-h: 2rem;
|
|
19
|
+
--cal-font-size: 0.875rem;
|
|
20
|
+
--cal-header-font-size: 1.125rem;
|
|
21
|
+
|
|
22
|
+
display: inline-block;
|
|
23
|
+
padding: 0.75rem 1rem;
|
|
24
|
+
background: var(--cal-bg);
|
|
25
|
+
color: var(--cal-fg);
|
|
26
|
+
font-family: ui-sans-serif, system-ui, sans-serif;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.calendar table {
|
|
30
|
+
border-collapse: collapse;
|
|
31
|
+
border-spacing: 0;
|
|
32
|
+
font-variant-numeric: tabular-nums;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.calendar th,
|
|
36
|
+
.calendar td {
|
|
37
|
+
width: var(--cal-cell-w);
|
|
38
|
+
height: var(--cal-cell-h);
|
|
39
|
+
padding: 0.125rem 0.375rem;
|
|
40
|
+
text-align: center;
|
|
41
|
+
font-size: var(--cal-font-size);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.calendar th {
|
|
45
|
+
color: var(--cal-accent);
|
|
46
|
+
font-weight: 600;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.calendar .calendar-header {
|
|
50
|
+
text-align: center;
|
|
51
|
+
margin-bottom: 0.5rem;
|
|
52
|
+
font-size: 1rem;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.calendar .calendar-header h2 {
|
|
56
|
+
margin: 0;
|
|
57
|
+
font-size: var(--cal-header-font-size);
|
|
58
|
+
font-weight: 700;
|
|
59
|
+
color: var(--cal-fg);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.calendar td.is-weekend {
|
|
63
|
+
color: var(--cal-weekend-fg);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.calendar td.is-today {
|
|
67
|
+
background: var(--cal-today-bg);
|
|
68
|
+
color: var(--cal-today-fg);
|
|
69
|
+
font-weight: 700;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.calendar td.is-highlight {
|
|
73
|
+
background: var(--cal-highlight-bg);
|
|
74
|
+
color: var(--cal-highlight-fg);
|
|
75
|
+
font-weight: 700;
|
|
76
|
+
border-radius: 0.375rem;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.calendar td.is-in-range {
|
|
80
|
+
background: var(--cal-range-bg);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/* ─── Size ────────────────────────────────────────────── */
|
|
84
|
+
|
|
85
|
+
.calendar-size-sm {
|
|
86
|
+
--cal-cell-w: 1.75rem;
|
|
87
|
+
--cal-cell-h: 1.5rem;
|
|
88
|
+
--cal-font-size: 0.75rem;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.calendar-size-lg {
|
|
92
|
+
--cal-cell-w: 3.125rem;
|
|
93
|
+
--cal-cell-h: 2.75rem;
|
|
94
|
+
--cal-font-size: 1rem;
|
|
95
|
+
--cal-header-font-size: 1.25rem;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* ─── Theme: default ───────────────────────────────────── */
|
|
99
|
+
|
|
100
|
+
.calendar-theme-default table {
|
|
101
|
+
border: 1px solid var(--cal-border);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.calendar-theme-default th {
|
|
105
|
+
border-bottom: 2px solid var(--cal-border);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.calendar-theme-default td {
|
|
109
|
+
border: 1px solid var(--cal-border);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.calendar-theme-default td.is-highlight {
|
|
113
|
+
border-radius: 0;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/* ─── Theme: modern ────────────────────────────────────── */
|
|
117
|
+
|
|
118
|
+
.calendar-theme-modern {
|
|
119
|
+
border-radius: 1rem;
|
|
120
|
+
box-shadow:
|
|
121
|
+
0 1px 3px rgb(0 0 0 / 0.1),
|
|
122
|
+
0 8px 24px rgb(0 0 0 / 0.08);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.calendar-theme-modern .calendar-header {
|
|
126
|
+
background: var(--cal-header-bg);
|
|
127
|
+
margin: -0.75rem -1rem 0.75rem;
|
|
128
|
+
padding: 0.75rem 1rem;
|
|
129
|
+
border-radius: 1rem 1rem 0 0;
|
|
130
|
+
border-bottom: 1px solid var(--cal-border);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.calendar-theme-modern table {
|
|
134
|
+
border: 1px solid var(--cal-border);
|
|
135
|
+
border-radius: 0.5rem;
|
|
136
|
+
overflow: hidden;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.calendar-theme-modern th {
|
|
140
|
+
background: var(--cal-header-bg);
|
|
141
|
+
border-bottom: 2px solid var(--cal-border);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.calendar-theme-modern td {
|
|
145
|
+
border: 1px solid var(--cal-border);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.calendar-theme-modern td:empty {
|
|
149
|
+
border-color: transparent;
|
|
150
|
+
background: transparent;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.calendar-theme-modern td.is-today {
|
|
154
|
+
border-radius: 0.375rem;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.calendar-theme-modern td.is-highlight {
|
|
158
|
+
box-shadow: 0 1px 2px rgb(0 0 0 / 0.15);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/* ─── Theme: minimal ───────────────────────────────────── */
|
|
162
|
+
|
|
163
|
+
.calendar-theme-minimal {
|
|
164
|
+
padding: 0.5rem;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.calendar-theme-minimal .calendar-header {
|
|
168
|
+
margin-bottom: 0.25rem;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.calendar-theme-minimal table {
|
|
172
|
+
border: 0;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.calendar-theme-minimal th {
|
|
176
|
+
border-bottom: 1px solid var(--cal-border);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.calendar-theme-minimal td {
|
|
180
|
+
border: 0;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.calendar-theme-minimal td.is-highlight {
|
|
184
|
+
border-radius: 0.25rem;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/* ─── Theme: rounded ───────────────────────────────────── */
|
|
188
|
+
|
|
189
|
+
.calendar-theme-rounded {
|
|
190
|
+
border-radius: 1rem;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.calendar-theme-rounded table {
|
|
194
|
+
border-collapse: separate;
|
|
195
|
+
border-spacing: 0.25rem;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.calendar-theme-rounded th {
|
|
199
|
+
border: 0;
|
|
200
|
+
border-radius: 999px;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.calendar-theme-rounded td {
|
|
204
|
+
border: 0;
|
|
205
|
+
border-radius: 999px;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.calendar-theme-rounded td.is-today,
|
|
209
|
+
.calendar-theme-rounded td.is-highlight,
|
|
210
|
+
.calendar-theme-rounded td.is-in-range {
|
|
211
|
+
border-radius: 999px;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.calendar-theme-rounded td:empty {
|
|
215
|
+
background: transparent;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/* ─── Interactive ──────────────────────────────────────── */
|
|
219
|
+
|
|
220
|
+
.calendar-interactive {
|
|
221
|
+
outline: none;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.calendar-interactive:focus-visible {
|
|
225
|
+
box-shadow: 0 0 0 2px var(--cal-accent);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.calendar-interactive td button.calendar-day-btn {
|
|
229
|
+
display: block;
|
|
230
|
+
width: 100%;
|
|
231
|
+
height: 100%;
|
|
232
|
+
margin: 0;
|
|
233
|
+
padding: 0;
|
|
234
|
+
border: 0;
|
|
235
|
+
background: transparent;
|
|
236
|
+
color: inherit;
|
|
237
|
+
font: inherit;
|
|
238
|
+
line-height: inherit;
|
|
239
|
+
text-align: center;
|
|
240
|
+
border-radius: inherit;
|
|
241
|
+
cursor: pointer;
|
|
242
|
+
transition:
|
|
243
|
+
background-color 0.15s ease,
|
|
244
|
+
color 0.15s ease,
|
|
245
|
+
transform 0.1s ease;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
.calendar-interactive td button.calendar-day-btn:hover {
|
|
249
|
+
background: var(--cal-range-bg);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
.calendar-interactive td button.calendar-day-btn:focus-visible {
|
|
253
|
+
outline: 2px solid var(--cal-accent);
|
|
254
|
+
outline-offset: -4px;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
.calendar-interactive td button.calendar-day-btn:active {
|
|
258
|
+
transform: scale(0.95);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/* ─── Theme: retro ─────────────────────────────────────── */
|
|
262
|
+
|
|
263
|
+
.calendar-theme-retro {
|
|
264
|
+
padding: 0.75rem;
|
|
265
|
+
border: 2px solid var(--cal-fg);
|
|
266
|
+
border-radius: 0;
|
|
267
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.calendar-theme-retro .calendar-header {
|
|
271
|
+
background: var(--cal-header-bg);
|
|
272
|
+
border-bottom: 3px double var(--cal-fg);
|
|
273
|
+
margin: -0.75rem -0.75rem 0.75rem;
|
|
274
|
+
padding: 0.5rem 0.75rem;
|
|
275
|
+
letter-spacing: 0.05em;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
.calendar-theme-retro table {
|
|
279
|
+
border: 2px solid var(--cal-fg);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.calendar-theme-retro th {
|
|
283
|
+
background: var(--cal-header-bg);
|
|
284
|
+
border: 1px solid var(--cal-fg);
|
|
285
|
+
font-weight: 700;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
.calendar-theme-retro td {
|
|
289
|
+
border: 1px solid var(--cal-fg);
|
|
290
|
+
border-radius: 0;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
.calendar-theme-retro td.is-highlight,
|
|
294
|
+
.calendar-theme-retro td.is-today {
|
|
295
|
+
border-radius: 0;
|
|
296
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isDateInRange, isSameDay } from "@typescript-calendar/core";
|
|
2
|
+
|
|
3
|
+
// ─── セル状態クラス ───────────────────────────────────────
|
|
4
|
+
|
|
5
|
+
export interface CellStateOptions {
|
|
6
|
+
today?: Date;
|
|
7
|
+
highlight?: Date;
|
|
8
|
+
range?: { from: Date; to: Date };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** 日付セルの状態(週末・今日・ハイライト・範囲)に応じたCSSクラスを組み立てる */
|
|
12
|
+
export function getCellClasses(date: Date, options: CellStateOptions): string {
|
|
13
|
+
const { today, highlight, range } = options;
|
|
14
|
+
const classes: string[] = [];
|
|
15
|
+
if (date.getDay() === 0 || date.getDay() === 6) classes.push("is-weekend");
|
|
16
|
+
if (today !== undefined && isSameDay(date, today)) classes.push("is-today");
|
|
17
|
+
if (highlight !== undefined && isSameDay(date, highlight))
|
|
18
|
+
classes.push("is-highlight");
|
|
19
|
+
if (range !== undefined && isDateInRange(date, range))
|
|
20
|
+
classes.push("is-in-range");
|
|
21
|
+
return classes.join(" ");
|
|
22
|
+
}
|
package/src/global.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module "*.css";
|
package/src/hooks.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CalendarState,
|
|
3
|
+
CalendarStateOptions,
|
|
4
|
+
Direction,
|
|
5
|
+
MonthDirection,
|
|
6
|
+
} from "@typescript-calendar/tui";
|
|
7
|
+
import {
|
|
8
|
+
createCalendarState,
|
|
9
|
+
getCursorDate,
|
|
10
|
+
getSelectedDate,
|
|
11
|
+
navigateMonth,
|
|
12
|
+
clearSelection as tuiClearSelection,
|
|
13
|
+
goToToday as tuiGoToToday,
|
|
14
|
+
moveCursor as tuiMoveCursor,
|
|
15
|
+
selectDate as tuiSelectDate,
|
|
16
|
+
} from "@typescript-calendar/tui";
|
|
17
|
+
import { useCallback, useMemo, useState } from "react";
|
|
18
|
+
|
|
19
|
+
export interface UseCalendarStateOptions
|
|
20
|
+
extends Pick<
|
|
21
|
+
CalendarStateOptions,
|
|
22
|
+
"locale" | "weekStart" | "today" | "highlight" | "range"
|
|
23
|
+
> {
|
|
24
|
+
initialYear?: number;
|
|
25
|
+
initialMonth?: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface UseCalendarStateReturn {
|
|
29
|
+
/** 現在のカレンダー状態 */
|
|
30
|
+
state: CalendarState;
|
|
31
|
+
/** カーソルを指定方向に移動 (wrap around) */
|
|
32
|
+
moveCursor: (direction: Direction) => void;
|
|
33
|
+
/** 前月/翌月へ移動 */
|
|
34
|
+
goNext: () => void;
|
|
35
|
+
goPrev: () => void;
|
|
36
|
+
/** 今日の月へジャンプ */
|
|
37
|
+
goToday: () => void;
|
|
38
|
+
/** カーソル位置の日付を選択 */
|
|
39
|
+
selectDate: () => void;
|
|
40
|
+
/** 選択を解除 */
|
|
41
|
+
clearSelection: () => void;
|
|
42
|
+
/** カーソル位置の日付(null の場合あり) */
|
|
43
|
+
cursorDate: Date | null;
|
|
44
|
+
/** 選択済み日付(null の場合あり) */
|
|
45
|
+
selectedDate: Date | null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* tui の不変状態マシンを包む React hook。
|
|
50
|
+
* カレンダーのインタラクティブ操作をシンプルに利用できる。
|
|
51
|
+
*/
|
|
52
|
+
export function useCalendarState(
|
|
53
|
+
options: UseCalendarStateOptions = {},
|
|
54
|
+
): UseCalendarStateReturn {
|
|
55
|
+
const [state, setState] = useState<CalendarState>(() =>
|
|
56
|
+
createCalendarState({
|
|
57
|
+
initialYear: options.initialYear,
|
|
58
|
+
initialMonth: options.initialMonth,
|
|
59
|
+
today: options.today,
|
|
60
|
+
locale: options.locale,
|
|
61
|
+
weekStart: options.weekStart,
|
|
62
|
+
highlight: options.highlight,
|
|
63
|
+
range: options.range,
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const move = useCallback((direction: Direction) => {
|
|
68
|
+
setState((prev) => tuiMoveCursor(prev, direction));
|
|
69
|
+
}, []);
|
|
70
|
+
|
|
71
|
+
const goNext = useCallback(() => {
|
|
72
|
+
setState((prev) => navigateMonth(prev, "next"));
|
|
73
|
+
}, []);
|
|
74
|
+
|
|
75
|
+
const goPrev = useCallback(() => {
|
|
76
|
+
setState((prev) => navigateMonth(prev, "prev"));
|
|
77
|
+
}, []);
|
|
78
|
+
|
|
79
|
+
const goToday = useCallback(() => {
|
|
80
|
+
setState((prev) => tuiGoToToday(prev));
|
|
81
|
+
}, []);
|
|
82
|
+
|
|
83
|
+
const select = useCallback(() => {
|
|
84
|
+
setState((prev) => tuiSelectDate(prev));
|
|
85
|
+
}, []);
|
|
86
|
+
|
|
87
|
+
const clear = useCallback(() => {
|
|
88
|
+
setState((prev) => tuiClearSelection(prev));
|
|
89
|
+
}, []);
|
|
90
|
+
|
|
91
|
+
const cursorDate = useMemo(() => getCursorDate(state), [state]);
|
|
92
|
+
const selectedDate = useMemo(() => getSelectedDate(state), [state]);
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
state,
|
|
96
|
+
moveCursor: move,
|
|
97
|
+
goNext,
|
|
98
|
+
goPrev,
|
|
99
|
+
goToday,
|
|
100
|
+
selectDate: select,
|
|
101
|
+
clearSelection: clear,
|
|
102
|
+
cursorDate,
|
|
103
|
+
selectedDate,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export type { Direction, MonthDirection };
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
|
2
|
+
import { createElement } from "react";
|
|
3
|
+
import { afterEach, describe, expect, test, vi } from "vitest";
|
|
4
|
+
import "@testing-library/jest-dom/vitest";
|
|
5
|
+
import { useCalendarState } from "./hooks.ts";
|
|
6
|
+
import { Calendar } from "./index.tsx";
|
|
7
|
+
|
|
8
|
+
const TODAY = new Date(2026, 8, 15); // 2026-09-15
|
|
9
|
+
|
|
10
|
+
afterEach(cleanup);
|
|
11
|
+
|
|
12
|
+
// ─── useCalendarState hook ──────────────────────────────
|
|
13
|
+
|
|
14
|
+
function HookTestComponent() {
|
|
15
|
+
const {
|
|
16
|
+
state,
|
|
17
|
+
goNext,
|
|
18
|
+
goPrev,
|
|
19
|
+
goToday,
|
|
20
|
+
moveCursor,
|
|
21
|
+
selectDate,
|
|
22
|
+
cursorDate,
|
|
23
|
+
selectedDate,
|
|
24
|
+
} = useCalendarState({
|
|
25
|
+
initialYear: 2026,
|
|
26
|
+
initialMonth: 9,
|
|
27
|
+
today: TODAY,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return createElement(
|
|
31
|
+
"div",
|
|
32
|
+
null,
|
|
33
|
+
createElement("span", { "data-testid": "title" }, state.monthData.title),
|
|
34
|
+
createElement(
|
|
35
|
+
"span",
|
|
36
|
+
{ "data-testid": "cursor" },
|
|
37
|
+
cursorDate?.toISOString() ?? "null",
|
|
38
|
+
),
|
|
39
|
+
createElement(
|
|
40
|
+
"span",
|
|
41
|
+
{ "data-testid": "selected" },
|
|
42
|
+
selectedDate?.toISOString() ?? "null",
|
|
43
|
+
),
|
|
44
|
+
createElement(
|
|
45
|
+
"button",
|
|
46
|
+
{ "data-testid": "next", type: "button", onClick: goNext },
|
|
47
|
+
"Next",
|
|
48
|
+
),
|
|
49
|
+
createElement(
|
|
50
|
+
"button",
|
|
51
|
+
{ "data-testid": "prev", type: "button", onClick: goPrev },
|
|
52
|
+
"Prev",
|
|
53
|
+
),
|
|
54
|
+
createElement(
|
|
55
|
+
"button",
|
|
56
|
+
{ "data-testid": "today", type: "button", onClick: goToday },
|
|
57
|
+
"Today",
|
|
58
|
+
),
|
|
59
|
+
createElement(
|
|
60
|
+
"button",
|
|
61
|
+
{
|
|
62
|
+
"data-testid": "right",
|
|
63
|
+
type: "button",
|
|
64
|
+
onClick: () => moveCursor("right"),
|
|
65
|
+
},
|
|
66
|
+
"Right",
|
|
67
|
+
),
|
|
68
|
+
createElement(
|
|
69
|
+
"button",
|
|
70
|
+
{ "data-testid": "select", type: "button", onClick: selectDate },
|
|
71
|
+
"Select",
|
|
72
|
+
),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
describe("useCalendarState", () => {
|
|
77
|
+
test("初期状態は指定月を表示", () => {
|
|
78
|
+
render(createElement(HookTestComponent));
|
|
79
|
+
expect(screen.getByTestId("title").textContent).toBe("September 2026");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("カーソルは今日の日付を指す", () => {
|
|
83
|
+
render(createElement(HookTestComponent));
|
|
84
|
+
expect(screen.getByTestId("cursor").textContent).toBe(TODAY.toISOString());
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("翌月に移動できる", () => {
|
|
88
|
+
render(createElement(HookTestComponent));
|
|
89
|
+
fireEvent.click(screen.getByTestId("next"));
|
|
90
|
+
expect(screen.getByTestId("title").textContent).toBe("October 2026");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("前月に移動できる", () => {
|
|
94
|
+
render(createElement(HookTestComponent));
|
|
95
|
+
fireEvent.click(screen.getByTestId("prev"));
|
|
96
|
+
expect(screen.getByTestId("title").textContent).toBe("August 2026");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("今日にジャンプできる", () => {
|
|
100
|
+
render(createElement(HookTestComponent));
|
|
101
|
+
fireEvent.click(screen.getByTestId("next"));
|
|
102
|
+
fireEvent.click(screen.getByTestId("next"));
|
|
103
|
+
fireEvent.click(screen.getByTestId("today"));
|
|
104
|
+
expect(screen.getByTestId("title").textContent).toBe("September 2026");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("カーソルを右に動かせる", () => {
|
|
108
|
+
render(createElement(HookTestComponent));
|
|
109
|
+
const before = screen.getByTestId("cursor").textContent;
|
|
110
|
+
fireEvent.click(screen.getByTestId("right"));
|
|
111
|
+
const after = screen.getByTestId("cursor").textContent;
|
|
112
|
+
expect(after).not.toBe(before);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("日付を選択できる", () => {
|
|
116
|
+
render(createElement(HookTestComponent));
|
|
117
|
+
fireEvent.click(screen.getByTestId("select"));
|
|
118
|
+
expect(screen.getByTestId("selected").textContent).toBe(
|
|
119
|
+
TODAY.toISOString(),
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// ─── Calendar component interaction ─────────────────────
|
|
125
|
+
|
|
126
|
+
describe("Calendar interactive", () => {
|
|
127
|
+
test("interactive モードではセル内に button がレンダリングされる", () => {
|
|
128
|
+
render(
|
|
129
|
+
createElement(Calendar, {
|
|
130
|
+
year: 2026,
|
|
131
|
+
month: 9,
|
|
132
|
+
interactive: true,
|
|
133
|
+
today: TODAY,
|
|
134
|
+
}),
|
|
135
|
+
);
|
|
136
|
+
const buttons = screen.getAllByRole("button");
|
|
137
|
+
expect(buttons.length).toBeGreaterThan(0);
|
|
138
|
+
// テーブルセルのセマンティクスを保つため button は td の内側にある
|
|
139
|
+
expect(buttons[0]!.closest("td")).not.toBeNull();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("interactive でない場合は button がない", () => {
|
|
143
|
+
const { container } = render(
|
|
144
|
+
createElement(Calendar, {
|
|
145
|
+
year: 2026,
|
|
146
|
+
month: 9,
|
|
147
|
+
today: TODAY,
|
|
148
|
+
}),
|
|
149
|
+
);
|
|
150
|
+
expect(container.querySelectorAll("button")).toHaveLength(0);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("セルクリックで onDateClick が呼ばれる", () => {
|
|
154
|
+
const onClick = vi.fn();
|
|
155
|
+
render(
|
|
156
|
+
createElement(Calendar, {
|
|
157
|
+
year: 2026,
|
|
158
|
+
month: 9,
|
|
159
|
+
interactive: true,
|
|
160
|
+
today: TODAY,
|
|
161
|
+
onDateClick: onClick,
|
|
162
|
+
}),
|
|
163
|
+
);
|
|
164
|
+
const cells = screen.getAllByRole("button");
|
|
165
|
+
fireEvent.click(cells[0]!);
|
|
166
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
167
|
+
expect(onClick.mock.calls[0]![0]).toBeInstanceOf(Date);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test("セルホバーで onDateHover が呼ばれる", () => {
|
|
171
|
+
const onHover = vi.fn();
|
|
172
|
+
render(
|
|
173
|
+
createElement(Calendar, {
|
|
174
|
+
year: 2026,
|
|
175
|
+
month: 9,
|
|
176
|
+
interactive: true,
|
|
177
|
+
today: TODAY,
|
|
178
|
+
onDateHover: onHover,
|
|
179
|
+
}),
|
|
180
|
+
);
|
|
181
|
+
const cells = screen.getAllByRole("button");
|
|
182
|
+
fireEvent.mouseEnter(cells[0]!);
|
|
183
|
+
expect(onHover).toHaveBeenCalledTimes(1);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test("Enter キーで onDateClick が呼ばれる", () => {
|
|
187
|
+
const onClick = vi.fn();
|
|
188
|
+
render(
|
|
189
|
+
createElement(Calendar, {
|
|
190
|
+
year: 2026,
|
|
191
|
+
month: 9,
|
|
192
|
+
interactive: true,
|
|
193
|
+
today: TODAY,
|
|
194
|
+
onDateClick: onClick,
|
|
195
|
+
}),
|
|
196
|
+
);
|
|
197
|
+
const cells = screen.getAllByRole("button");
|
|
198
|
+
cells[0]!.focus();
|
|
199
|
+
// 実ブラウザではフォーカス中の button への Enter は click を発火する。
|
|
200
|
+
// jsdom はこの既定動作を実装していないため、keyDown 後の click で再現する。
|
|
201
|
+
fireEvent.keyDown(cells[0]!, { key: "Enter" });
|
|
202
|
+
fireEvent.click(cells[0]!);
|
|
203
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test("interactive モードで calendar-interactive クラスがつく", () => {
|
|
207
|
+
const { container } = render(
|
|
208
|
+
createElement(Calendar, {
|
|
209
|
+
year: 2026,
|
|
210
|
+
month: 9,
|
|
211
|
+
interactive: true,
|
|
212
|
+
today: TODAY,
|
|
213
|
+
}),
|
|
214
|
+
);
|
|
215
|
+
expect(container.firstChild).toHaveClass("calendar-interactive");
|
|
216
|
+
});
|
|
217
|
+
});
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import type { CalendarOptions } from "@typescript-calendar/core";
|
|
2
|
+
import {
|
|
3
|
+
buildMonthGrid,
|
|
4
|
+
getMonthName,
|
|
5
|
+
getWeekdayHeaders,
|
|
6
|
+
} from "@typescript-calendar/core";
|
|
7
|
+
import type { CSSProperties } from "react";
|
|
8
|
+
import { getCellClasses } from "./cell-classes.ts";
|
|
9
|
+
import type { CalendarSize } from "./size.ts";
|
|
10
|
+
import { buildSizeStyle, isSizeName } from "./size.ts";
|
|
11
|
+
import type {
|
|
12
|
+
ColorSchemeName,
|
|
13
|
+
ReactColorScheme,
|
|
14
|
+
ReactTheme,
|
|
15
|
+
ThemeName,
|
|
16
|
+
} from "./themes.ts";
|
|
17
|
+
import { resolveColorScheme, resolveTheme } from "./themes.ts";
|
|
18
|
+
import "./calendar.css";
|
|
19
|
+
|
|
20
|
+
export type {
|
|
21
|
+
CalendarCustomSize,
|
|
22
|
+
CalendarSize,
|
|
23
|
+
CalendarSizeName,
|
|
24
|
+
} from "./size.ts";
|
|
25
|
+
|
|
26
|
+
export interface CalendarProps {
|
|
27
|
+
year: number;
|
|
28
|
+
month: number;
|
|
29
|
+
locale?: CalendarOptions["locale"];
|
|
30
|
+
weekStart?: CalendarOptions["weekStart"];
|
|
31
|
+
highlight?: Date;
|
|
32
|
+
/** 範囲強調 */
|
|
33
|
+
range?: { from: Date; to: Date };
|
|
34
|
+
/** 今日の基準日。カラースキームの today 着色に使用 */
|
|
35
|
+
today?: Date;
|
|
36
|
+
/** 見た目テーマ。既定は "default" */
|
|
37
|
+
theme?: ThemeName | ReactTheme;
|
|
38
|
+
/** カラースキーム。既定は "default" */
|
|
39
|
+
colorScheme?: ColorSchemeName | ReactColorScheme;
|
|
40
|
+
/** セルサイズ。既定は "md"。{ width, height } で自由に指定できる */
|
|
41
|
+
size?: CalendarSize;
|
|
42
|
+
/** root 要素に追加するスタイル。CSS変数(--cal-*)で自由に上書きできる */
|
|
43
|
+
style?: CSSProperties;
|
|
44
|
+
|
|
45
|
+
// ── インタラクション ──
|
|
46
|
+
|
|
47
|
+
/** インタラクティブモードを有効にする。セルクリック・ホバー・キーボード選択が可能になる */
|
|
48
|
+
interactive?: boolean;
|
|
49
|
+
/** セルクリック時のコールバック */
|
|
50
|
+
onDateClick?: (date: Date) => void;
|
|
51
|
+
/** セルホバー時のコールバック */
|
|
52
|
+
onDateHover?: (date: Date) => void;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Reactカレンダーコンポーネント
|
|
57
|
+
*/
|
|
58
|
+
export function Calendar({
|
|
59
|
+
year,
|
|
60
|
+
month,
|
|
61
|
+
locale = "en",
|
|
62
|
+
weekStart = "sunday",
|
|
63
|
+
highlight,
|
|
64
|
+
range,
|
|
65
|
+
today,
|
|
66
|
+
theme = "default",
|
|
67
|
+
colorScheme = "default",
|
|
68
|
+
size = "md",
|
|
69
|
+
style,
|
|
70
|
+
interactive = false,
|
|
71
|
+
onDateClick,
|
|
72
|
+
onDateHover,
|
|
73
|
+
}: CalendarProps) {
|
|
74
|
+
const monthName = getMonthName(locale, month);
|
|
75
|
+
const weekdays = getWeekdayHeaders(locale, weekStart);
|
|
76
|
+
const grid = buildMonthGrid(year, month, weekStart);
|
|
77
|
+
|
|
78
|
+
const resolvedTheme = resolveTheme(theme);
|
|
79
|
+
const cssVars = resolveColorScheme(colorScheme) as CSSProperties;
|
|
80
|
+
|
|
81
|
+
const className = (day: number): string =>
|
|
82
|
+
getCellClasses(new Date(year, month - 1, day), { today, highlight, range });
|
|
83
|
+
|
|
84
|
+
const sizeClass = isSizeName(size) ? ` calendar-size-${size}` : "";
|
|
85
|
+
|
|
86
|
+
const handleCellClick = (day: number) => {
|
|
87
|
+
if (!interactive || !onDateClick) return;
|
|
88
|
+
onDateClick(new Date(year, month - 1, day));
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const handleCellHover = (day: number) => {
|
|
92
|
+
if (!interactive || !onDateHover) return;
|
|
93
|
+
onDateHover(new Date(year, month - 1, day));
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<div
|
|
98
|
+
className={`calendar ${resolvedTheme.className}${sizeClass}${interactive ? " calendar-interactive" : ""}`}
|
|
99
|
+
style={{ ...cssVars, ...buildSizeStyle(size), ...style }}
|
|
100
|
+
>
|
|
101
|
+
<div className="calendar-header">
|
|
102
|
+
<h2>
|
|
103
|
+
{monthName} {year}
|
|
104
|
+
</h2>
|
|
105
|
+
</div>
|
|
106
|
+
<table>
|
|
107
|
+
<thead>
|
|
108
|
+
<tr>
|
|
109
|
+
{weekdays.map((day) => (
|
|
110
|
+
<th key={day}>{day}</th>
|
|
111
|
+
))}
|
|
112
|
+
</tr>
|
|
113
|
+
</thead>
|
|
114
|
+
<tbody>
|
|
115
|
+
{grid.map((row, i) => {
|
|
116
|
+
if (row.every((d) => d === null)) return null;
|
|
117
|
+
return (
|
|
118
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: 月グリッドは静的で並び順が変わらない
|
|
119
|
+
<tr key={i}>
|
|
120
|
+
{row.map((day, j) => {
|
|
121
|
+
if (day === null)
|
|
122
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: パディングセルは位置が唯一の識別子
|
|
123
|
+
return <td key={j} />;
|
|
124
|
+
const cellClass = className(day) || undefined;
|
|
125
|
+
if (!interactive) {
|
|
126
|
+
return (
|
|
127
|
+
<td key={day} className={cellClass}>
|
|
128
|
+
{day}
|
|
129
|
+
</td>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
return (
|
|
133
|
+
<td key={day} className={cellClass}>
|
|
134
|
+
<button
|
|
135
|
+
type="button"
|
|
136
|
+
className="calendar-day-btn"
|
|
137
|
+
onClick={() => handleCellClick(day)}
|
|
138
|
+
onMouseEnter={() => handleCellHover(day)}
|
|
139
|
+
tabIndex={0}
|
|
140
|
+
aria-label={`${getMonthName(locale, month)} ${day}, ${year}`}
|
|
141
|
+
>
|
|
142
|
+
{day}
|
|
143
|
+
</button>
|
|
144
|
+
</td>
|
|
145
|
+
);
|
|
146
|
+
})}
|
|
147
|
+
</tr>
|
|
148
|
+
);
|
|
149
|
+
})}
|
|
150
|
+
</tbody>
|
|
151
|
+
</table>
|
|
152
|
+
</div>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export default Calendar;
|
|
157
|
+
|
|
158
|
+
export type {
|
|
159
|
+
UseCalendarStateOptions,
|
|
160
|
+
UseCalendarStateReturn,
|
|
161
|
+
} from "./hooks.ts";
|
|
162
|
+
export { useCalendarState } from "./hooks.ts";
|
|
163
|
+
export type {
|
|
164
|
+
ColorSchemeName,
|
|
165
|
+
ReactColorScheme,
|
|
166
|
+
ReactTheme,
|
|
167
|
+
ThemeName,
|
|
168
|
+
} from "./themes.ts";
|
|
169
|
+
export {
|
|
170
|
+
COLOR_SCHEMES,
|
|
171
|
+
resolveColorScheme,
|
|
172
|
+
resolveTheme,
|
|
173
|
+
THEMES,
|
|
174
|
+
} from "./themes.ts";
|
package/src/size.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CSSProperties } from "react";
|
|
2
|
+
|
|
3
|
+
// ─── セルサイズ ───────────────────────────────────────────
|
|
4
|
+
|
|
5
|
+
/** 組み込みサイズ名 */
|
|
6
|
+
export type CalendarSizeName = "sm" | "md" | "lg";
|
|
7
|
+
|
|
8
|
+
/** カスタムセルサイズ。数値は px、文字列は CSS 長さのまま渡す */
|
|
9
|
+
export interface CalendarCustomSize {
|
|
10
|
+
width?: number | string;
|
|
11
|
+
height?: number | string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** セルサイズ指定 */
|
|
15
|
+
export type CalendarSize = CalendarSizeName | CalendarCustomSize;
|
|
16
|
+
|
|
17
|
+
export function isSizeName(size: CalendarSize): size is CalendarSizeName {
|
|
18
|
+
return typeof size === "string";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function toCssLength(value: number | string): string {
|
|
22
|
+
return typeof value === "number" ? `${value}px` : value;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function buildSizeStyle(size: CalendarSize): CSSProperties {
|
|
26
|
+
if (isSizeName(size)) return {};
|
|
27
|
+
const style: Record<string, string> = {};
|
|
28
|
+
if (size.width !== undefined) style["--cal-cell-w"] = toCssLength(size.width);
|
|
29
|
+
if (size.height !== undefined)
|
|
30
|
+
style["--cal-cell-h"] = toCssLength(size.height);
|
|
31
|
+
return style;
|
|
32
|
+
}
|
package/src/themes.ts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// ─── テーマ ───────────────────────────────────────────────
|
|
2
|
+
|
|
3
|
+
/** 組み込みテーマ名。カスタムテーマは ReactTheme オブジェクトを直接渡せる */
|
|
4
|
+
export type ThemeName = "default" | "modern" | "minimal" | "rounded" | "retro";
|
|
5
|
+
|
|
6
|
+
/** React の見た目定義。テーマは主に CSS クラスで切り替える */
|
|
7
|
+
export interface ReactTheme {
|
|
8
|
+
/** root 要素に追加するクラス */
|
|
9
|
+
className: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const THEMES: Record<ThemeName, ReactTheme> = {
|
|
13
|
+
default: { className: "calendar-theme-default" },
|
|
14
|
+
modern: { className: "calendar-theme-modern" },
|
|
15
|
+
minimal: { className: "calendar-theme-minimal" },
|
|
16
|
+
rounded: { className: "calendar-theme-rounded" },
|
|
17
|
+
retro: { className: "calendar-theme-retro" },
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export function resolveTheme(theme?: ThemeName | ReactTheme): ReactTheme {
|
|
21
|
+
if (theme === undefined) return THEMES.default;
|
|
22
|
+
if (typeof theme === "string") return THEMES[theme] ?? THEMES.default;
|
|
23
|
+
return theme;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// ─── カラースキーム ───────────────────────────────────────
|
|
27
|
+
|
|
28
|
+
/** 組み込みカラースキーム名。カスタムは CSS 変数マップを直接渡せる */
|
|
29
|
+
export type ColorSchemeName =
|
|
30
|
+
| "default"
|
|
31
|
+
| "ocean"
|
|
32
|
+
| "forest"
|
|
33
|
+
| "sunset"
|
|
34
|
+
| "mono"
|
|
35
|
+
| "midnight"
|
|
36
|
+
| "blossom";
|
|
37
|
+
|
|
38
|
+
/** CSS カスタムプロパティ(--cal-*)の値マップ */
|
|
39
|
+
export type ReactColorScheme = Record<`--cal-${string}`, string>;
|
|
40
|
+
|
|
41
|
+
export const COLOR_SCHEMES: Record<ColorSchemeName, ReactColorScheme> = {
|
|
42
|
+
default: {
|
|
43
|
+
"--cal-bg": "#ffffff",
|
|
44
|
+
"--cal-fg": "#1e293b",
|
|
45
|
+
"--cal-accent": "#dc2626",
|
|
46
|
+
"--cal-weekend-fg": "#94a3b8",
|
|
47
|
+
"--cal-border": "#e2e8f0",
|
|
48
|
+
"--cal-header-bg": "#f8fafc",
|
|
49
|
+
"--cal-highlight-bg": "#dc2626",
|
|
50
|
+
"--cal-highlight-fg": "#ffffff",
|
|
51
|
+
"--cal-range-bg": "#fef3c7",
|
|
52
|
+
"--cal-today-bg": "#fff7ed",
|
|
53
|
+
"--cal-today-fg": "#c2410c",
|
|
54
|
+
},
|
|
55
|
+
ocean: {
|
|
56
|
+
"--cal-bg": "#f0f9ff",
|
|
57
|
+
"--cal-fg": "#0f172a",
|
|
58
|
+
"--cal-accent": "#0e7490",
|
|
59
|
+
"--cal-weekend-fg": "#7dd3fc",
|
|
60
|
+
"--cal-border": "#bae6fd",
|
|
61
|
+
"--cal-header-bg": "#e0f2fe",
|
|
62
|
+
"--cal-highlight-bg": "#0e7490",
|
|
63
|
+
"--cal-highlight-fg": "#ffffff",
|
|
64
|
+
"--cal-range-bg": "#dff3fe",
|
|
65
|
+
"--cal-today-bg": "#cffafe",
|
|
66
|
+
"--cal-today-fg": "#155e75",
|
|
67
|
+
},
|
|
68
|
+
forest: {
|
|
69
|
+
"--cal-bg": "#f0fdf4",
|
|
70
|
+
"--cal-fg": "#052e16",
|
|
71
|
+
"--cal-accent": "#15803d",
|
|
72
|
+
"--cal-weekend-fg": "#86efac",
|
|
73
|
+
"--cal-border": "#bbf7d0",
|
|
74
|
+
"--cal-header-bg": "#dcfce7",
|
|
75
|
+
"--cal-highlight-bg": "#15803d",
|
|
76
|
+
"--cal-highlight-fg": "#ffffff",
|
|
77
|
+
"--cal-range-bg": "#dcfce7",
|
|
78
|
+
"--cal-today-bg": "#f0fdf4",
|
|
79
|
+
"--cal-today-fg": "#166534",
|
|
80
|
+
},
|
|
81
|
+
sunset: {
|
|
82
|
+
"--cal-bg": "#fffaf5",
|
|
83
|
+
"--cal-fg": "#431407",
|
|
84
|
+
"--cal-accent": "#ea580c",
|
|
85
|
+
"--cal-weekend-fg": "#fdba74",
|
|
86
|
+
"--cal-border": "#fed7aa",
|
|
87
|
+
"--cal-header-bg": "#ffedd5",
|
|
88
|
+
"--cal-highlight-bg": "#ea580c",
|
|
89
|
+
"--cal-highlight-fg": "#ffffff",
|
|
90
|
+
"--cal-range-bg": "#ffedd5",
|
|
91
|
+
"--cal-today-bg": "#fff7ed",
|
|
92
|
+
"--cal-today-fg": "#9a3412",
|
|
93
|
+
},
|
|
94
|
+
mono: {
|
|
95
|
+
"--cal-bg": "#ffffff",
|
|
96
|
+
"--cal-fg": "#111827",
|
|
97
|
+
"--cal-accent": "#374151",
|
|
98
|
+
"--cal-weekend-fg": "#d1d5db",
|
|
99
|
+
"--cal-border": "#e5e7eb",
|
|
100
|
+
"--cal-header-bg": "#f3f4f6",
|
|
101
|
+
"--cal-highlight-bg": "#111827",
|
|
102
|
+
"--cal-highlight-fg": "#ffffff",
|
|
103
|
+
"--cal-range-bg": "#f3f4f6",
|
|
104
|
+
"--cal-today-bg": "#e5e7eb",
|
|
105
|
+
"--cal-today-fg": "#111827",
|
|
106
|
+
},
|
|
107
|
+
midnight: {
|
|
108
|
+
"--cal-bg": "#0f172a",
|
|
109
|
+
"--cal-fg": "#e2e8f0",
|
|
110
|
+
"--cal-accent": "#38bdf8",
|
|
111
|
+
"--cal-weekend-fg": "#475569",
|
|
112
|
+
"--cal-border": "#1e293b",
|
|
113
|
+
"--cal-header-bg": "#1e293b",
|
|
114
|
+
"--cal-highlight-bg": "#38bdf8",
|
|
115
|
+
"--cal-highlight-fg": "#0f172a",
|
|
116
|
+
"--cal-range-bg": "#0c4a6e",
|
|
117
|
+
"--cal-today-bg": "#0c4a6e",
|
|
118
|
+
"--cal-today-fg": "#7dd3fc",
|
|
119
|
+
},
|
|
120
|
+
blossom: {
|
|
121
|
+
"--cal-bg": "#fffaff",
|
|
122
|
+
"--cal-fg": "#500724",
|
|
123
|
+
"--cal-accent": "#db2777",
|
|
124
|
+
"--cal-weekend-fg": "#f9a8d4",
|
|
125
|
+
"--cal-border": "#fbcfe8",
|
|
126
|
+
"--cal-header-bg": "#fdf2f8",
|
|
127
|
+
"--cal-highlight-bg": "#db2777",
|
|
128
|
+
"--cal-highlight-fg": "#ffffff",
|
|
129
|
+
"--cal-range-bg": "#fce7f3",
|
|
130
|
+
"--cal-today-bg": "#fdf2f8",
|
|
131
|
+
"--cal-today-fg": "#be185d",
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export function resolveColorScheme(
|
|
136
|
+
scheme?: ColorSchemeName | ReactColorScheme,
|
|
137
|
+
): ReactColorScheme {
|
|
138
|
+
if (scheme === undefined) return COLOR_SCHEMES.default;
|
|
139
|
+
if (typeof scheme === "string") {
|
|
140
|
+
return COLOR_SCHEMES[scheme] ?? COLOR_SCHEMES.default;
|
|
141
|
+
}
|
|
142
|
+
return scheme;
|
|
143
|
+
}
|