@molecule/app-class-schedule-react 1.0.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 ADDED
@@ -0,0 +1,115 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work.
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship.
43
+
44
+ "Contribution" shall mean any work of authorship, including the
45
+ original version of the Work and any modifications or additions
46
+ to that Work, that is intentionally submitted to the Licensor for
47
+ inclusion in the Work by the copyright owner or by an individual or
48
+ Legal Entity authorized to submit on behalf of the copyright owner.
49
+
50
+ "Contributor" shall mean Licensor and any individual or Legal Entity
51
+ on behalf of whom a Contribution has been received by the Licensor and
52
+ subsequently incorporated within the Work.
53
+
54
+ 2. Grant of Copyright License. Subject to the terms and conditions of
55
+ this License, each Contributor hereby grants to You a perpetual,
56
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
57
+ copyright license to reproduce, prepare Derivative Works of,
58
+ publicly display, publicly perform, sublicense, and distribute the
59
+ Work and such Derivative Works in Source or Object form.
60
+
61
+ 3. Grant of Patent License. Subject to the terms and conditions of
62
+ this License, each Contributor hereby grants to You a perpetual,
63
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
64
+ patent license to make, have made, use, offer to sell, sell, import,
65
+ and otherwise transfer the Work.
66
+
67
+ 4. Redistribution. You may reproduce and distribute copies of the
68
+ Work or Derivative Works thereof in any medium, with or without
69
+ modifications, and in Source or Object form, provided that You
70
+ meet the following conditions:
71
+
72
+ (a) You must give any other recipients of the Work or
73
+ Derivative Works a copy of this License; and
74
+
75
+ (b) You must cause any modified files to carry prominent notices
76
+ stating that You changed the files; and
77
+
78
+ (c) You must retain, in the Source form of any Derivative Works
79
+ that You distribute, all copyright, patent, trademark, and
80
+ attribution notices from the Source form of the Work,
81
+ excluding those notices that do not pertain to any part of
82
+ the Derivative Works; and
83
+
84
+ (d) If the Work includes a "NOTICE" text file as part of its
85
+ distribution, then any Derivative Works that You distribute must
86
+ include a readable copy of the attribution notices contained
87
+ within such NOTICE file.
88
+
89
+ 5. Submission of Contributions.
90
+
91
+ 6. Trademarks. This License does not grant permission to use the trade
92
+ names, trademarks, service marks, or product names of the Licensor.
93
+
94
+ 7. Disclaimer of Warranty. Unless required by applicable law or
95
+ agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
96
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
97
+
98
+ 8. Limitation of Liability. In no event and under no legal theory shall
99
+ any Contributor be liable to You for damages.
100
+
101
+ 9. Accepting Warranty or Additional Liability.
102
+
103
+ Copyright 2026 Molecule Dev, Inc.
104
+
105
+ Licensed under the Apache License, Version 2.0 (the "License");
106
+ you may not use this file except in compliance with the License.
107
+ You may obtain a copy of the License at
108
+
109
+ http://www.apache.org/licenses/LICENSE-2.0
110
+
111
+ Unless required by applicable law or agreed to in writing, software
112
+ distributed under the License is distributed on an "AS IS" BASIS,
113
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
114
+ See the License for the specific language governing permissions and
115
+ limitations under the License.
@@ -0,0 +1,103 @@
1
+ import type { ReactElement, ReactNode } from 'react';
2
+ /**
3
+ * A single event on the weekly schedule grid.
4
+ *
5
+ * `start` and `end` are minute offsets from midnight (`0`–`1440`). For
6
+ * example a class running 09:00–10:30 is `{ start: 540, end: 630 }`.
7
+ */
8
+ export interface ScheduleEvent {
9
+ /** Stable identifier (used as React key + passed to click handlers). */
10
+ id: string;
11
+ /** ISO weekday: `0` = Sunday, `1` = Monday … `6` = Saturday. */
12
+ weekday: 0 | 1 | 2 | 3 | 4 | 5 | 6;
13
+ /** Start time in minutes from midnight (e.g. `540` = 09:00). */
14
+ start: number;
15
+ /** End time in minutes from midnight (e.g. `630` = 10:30). */
16
+ end: number;
17
+ /** Primary label rendered inside the event tile. */
18
+ title: ReactNode;
19
+ /** Secondary line — typically room or location. */
20
+ subtitle?: ReactNode;
21
+ /** Tertiary line — typically teacher or instructor. */
22
+ meta?: ReactNode;
23
+ /** Optional accent color applied as a left border on the tile. */
24
+ accentColor?: string;
25
+ }
26
+ /**
27
+ * Empty-slot click payload — `weekday` plus the start of the clicked hour
28
+ * (in minutes from midnight, snapped down to the row).
29
+ */
30
+ export interface ScheduleSlot {
31
+ weekday: 0 | 1 | 2 | 3 | 4 | 5 | 6;
32
+ /** Hour-of-day boundary in minutes (e.g. `540` for the 09:00 row). */
33
+ start: number;
34
+ }
35
+ /** Props for the {@link ClassSchedule} weekly timetable component. */
36
+ export interface ClassScheduleProps {
37
+ /** Events to render. */
38
+ events: ScheduleEvent[];
39
+ /** First day-of-week (`0` = Sunday, `1` = Monday). Defaults to `1`. */
40
+ weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
41
+ /** Visible hour range as `[startHour, endHour]` in 24-hour clock. Defaults to `[8, 18]`. */
42
+ dayHours?: [number, number];
43
+ /** Pixel height of one hour row. Defaults to `60`. */
44
+ cellHeight?: number;
45
+ /** Whether to show Saturday + Sunday columns. Defaults to `true`. */
46
+ showWeekendCols?: boolean;
47
+ /** Locale for weekday name formatting (passes through to `Intl.DateTimeFormat`). */
48
+ locale?: string;
49
+ /** Called when an event tile is clicked. */
50
+ onEventClick?: (event: ScheduleEvent) => void;
51
+ /** Called when an empty grid cell is clicked. */
52
+ onSlotClick?: (slot: ScheduleSlot) => void;
53
+ /** Extra classes for the root container. */
54
+ className?: string;
55
+ }
56
+ /**
57
+ * Format a minute-of-day value (0–1440) as `HH:MM` 24-hour clock.
58
+ *
59
+ * @param minutes - Minutes from midnight.
60
+ * @returns Zero-padded `HH:MM` string.
61
+ */
62
+ export declare function formatHourLabel(minutes: number): string;
63
+ /**
64
+ * Lay out events that share a weekday into non-overlapping side-by-side
65
+ * lanes. Each event gets a `lane` index (0…N) and a `lanes` count for the
66
+ * group it belongs to so the caller can compute width/left as
67
+ * `width = (1/lanes) * 100%` / `left = (lane/lanes) * 100%`.
68
+ *
69
+ * @param events - Events occurring on a single weekday.
70
+ * @returns Array of `{ event, lane, lanes }` records, in input order.
71
+ */
72
+ export declare function assignLanes<E extends {
73
+ start: number;
74
+ end: number;
75
+ }>(events: E[]): Array<{
76
+ event: E;
77
+ lane: number;
78
+ lanes: number;
79
+ }>;
80
+ /**
81
+ * Weekly class-schedule grid. Renders a 7-column (or 5-column when
82
+ * `showWeekendCols` is `false`) timetable with hour rows down the left
83
+ * and absolutely positioned event tiles inside each day column. Events
84
+ * that overlap on the same weekday are split into side-by-side lanes.
85
+ *
86
+ * Suitable for school timetables, virtual-classroom schedules, gym
87
+ * class calendars, conference tracks, or any weekly recurring time
88
+ * grid.
89
+ *
90
+ * @param props - Component props.
91
+ * @param props.events - Events to render.
92
+ * @param props.weekStartsOn - First day-of-week (`0` Sun, `1` Mon).
93
+ * @param props.dayHours - Visible hour range `[start, end]`.
94
+ * @param props.cellHeight - Pixel height per hour row.
95
+ * @param props.showWeekendCols - Hide Sat + Sun when `false`.
96
+ * @param props.locale - Locale for weekday names.
97
+ * @param props.onEventClick - Click handler for event tiles.
98
+ * @param props.onSlotClick - Click handler for empty grid cells.
99
+ * @param props.className - Extra classes for the root container.
100
+ * @returns The rendered schedule grid.
101
+ */
102
+ export declare function ClassSchedule({ events, weekStartsOn, dayHours, cellHeight, showWeekendCols, locale, onEventClick, onSlotClick, className, }: ClassScheduleProps): ReactElement;
103
+ //# sourceMappingURL=ClassSchedule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClassSchedule.d.ts","sourceRoot":"","sources":["../src/ClassSchedule.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAKpD;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,wEAAwE;IACxE,EAAE,EAAE,MAAM,CAAA;IACV,gEAAgE;IAChE,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAClC,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAA;IACb,8DAA8D;IAC9D,GAAG,EAAE,MAAM,CAAA;IACX,oDAAoD;IACpD,KAAK,EAAE,SAAS,CAAA;IAChB,mDAAmD;IACnD,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,uDAAuD;IACvD,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,kEAAkE;IAClE,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAClC,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAA;CACd;AAED,sEAAsE;AACtE,MAAM,WAAW,kBAAkB;IACjC,wBAAwB;IACxB,MAAM,EAAE,aAAa,EAAE,CAAA;IACvB,uEAAuE;IACvE,YAAY,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACxC,4FAA4F;IAC5F,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC3B,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,qEAAqE;IACrE,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,oFAAoF;IACpF,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,4CAA4C;IAC5C,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAA;IAC7C,iDAAiD;IACjD,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,IAAI,CAAA;IAC1C,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAKD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAIvD;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EAClE,MAAM,EAAE,CAAC,EAAE,GACV,KAAK,CAAC;IAAE,KAAK,EAAE,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAgClD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,YAAgB,EAChB,QAAkB,EAClB,UAAe,EACf,eAAsB,EACtB,MAAM,EACN,YAAY,EACZ,WAAW,EACX,SAAS,GACV,EAAE,kBAAkB,GAAG,YAAY,CA4NnC"}
@@ -0,0 +1,175 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useTranslation } from '@molecule/app-react';
3
+ import { getClassMap } from '@molecule/app-ui';
4
+ const MINUTES_PER_HOUR = 60;
5
+ const WEEKEND_DAYS = new Set([0, 6]);
6
+ /**
7
+ * Format a minute-of-day value (0–1440) as `HH:MM` 24-hour clock.
8
+ *
9
+ * @param minutes - Minutes from midnight.
10
+ * @returns Zero-padded `HH:MM` string.
11
+ */
12
+ export function formatHourLabel(minutes) {
13
+ const h = Math.floor(minutes / MINUTES_PER_HOUR);
14
+ const m = minutes % MINUTES_PER_HOUR;
15
+ return `${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}`;
16
+ }
17
+ /**
18
+ * Lay out events that share a weekday into non-overlapping side-by-side
19
+ * lanes. Each event gets a `lane` index (0…N) and a `lanes` count for the
20
+ * group it belongs to so the caller can compute width/left as
21
+ * `width = (1/lanes) * 100%` / `left = (lane/lanes) * 100%`.
22
+ *
23
+ * @param events - Events occurring on a single weekday.
24
+ * @returns Array of `{ event, lane, lanes }` records, in input order.
25
+ */
26
+ export function assignLanes(events) {
27
+ const sorted = events
28
+ .map((event, originalIndex) => ({ event, originalIndex }))
29
+ .sort((a, b) => a.event.start - b.event.start || a.event.end - b.event.end);
30
+ const groups = [];
31
+ let current = [];
32
+ let currentMaxEnd = -Infinity;
33
+ for (const { event, originalIndex } of sorted) {
34
+ if (event.start >= currentMaxEnd && current.length > 0) {
35
+ groups.push(current);
36
+ current = [];
37
+ currentMaxEnd = -Infinity;
38
+ }
39
+ // Find lowest free lane in `current`.
40
+ const taken = new Set(current.filter((a) => a.event.end > event.start).map((a) => a.lane));
41
+ let lane = 0;
42
+ while (taken.has(lane))
43
+ lane++;
44
+ current.push({ event, lane, originalIndex });
45
+ if (event.end > currentMaxEnd)
46
+ currentMaxEnd = event.end;
47
+ }
48
+ if (current.length > 0)
49
+ groups.push(current);
50
+ const result = [];
51
+ for (const group of groups) {
52
+ const lanes = group.reduce((max, a) => Math.max(max, a.lane + 1), 1);
53
+ for (const a of group)
54
+ result.push({ ...a, lanes });
55
+ }
56
+ result.sort((a, b) => a.originalIndex - b.originalIndex);
57
+ return result.map(({ event, lane, lanes }) => ({ event, lane, lanes }));
58
+ }
59
+ /**
60
+ * Weekly class-schedule grid. Renders a 7-column (or 5-column when
61
+ * `showWeekendCols` is `false`) timetable with hour rows down the left
62
+ * and absolutely positioned event tiles inside each day column. Events
63
+ * that overlap on the same weekday are split into side-by-side lanes.
64
+ *
65
+ * Suitable for school timetables, virtual-classroom schedules, gym
66
+ * class calendars, conference tracks, or any weekly recurring time
67
+ * grid.
68
+ *
69
+ * @param props - Component props.
70
+ * @param props.events - Events to render.
71
+ * @param props.weekStartsOn - First day-of-week (`0` Sun, `1` Mon).
72
+ * @param props.dayHours - Visible hour range `[start, end]`.
73
+ * @param props.cellHeight - Pixel height per hour row.
74
+ * @param props.showWeekendCols - Hide Sat + Sun when `false`.
75
+ * @param props.locale - Locale for weekday names.
76
+ * @param props.onEventClick - Click handler for event tiles.
77
+ * @param props.onSlotClick - Click handler for empty grid cells.
78
+ * @param props.className - Extra classes for the root container.
79
+ * @returns The rendered schedule grid.
80
+ */
81
+ export function ClassSchedule({ events, weekStartsOn = 1, dayHours = [8, 18], cellHeight = 60, showWeekendCols = true, locale, onEventClick, onSlotClick, className, }) {
82
+ const cm = getClassMap();
83
+ const { t } = useTranslation();
84
+ const [startHour, endHour] = dayHours;
85
+ const safeStart = Math.max(0, Math.min(23, Math.floor(startHour)));
86
+ const safeEnd = Math.max(safeStart + 1, Math.min(24, Math.floor(endHour)));
87
+ const startMinutes = safeStart * MINUTES_PER_HOUR;
88
+ const endMinutes = safeEnd * MINUTES_PER_HOUR;
89
+ const totalMinutes = endMinutes - startMinutes;
90
+ const hourCount = safeEnd - safeStart;
91
+ // Column ordering: rotate weekdays so `weekStartsOn` is first.
92
+ const allWeekdays = [0, 1, 2, 3, 4, 5, 6];
93
+ const rotated = [
94
+ ...allWeekdays.slice(weekStartsOn),
95
+ ...allWeekdays.slice(0, weekStartsOn),
96
+ ];
97
+ const visibleWeekdays = showWeekendCols ? rotated : rotated.filter((d) => !WEEKEND_DAYS.has(d));
98
+ // Localized weekday header. Use a known reference Sunday (1970-01-04 was a Sunday)
99
+ // so each weekday number maps to a real Date the formatter can render.
100
+ const weekdayFmt = new Intl.DateTimeFormat(locale, { weekday: 'short' });
101
+ /**
102
+ * Returns the localized short weekday name for a given ISO weekday number.
103
+ *
104
+ * @param weekday - ISO weekday number (0 = Sunday … 6 = Saturday).
105
+ * @returns Localized short weekday name, e.g. `"Mon"`.
106
+ */
107
+ function weekdayLabel(weekday) {
108
+ // 1970-01-04 = Sunday → add `weekday` days to get the right name.
109
+ return weekdayFmt.format(new Date(Date.UTC(1970, 0, 4 + weekday)));
110
+ }
111
+ // Group events by weekday + run lane assignment per day.
112
+ const eventsByDay = new Map();
113
+ for (const event of events) {
114
+ if (!visibleWeekdays.includes(event.weekday))
115
+ continue;
116
+ const list = eventsByDay.get(event.weekday) ?? [];
117
+ list.push(event);
118
+ eventsByDay.set(event.weekday, list);
119
+ }
120
+ const totalHeightPx = hourCount * cellHeight;
121
+ return (_jsx("div", { className: cm.cn(className), "data-mol-id": "class-schedule", role: "grid", "aria-label": t('classSchedule.aria.region', {}, { defaultValue: 'Weekly class schedule' }), children: _jsxs("div", { className: cm.cn(cm.grid({ cols: visibleWeekdays.length + 1, gap: 'none' })), style: {
122
+ gridTemplateColumns: `auto repeat(${visibleWeekdays.length}, minmax(0, 1fr))`,
123
+ }, children: [_jsx("div", { className: cm.cn(cm.textSize('xs'), cm.fontWeight('semibold'), cm.sp('p', 2)), "aria-hidden": "true" }), visibleWeekdays.map((weekday) => (_jsx("div", { role: "columnheader", "data-mol-id": "class-schedule-day-header", "data-weekday": weekday, className: cm.cn(cm.textSize('xs'), cm.fontWeight('semibold'), cm.textCenter, cm.sp('p', 2)), children: weekdayLabel(weekday) }, `head-${weekday}`))), _jsx("div", { "data-mol-id": "class-schedule-time-axis", className: cm.cn(cm.position('relative')), style: { height: `${totalHeightPx}px` }, children: Array.from({ length: hourCount }).map((_, i) => {
124
+ const hourMinutes = startMinutes + i * MINUTES_PER_HOUR;
125
+ return (_jsx("div", { "data-mol-id": "class-schedule-hour-label", className: cm.cn(cm.textSize('xs'), cm.sp('px', 2)), style: {
126
+ position: 'absolute',
127
+ top: `${i * cellHeight}px`,
128
+ height: `${cellHeight}px`,
129
+ right: 0,
130
+ left: 0,
131
+ textAlign: 'right',
132
+ }, children: formatHourLabel(hourMinutes) }, `hour-${i}`));
133
+ }) }), visibleWeekdays.map((weekday) => {
134
+ const dayEvents = eventsByDay.get(weekday) ?? [];
135
+ const laned = assignLanes(dayEvents);
136
+ return (_jsxs("div", { role: "presentation", "data-mol-id": "class-schedule-day-column", "data-weekday": weekday, className: cm.cn(cm.position('relative')), style: { height: `${totalHeightPx}px` }, children: [Array.from({ length: hourCount }).map((_, i) => {
137
+ const slotStart = startMinutes + i * MINUTES_PER_HOUR;
138
+ return (_jsx("button", { type: "button", "data-mol-id": "class-schedule-slot", "data-weekday": weekday, "data-start": slotStart, "aria-label": t('classSchedule.aria.slot', { weekday: weekdayLabel(weekday), time: formatHourLabel(slotStart) }, { defaultValue: 'Empty slot, {{weekday}} {{time}}' }), onClick: () => onSlotClick?.({ weekday, start: slotStart }), style: {
139
+ position: 'absolute',
140
+ top: `${i * cellHeight}px`,
141
+ left: 0,
142
+ right: 0,
143
+ height: `${cellHeight}px`,
144
+ background: 'transparent',
145
+ border: 0,
146
+ padding: 0,
147
+ cursor: onSlotClick ? 'pointer' : 'default',
148
+ } }, `slot-${weekday}-${i}`));
149
+ }), laned.map(({ event, lane, lanes }) => {
150
+ const eventStart = Math.max(event.start, startMinutes);
151
+ const eventEnd = Math.min(event.end, endMinutes);
152
+ if (eventEnd <= eventStart)
153
+ return null;
154
+ const topPx = ((eventStart - startMinutes) / totalMinutes) * totalHeightPx;
155
+ const heightPx = ((eventEnd - eventStart) / totalMinutes) * totalHeightPx;
156
+ const leftPct = (lane / lanes) * 100;
157
+ const widthPct = (1 / lanes) * 100;
158
+ return (_jsxs("button", { type: "button", "data-mol-id": "class-schedule-event", "data-event-id": event.id, "aria-label": t('classSchedule.aria.event', {
159
+ weekday: weekdayLabel(weekday),
160
+ start: formatHourLabel(event.start),
161
+ end: formatHourLabel(event.end),
162
+ }, { defaultValue: '{{weekday}} {{start}} – {{end}}' }), onClick: () => onEventClick?.(event), className: cm.cn(cm.flex({ direction: 'col', align: 'start' }), cm.sp('p', 1), cm.textSize('xs'), cm.fontWeight('semibold')), style: {
163
+ position: 'absolute',
164
+ top: `${topPx}px`,
165
+ height: `${heightPx}px`,
166
+ left: `calc(${leftPct}% + 2px)`,
167
+ width: `calc(${widthPct}% - 4px)`,
168
+ overflow: 'hidden',
169
+ textAlign: 'left',
170
+ cursor: onEventClick ? 'pointer' : 'default',
171
+ borderLeft: event.accentColor ? `3px solid ${event.accentColor}` : undefined,
172
+ }, children: [_jsx("span", { "data-mol-id": "class-schedule-event-title", children: event.title }), event.subtitle && (_jsx("span", { "data-mol-id": "class-schedule-event-subtitle", className: cm.cn(cm.textSize('xs'), cm.fontWeight('normal')), children: event.subtitle })), event.meta && (_jsx("span", { "data-mol-id": "class-schedule-event-meta", className: cm.cn(cm.textSize('xs'), cm.fontWeight('normal')), children: event.meta }))] }, event.id));
173
+ })] }, `col-${weekday}`));
174
+ })] }) }));
175
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Weekly class-schedule grid.
3
+ *
4
+ * Renders a 7-day × N-hour time grid with absolutely positioned event
5
+ * tiles inside each day column. Overlapping events on the same weekday
6
+ * are split into side-by-side lanes. Click handlers fire separately for
7
+ * event tiles and empty time slots.
8
+ *
9
+ * Designed for school timetables, virtual classroom schedules, gym /
10
+ * studio class calendars, conference tracks, and any other weekly
11
+ * recurring time-of-day grid.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * import { ClassSchedule } from '@molecule/app-class-schedule-react'
16
+ *
17
+ * <ClassSchedule
18
+ * events={[
19
+ * { id: 'math', weekday: 1, start: 9 * 60, end: 10 * 60, title: 'Math 101', subtitle: 'Room 4B' },
20
+ * { id: 'eng', weekday: 3, start: 11 * 60, end: 12 * 60, title: 'English', subtitle: 'Room 12' },
21
+ * ]}
22
+ * onEventClick={(e) => console.log('clicked', e.id)}
23
+ * onSlotClick={(s) => console.log('empty slot', s)}
24
+ * />
25
+ * ```
26
+ *
27
+ * @remarks
28
+ * Pair with `@molecule/app-locales-class-schedule` for translations
29
+ * in 79 languages. All styling routes through `getClassMap()`; all
30
+ * user-facing text routes through `t()`.
31
+ *
32
+ * @module
33
+ */
34
+ export * from './ClassSchedule.js';
35
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,cAAc,oBAAoB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Weekly class-schedule grid.
3
+ *
4
+ * Renders a 7-day × N-hour time grid with absolutely positioned event
5
+ * tiles inside each day column. Overlapping events on the same weekday
6
+ * are split into side-by-side lanes. Click handlers fire separately for
7
+ * event tiles and empty time slots.
8
+ *
9
+ * Designed for school timetables, virtual classroom schedules, gym /
10
+ * studio class calendars, conference tracks, and any other weekly
11
+ * recurring time-of-day grid.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * import { ClassSchedule } from '@molecule/app-class-schedule-react'
16
+ *
17
+ * <ClassSchedule
18
+ * events={[
19
+ * { id: 'math', weekday: 1, start: 9 * 60, end: 10 * 60, title: 'Math 101', subtitle: 'Room 4B' },
20
+ * { id: 'eng', weekday: 3, start: 11 * 60, end: 12 * 60, title: 'English', subtitle: 'Room 12' },
21
+ * ]}
22
+ * onEventClick={(e) => console.log('clicked', e.id)}
23
+ * onSlotClick={(s) => console.log('empty slot', s)}
24
+ * />
25
+ * ```
26
+ *
27
+ * @remarks
28
+ * Pair with `@molecule/app-locales-class-schedule` for translations
29
+ * in 79 languages. All styling routes through `getClassMap()`; all
30
+ * user-facing text routes through `t()`.
31
+ *
32
+ * @module
33
+ */
34
+ export * from './ClassSchedule.js';
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@molecule/app-class-schedule-react",
3
+ "version": "1.0.0",
4
+ "description": "Weekly class-schedule grid — 7-day × N-hour time grid with absolutely positioned events, click-event vs click-empty-slot dispatch, side-by-side stacking for overlaps",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "test": "vitest run",
11
+ "test:watch": "vitest"
12
+ },
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "keywords": [
23
+ "molecule",
24
+ "class-schedule",
25
+ "weekly-schedule",
26
+ "timetable",
27
+ "react"
28
+ ],
29
+ "license": "Apache-2.0",
30
+ "peerDependencies": {
31
+ "@molecule/app-react": "^1.0.0",
32
+ "@molecule/app-ui": "^1.0.0",
33
+ "react": "^18.0.0 || ^19.0.0"
34
+ },
35
+ "devDependencies": {
36
+ "@molecule/app-i18n": "1.0.0",
37
+ "@molecule/app-react": "1.0.0",
38
+ "@molecule/app-ui": "1.0.0",
39
+ "@testing-library/react": "16.3.2",
40
+ "@types/node": "26.1.2",
41
+ "@types/react": "19.2.17",
42
+ "jsdom": "30.0.1",
43
+ "react": "19.2.8",
44
+ "react-dom": "19.2.8",
45
+ "typescript": "6.0.3",
46
+ "vitest": "4.1.10"
47
+ }
48
+ }