@super-calendar/solid 0.0.0-stage → 2.17.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 +311 -2
- package/dist/client/index.d.ts +1119 -0
- package/dist/client/index.js +7051 -0
- package/dist/server/index.d.ts +1119 -0
- package/dist/server/index.js +8527 -0
- package/package.json +59 -3
- package/src/Agenda.tsx +296 -0
- package/src/Calendar.tsx +645 -0
- package/src/DateRangePicker.tsx +405 -0
- package/src/EventActions.tsx +497 -0
- package/src/MonthList.tsx +233 -0
- package/src/MonthView.tsx +1936 -0
- package/src/MultiWeekView.tsx +49 -0
- package/src/ResourceTimeline.tsx +1748 -0
- package/src/TimeGrid.tsx +2833 -0
- package/src/VirtualList.tsx +119 -0
- package/src/YearView.tsx +652 -0
- package/src/createEventSource.ts +76 -0
- package/src/index.ts +113 -0
- package/src/props.ts +24 -0
- package/src/slots.ts +91 -0
- package/src/state.ts +62 -0
- package/src/styles.ts +68 -0
- package/src/theme.ts +44 -0
- package/src/touch.ts +131 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { type JSX } from "@solidjs/web";
|
|
2
|
+
import type { CalendarLabels } from "@super-calendar/core/vanilla";
|
|
3
|
+
import {
|
|
4
|
+
buildMonthGrid,
|
|
5
|
+
type CalendarEvent,
|
|
6
|
+
compareDayEvents,
|
|
7
|
+
type DateRange,
|
|
8
|
+
type DateSelectionConstraints,
|
|
9
|
+
type EventAccessibilityLabeler,
|
|
10
|
+
groupEventsByDay,
|
|
11
|
+
isBackgroundEvent,
|
|
12
|
+
type WeekdayFormat,
|
|
13
|
+
type WeekStartsOn,
|
|
14
|
+
} from "@super-calendar/core/vanilla";
|
|
15
|
+
import { addMonths, type Locale, startOfMonth } from "date-fns";
|
|
16
|
+
import { createMemo, For } from "solid-js";
|
|
17
|
+
import { MonthView, type MonthViewSlot, type SolidMonthEvent } from "./MonthView";
|
|
18
|
+
import { withDefaults } from "./props";
|
|
19
|
+
import { createSlots, type SlotStyleProps } from "./slots";
|
|
20
|
+
import { css, type CSSProperties } from "./styles";
|
|
21
|
+
import { mergeSolidTheme, type SolidCalendarTheme } from "./theme";
|
|
22
|
+
import { VirtualList } from "./VirtualList";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Styleable parts of {@link MonthList}. The shared weekday header uses `weekdays`
|
|
26
|
+
* / `weekday`; every other slot is forwarded to each month's {@link MonthView}
|
|
27
|
+
* (e.g. `title`, `day`, `chip`). See {@link MonthViewSlot}.
|
|
28
|
+
*/
|
|
29
|
+
export type MonthListSlot = MonthViewSlot;
|
|
30
|
+
|
|
31
|
+
/** Props for {@link MonthList}. */
|
|
32
|
+
export interface MonthListProps<T = unknown>
|
|
33
|
+
extends DateSelectionConstraints, SlotStyleProps<MonthListSlot> {
|
|
34
|
+
/** Anchor month; the list spans `pastMonths` before to `futureMonths` after. */
|
|
35
|
+
date: Date;
|
|
36
|
+
/** Months to render before the anchor (default 1). */
|
|
37
|
+
pastMonths?: number;
|
|
38
|
+
/** Months to render after the anchor (default 12). */
|
|
39
|
+
futureMonths?: number;
|
|
40
|
+
/** First day of the week. Sunday = 0 (default) ... Saturday = 6. */
|
|
41
|
+
weekStartsOn?: WeekStartsOn;
|
|
42
|
+
/** Weekday header label width: `narrow` ("M"), `short` ("Mon", default), or `long` ("Monday"). */
|
|
43
|
+
weekdayFormat?: WeekdayFormat;
|
|
44
|
+
/** Tint weekend day cells with the theme's weekend background (default true). */
|
|
45
|
+
highlightWeekends?: boolean;
|
|
46
|
+
/** Events to render as chips in each day cell (calendar layout when provided). */
|
|
47
|
+
events?: CalendarEvent<T>[];
|
|
48
|
+
/** Custom chip renderer; falls back to the built-in titled chip. */
|
|
49
|
+
renderEvent?: SolidMonthEvent<T>;
|
|
50
|
+
/**
|
|
51
|
+
* Override the screen-reader label for each event chip. Receives the event and a
|
|
52
|
+
* `{ mode: "month", isAllDay, ampm: false }` context; return the full text to
|
|
53
|
+
* announce. Defaults to the event title and day (e.g. "Standup, 15 July").
|
|
54
|
+
*/
|
|
55
|
+
eventAccessibilityLabel?: EventAccessibilityLabeler<T>;
|
|
56
|
+
/** Max chips shown per day before a "+N more" row (default 3). */
|
|
57
|
+
maxVisibleEventCount?: number;
|
|
58
|
+
/** Month chip height in pixels; omit to keep the renderer default. */
|
|
59
|
+
chipHeight?: number;
|
|
60
|
+
/** Gap between month chip rows in pixels (default 2). */
|
|
61
|
+
chipGap?: number;
|
|
62
|
+
/** Template for the overflow row; `{moreCount}` is replaced. */
|
|
63
|
+
moreLabel?: string;
|
|
64
|
+
/** Translations for the screen-reader words and gutter text; omitted keys use English. */
|
|
65
|
+
labels?: Partial<CalendarLabels>;
|
|
66
|
+
/** Tap an event chip. */
|
|
67
|
+
onPressEvent?: (event: CalendarEvent<T>) => void;
|
|
68
|
+
/** Tap the "+N more" overflow row. */
|
|
69
|
+
onPressMore?: (events: CalendarEvent<T>[], date: Date) => void;
|
|
70
|
+
/** Selected span; days between the endpoints get the range band. */
|
|
71
|
+
selectedRange?: DateRange;
|
|
72
|
+
/** Discrete selected days (single / multiple). */
|
|
73
|
+
selectedDates?: Date[];
|
|
74
|
+
/** Fill the whole cell on selection instead of the default rounded pill band. */
|
|
75
|
+
fillCellOnSelection?: boolean;
|
|
76
|
+
/** date-fns locale for the month titles and weekday labels. */
|
|
77
|
+
locale?: Locale;
|
|
78
|
+
/** Theme overrides; falls back to the default light theme. */
|
|
79
|
+
theme?: Partial<SolidCalendarTheme>;
|
|
80
|
+
/** Height of the scroll viewport, in px (default 480). */
|
|
81
|
+
height?: number | string;
|
|
82
|
+
/**
|
|
83
|
+
* When events are shown, make each month's day cells keyboard-navigable (roving
|
|
84
|
+
* tab stop, arrow keys, Enter to open the day). Default false. The picker
|
|
85
|
+
* layout (no `events`) is always navigable regardless.
|
|
86
|
+
*/
|
|
87
|
+
keyboardDayNavigation?: boolean;
|
|
88
|
+
/** Fired when a selectable day is clicked. */
|
|
89
|
+
onPressDay?: (date: Date) => void;
|
|
90
|
+
/** Class applied to the root element. */
|
|
91
|
+
className?: string;
|
|
92
|
+
/** Inline styles applied to the root element. */
|
|
93
|
+
style?: CSSProperties;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A vertically scrolling, virtualized list of months: the date picker. Built on
|
|
98
|
+
* measured row virtualization and the library's headless grid logic. Selection is
|
|
99
|
+
* controlled, pass `selectedRange` (or `selectedDates`) and handle `onPressDay`.
|
|
100
|
+
*/
|
|
101
|
+
export function MonthList<T = unknown>(incoming: MonthListProps<T>): JSX.Element {
|
|
102
|
+
const props = withDefaults(
|
|
103
|
+
{
|
|
104
|
+
pastMonths: 1,
|
|
105
|
+
futureMonths: 12,
|
|
106
|
+
weekdayFormat: "short",
|
|
107
|
+
highlightWeekends: true,
|
|
108
|
+
weekStartsOn: 0,
|
|
109
|
+
fillCellOnSelection: false,
|
|
110
|
+
height: 480,
|
|
111
|
+
} satisfies Partial<MonthListProps<T>>,
|
|
112
|
+
incoming,
|
|
113
|
+
);
|
|
114
|
+
const theme = createMemo(() => mergeSolidTheme(props.theme));
|
|
115
|
+
const slot = createSlots<MonthListSlot>(props);
|
|
116
|
+
const months = createMemo(() => {
|
|
117
|
+
const first = startOfMonth(addMonths(props.date, -props.pastMonths));
|
|
118
|
+
const count = props.pastMonths + props.futureMonths + 1;
|
|
119
|
+
return Array.from(
|
|
120
|
+
{
|
|
121
|
+
length: count,
|
|
122
|
+
},
|
|
123
|
+
(_, i) => addMonths(first, i),
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// The weekday header only depends on the week start and locale, not the
|
|
128
|
+
// rendered month window.
|
|
129
|
+
const weekdays = createMemo(
|
|
130
|
+
() =>
|
|
131
|
+
buildMonthGrid(props.date, {
|
|
132
|
+
weekStartsOn: props.weekStartsOn,
|
|
133
|
+
weekdayFormat: props.weekdayFormat,
|
|
134
|
+
locale: props.locale,
|
|
135
|
+
}).weekdays,
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
// Build the day→events index once for the whole list rather than per month.
|
|
139
|
+
const eventsByDay = createMemo(() => {
|
|
140
|
+
if (!props.events) return undefined;
|
|
141
|
+
// Background events shade the time grid; the month grids ignore them.
|
|
142
|
+
const map = groupEventsByDay(props.events.filter((event) => !isBackgroundEvent(event)));
|
|
143
|
+
// Each day reads all-day events first, then timed events by start.
|
|
144
|
+
for (const list of map.values()) list.sort(compareDayEvents);
|
|
145
|
+
return map;
|
|
146
|
+
});
|
|
147
|
+
return (
|
|
148
|
+
<div
|
|
149
|
+
class={props.className}
|
|
150
|
+
style={css({
|
|
151
|
+
fontFamily: theme().fontFamily,
|
|
152
|
+
color: theme().text,
|
|
153
|
+
...props.style,
|
|
154
|
+
})}
|
|
155
|
+
>
|
|
156
|
+
<div
|
|
157
|
+
{...slot("weekdays", {
|
|
158
|
+
base: {
|
|
159
|
+
display: "grid",
|
|
160
|
+
gridTemplateColumns: "repeat(7, minmax(0, 1fr))",
|
|
161
|
+
},
|
|
162
|
+
themed: {
|
|
163
|
+
borderBottom: `1px solid ${theme().gridLine}`,
|
|
164
|
+
padding: "8px 0",
|
|
165
|
+
},
|
|
166
|
+
})}
|
|
167
|
+
>
|
|
168
|
+
{
|
|
169
|
+
<For each={weekdays()} keyed={false}>
|
|
170
|
+
{(wd) => (
|
|
171
|
+
<span
|
|
172
|
+
{...slot("weekday", {
|
|
173
|
+
themed: {
|
|
174
|
+
textAlign: "center",
|
|
175
|
+
fontSize: 12,
|
|
176
|
+
fontWeight: 600,
|
|
177
|
+
color: theme().textMuted,
|
|
178
|
+
},
|
|
179
|
+
})}
|
|
180
|
+
>
|
|
181
|
+
{wd().label}
|
|
182
|
+
</span>
|
|
183
|
+
)}
|
|
184
|
+
</For>
|
|
185
|
+
}
|
|
186
|
+
</div>
|
|
187
|
+
<VirtualList
|
|
188
|
+
data={months()}
|
|
189
|
+
keyExtractor={(m: Date) => m.toISOString()}
|
|
190
|
+
estimatedItemSize={theme().cellHeight * 7 + 40}
|
|
191
|
+
// Open on the anchor month (today by default), not the first past month.
|
|
192
|
+
// `months` starts `pastMonths` before the anchor, so it sits at that index.
|
|
193
|
+
initialScrollIndex={props.pastMonths}
|
|
194
|
+
style={css({
|
|
195
|
+
height: props.height,
|
|
196
|
+
overflowY: "auto",
|
|
197
|
+
})}
|
|
198
|
+
renderItem={(row: { item: Date }) => (
|
|
199
|
+
<MonthView<T>
|
|
200
|
+
date={row.item}
|
|
201
|
+
weekStartsOn={props.weekStartsOn}
|
|
202
|
+
highlightWeekends={props.highlightWeekends}
|
|
203
|
+
events={props.events}
|
|
204
|
+
eventsByDay={eventsByDay()}
|
|
205
|
+
renderEvent={props.renderEvent}
|
|
206
|
+
eventAccessibilityLabel={props.eventAccessibilityLabel}
|
|
207
|
+
maxVisibleEventCount={props.maxVisibleEventCount}
|
|
208
|
+
chipHeight={props.chipHeight}
|
|
209
|
+
chipGap={props.chipGap}
|
|
210
|
+
moreLabel={props.moreLabel}
|
|
211
|
+
labels={props.labels}
|
|
212
|
+
onPressEvent={props.onPressEvent}
|
|
213
|
+
onPressMore={props.onPressMore}
|
|
214
|
+
selectedRange={props.selectedRange}
|
|
215
|
+
selectedDates={props.selectedDates}
|
|
216
|
+
fillCellOnSelection={props.fillCellOnSelection}
|
|
217
|
+
showAdjacentMonths={false}
|
|
218
|
+
showWeekdays={false}
|
|
219
|
+
locale={props.locale}
|
|
220
|
+
theme={props.theme}
|
|
221
|
+
minDate={props.minDate}
|
|
222
|
+
maxDate={props.maxDate}
|
|
223
|
+
isDateDisabled={props.isDateDisabled}
|
|
224
|
+
keyboardDayNavigation={props.keyboardDayNavigation}
|
|
225
|
+
onPressDay={props.onPressDay}
|
|
226
|
+
classNames={props.classNames}
|
|
227
|
+
styles={props.styles}
|
|
228
|
+
/>
|
|
229
|
+
)}
|
|
230
|
+
/>
|
|
231
|
+
</div>
|
|
232
|
+
);
|
|
233
|
+
}
|