@typescript-calendar-lib/react 0.1.1 → 0.4.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 +21 -0
- package/README.md +344 -0
- package/{src → dist}/calendar.css +40 -73
- package/dist/index.d.ts +158 -0
- package/dist/index.js +373 -0
- package/dist/index.js.map +1 -0
- package/package.json +23 -8
- package/src/cell-classes.ts +0 -22
- package/src/global.d.ts +0 -1
- package/src/hooks.ts +0 -107
- package/src/index.test.tsx +0 -217
- package/src/index.tsx +0 -174
- package/src/size.ts +0 -32
- package/src/themes.ts +0 -143
package/src/cell-classes.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
declare module "*.css";
|
package/src/hooks.ts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
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 };
|
package/src/index.test.tsx
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
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
|
-
}
|