@hydralms/components 0.1.0 → 0.1.2

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.
Files changed (159) hide show
  1. package/dist/components.css +1 -1
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.js +442 -110
  4. package/dist/modules/CoursePlayer/CoursePlayer.d.ts +2 -0
  5. package/dist/modules/CoursePlayer/types.d.ts +59 -0
  6. package/dist/modules/FlashcardLab/FlashcardLab.d.ts +2 -0
  7. package/dist/modules/FlashcardLab/types.d.ts +55 -0
  8. package/dist/modules/QuizModule/QuizModule.d.ts +2 -0
  9. package/dist/modules/QuizModule/types.d.ts +54 -0
  10. package/dist/modules/index.d.ts +6 -0
  11. package/dist/provider/HydraProvider.d.ts +1 -1
  12. package/dist/sections.cjs +1 -1
  13. package/dist/sections.js +261 -291
  14. package/dist/table-BrS5cDQu.js +2510 -0
  15. package/dist/table-D6AkBBEo.cjs +1 -0
  16. package/dist/ui/alert-dialog.d.ts +14 -8
  17. package/dist/ui/button.d.ts +1 -1
  18. package/dist/ui/tabs.d.ts +15 -5
  19. package/dist/ui/tooltip.d.ts +12 -5
  20. package/dist/video/index.d.ts +6 -1
  21. package/dist/video/types.d.ts +167 -0
  22. package/dist/video/video-bookmark.d.ts +2 -0
  23. package/dist/video/video-chapter-list.d.ts +2 -0
  24. package/dist/video/video-playlist-item.d.ts +2 -0
  25. package/dist/video/video-thumbnail-card.d.ts +2 -0
  26. package/dist/video/video-transcript.d.ts +2 -0
  27. package/package.json +135 -24
  28. package/src/__tests__/setup.ts +1 -0
  29. package/src/assessment-toolbar/assessment-toolbar.tsx +96 -0
  30. package/src/assessment-toolbar/index.ts +10 -0
  31. package/src/assessment-toolbar/question-navigator.tsx +86 -0
  32. package/src/assessment-toolbar/timer-display.tsx +73 -0
  33. package/src/assessment-toolbar/types.ts +92 -0
  34. package/src/assets/hydra-icon.png +0 -0
  35. package/src/assets/hydra-icon.svg +18 -0
  36. package/src/assets/hydra-lms-icon.png +0 -0
  37. package/src/assets/hydra-lms-icon.svg +9 -0
  38. package/src/common/confirm-dialog.tsx +60 -0
  39. package/src/common/due-date-display.tsx +64 -0
  40. package/src/common/empty-state.tsx +24 -0
  41. package/src/common/index.ts +12 -0
  42. package/src/common/search-input.tsx +68 -0
  43. package/src/common/status-badge.test.tsx +43 -0
  44. package/src/common/status-badge.tsx +81 -0
  45. package/src/common/types.ts +129 -0
  46. package/src/content/content-block.tsx +116 -0
  47. package/src/content/file-upload-zone.tsx +109 -0
  48. package/src/content/index.ts +7 -0
  49. package/src/content/types.ts +76 -0
  50. package/src/curriculum/curriculum-item.tsx +81 -0
  51. package/src/curriculum/curriculum-tree.tsx +69 -0
  52. package/src/curriculum/index.ts +11 -0
  53. package/src/curriculum/learning-object-icon.tsx +44 -0
  54. package/src/curriculum/types.ts +83 -0
  55. package/src/feedback/feedback-banner.tsx +46 -0
  56. package/src/feedback/index.ts +8 -0
  57. package/src/feedback/likert-scale.tsx +58 -0
  58. package/src/feedback/star-rating.tsx +65 -0
  59. package/src/feedback/types.ts +86 -0
  60. package/src/flashcards/flashcard-deck.tsx +130 -0
  61. package/src/flashcards/flashcard.tsx +108 -0
  62. package/src/flashcards/index.ts +3 -0
  63. package/src/flashcards/types.ts +60 -0
  64. package/src/index.ts +38 -0
  65. package/src/lib/utils.ts +6 -0
  66. package/src/modules/CoursePlayer/CoursePlayer.tsx +281 -0
  67. package/src/modules/CoursePlayer/types.ts +48 -0
  68. package/src/modules/FlashcardLab/FlashcardLab.tsx +275 -0
  69. package/src/modules/FlashcardLab/types.ts +58 -0
  70. package/src/modules/QuizModule/QuizModule.tsx +241 -0
  71. package/src/modules/QuizModule/types.ts +56 -0
  72. package/src/modules/index.ts +12 -0
  73. package/src/progress/grade-indicator.tsx +65 -0
  74. package/src/progress/index.ts +8 -0
  75. package/src/progress/progress-ring.tsx +56 -0
  76. package/src/progress/stat-card.tsx +42 -0
  77. package/src/progress/types.ts +73 -0
  78. package/src/provider/HydraProvider.tsx +26 -0
  79. package/src/provider/index.ts +2 -0
  80. package/src/questions/choice.tsx +90 -0
  81. package/src/questions/essay.tsx +59 -0
  82. package/src/questions/fill-in-the-blank.tsx +69 -0
  83. package/src/questions/index.ts +14 -0
  84. package/src/questions/multiple-choice.test.tsx +104 -0
  85. package/src/questions/multiple-choice.tsx +97 -0
  86. package/src/questions/question-renderer.tsx +37 -0
  87. package/src/questions/true-false.test.tsx +89 -0
  88. package/src/questions/true-false.tsx +90 -0
  89. package/src/questions/types.ts +53 -0
  90. package/src/sections/AnnouncementFeed/AnnouncementFeed.tsx +141 -0
  91. package/src/sections/AnnouncementFeed/types.ts +50 -0
  92. package/src/sections/AssessmentReview/AssessmentReview.tsx +148 -0
  93. package/src/sections/AssessmentReview/types.ts +61 -0
  94. package/src/sections/AssignmentSubmission/AssignmentSubmission.tsx +190 -0
  95. package/src/sections/AssignmentSubmission/types.ts +60 -0
  96. package/src/sections/CertificateViewer/CertificateViewer.tsx +117 -0
  97. package/src/sections/CertificateViewer/types.ts +45 -0
  98. package/src/sections/CourseOutline/CourseOutline.tsx +79 -0
  99. package/src/sections/CourseOutline/types.ts +53 -0
  100. package/src/sections/DiscussionThread/DiscussionThread.tsx +186 -0
  101. package/src/sections/DiscussionThread/types.ts +77 -0
  102. package/src/sections/ExamSession/ExamSession.tsx +182 -0
  103. package/src/sections/ExamSession/types.ts +64 -0
  104. package/src/sections/FlashcardStudySession/FlashcardStudySession.tsx +76 -0
  105. package/src/sections/FlashcardStudySession/types.ts +42 -0
  106. package/src/sections/GradebookTable/GradebookTable.tsx +229 -0
  107. package/src/sections/GradebookTable/types.ts +75 -0
  108. package/src/sections/LecturePlayer/LecturePlayer.tsx +60 -0
  109. package/src/sections/LecturePlayer/types.ts +48 -0
  110. package/src/sections/LessonPage/LessonPage.tsx +91 -0
  111. package/src/sections/LessonPage/types.ts +41 -0
  112. package/src/sections/PracticeQuiz/PracticeQuiz.tsx +199 -0
  113. package/src/sections/PracticeQuiz/types.ts +44 -0
  114. package/src/sections/ProgressDashboard/ProgressDashboard.tsx +140 -0
  115. package/src/sections/ProgressDashboard/types.ts +74 -0
  116. package/src/sections/QuizSession/QuizSession.tsx +113 -0
  117. package/src/sections/QuizSession/types.ts +47 -0
  118. package/src/sections/ResourceLibrary/ResourceLibrary.tsx +218 -0
  119. package/src/sections/ResourceLibrary/types.ts +57 -0
  120. package/src/sections/ScrollableQuiz/ScrollableQuiz.tsx +170 -0
  121. package/src/sections/ScrollableQuiz/types.ts +40 -0
  122. package/src/sections/SurveyForm/SurveyForm.tsx +180 -0
  123. package/src/sections/SurveyForm/types.ts +69 -0
  124. package/src/sections/index.ts +90 -0
  125. package/src/social/index.ts +3 -0
  126. package/src/social/post-card.tsx +91 -0
  127. package/src/social/types.ts +57 -0
  128. package/src/social/user-avatar.tsx +76 -0
  129. package/src/styles/globals.css +125 -0
  130. package/src/ui/alert-dialog.tsx +343 -0
  131. package/src/ui/alert.tsx +65 -0
  132. package/src/ui/avatar.tsx +52 -0
  133. package/src/ui/badge.tsx +53 -0
  134. package/src/ui/button.tsx +62 -0
  135. package/src/ui/card.tsx +92 -0
  136. package/src/ui/index.ts +44 -0
  137. package/src/ui/input.tsx +21 -0
  138. package/src/ui/progress.tsx +73 -0
  139. package/src/ui/separator.tsx +29 -0
  140. package/src/ui/skeleton.tsx +15 -0
  141. package/src/ui/slot.tsx +48 -0
  142. package/src/ui/table.tsx +108 -0
  143. package/src/ui/tabs.tsx +147 -0
  144. package/src/ui/textarea.tsx +20 -0
  145. package/src/ui/tooltip.tsx +177 -0
  146. package/src/utils/debounce.test.ts +59 -0
  147. package/src/utils/debounce.ts +10 -0
  148. package/src/utils/format-duration.test.ts +55 -0
  149. package/src/utils/format-duration.ts +30 -0
  150. package/src/video/index.ts +17 -0
  151. package/src/video/types.ts +216 -0
  152. package/src/video/video-bookmark.tsx +76 -0
  153. package/src/video/video-chapter-list.tsx +93 -0
  154. package/src/video/video-player.tsx +103 -0
  155. package/src/video/video-playlist-item.tsx +90 -0
  156. package/src/video/video-thumbnail-card.tsx +74 -0
  157. package/src/video/video-transcript.tsx +102 -0
  158. package/dist/table-CW4_BYny.js +0 -9869
  159. package/dist/table-DSBBqb9X.cjs +0 -56
@@ -0,0 +1,177 @@
1
+ import * as React from "react";
2
+ import {
3
+ createContext,
4
+ useContext,
5
+ useState,
6
+ useRef,
7
+ useCallback,
8
+ useLayoutEffect,
9
+ useId,
10
+ cloneElement,
11
+ isValidElement,
12
+ } from "react";
13
+ import { createPortal } from "react-dom";
14
+
15
+ import { cn } from "../lib/utils";
16
+
17
+ /* --------------------------------- Context -------------------------------- */
18
+
19
+ interface TooltipContextValue {
20
+ open: boolean;
21
+ show: () => void;
22
+ hide: () => void;
23
+ triggerRef: React.RefObject<HTMLElement | null>;
24
+ tooltipId: string;
25
+ }
26
+
27
+ const TooltipContext = createContext<TooltipContextValue | null>(null);
28
+
29
+ function useTooltipContext() {
30
+ const ctx = useContext(TooltipContext);
31
+ if (!ctx) throw new Error("Tooltip compound components must be used within <Tooltip>");
32
+ return ctx;
33
+ }
34
+
35
+ /* --------------------------------- Tooltip -------------------------------- */
36
+
37
+ interface TooltipProps {
38
+ children: React.ReactNode;
39
+ delayDuration?: number;
40
+ }
41
+
42
+ function Tooltip({ children, delayDuration = 300 }: TooltipProps) {
43
+ const [open, setOpen] = useState(false);
44
+ const triggerRef = useRef<HTMLElement | null>(null);
45
+ const delayRef = useRef<ReturnType<typeof setTimeout>>(undefined);
46
+ const tooltipId = useId();
47
+
48
+ const show = useCallback(() => {
49
+ clearTimeout(delayRef.current);
50
+ delayRef.current = setTimeout(() => setOpen(true), delayDuration);
51
+ }, [delayDuration]);
52
+
53
+ const hide = useCallback(() => {
54
+ clearTimeout(delayRef.current);
55
+ setOpen(false);
56
+ }, []);
57
+
58
+ return (
59
+ <TooltipContext.Provider value={{ open, show, hide, triggerRef, tooltipId }}>
60
+ {children}
61
+ </TooltipContext.Provider>
62
+ );
63
+ }
64
+
65
+ /* ------------------------------ TooltipTrigger ----------------------------- */
66
+
67
+ interface TooltipTriggerProps {
68
+ children: React.ReactElement<Record<string, unknown>>;
69
+ }
70
+
71
+ function TooltipTrigger({ children }: TooltipTriggerProps) {
72
+ const { show, hide, triggerRef, tooltipId, open } = useTooltipContext();
73
+
74
+ if (!isValidElement(children)) return children;
75
+
76
+ return cloneElement(children, {
77
+ ref: (node: HTMLElement | null) => {
78
+ triggerRef.current = node;
79
+ // Forward ref if child has one
80
+ const childRef = (children as React.ReactElement & { ref?: React.Ref<HTMLElement> }).ref;
81
+ if (typeof childRef === "function") childRef(node);
82
+ else if (childRef && typeof childRef === "object") {
83
+ (childRef as React.MutableRefObject<HTMLElement | null>).current = node;
84
+ }
85
+ },
86
+ onMouseEnter: (e: React.MouseEvent) => {
87
+ show();
88
+ const handler = (children.props as Record<string, Function | undefined>).onMouseEnter;
89
+ handler?.(e);
90
+ },
91
+ onMouseLeave: (e: React.MouseEvent) => {
92
+ hide();
93
+ const handler = (children.props as Record<string, Function | undefined>).onMouseLeave;
94
+ handler?.(e);
95
+ },
96
+ onFocus: (e: React.FocusEvent) => {
97
+ show();
98
+ const handler = (children.props as Record<string, Function | undefined>).onFocus;
99
+ handler?.(e);
100
+ },
101
+ onBlur: (e: React.FocusEvent) => {
102
+ hide();
103
+ const handler = (children.props as Record<string, Function | undefined>).onBlur;
104
+ handler?.(e);
105
+ },
106
+ "aria-describedby": open ? tooltipId : undefined,
107
+ } as Record<string, unknown>);
108
+ }
109
+
110
+ /* ------------------------------ TooltipContent ----------------------------- */
111
+
112
+ interface TooltipContentProps extends React.ComponentProps<"div"> {
113
+ sideOffset?: number;
114
+ }
115
+
116
+ function TooltipContent({
117
+ className,
118
+ sideOffset = 8,
119
+ children,
120
+ style,
121
+ ...props
122
+ }: TooltipContentProps) {
123
+ const { open, triggerRef, tooltipId } = useTooltipContext();
124
+ const popupRef = useRef<HTMLDivElement>(null);
125
+ const [position, setPosition] = useState<React.CSSProperties>({
126
+ position: "fixed",
127
+ top: 0,
128
+ left: 0,
129
+ visibility: "hidden",
130
+ });
131
+
132
+ useLayoutEffect(() => {
133
+ if (!open || !triggerRef.current || !popupRef.current) return;
134
+
135
+ const trigger = triggerRef.current.getBoundingClientRect();
136
+ const popup = popupRef.current.getBoundingClientRect();
137
+
138
+ // Default: above trigger, centered horizontally
139
+ let top = trigger.top - popup.height - sideOffset;
140
+ let left = trigger.left + trigger.width / 2 - popup.width / 2;
141
+
142
+ // Flip below if overflows top
143
+ if (top < 4) {
144
+ top = trigger.bottom + sideOffset;
145
+ }
146
+
147
+ // Clamp horizontally
148
+ if (left < 4) left = 4;
149
+ if (left + popup.width > window.innerWidth - 4) {
150
+ left = window.innerWidth - popup.width - 4;
151
+ }
152
+
153
+ setPosition({ position: "fixed", top, left, visibility: "visible" });
154
+ }, [open, sideOffset, triggerRef]);
155
+
156
+ if (!open) return null;
157
+
158
+ return createPortal(
159
+ <div
160
+ ref={popupRef}
161
+ id={tooltipId}
162
+ role="tooltip"
163
+ data-slot="tooltip-content"
164
+ className={cn(
165
+ "bg-primary text-primary-foreground z-50 max-w-60 rounded-md px-2.5 py-1.5 text-xs leading-snug shadow-md animate-in fade-in-0 zoom-in-95",
166
+ className,
167
+ )}
168
+ style={{ ...position, ...style }}
169
+ {...props}
170
+ >
171
+ {children}
172
+ </div>,
173
+ document.body,
174
+ );
175
+ }
176
+
177
+ export { Tooltip, TooltipTrigger, TooltipContent };
@@ -0,0 +1,59 @@
1
+ import { debounce } from "./debounce";
2
+
3
+ describe("debounce", () => {
4
+ beforeEach(() => {
5
+ vi.useFakeTimers();
6
+ });
7
+
8
+ afterEach(() => {
9
+ vi.useRealTimers();
10
+ });
11
+
12
+ it("delays function execution", () => {
13
+ const fn = vi.fn();
14
+ const debounced = debounce(fn, 100);
15
+
16
+ debounced();
17
+ expect(fn).not.toHaveBeenCalled();
18
+
19
+ vi.advanceTimersByTime(100);
20
+ expect(fn).toHaveBeenCalledOnce();
21
+ });
22
+
23
+ it("resets the timer on subsequent calls", () => {
24
+ const fn = vi.fn();
25
+ const debounced = debounce(fn, 100);
26
+
27
+ debounced();
28
+ vi.advanceTimersByTime(50);
29
+ debounced();
30
+ vi.advanceTimersByTime(50);
31
+
32
+ expect(fn).not.toHaveBeenCalled();
33
+
34
+ vi.advanceTimersByTime(50);
35
+ expect(fn).toHaveBeenCalledOnce();
36
+ });
37
+
38
+ it("passes arguments to the debounced function", () => {
39
+ const fn = vi.fn();
40
+ const debounced = debounce(fn, 100);
41
+
42
+ debounced("hello", "world");
43
+ vi.advanceTimersByTime(100);
44
+
45
+ expect(fn).toHaveBeenCalledWith("hello", "world");
46
+ });
47
+
48
+ it("uses arguments from the last call", () => {
49
+ const fn = vi.fn();
50
+ const debounced = debounce(fn, 100);
51
+
52
+ debounced("first");
53
+ debounced("second");
54
+ vi.advanceTimersByTime(100);
55
+
56
+ expect(fn).toHaveBeenCalledOnce();
57
+ expect(fn).toHaveBeenCalledWith("second");
58
+ });
59
+ });
@@ -0,0 +1,10 @@
1
+ export function debounce<T extends (...args: Parameters<T>) => void>(
2
+ fn: T,
3
+ delay: number,
4
+ ): (...args: Parameters<T>) => void {
5
+ let timer: ReturnType<typeof setTimeout>;
6
+ return (...args: Parameters<T>) => {
7
+ clearTimeout(timer);
8
+ timer = setTimeout(() => fn(...args), delay);
9
+ };
10
+ }
@@ -0,0 +1,55 @@
1
+ import { formatDuration, formatTimer } from "./format-duration";
2
+
3
+ describe("formatDuration", () => {
4
+ it("returns dash for values less than 1", () => {
5
+ expect(formatDuration(0)).toBe("-");
6
+ expect(formatDuration(-5)).toBe("-");
7
+ expect(formatDuration(0.5)).toBe("-");
8
+ });
9
+
10
+ it("formats seconds only", () => {
11
+ expect(formatDuration(45)).toBe("45s");
12
+ });
13
+
14
+ it("formats minutes and seconds", () => {
15
+ expect(formatDuration(125)).toBe("2m 5s");
16
+ });
17
+
18
+ it("formats hours, minutes, and seconds", () => {
19
+ expect(formatDuration(3661)).toBe("1h 1m 1s");
20
+ });
21
+
22
+ it("formats exact hours", () => {
23
+ expect(formatDuration(7200)).toBe("2h");
24
+ });
25
+
26
+ it("formats hours and minutes without seconds", () => {
27
+ expect(formatDuration(3660)).toBe("1h 1m");
28
+ });
29
+
30
+ it("formats hours and seconds without minutes", () => {
31
+ expect(formatDuration(3601)).toBe("1h 1s");
32
+ });
33
+ });
34
+
35
+ describe("formatTimer", () => {
36
+ it("formats zero as 00:00", () => {
37
+ expect(formatTimer(0)).toBe("00:00");
38
+ });
39
+
40
+ it("formats seconds with padding", () => {
41
+ expect(formatTimer(5)).toBe("00:05");
42
+ });
43
+
44
+ it("formats minutes and seconds", () => {
45
+ expect(formatTimer(125)).toBe("02:05");
46
+ });
47
+
48
+ it("includes hours when applicable", () => {
49
+ expect(formatTimer(3661)).toBe("01:01:01");
50
+ });
51
+
52
+ it("pads all segments", () => {
53
+ expect(formatTimer(3600)).toBe("01:00:00");
54
+ });
55
+ });
@@ -0,0 +1,30 @@
1
+ export const formatDuration = (duration: number): string => {
2
+ if (duration < 1) {
3
+ return "-";
4
+ }
5
+
6
+ const hours = Math.floor(duration / 3600);
7
+ const minutes = Math.floor((duration % 3600) / 60);
8
+ const seconds = duration % 60;
9
+ const parts: string[] = [];
10
+
11
+ if (hours > 0) parts.push(`${hours}h`);
12
+ if (minutes > 0) parts.push(`${minutes}m`);
13
+ if (seconds > 0) parts.push(`${seconds}s`);
14
+
15
+ return parts.join(" ");
16
+ };
17
+
18
+ export const formatTimer = (totalSeconds: number): string => {
19
+ const hours = Math.floor(totalSeconds / 3600);
20
+ const minutes = Math.floor((totalSeconds % 3600) / 60);
21
+ const seconds = totalSeconds % 60;
22
+
23
+ const pad = (n: number) => n.toString().padStart(2, "0");
24
+
25
+ if (hours > 0) {
26
+ return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
27
+ }
28
+
29
+ return `${pad(minutes)}:${pad(seconds)}`;
30
+ };
@@ -0,0 +1,17 @@
1
+ export { VideoPlayer } from "./video-player";
2
+ export { VideoTranscript } from "./video-transcript";
3
+ export { VideoChapterList } from "./video-chapter-list";
4
+ export { VideoThumbnailCard } from "./video-thumbnail-card";
5
+ export { VideoBookmark } from "./video-bookmark";
6
+ export { VideoPlaylistItem } from "./video-playlist-item";
7
+ export type {
8
+ VideoPlayerProps,
9
+ VideoTranscriptProps,
10
+ VideoChapterListProps,
11
+ VideoThumbnailCardProps,
12
+ VideoBookmarkProps,
13
+ VideoPlaylistItemProps,
14
+ TranscriptEntry,
15
+ VideoChapter,
16
+ VideoBookmarkData,
17
+ } from "./types";
@@ -0,0 +1,216 @@
1
+ /**
2
+ * VideoPlayer component for rendering video content with interactive playback controls.
3
+ *
4
+ * @example
5
+ * <VideoPlayer
6
+ * src="https://example.com/lesson.mp4"
7
+ * poster="https://example.com/thumbnail.jpg"
8
+ * title="Introduction to React"
9
+ * onEnded={() => markLessonComplete()}
10
+ * />
11
+ */
12
+ export interface VideoPlayerProps {
13
+ /** URL of the video source */
14
+ src?: string;
15
+ /** URL of the poster/thumbnail image */
16
+ poster?: string;
17
+ /** Title displayed above the video */
18
+ title?: string;
19
+ /** Whether the video should autoplay */
20
+ autoPlay?: boolean;
21
+ /** Called when the video starts playing */
22
+ onPlay?: () => void;
23
+ /** Called when the video is paused */
24
+ onPause?: () => void;
25
+ /** Called when the video ends */
26
+ onEnded?: () => void;
27
+ /** Called on each time update tick with currentTime and duration */
28
+ onTimeUpdate?: (currentTime: number, duration: number) => void;
29
+ /** When true, shows a poster image instead of interactive controls */
30
+ readOnly?: boolean;
31
+ /** Aspect ratio of the video container */
32
+ aspectRatio?: "16/9" | "4/3" | "1/1";
33
+ /** CSS class name for the root element */
34
+ className?: string;
35
+ /** Inline styles for the root element */
36
+ style?: React.CSSProperties;
37
+ }
38
+
39
+ // ─── Data Types ───
40
+
41
+ export interface TranscriptEntry {
42
+ /** Timestamp in seconds */
43
+ time: number;
44
+ /** Optional speaker name */
45
+ speaker?: string;
46
+ /** Transcript text content */
47
+ text: string;
48
+ }
49
+
50
+ export interface VideoChapter {
51
+ /** Chapter start time in seconds */
52
+ time: number;
53
+ /** Chapter title */
54
+ title: string;
55
+ /** Optional chapter thumbnail URL */
56
+ thumbnail?: string;
57
+ /** Chapter duration in seconds */
58
+ duration?: number;
59
+ }
60
+
61
+ export interface VideoBookmarkData {
62
+ /** Unique bookmark identifier */
63
+ id: string;
64
+ /** Bookmark timestamp in seconds */
65
+ time: number;
66
+ /** Optional note attached to the bookmark */
67
+ note?: string;
68
+ /** ISO 8601 creation timestamp */
69
+ createdAt?: string;
70
+ }
71
+
72
+ // ─── Component Props ───
73
+
74
+ /**
75
+ * VideoTranscript renders a scrollable timestamped transcript with active-line
76
+ * highlighting based on the current playback time.
77
+ *
78
+ * @example
79
+ * <VideoTranscript
80
+ * entries={transcript}
81
+ * currentTime={42}
82
+ * onSeek={(time) => player.seekTo(time)}
83
+ * />
84
+ */
85
+ export interface VideoTranscriptProps {
86
+ /** Array of transcript entries with timestamps */
87
+ entries: TranscriptEntry[];
88
+ /** Current playback time in seconds — used to highlight the active entry */
89
+ currentTime?: number;
90
+ /** Called when the user clicks a transcript entry to seek */
91
+ onSeek?: (time: number) => void;
92
+ /** When true, disables click-to-seek interaction */
93
+ readOnly?: boolean;
94
+ /** Maximum height of the scrollable container (CSS value) */
95
+ maxHeight?: string;
96
+ /** CSS class name for the root element */
97
+ className?: string;
98
+ /** Inline styles for the root element */
99
+ style?: React.CSSProperties;
100
+ }
101
+
102
+ /**
103
+ * VideoChapterList renders an ordered list of video chapters with timestamps,
104
+ * active chapter highlighting, and optional thumbnails.
105
+ *
106
+ * @example
107
+ * <VideoChapterList
108
+ * chapters={chapters}
109
+ * currentTime={120}
110
+ * onSeek={(time) => player.seekTo(time)}
111
+ * />
112
+ */
113
+ export interface VideoChapterListProps {
114
+ /** Array of chapter markers */
115
+ chapters: VideoChapter[];
116
+ /** Current playback time in seconds — used to determine the active chapter */
117
+ currentTime?: number;
118
+ /** Called when the user clicks a chapter to seek */
119
+ onSeek?: (time: number) => void;
120
+ /** CSS class name for the root element */
121
+ className?: string;
122
+ /** Inline styles for the root element */
123
+ style?: React.CSSProperties;
124
+ }
125
+
126
+ /**
127
+ * VideoThumbnailCard renders a clickable card-style video preview with a poster
128
+ * image, play icon overlay, duration badge, title, and optional progress bar.
129
+ *
130
+ * @example
131
+ * <VideoThumbnailCard
132
+ * poster="https://example.com/thumb.jpg"
133
+ * title="Introduction to React"
134
+ * duration={420}
135
+ * progress={65}
136
+ * onClick={() => navigate('/lesson/1')}
137
+ * />
138
+ */
139
+ export interface VideoThumbnailCardProps {
140
+ /** URL of the poster/thumbnail image */
141
+ poster?: string;
142
+ /** Video title displayed below the poster */
143
+ title: string;
144
+ /** Video duration in seconds */
145
+ duration?: number;
146
+ /** Watch progress percentage (0–100) */
147
+ progress?: number;
148
+ /** Called when the card is clicked */
149
+ onClick?: () => void;
150
+ /** CSS class name for the root element */
151
+ className?: string;
152
+ /** Inline styles for the root element */
153
+ style?: React.CSSProperties;
154
+ }
155
+
156
+ /**
157
+ * VideoBookmark renders a single timestamped bookmark row with an optional note,
158
+ * clickable timestamp for seeking, and edit/delete action buttons.
159
+ *
160
+ * @example
161
+ * <VideoBookmark
162
+ * bookmark={{ id: "b1", time: 125, note: "Key concept explained here" }}
163
+ * onSeek={(time) => player.seekTo(time)}
164
+ * onDelete={(id) => removeBookmark(id)}
165
+ * />
166
+ */
167
+ export interface VideoBookmarkProps {
168
+ /** Bookmark data object */
169
+ bookmark: VideoBookmarkData;
170
+ /** Called when the user clicks the timestamp to seek */
171
+ onSeek?: (time: number) => void;
172
+ /** Called when the user clicks the delete button */
173
+ onDelete?: (id: string) => void;
174
+ /** Called when the user clicks the edit button */
175
+ onEdit?: (id: string) => void;
176
+ /** CSS class name for the root element */
177
+ className?: string;
178
+ /** Inline styles for the root element */
179
+ style?: React.CSSProperties;
180
+ }
181
+
182
+ /**
183
+ * VideoPlaylistItem renders a horizontal row for a sequential video playlist,
184
+ * showing a thumbnail, title, duration, completion status, and active state.
185
+ *
186
+ * @example
187
+ * <VideoPlaylistItem
188
+ * thumbnail="https://example.com/thumb.jpg"
189
+ * title="Lesson 1: Getting Started"
190
+ * duration={420}
191
+ * status="completed"
192
+ * isActive={false}
193
+ * index={1}
194
+ * onClick={() => navigate('/lesson/1')}
195
+ * />
196
+ */
197
+ export interface VideoPlaylistItemProps {
198
+ /** URL of the video thumbnail */
199
+ thumbnail?: string;
200
+ /** Video title */
201
+ title: string;
202
+ /** Video duration in seconds */
203
+ duration?: number;
204
+ /** Watch status of this video */
205
+ status?: "unwatched" | "in-progress" | "completed";
206
+ /** Whether this is the currently playing item */
207
+ isActive?: boolean;
208
+ /** 1-based display index in the playlist */
209
+ index?: number;
210
+ /** Called when the item is clicked */
211
+ onClick?: () => void;
212
+ /** CSS class name for the root element */
213
+ className?: string;
214
+ /** Inline styles for the root element */
215
+ style?: React.CSSProperties;
216
+ }
@@ -0,0 +1,76 @@
1
+ import { Bookmark, Pencil, Trash2 } from "lucide-react";
2
+ import type { VideoBookmarkProps } from "./types";
3
+ import { cn } from "../lib/utils";
4
+ import { formatTimer } from "../utils/format-duration";
5
+
6
+ export const VideoBookmark = ({
7
+ bookmark,
8
+ onSeek,
9
+ onDelete,
10
+ onEdit,
11
+ className,
12
+ style,
13
+ }: VideoBookmarkProps) => {
14
+ return (
15
+ <div
16
+ className={cn(
17
+ "flex items-start gap-3 rounded-md border border-border p-3",
18
+ className,
19
+ )}
20
+ style={style}
21
+ >
22
+ <div className="flex shrink-0 items-center justify-center size-8 rounded-full bg-primary/10 text-primary">
23
+ <Bookmark size={16} />
24
+ </div>
25
+
26
+ <div className="min-w-0 flex-1">
27
+ <button
28
+ type="button"
29
+ className={cn(
30
+ "font-mono text-xs font-medium tabular-nums",
31
+ onSeek
32
+ ? "cursor-pointer text-primary hover:underline"
33
+ : "text-muted-foreground",
34
+ )}
35
+ onClick={() => onSeek?.(bookmark.time)}
36
+ disabled={!onSeek}
37
+ >
38
+ {formatTimer(Math.floor(bookmark.time))}
39
+ </button>
40
+ {bookmark.note && (
41
+ <p className="mt-0.5 text-sm text-foreground">{bookmark.note}</p>
42
+ )}
43
+ {bookmark.createdAt && (
44
+ <span className="text-xs text-muted-foreground">
45
+ {new Date(bookmark.createdAt).toLocaleDateString()}
46
+ </span>
47
+ )}
48
+ </div>
49
+
50
+ {(onEdit || onDelete) && (
51
+ <div className="flex shrink-0 items-center gap-1">
52
+ {onEdit && (
53
+ <button
54
+ type="button"
55
+ className="inline-flex items-center justify-center rounded-md p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"
56
+ aria-label="Edit bookmark"
57
+ onClick={() => onEdit(bookmark.id)}
58
+ >
59
+ <Pencil size={14} />
60
+ </button>
61
+ )}
62
+ {onDelete && (
63
+ <button
64
+ type="button"
65
+ className="inline-flex items-center justify-center rounded-md p-1.5 text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive"
66
+ aria-label="Delete bookmark"
67
+ onClick={() => onDelete(bookmark.id)}
68
+ >
69
+ <Trash2 size={14} />
70
+ </button>
71
+ )}
72
+ </div>
73
+ )}
74
+ </div>
75
+ );
76
+ };