@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/package.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
2
  "name": "@super-calendar/solid",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "2.17.0",
4
+ "description": "Solid 2 calendar and date picker with virtualized views, keyboard navigation, and pointer gestures.",
5
+ "keywords": [
6
+ "calendar",
7
+ "date-picker",
8
+ "solid",
9
+ "solidjs"
10
+ ],
11
+ "homepage": "https://super-calendar.afonsojramos.me",
12
+ "bugs": {
13
+ "url": "https://github.com/afonsojramos/super-calendar/issues"
14
+ },
15
+ "license": "MIT",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/afonsojramos/super-calendar.git",
19
+ "directory": "packages/solid"
20
+ },
21
+ "source": "./src/index.ts",
22
+ "files": [
23
+ "dist",
24
+ "src",
25
+ "!**/__tests__"
26
+ ],
27
+ "type": "module",
28
+ "sideEffects": false,
29
+ "main": "./dist/server/index.js",
30
+ "module": "./dist/client/index.js",
31
+ "types": "./dist/client/index.d.ts",
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/client/index.d.ts",
35
+ "solid": "./src/index.ts",
36
+ "browser": "./dist/client/index.js",
37
+ "default": "./dist/server/index.js"
38
+ },
39
+ "./package.json": "./package.json"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "dependencies": {
45
+ "@super-calendar/core": "^2.17.0",
46
+ "csstype": "^3.1.0"
47
+ },
48
+ "devDependencies": {
49
+ "@solidjs/babel-plugin": "2.0.0-rc.20",
50
+ "@solidjs/web": "2.0.0-rc.20",
51
+ "solid-js": "2.0.0-rc.20"
52
+ },
53
+ "peerDependencies": {
54
+ "@solidjs/web": "2.0.0-rc.20",
55
+ "date-fns": ">=3",
56
+ "solid-js": "2.0.0-rc.20"
57
+ },
58
+ "scripts": {
59
+ "build": "node scripts/build.mjs",
60
+ "typecheck": "tsc --noEmit -p tsconfig.json"
61
+ }
6
62
  }
package/src/Agenda.tsx ADDED
@@ -0,0 +1,296 @@
1
+ import { Dynamic, type JSX } from "@solidjs/web";
2
+ import type { CalendarEvent, EventAccessibilityLabeler } from "@super-calendar/core/vanilla";
3
+ import {
4
+ eventTimeLabel,
5
+ getIsToday,
6
+ isAllDayEvent,
7
+ isBackgroundEvent,
8
+ } from "@super-calendar/core/vanilla";
9
+ import { format, isSameDay, type Locale, startOfDay } from "date-fns";
10
+ import { type Component, createMemo, Show } from "solid-js";
11
+ import { withDefaults } from "./props";
12
+ import { createSlots, type ResolvedSlot, type SlotStyleProps } from "./slots";
13
+ import { css, type CSSProperties } from "./styles";
14
+ import { mergeSolidTheme, type SolidCalendarTheme } from "./theme";
15
+ import { VirtualList } from "./VirtualList";
16
+
17
+ /**
18
+ * Styleable parts of {@link Agenda}. Pass a class or inline style per slot via the
19
+ * `classNames` / `styles` props.
20
+ */
21
+ export type AgendaSlot = "dayHeader" | "eventRow" | "event" | "empty";
22
+
23
+ /** Props passed to a custom agenda (schedule) event renderer. */
24
+ export interface SolidAgendaEventArgs<T = unknown> {
25
+ /** The event to render. */
26
+ event: CalendarEvent<T>;
27
+ /** Always "schedule"; lets a renderer shared with other views branch on it. */
28
+ mode: "schedule";
29
+ /** Whether the event is all-day. */
30
+ isAllDay: boolean;
31
+ /** Render the time range in 12-hour AM/PM. */
32
+ ampm?: boolean;
33
+ /** Call to fire the view's `onPressEvent` for this row. */
34
+ onPress: () => void;
35
+ }
36
+
37
+ /** A component that renders a single agenda (schedule) event row. */
38
+ export type SolidAgendaEvent<T = unknown> = Component<SolidAgendaEventArgs<T>>;
39
+
40
+ /** Props for {@link Agenda}. */
41
+ export interface AgendaProps<T = unknown> extends SlotStyleProps<AgendaSlot> {
42
+ /** Events to list. The consumer controls which (and therefore the date range). */
43
+ events: CalendarEvent<T>[];
44
+ /** date-fns locale for the day headers and time labels. */
45
+ locale?: Locale;
46
+ /** Render times in 12-hour AM/PM (default false, 24h). */
47
+ ampm?: boolean;
48
+ /** Highlight this date's header instead of the real "today". */
49
+ activeDate?: Date;
50
+ /** Theme overrides; falls back to the default light theme. */
51
+ theme?: Partial<SolidCalendarTheme>;
52
+ /** Height of the scroll viewport, in px (default 480). */
53
+ height?: number | string;
54
+ /** Replace the built-in event row. */
55
+ renderEvent?: SolidAgendaEvent<T>;
56
+ /**
57
+ * Override the screen-reader label for each event row. Receives the event and a
58
+ * `{ mode: "schedule", isAllDay, ampm }` context; return the full text to
59
+ * announce. Defaults to the row's own text content.
60
+ */
61
+ eventAccessibilityLabel?: EventAccessibilityLabeler<T>;
62
+ /** Tap an event row. */
63
+ onPressEvent?: (event: CalendarEvent<T>) => void;
64
+ /** Tap a day's header. */
65
+ onPressDay?: (date: Date) => void;
66
+ /** Class applied to the root element. */
67
+ className?: string;
68
+ /** Inline styles applied to the root element. */
69
+ style?: CSSProperties;
70
+ }
71
+ type Row<T> =
72
+ | {
73
+ kind: "header";
74
+ date: Date;
75
+ key: string;
76
+ }
77
+ | {
78
+ kind: "event";
79
+ event: CalendarEvent<T>;
80
+ key: string;
81
+ };
82
+ function DefaultAgendaRow<T>(
83
+ incoming: SolidAgendaEventArgs<T> & {
84
+ cardProps: ResolvedSlot;
85
+ },
86
+ ) {
87
+ const props = withDefaults(
88
+ {
89
+ ampm: false,
90
+ } satisfies Partial<
91
+ SolidAgendaEventArgs<T> & {
92
+ cardProps: ResolvedSlot;
93
+ }
94
+ >,
95
+ incoming,
96
+ );
97
+ const time = createMemo(
98
+ () =>
99
+ eventTimeLabel({
100
+ mode: "schedule",
101
+ isAllDay: props.isAllDay,
102
+ start: props.event.start,
103
+ end: props.event.end,
104
+ ampm: props.ampm,
105
+ showTime: true,
106
+ }) ?? "",
107
+ );
108
+ // A filled card with the title on top and the time below, matching the native
109
+ // schedule row.
110
+ return (
111
+ <div {...props.cardProps}>
112
+ <div
113
+ style={css({
114
+ fontWeight: 600,
115
+ fontSize: 14,
116
+ })}
117
+ >
118
+ {props.event.title}
119
+ </div>
120
+ {time() ? (
121
+ <div
122
+ style={css({
123
+ fontSize: 13,
124
+ opacity: 0.75,
125
+ })}
126
+ >
127
+ {time()}
128
+ </div>
129
+ ) : null}
130
+ </div>
131
+ );
132
+ }
133
+
134
+ /**
135
+ * A vertical, day-grouped list of events: the schedule view, with plain DOM
136
+ * elements. Events are sorted by start and grouped under a date header per day;
137
+ * the consumer controls which events (and therefore which dates) are shown. The
138
+ * Solid agenda with measured, virtualized rows.
139
+ *
140
+ * @example
141
+ * ```tsx
142
+ * <Agenda events={events} onPressEvent={(e) => console.log(e.title)} />
143
+ * ```
144
+ */
145
+ export function Agenda<T = unknown>(incoming: AgendaProps<T>): JSX.Element {
146
+ const props = withDefaults(
147
+ {
148
+ ampm: false,
149
+ height: 480,
150
+ } satisfies Partial<AgendaProps<T>>,
151
+ incoming,
152
+ );
153
+ const theme = createMemo(() => mergeSolidTheme(props.theme));
154
+ const slot = createSlots<AgendaSlot>(props);
155
+ const Renderer = createMemo(() => props.renderEvent);
156
+ const rows = createMemo<Row<T>[]>(() => {
157
+ const sorted = props.events // Background events shade the grids; they have no agenda row.
158
+ .filter((event) => !isBackgroundEvent(event))
159
+ .sort((a, b) => a.start.getTime() - b.start.getTime());
160
+ const out: Row<T>[] = [];
161
+ let currentDay: Date | null = null;
162
+ sorted.forEach((event, index) => {
163
+ if (!currentDay || !isSameDay(event.start, currentDay)) {
164
+ currentDay = startOfDay(event.start);
165
+ out.push({
166
+ kind: "header",
167
+ date: currentDay,
168
+ key: `h-${currentDay.toISOString()}`,
169
+ });
170
+ }
171
+ out.push({
172
+ kind: "event",
173
+ event,
174
+ key: `e-${event.start.toISOString()}-${index}`,
175
+ });
176
+ });
177
+ return out;
178
+ });
179
+ const Header = (row: { date: Date }): JSX.Element => {
180
+ const highlighted = createMemo(() =>
181
+ props.activeDate ? isSameDay(row.date, props.activeDate) : getIsToday(row.date),
182
+ );
183
+ const label = createMemo(() => format(row.date, "EEEE, d LLLL", { locale: props.locale }));
184
+ const headerProps = createMemo(() =>
185
+ slot("dayHeader", {
186
+ base: props.onPressDay
187
+ ? {
188
+ display: "block",
189
+ width: "100%",
190
+ border: "none",
191
+ background: "transparent",
192
+ cursor: "pointer",
193
+ font: "inherit",
194
+ textAlign: "left",
195
+ }
196
+ : { display: "block", width: "100%" },
197
+ themed: {
198
+ padding: "12px 12px 4px",
199
+ fontSize: 13,
200
+ fontWeight: 600,
201
+ color: highlighted() ? theme().todayBackground : theme().textMuted,
202
+ },
203
+ }),
204
+ );
205
+ return (
206
+ <Show when={!!props.onPressDay} fallback={<div {...headerProps()}>{label()}</div>}>
207
+ <button type="button" onClick={() => props.onPressDay?.(row.date)} {...headerProps()}>
208
+ {label()}
209
+ </button>
210
+ </Show>
211
+ );
212
+ };
213
+ const EventRow = (row: { event: CalendarEvent<T> }): JSX.Element => {
214
+ const args = createMemo<SolidAgendaEventArgs<T>>(() => ({
215
+ event: row.event,
216
+ mode: "schedule",
217
+ isAllDay: isAllDayEvent(row.event),
218
+ ampm: props.ampm,
219
+ onPress: () => props.onPressEvent?.(row.event),
220
+ }));
221
+ return (
222
+ <button
223
+ type="button"
224
+ onClick={() => props.onPressEvent?.(row.event)}
225
+ aria-label={props.eventAccessibilityLabel?.(row.event, {
226
+ mode: "schedule",
227
+ isAllDay: isAllDayEvent(row.event),
228
+ ampm: props.ampm,
229
+ })}
230
+ {...slot("eventRow", {
231
+ base: {
232
+ display: "block",
233
+ width: "100%",
234
+ textAlign: "left",
235
+ border: "none",
236
+ background: "transparent",
237
+ cursor: "pointer",
238
+ font: "inherit",
239
+ },
240
+ themed: { padding: "2px 12px" },
241
+ })}
242
+ >
243
+ <Show
244
+ when={Renderer()}
245
+ fallback={
246
+ <DefaultAgendaRow
247
+ {...args()}
248
+ cardProps={slot("event", {
249
+ themed: {
250
+ padding: "6px 10px",
251
+ borderRadius: 8,
252
+ background: theme().eventBackground,
253
+ color: theme().eventText,
254
+ },
255
+ })}
256
+ />
257
+ }
258
+ >
259
+ <Dynamic component={Renderer()} {...args()} />
260
+ </Show>
261
+ </button>
262
+ );
263
+ };
264
+ return (
265
+ <div
266
+ class={props.className}
267
+ style={css({ fontFamily: theme().fontFamily, color: theme().text, ...props.style })}
268
+ >
269
+ <VirtualList
270
+ data={rows()}
271
+ keyExtractor={(row: Row<T>) => row.key}
272
+ estimatedItemSize={44}
273
+ style={css({ height: props.height, overflowY: "auto" })}
274
+ renderItem={(row) => {
275
+ const header = createMemo(() => (row.item.kind === "header" ? row.item : undefined));
276
+ const event = createMemo(() => (row.item.kind === "event" ? row.item.event : undefined));
277
+ return (
278
+ <>
279
+ <Show when={header()}>{(value) => <Header date={value().date} />}</Show>
280
+ <Show when={event()}>{(value) => <EventRow event={value()} />}</Show>
281
+ </>
282
+ );
283
+ }}
284
+ />
285
+ <Show when={rows().length === 0}>
286
+ <div
287
+ {...slot("empty", {
288
+ themed: { padding: "16px 12px", color: theme().textMuted, fontSize: 14 },
289
+ })}
290
+ >
291
+ No events
292
+ </div>
293
+ </Show>
294
+ </div>
295
+ );
296
+ }