@typescript-calendar-lib/react 0.1.1 → 0.3.0
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 +279 -0
- package/{src → dist}/calendar.css +40 -73
- package/dist/index.d.ts +103 -0
- package/dist/index.js +279 -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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 nazozokc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
# @typescript-calendar-lib/react
|
|
2
|
+
|
|
3
|
+
A `<Calendar />` React component with CSS-based themes and color schemes, plus a `useCalendarState` hook for full interactivity. The component is fully controlled — you pass `year` and `month` and it renders the grid.
|
|
4
|
+
|
|
5
|
+
> **Warning: Peer dependency** — Requires React 19. The package doesn't bundle React; install it in your app:
|
|
6
|
+
>
|
|
7
|
+
> ```sh
|
|
8
|
+
> npm install react @typescript-calendar-lib/react
|
|
9
|
+
> ```
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install @typescript-calendar-lib/react
|
|
15
|
+
# or
|
|
16
|
+
bun add @typescript-calendar-lib/react
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { Calendar } from "@typescript-calendar-lib/react";
|
|
23
|
+
import "@typescript-calendar-lib/react/calendar.css"; // required — component styles
|
|
24
|
+
|
|
25
|
+
export function App() {
|
|
26
|
+
return (
|
|
27
|
+
<Calendar
|
|
28
|
+
year={2026}
|
|
29
|
+
month={9}
|
|
30
|
+
colorScheme="ocean"
|
|
31
|
+
theme="modern"
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Component API
|
|
38
|
+
|
|
39
|
+
### `Calendar`
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
<Calendar year={2026} month={9} />
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
| Prop | Type | Default | Description |
|
|
46
|
+
| :--- | :--- | :--- | :--- |
|
|
47
|
+
| `year` | `number` | — (required) | Calendar year |
|
|
48
|
+
| `month` | `number` | — (required) | Month, 1-indexed (`1`–`12`) |
|
|
49
|
+
| `locale` | `"en" \| "ja" \| "es" \| "de" \| "fr" \| "ko" \| "zh"` | `"en"` | Language |
|
|
50
|
+
| `weekStart` | `"sunday" \| "monday"` | `"sunday"` | First day of the week |
|
|
51
|
+
| `highlight` | `Date` | — | Date to highlight |
|
|
52
|
+
| `range` | `{ from: Date; to: Date }` | — | Dates to emphasize |
|
|
53
|
+
| `today` | `Date` | — | Reference date for "today" styling |
|
|
54
|
+
| `theme` | `ThemeName \| ReactTheme` | `"default"` | CSS class-based theme |
|
|
55
|
+
| `colorScheme` | `ColorSchemeName \| ReactColorScheme` | `"default"` | CSS variable-based colors |
|
|
56
|
+
| `size` | `CalendarSize` | `"md"` | Cell size |
|
|
57
|
+
| `style` | `CSSProperties` | — | Extra styles for the root element |
|
|
58
|
+
| `interactive` | `boolean` | `false` | Enable cell click/hover/keyboard selection |
|
|
59
|
+
| `onDateClick` | `(date: Date) => void` | — | Called when a day cell is clicked (or Enter/Space pressed) |
|
|
60
|
+
| `onDateHover` | `(date: Date) => void` | — | Called when a day cell is hovered |
|
|
61
|
+
|
|
62
|
+
The component exports as both named `Calendar` and default.
|
|
63
|
+
|
|
64
|
+
## Interactive Mode
|
|
65
|
+
|
|
66
|
+
Set `interactive` to make day cells clickable. Each cell becomes a `<button class="calendar-day-btn">` — clickable, hoverable, and keyboard-accessible (Enter / Space):
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
<Calendar
|
|
70
|
+
year={2026}
|
|
71
|
+
month={9}
|
|
72
|
+
interactive
|
|
73
|
+
onDateClick={(date) => console.log("Selected", date)}
|
|
74
|
+
onDateHover={(date) => console.log("Hovered", date)}
|
|
75
|
+
/>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### `useCalendarState` hook
|
|
79
|
+
|
|
80
|
+
For full interactivity (cursor movement, month navigation, selection), use the `useCalendarState` hook. It wraps the `@typescript-calendar-lib/tui` state machine as React state:
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
import { Calendar, useCalendarState } from "@typescript-calendar-lib/react";
|
|
84
|
+
import "@typescript-calendar-lib/react/calendar.css"; // required — component styles
|
|
85
|
+
|
|
86
|
+
function App() {
|
|
87
|
+
const {
|
|
88
|
+
state, // CalendarState (tui)
|
|
89
|
+
goNext, // () => void — next month
|
|
90
|
+
goPrev, // () => void — previous month
|
|
91
|
+
goToday, // () => void — jump to today
|
|
92
|
+
moveCursor, // (direction) => void — "up" | "down" | "left" | "right"
|
|
93
|
+
selectDate, // () => void — select date under cursor
|
|
94
|
+
clearSelection,
|
|
95
|
+
cursorDate, // Date | null
|
|
96
|
+
selectedDate, // Date | null
|
|
97
|
+
} = useCalendarState({
|
|
98
|
+
initialYear: 2026,
|
|
99
|
+
initialMonth: 9,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<>
|
|
104
|
+
<button onClick={goPrev}>‹</button>
|
|
105
|
+
<Calendar year={state.year} month={state.month} interactive />
|
|
106
|
+
<button onClick={goNext}>›</button>
|
|
107
|
+
</>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
See the interactive demo in the repository docs (`docs/guide/interactive-demo.md`) for a complete example.
|
|
113
|
+
|
|
114
|
+
## Themes
|
|
115
|
+
|
|
116
|
+
### `ThemeName`
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
type ThemeName = "default" | "modern" | "minimal" | "rounded" | "retro";
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Themes are implemented as CSS classes applied to the root element:
|
|
123
|
+
|
|
124
|
+
- `calendar-theme-default`
|
|
125
|
+
- `calendar-theme-modern`
|
|
126
|
+
- `calendar-theme-minimal`
|
|
127
|
+
- `calendar-theme-rounded`
|
|
128
|
+
- `calendar-theme-retro`
|
|
129
|
+
|
|
130
|
+
Pass a custom theme as an object:
|
|
131
|
+
|
|
132
|
+
```tsx
|
|
133
|
+
const myTheme: ReactTheme = { className: "my-calendar" };
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### `ReactTheme`
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
interface ReactTheme {
|
|
140
|
+
className: string;
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### `THEMES` / `resolveTheme(theme?)`
|
|
145
|
+
|
|
146
|
+
Predefined theme map and resolver.
|
|
147
|
+
|
|
148
|
+
## Color Schemes
|
|
149
|
+
|
|
150
|
+
### `ColorSchemeName`
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
type ColorSchemeName =
|
|
154
|
+
| "default" | "ocean" | "forest" | "sunset"
|
|
155
|
+
| "mono" | "midnight" | "blossom";
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### `ReactColorScheme`
|
|
159
|
+
|
|
160
|
+
A color scheme is a map of `--cal-*` CSS custom properties:
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
type ReactColorScheme = Record<`--cal-${string}`, string>;
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Available variables:
|
|
167
|
+
|
|
168
|
+
| Variable | Purpose |
|
|
169
|
+
| :--- | :--- |
|
|
170
|
+
| `--cal-bg` | Background |
|
|
171
|
+
| `--cal-fg` | Foreground |
|
|
172
|
+
| `--cal-accent` | Accent (highlight) |
|
|
173
|
+
| `--cal-weekend-fg` | Weekend foreground |
|
|
174
|
+
| `--cal-border` | Borders |
|
|
175
|
+
| `--cal-header-bg` | Header background |
|
|
176
|
+
| `--cal-highlight-bg` | Highlight background |
|
|
177
|
+
| `--cal-highlight-fg` | Highlight foreground |
|
|
178
|
+
| `--cal-range-bg` | Range background |
|
|
179
|
+
| `--cal-today-bg` | Today background |
|
|
180
|
+
| `--cal-today-fg` | Today foreground |
|
|
181
|
+
|
|
182
|
+
Pass a custom scheme directly:
|
|
183
|
+
|
|
184
|
+
```tsx
|
|
185
|
+
const myScheme: ReactColorScheme = {
|
|
186
|
+
"--cal-bg": "#ffffff",
|
|
187
|
+
"--cal-fg": "#1e293b",
|
|
188
|
+
"--cal-accent": "#6366f1",
|
|
189
|
+
// ...all keys required
|
|
190
|
+
};
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### `COLOR_SCHEMES` / `resolveColorScheme(scheme?)`
|
|
194
|
+
|
|
195
|
+
Predefined schemes and resolver.
|
|
196
|
+
|
|
197
|
+
## Sizing
|
|
198
|
+
|
|
199
|
+
### `CalendarSize`
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
type CalendarSizeName = "sm" | "md" | "lg";
|
|
203
|
+
type CalendarCustomSize = {
|
|
204
|
+
width?: number | string;
|
|
205
|
+
height?: number | string;
|
|
206
|
+
};
|
|
207
|
+
type CalendarSize = CalendarSizeName | CalendarCustomSize;
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Use preset sizes (`"sm" | "md" | "lg"`):
|
|
211
|
+
|
|
212
|
+
```tsx
|
|
213
|
+
<Calendar year={2026} month={9} size="lg" />
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Or custom pixel sizes:
|
|
217
|
+
|
|
218
|
+
```tsx
|
|
219
|
+
<Calendar
|
|
220
|
+
year={2026}
|
|
221
|
+
month={9}
|
|
222
|
+
size={{ width: 48, height: 40 }}
|
|
223
|
+
/>
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Numbers are treated as pixels; strings pass through as CSS lengths (`"3rem"`, `"2.5em"`, etc.).
|
|
227
|
+
|
|
228
|
+
## Styling with `style`
|
|
229
|
+
|
|
230
|
+
The `style` prop can override any CSS variable or add custom styles:
|
|
231
|
+
|
|
232
|
+
```tsx
|
|
233
|
+
<Calendar
|
|
234
|
+
year={2026}
|
|
235
|
+
month={9}
|
|
236
|
+
style={{ "--cal-accent": "#8b5cf6", borderRadius: "1rem" } as React.CSSProperties}
|
|
237
|
+
/>
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## Cell Classes
|
|
241
|
+
|
|
242
|
+
Each day cell gets semantic classes you can target with CSS:
|
|
243
|
+
|
|
244
|
+
| Class | When |
|
|
245
|
+
| :--- | :--- |
|
|
246
|
+
| `is-weekend` | Saturday or Sunday |
|
|
247
|
+
| `is-today` | Matches `today` |
|
|
248
|
+
| `is-highlight` | Matches `highlight` |
|
|
249
|
+
| `is-in-range` | Inside `range` |
|
|
250
|
+
|
|
251
|
+
## Exports
|
|
252
|
+
|
|
253
|
+
```ts
|
|
254
|
+
import Calendar, {
|
|
255
|
+
Calendar,
|
|
256
|
+
COLOR_SCHEMES,
|
|
257
|
+
resolveColorScheme,
|
|
258
|
+
resolveTheme,
|
|
259
|
+
THEMES,
|
|
260
|
+
useCalendarState,
|
|
261
|
+
} from "@typescript-calendar-lib/react";
|
|
262
|
+
|
|
263
|
+
import type {
|
|
264
|
+
CalendarCustomSize,
|
|
265
|
+
CalendarProps,
|
|
266
|
+
CalendarSize,
|
|
267
|
+
CalendarSizeName,
|
|
268
|
+
ColorSchemeName,
|
|
269
|
+
ReactColorScheme,
|
|
270
|
+
ReactTheme,
|
|
271
|
+
ThemeName,
|
|
272
|
+
UseCalendarStateOptions,
|
|
273
|
+
UseCalendarStateReturn,
|
|
274
|
+
} from "@typescript-calendar-lib/react";
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## License
|
|
278
|
+
|
|
279
|
+
MIT
|
|
@@ -1,29 +1,24 @@
|
|
|
1
|
-
/* ─── Base ─────────────────────────────────────────────── */
|
|
2
|
-
|
|
3
1
|
.calendar {
|
|
4
|
-
--cal-bg: #
|
|
2
|
+
--cal-bg: #fff;
|
|
5
3
|
--cal-fg: #1e293b;
|
|
6
4
|
--cal-accent: #dc2626;
|
|
7
5
|
--cal-weekend-fg: #94a3b8;
|
|
8
6
|
--cal-border: #e2e8f0;
|
|
9
7
|
--cal-header-bg: #f8fafc;
|
|
10
8
|
--cal-highlight-bg: #dc2626;
|
|
11
|
-
--cal-highlight-fg: #
|
|
9
|
+
--cal-highlight-fg: #fff;
|
|
12
10
|
--cal-range-bg: #fef3c7;
|
|
13
11
|
--cal-today-bg: #fff7ed;
|
|
14
12
|
--cal-today-fg: #c2410c;
|
|
15
|
-
|
|
16
|
-
/* セルサイズ(size propや style の CSS 変数で上書きできる) */
|
|
17
13
|
--cal-cell-w: 2.25rem;
|
|
18
14
|
--cal-cell-h: 2rem;
|
|
19
|
-
--cal-font-size:
|
|
15
|
+
--cal-font-size: .875rem;
|
|
20
16
|
--cal-header-font-size: 1.125rem;
|
|
21
|
-
|
|
22
|
-
display: inline-block;
|
|
23
|
-
padding: 0.75rem 1rem;
|
|
24
17
|
background: var(--cal-bg);
|
|
25
18
|
color: var(--cal-fg);
|
|
19
|
+
padding: .75rem 1rem;
|
|
26
20
|
font-family: ui-sans-serif, system-ui, sans-serif;
|
|
21
|
+
display: inline-block;
|
|
27
22
|
}
|
|
28
23
|
|
|
29
24
|
.calendar table {
|
|
@@ -32,13 +27,12 @@
|
|
|
32
27
|
font-variant-numeric: tabular-nums;
|
|
33
28
|
}
|
|
34
29
|
|
|
35
|
-
.calendar th,
|
|
36
|
-
.calendar td {
|
|
30
|
+
.calendar th, .calendar td {
|
|
37
31
|
width: var(--cal-cell-w);
|
|
38
32
|
height: var(--cal-cell-h);
|
|
39
|
-
padding: 0.125rem 0.375rem;
|
|
40
33
|
text-align: center;
|
|
41
34
|
font-size: var(--cal-font-size);
|
|
35
|
+
padding: .125rem .375rem;
|
|
42
36
|
}
|
|
43
37
|
|
|
44
38
|
.calendar th {
|
|
@@ -48,15 +42,15 @@
|
|
|
48
42
|
|
|
49
43
|
.calendar .calendar-header {
|
|
50
44
|
text-align: center;
|
|
51
|
-
margin-bottom:
|
|
45
|
+
margin-bottom: .5rem;
|
|
52
46
|
font-size: 1rem;
|
|
53
47
|
}
|
|
54
48
|
|
|
55
49
|
.calendar .calendar-header h2 {
|
|
56
|
-
margin: 0;
|
|
57
50
|
font-size: var(--cal-header-font-size);
|
|
58
|
-
font-weight: 700;
|
|
59
51
|
color: var(--cal-fg);
|
|
52
|
+
margin: 0;
|
|
53
|
+
font-weight: 700;
|
|
60
54
|
}
|
|
61
55
|
|
|
62
56
|
.calendar td.is-weekend {
|
|
@@ -72,20 +66,18 @@
|
|
|
72
66
|
.calendar td.is-highlight {
|
|
73
67
|
background: var(--cal-highlight-bg);
|
|
74
68
|
color: var(--cal-highlight-fg);
|
|
69
|
+
border-radius: .375rem;
|
|
75
70
|
font-weight: 700;
|
|
76
|
-
border-radius: 0.375rem;
|
|
77
71
|
}
|
|
78
72
|
|
|
79
73
|
.calendar td.is-in-range {
|
|
80
74
|
background: var(--cal-range-bg);
|
|
81
75
|
}
|
|
82
76
|
|
|
83
|
-
/* ─── Size ────────────────────────────────────────────── */
|
|
84
|
-
|
|
85
77
|
.calendar-size-sm {
|
|
86
78
|
--cal-cell-w: 1.75rem;
|
|
87
79
|
--cal-cell-h: 1.5rem;
|
|
88
|
-
--cal-font-size:
|
|
80
|
+
--cal-font-size: .75rem;
|
|
89
81
|
}
|
|
90
82
|
|
|
91
83
|
.calendar-size-lg {
|
|
@@ -95,8 +87,6 @@
|
|
|
95
87
|
--cal-header-font-size: 1.25rem;
|
|
96
88
|
}
|
|
97
89
|
|
|
98
|
-
/* ─── Theme: default ───────────────────────────────────── */
|
|
99
|
-
|
|
100
90
|
.calendar-theme-default table {
|
|
101
91
|
border: 1px solid var(--cal-border);
|
|
102
92
|
}
|
|
@@ -113,26 +103,22 @@
|
|
|
113
103
|
border-radius: 0;
|
|
114
104
|
}
|
|
115
105
|
|
|
116
|
-
/* ─── Theme: modern ────────────────────────────────────── */
|
|
117
|
-
|
|
118
106
|
.calendar-theme-modern {
|
|
119
107
|
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);
|
|
108
|
+
box-shadow: 0 1px 3px #0000001a, 0 8px 24px #00000014;
|
|
123
109
|
}
|
|
124
110
|
|
|
125
111
|
.calendar-theme-modern .calendar-header {
|
|
126
112
|
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
113
|
border-bottom: 1px solid var(--cal-border);
|
|
114
|
+
border-radius: 1rem 1rem 0 0;
|
|
115
|
+
margin: -.75rem -1rem .75rem;
|
|
116
|
+
padding: .75rem 1rem;
|
|
131
117
|
}
|
|
132
118
|
|
|
133
119
|
.calendar-theme-modern table {
|
|
134
120
|
border: 1px solid var(--cal-border);
|
|
135
|
-
border-radius:
|
|
121
|
+
border-radius: .5rem;
|
|
136
122
|
overflow: hidden;
|
|
137
123
|
}
|
|
138
124
|
|
|
@@ -146,26 +132,24 @@
|
|
|
146
132
|
}
|
|
147
133
|
|
|
148
134
|
.calendar-theme-modern td:empty {
|
|
149
|
-
|
|
150
|
-
|
|
135
|
+
background: none;
|
|
136
|
+
border-color: #0000;
|
|
151
137
|
}
|
|
152
138
|
|
|
153
139
|
.calendar-theme-modern td.is-today {
|
|
154
|
-
border-radius:
|
|
140
|
+
border-radius: .375rem;
|
|
155
141
|
}
|
|
156
142
|
|
|
157
143
|
.calendar-theme-modern td.is-highlight {
|
|
158
|
-
box-shadow: 0 1px 2px
|
|
144
|
+
box-shadow: 0 1px 2px #00000026;
|
|
159
145
|
}
|
|
160
146
|
|
|
161
|
-
/* ─── Theme: minimal ───────────────────────────────────── */
|
|
162
|
-
|
|
163
147
|
.calendar-theme-minimal {
|
|
164
|
-
padding:
|
|
148
|
+
padding: .5rem;
|
|
165
149
|
}
|
|
166
150
|
|
|
167
151
|
.calendar-theme-minimal .calendar-header {
|
|
168
|
-
margin-bottom:
|
|
152
|
+
margin-bottom: .25rem;
|
|
169
153
|
}
|
|
170
154
|
|
|
171
155
|
.calendar-theme-minimal table {
|
|
@@ -181,42 +165,31 @@
|
|
|
181
165
|
}
|
|
182
166
|
|
|
183
167
|
.calendar-theme-minimal td.is-highlight {
|
|
184
|
-
border-radius:
|
|
168
|
+
border-radius: .25rem;
|
|
185
169
|
}
|
|
186
170
|
|
|
187
|
-
/* ─── Theme: rounded ───────────────────────────────────── */
|
|
188
|
-
|
|
189
171
|
.calendar-theme-rounded {
|
|
190
172
|
border-radius: 1rem;
|
|
191
173
|
}
|
|
192
174
|
|
|
193
175
|
.calendar-theme-rounded table {
|
|
194
176
|
border-collapse: separate;
|
|
195
|
-
border-spacing:
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
.calendar-theme-rounded th {
|
|
199
|
-
border: 0;
|
|
200
|
-
border-radius: 999px;
|
|
177
|
+
border-spacing: .25rem;
|
|
201
178
|
}
|
|
202
179
|
|
|
203
|
-
.calendar-theme-rounded td {
|
|
180
|
+
.calendar-theme-rounded th, .calendar-theme-rounded td {
|
|
204
181
|
border: 0;
|
|
205
182
|
border-radius: 999px;
|
|
206
183
|
}
|
|
207
184
|
|
|
208
|
-
.calendar-theme-rounded td.is-today,
|
|
209
|
-
.calendar-theme-rounded td.is-highlight,
|
|
210
|
-
.calendar-theme-rounded td.is-in-range {
|
|
185
|
+
.calendar-theme-rounded td.is-today, .calendar-theme-rounded td.is-highlight, .calendar-theme-rounded td.is-in-range {
|
|
211
186
|
border-radius: 999px;
|
|
212
187
|
}
|
|
213
188
|
|
|
214
189
|
.calendar-theme-rounded td:empty {
|
|
215
|
-
background:
|
|
190
|
+
background: none;
|
|
216
191
|
}
|
|
217
192
|
|
|
218
|
-
/* ─── Interactive ──────────────────────────────────────── */
|
|
219
|
-
|
|
220
193
|
.calendar-interactive {
|
|
221
194
|
outline: none;
|
|
222
195
|
}
|
|
@@ -226,23 +199,20 @@
|
|
|
226
199
|
}
|
|
227
200
|
|
|
228
201
|
.calendar-interactive td button.calendar-day-btn {
|
|
229
|
-
display: block;
|
|
230
202
|
width: 100%;
|
|
231
203
|
height: 100%;
|
|
232
|
-
margin: 0;
|
|
233
|
-
padding: 0;
|
|
234
|
-
border: 0;
|
|
235
|
-
background: transparent;
|
|
236
204
|
color: inherit;
|
|
237
205
|
font: inherit;
|
|
238
206
|
line-height: inherit;
|
|
239
207
|
text-align: center;
|
|
240
208
|
border-radius: inherit;
|
|
241
209
|
cursor: pointer;
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
210
|
+
background: none;
|
|
211
|
+
border: 0;
|
|
212
|
+
margin: 0;
|
|
213
|
+
padding: 0;
|
|
214
|
+
transition: background-color .15s, color .15s, transform .1s;
|
|
215
|
+
display: block;
|
|
246
216
|
}
|
|
247
217
|
|
|
248
218
|
.calendar-interactive td button.calendar-day-btn:hover {
|
|
@@ -255,24 +225,22 @@
|
|
|
255
225
|
}
|
|
256
226
|
|
|
257
227
|
.calendar-interactive td button.calendar-day-btn:active {
|
|
258
|
-
transform: scale(
|
|
228
|
+
transform: scale(.95);
|
|
259
229
|
}
|
|
260
230
|
|
|
261
|
-
/* ─── Theme: retro ─────────────────────────────────────── */
|
|
262
|
-
|
|
263
231
|
.calendar-theme-retro {
|
|
264
|
-
padding: 0.75rem;
|
|
265
232
|
border: 2px solid var(--cal-fg);
|
|
266
233
|
border-radius: 0;
|
|
234
|
+
padding: .75rem;
|
|
267
235
|
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
268
236
|
}
|
|
269
237
|
|
|
270
238
|
.calendar-theme-retro .calendar-header {
|
|
271
239
|
background: var(--cal-header-bg);
|
|
272
240
|
border-bottom: 3px double var(--cal-fg);
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
241
|
+
letter-spacing: .05em;
|
|
242
|
+
margin: -.75rem -.75rem .75rem;
|
|
243
|
+
padding: .5rem .75rem;
|
|
276
244
|
}
|
|
277
245
|
|
|
278
246
|
.calendar-theme-retro table {
|
|
@@ -290,7 +258,6 @@
|
|
|
290
258
|
border-radius: 0;
|
|
291
259
|
}
|
|
292
260
|
|
|
293
|
-
.calendar-theme-retro td.is-highlight,
|
|
294
|
-
.calendar-theme-retro td.is-today {
|
|
261
|
+
.calendar-theme-retro td.is-highlight, .calendar-theme-retro td.is-today {
|
|
295
262
|
border-radius: 0;
|
|
296
263
|
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { CalendarOptions } from "@typescript-calendar-lib/core";
|
|
2
|
+
import { CalendarState, CalendarStateOptions, Direction } from "@typescript-calendar-lib/tui";
|
|
3
|
+
import { CSSProperties } from "react";
|
|
4
|
+
//#region src/size.d.ts
|
|
5
|
+
/** 組み込みサイズ名 */
|
|
6
|
+
type CalendarSizeName = "sm" | "md" | "lg";
|
|
7
|
+
/** カスタムセルサイズ。数値は px、文字列は CSS 長さのまま渡す */
|
|
8
|
+
interface CalendarCustomSize {
|
|
9
|
+
width?: number | string;
|
|
10
|
+
height?: number | string;
|
|
11
|
+
}
|
|
12
|
+
/** セルサイズ指定 */
|
|
13
|
+
type CalendarSize = CalendarSizeName | CalendarCustomSize;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/themes.d.ts
|
|
16
|
+
/** 組み込みテーマ名。カスタムテーマは ReactTheme オブジェクトを直接渡せる */
|
|
17
|
+
type ThemeName = "default" | "modern" | "minimal" | "rounded" | "retro";
|
|
18
|
+
/** React の見た目定義。テーマは主に CSS クラスで切り替える */
|
|
19
|
+
interface ReactTheme {
|
|
20
|
+
/** root 要素に追加するクラス */
|
|
21
|
+
className: string;
|
|
22
|
+
}
|
|
23
|
+
export declare const THEMES: Record<ThemeName, ReactTheme>;
|
|
24
|
+
export declare function resolveTheme(theme?: ThemeName | ReactTheme): ReactTheme;
|
|
25
|
+
/** 組み込みカラースキーム名。カスタムは CSS 変数マップを直接渡せる */
|
|
26
|
+
type ColorSchemeName = "default" | "ocean" | "forest" | "sunset" | "mono" | "midnight" | "blossom";
|
|
27
|
+
/** CSS カスタムプロパティ(--cal-*)の値マップ */
|
|
28
|
+
type ReactColorScheme = Record<`--cal-${string}`, string>;
|
|
29
|
+
export declare const COLOR_SCHEMES: Record<ColorSchemeName, ReactColorScheme>;
|
|
30
|
+
export declare function resolveColorScheme(scheme?: ColorSchemeName | ReactColorScheme): ReactColorScheme;
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/hooks.d.ts
|
|
33
|
+
interface UseCalendarStateOptions extends Pick<CalendarStateOptions, "locale" | "weekStart" | "today" | "highlight" | "range"> {
|
|
34
|
+
initialYear?: number;
|
|
35
|
+
initialMonth?: number;
|
|
36
|
+
}
|
|
37
|
+
interface UseCalendarStateReturn {
|
|
38
|
+
/** 現在のカレンダー状態 */
|
|
39
|
+
state: CalendarState;
|
|
40
|
+
/** カーソルを指定方向に移動 (wrap around) */
|
|
41
|
+
moveCursor: (direction: Direction) => void;
|
|
42
|
+
/** 前月/翌月へ移動 */
|
|
43
|
+
goNext: () => void;
|
|
44
|
+
goPrev: () => void;
|
|
45
|
+
/** 今日の月へジャンプ */
|
|
46
|
+
goToday: () => void;
|
|
47
|
+
/** カーソル位置の日付を選択 */
|
|
48
|
+
selectDate: () => void;
|
|
49
|
+
/** 選択を解除 */
|
|
50
|
+
clearSelection: () => void;
|
|
51
|
+
/** カーソル位置の日付(null の場合あり) */
|
|
52
|
+
cursorDate: Date | null;
|
|
53
|
+
/** 選択済み日付(null の場合あり) */
|
|
54
|
+
selectedDate: Date | null;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* tui の不変状態マシンを包む React hook。
|
|
58
|
+
* カレンダーのインタラクティブ操作をシンプルに利用できる。
|
|
59
|
+
*
|
|
60
|
+
* `options` の値(locale / weekStart / today / highlight / range /
|
|
61
|
+
* initialYear / initialMonth)が変わると、カーソル・選択を保ったまま
|
|
62
|
+
* 状態が再構築される。比較は値(Date は getTime)で行うため、インラインで
|
|
63
|
+
* オプションを渡しても値が同じなら再構築されない。
|
|
64
|
+
*
|
|
65
|
+
* `today` を省略した場合、最初に解決された値が状態に固定され、以降も
|
|
66
|
+
* 引き継がれる(毎レンダリング `new Date()` を渡さなくてよい)。
|
|
67
|
+
*/
|
|
68
|
+
export declare function useCalendarState(options?: UseCalendarStateOptions): UseCalendarStateReturn;
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/index.d.ts
|
|
71
|
+
export interface CalendarProps {
|
|
72
|
+
year: number;
|
|
73
|
+
month: number;
|
|
74
|
+
locale?: CalendarOptions["locale"];
|
|
75
|
+
weekStart?: CalendarOptions["weekStart"];
|
|
76
|
+
highlight?: Date;
|
|
77
|
+
/** 範囲強調 */
|
|
78
|
+
range?: {
|
|
79
|
+
from: Date;
|
|
80
|
+
to: Date;
|
|
81
|
+
};
|
|
82
|
+
/** 今日の基準日。カラースキームの today 着色に使用 */
|
|
83
|
+
today?: Date;
|
|
84
|
+
/** 見た目テーマ。既定は "default" */
|
|
85
|
+
theme?: ThemeName | ReactTheme;
|
|
86
|
+
/** カラースキーム。既定は "default" */
|
|
87
|
+
colorScheme?: ColorSchemeName | ReactColorScheme;
|
|
88
|
+
/** セルサイズ。既定は "md"。{ width, height } で自由に指定できる */
|
|
89
|
+
size?: CalendarSize;
|
|
90
|
+
/** root 要素に追加するスタイル。CSS変数(--cal-*)で自由に上書きできる */
|
|
91
|
+
style?: CSSProperties;
|
|
92
|
+
/** インタラクティブモードを有効にする。セルクリック・ホバー・キーボード選択が可能になる */
|
|
93
|
+
interactive?: boolean;
|
|
94
|
+
/** セルクリック時のコールバック */
|
|
95
|
+
onDateClick?: (date: Date) => void;
|
|
96
|
+
/** セルホバー時のコールバック */
|
|
97
|
+
onDateHover?: (date: Date) => void;
|
|
98
|
+
}
|
|
99
|
+
/** 月カレンダーコンポーネント */
|
|
100
|
+
export declare function Calendar({ year, month, locale, weekStart, highlight, range, today, theme, colorScheme, size, style, interactive, onDateClick, onDateHover }: CalendarProps): import("react").JSX.Element;
|
|
101
|
+
//#endregion
|
|
102
|
+
export { Calendar as default, type CalendarCustomSize, type CalendarSize, type CalendarSizeName, type ColorSchemeName, type ReactColorScheme, type ReactTheme, type ThemeName, type UseCalendarStateOptions, type UseCalendarStateReturn };
|
|
103
|
+
//# sourceMappingURL=index.d.ts.map
|