Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history

ui.tsx

Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.

ui.tsxBlame701 lines · 1 contributor
45e31d0Claude1/**
2 * Core UI Component Library — gluecron design system.
3 *
4 * Pure components. No raw HTML in routes. Every visual element
5 * is a composable, typed, reusable component.
6 */
7
8import type { FC, PropsWithChildren } from "hono/jsx";
9import { html } from "hono/html";
10
11// ─── Primitive Components ───────────────────────────────────────────────────
12
13/** Flex container with gap and alignment */
14export const Flex: FC<
15 PropsWithChildren<{
16 direction?: "row" | "column";
17 gap?: number;
18 align?: string;
19 justify?: string;
20 wrap?: boolean;
21 class?: string;
22 style?: string;
23 }>
24> = ({ children, direction = "row", gap = 0, align, justify, wrap, class: cls, style }) => (
25 <div
26 class={cls || ""}
27 style={`display:flex;flex-direction:${direction};${gap ? `gap:${gap}px;` : ""}${align ? `align-items:${align};` : ""}${justify ? `justify-content:${justify};` : ""}${wrap ? "flex-wrap:wrap;" : ""}${style || ""}`}
28 >
29 {children}
30 </div>
31);
32
33/** Grid container */
34export const Grid: FC<
35 PropsWithChildren<{ cols?: string; gap?: number; class?: string }>
36> = ({ children, cols = "repeat(auto-fill, minmax(340px, 1fr))", gap = 16, class: cls }) => (
37 <div class={cls || "card-grid"} style={`display:grid;grid-template-columns:${cols};gap:${gap}px;`}>
38 {children}
39 </div>
40);
41
42/** Spacer element */
43export const Spacer: FC<{ size?: number }> = ({ size = 16 }) => (
44 <div style={`height:${size}px`} />
45);
46
47/** Text with semantic styling */
48export const Text: FC<
49 PropsWithChildren<{
50 size?: number;
51 color?: string;
52 weight?: number | string;
53 mono?: boolean;
54 muted?: boolean;
55 style?: string;
56 }>
57> = ({ children, size, color, weight, mono, muted, style }) => (
58 <span
59 style={`${size ? `font-size:${size}px;` : ""}${color ? `color:${color};` : ""}${weight ? `font-weight:${weight};` : ""}${mono ? "font-family:var(--font-mono);" : ""}${muted ? "color:var(--text-muted);" : ""}${style || ""}`}
60 >
61 {children}
62 </span>
63);
64
65// ─── Buttons ────────────────────────────────────────────────────────────────
66
67export const Button: FC<
68 PropsWithChildren<{
69 variant?: "default" | "primary" | "danger" | "success" | "ghost";
70 size?: "sm" | "md" | "lg";
71 type?: "button" | "submit" | "reset";
72 disabled?: boolean;
73 formaction?: string;
74 class?: string;
75 }>
76> = ({ children, variant = "default", size = "md", type = "button", disabled, formaction, class: cls }: any) => {
77 const variantCls =
78 variant === "primary" ? " btn-primary" :
79 variant === "danger" ? " btn-danger" :
80 variant === "success" ? " btn-success" :
81 variant === "ghost" ? " btn-ghost" : "";
82 const sizeCls = size === "sm" ? " btn-sm" : size === "lg" ? " btn-lg" : "";
83 return (
84 <button
85 type={type}
86 class={`btn${variantCls}${sizeCls}${cls ? ` ${cls}` : ""}`}
87 disabled={disabled}
88 formaction={formaction}
89 >
90 {children}
91 </button>
92 );
93};
94
95export const LinkButton: FC<
96 PropsWithChildren<{
97 href: string;
98 variant?: "default" | "primary" | "danger" | "success";
99 size?: "sm" | "md";
100 }>
101> = ({ children, href, variant = "default", size = "md" }) => {
102 const variantCls = variant === "primary" ? " btn-primary" : variant === "danger" ? " btn-danger" : variant === "success" ? " btn-success" : "";
103 const sizeCls = size === "sm" ? " btn-sm" : "";
104 return (
105 <a href={href} class={`btn${variantCls}${sizeCls}`}>
106 {children}
107 </a>
108 );
109};
110
111// ─── Forms ──────────────────────────────────────────────────────────────────
112
113export const Form: FC<
114 PropsWithChildren<{
115 action: string;
116 method?: string;
117 csrfToken?: string;
118 class?: string;
119 }>
120> = ({ children, action, method = "POST", csrfToken, class: cls }) => (
121 <form method={method.toLowerCase() as any} action={action} class={cls || ""}>
122 {csrfToken && <input type="hidden" name="_csrf" value={csrfToken} />}
123 {children}
124 </form>
125);
126
127export const FormGroup: FC<
128 PropsWithChildren<{ label?: string; htmlFor?: string; hint?: string }>
129> = ({ children, label, htmlFor, hint }) => (
130 <div class="form-group">
131 {label && <label for={htmlFor}>{label}</label>}
132 {children}
133 {hint && <Text size={12} muted>{hint}</Text>}
134 </div>
135);
136
137export const Input: FC<{
138 name: string;
139 type?: string;
140 id?: string;
141 value?: string;
142 placeholder?: string;
143 required?: boolean;
144 disabled?: boolean;
145 pattern?: string;
146 autocomplete?: string;
147 autofocus?: boolean;
bb0f894Claude148 minLength?: number;
149 maxLength?: number;
45e31d0Claude150 style?: string;
151}> = (props) => (
152 <input
153 type={props.type || "text"}
154 id={props.id || props.name}
155 name={props.name}
156 value={props.value}
157 placeholder={props.placeholder}
158 required={props.required}
159 disabled={props.disabled}
160 pattern={props.pattern}
161 autocomplete={props.autocomplete}
162 autofocus={props.autofocus}
bb0f894Claude163 minLength={props.minLength}
164 maxLength={props.maxLength}
45e31d0Claude165 class={props.disabled ? "input-disabled" : ""}
166 style={props.style}
167 />
168);
169
170export const TextArea: FC<{
171 name: string;
172 id?: string;
173 rows?: number;
174 placeholder?: string;
175 required?: boolean;
176 value?: string;
177 mono?: boolean;
178 style?: string;
179}> = (props) => (
180 <textarea
181 id={props.id || props.name}
182 name={props.name}
183 rows={props.rows || 6}
184 placeholder={props.placeholder}
185 required={props.required}
186 style={`${props.mono ? "font-family:var(--font-mono);font-size:13px;" : ""}${props.style || ""}`}
187 >
188 {props.value}
189 </textarea>
190);
191
192export const Select: FC<
193 PropsWithChildren<{ name: string; id?: string; value?: string }>
194> = ({ children, name, id, value }) => (
195 <select id={id || name} name={name} value={value}>
196 {children}
197 </select>
198);
199
200// ─── Feedback Components ────────────────────────────────────────────────────
201
202export const Alert: FC<
203 PropsWithChildren<{ variant: "error" | "success" | "warning" | "info" }>
204> = ({ children, variant }) => {
205 const cls =
206 variant === "error" ? "auth-error" :
207 variant === "success" ? "auth-success" :
208 variant === "warning" ? "alert-warning" :
209 "alert-info";
210 return <div class={cls}>{children}</div>;
211};
212
213export const EmptyState: FC<
214 PropsWithChildren<{ title?: string; icon?: string }>
215> = ({ children, title, icon }) => (
216 <div class="empty-state">
217 {icon && <div style="font-size:48px;margin-bottom:12px">{icon}</div>}
218 {title && <h2>{title}</h2>}
219 {children}
220 </div>
221);
222
223export const Badge: FC<
224 PropsWithChildren<{
225 variant?: "default" | "open" | "closed" | "merged" | "success" | "danger" | "warning";
226 style?: string;
227 }>
228> = ({ children, variant = "default", style }) => {
229 const cls =
230 variant === "open" ? "badge-open" :
231 variant === "closed" ? "badge-closed" :
232 variant === "merged" ? "badge-merged" :
233 variant === "success" ? "badge-success" :
234 variant === "danger" ? "badge-danger" :
235 variant === "warning" ? "badge-warning" :
236 "badge";
237 return <span class={`issue-badge ${cls}`} style={style}>{children}</span>;
238};
239
240// ─── Card Components ────────────────────────────────────────────────────────
241
242export const Card: FC<PropsWithChildren<{ class?: string; style?: string }>> = ({
243 children,
244 class: cls,
245 style,
246}) => (
247 <div class={`card${cls ? ` ${cls}` : ""}`} style={style}>
248 {children}
249 </div>
250);
251
252export const CardMeta: FC<PropsWithChildren> = ({ children }) => (
253 <div class="card-meta">{children}</div>
254);
255
256// ─── Navigation Components ──────────────────────────────────────────────────
257
258export const TabNav: FC<{
259 tabs: Array<{ label: string; href: string; active?: boolean; count?: number }>;
260}> = ({ tabs }) => (
261 <div class="repo-nav">
262 {tabs.map((tab) => (
263 <a href={tab.href} class={tab.active ? "active" : ""}>
264 {tab.label}
265 {tab.count !== undefined && (
266 <span class="tab-count">{tab.count}</span>
267 )}
268 </a>
269 ))}
270 </div>
271);
272
273export const FilterTabs: FC<{
274 tabs: Array<{ label: string; href: string; active?: boolean }>;
275}> = ({ tabs }) => (
276 <div class="issue-tabs">
277 {tabs.map((tab) => (
278 <a href={tab.href} class={tab.active ? "active" : ""}>
279 {tab.label}
280 </a>
281 ))}
282 </div>
283);
284
285// ─── Page Layout Components ─────────────────────────────────────────────────
286
287export const PageHeader: FC<
288 PropsWithChildren<{ title: string; actions?: any }>
289> = ({ title, actions, children }) => (
290 <Flex justify="space-between" align="center" style="margin-bottom:20px">
291 <h2>{title}</h2>
292 {actions}
293 {children}
294 </Flex>
295);
296
297export const Section: FC<
298 PropsWithChildren<{ title?: string; style?: string }>
299> = ({ children, title, style }) => (
300 <div style={`margin-bottom:24px;${style || ""}`}>
301 {title && <h3 style="margin-bottom:12px">{title}</h3>}
302 {children}
303 </div>
304);
305
306export const Container: FC<
307 PropsWithChildren<{ maxWidth?: number; class?: string }>
308> = ({ children, maxWidth = 800, class: cls }) => (
309 <div class={cls || ""} style={`max-width:${maxWidth}px`}>
310 {children}
311 </div>
312);
313
314// ─── Data Display Components ────────────────────────────────────────────────
315
316export const StatGroup: FC<{
317 stats: Array<{ label: string; value: string | number; color?: string }>;
318}> = ({ stats }) => (
319 <Flex gap={24} wrap>
320 {stats.map((stat) => (
321 <div>
322 <div style={`font-size:24px;font-weight:700;${stat.color ? `color:${stat.color};` : ""}`}>
323 {stat.value}
324 </div>
325 <Text size={13} muted>{stat.label}</Text>
326 </div>
327 ))}
328 </Flex>
329);
330
331export const KeyValue: FC<{ label: string; value: string | number }> = ({
332 label,
333 value,
334}) => (
335 <Flex justify="space-between" align="center" style="padding:8px 0;border-bottom:1px solid var(--border)">
336 <Text size={14} muted>{label}</Text>
337 <Text size={14}>{String(value)}</Text>
338 </Flex>
339);
340
341export const DataTable: FC<{
342 headers: string[];
343 rows: Array<Array<string | any>>;
344 class?: string;
345}> = ({ headers, rows, class: cls }) => (
346 <table class={cls || "file-table"}>
347 <thead>
348 <tr>
349 {headers.map((h) => (
350 <th style="padding:8px 16px;text-align:left;font-size:13px;color:var(--text-muted);border-bottom:1px solid var(--border)">{h}</th>
351 ))}
352 </tr>
353 </thead>
354 <tbody>
355 {rows.map((row) => (
356 <tr>
357 {row.map((cell) => (
358 <td style="padding:8px 16px;font-size:14px">{cell}</td>
359 ))}
360 </tr>
361 ))}
362 </tbody>
363 </table>
364);
365
366// ─── List Components ────────────────────────────────────────────────────────
367
368export const ListItem: FC<
369 PropsWithChildren<{ style?: string }>
370> = ({ children, style }) => (
371 <div class="issue-item" style={style}>
372 {children}
373 </div>
374);
375
376export const List: FC<PropsWithChildren<{ class?: string }>> = ({ children, class: cls }) => (
377 <div class={cls || "issue-list"}>
378 {children}
379 </div>
380);
381
382// ─── Code Display ───────────────────────────────────────────────────────────
383
384export const CodeBlock: FC<{
385 code: string;
386 language?: string;
387 showLineNumbers?: boolean;
388}> = ({ code, showLineNumbers = true }) => {
389 const lines = code.split("\n");
390 if (lines[lines.length - 1] === "") lines.pop();
391 return (
392 <div class="blob-code">
393 <table>
394 <tbody>
395 {lines.map((line, i) => (
396 <tr>
397 {showLineNumbers && <td class="line-num">{i + 1}</td>}
398 <td class="line-content">{line}</td>
399 </tr>
400 ))}
401 </tbody>
402 </table>
403 </div>
404 );
405};
406
407export const InlineCode: FC<PropsWithChildren> = ({ children }) => (
408 <code style="font-size:12px;background:var(--bg-tertiary);padding:2px 6px;border-radius:3px;font-family:var(--font-mono)">
409 {children}
410 </code>
411);
412
413export const CopyBlock: FC<{
414 text: string;
415 label?: string;
416}> = ({ text, label }) => (
417 <Flex gap={8} align="center" class="copy-block">
418 {label && <Text size={13} muted>{label}</Text>}
419 <code
420 style="flex:1;padding:8px 12px;background:var(--bg-secondary);border:1px solid var(--border);border-radius:var(--radius);font-family:var(--font-mono);font-size:13px;overflow-x:auto"
421 data-copy={text}
422 >
423 {text}
424 </code>
425 <button
426 type="button"
427 class="btn btn-sm copy-btn"
428 data-clipboard={text}
429 title="Copy to clipboard"
430 >
431 Copy
432 </button>
433 </Flex>
434);
435
436// ─── Notification Components ────────────────────────────────────────────────
437
438export const NotificationBell: FC<{ count: number; href: string }> = ({
439 count,
440 href,
441}) => (
442 <a href={href} class="notification-bell" title="Notifications">
443 <svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
444 <path d="M8 16a2 2 0 002-2H6a2 2 0 002 2zM8 1.918l-.797.161A4.002 4.002 0 004 6c0 .628-.134 2.197-.459 3.742-.16.767-.376 1.566-.663 2.258h10.244c-.287-.692-.502-1.49-.663-2.258C12.134 8.197 12 6.628 12 6a4.002 4.002 0 00-3.203-3.92L8 1.917zM14.22 12c.223.447.481.801.78 1H1c.299-.199.557-.553.78-1C2.68 10.2 3 6.88 3 6c0-2.42 1.72-4.44 4.005-4.901a1 1 0 111.99 0A5.002 5.002 0 0113 6c0 .88.32 4.2 1.22 6z" />
445 </svg>
446 {count > 0 && <span class="notification-count">{count > 99 ? "99+" : count}</span>}
447 </a>
448);
449
450// ─── Profile Components ─────────────────────────────────────────────────────
451
452export const Avatar: FC<{
453 name: string;
454 url?: string;
455 size?: number;
456}> = ({ name, url, size = 40 }) => {
457 if (url) {
458 return (
459 <img
460 src={url}
461 alt={name}
462 style={`width:${size}px;height:${size}px;border-radius:50%;object-fit:cover`}
463 loading="lazy"
464 />
465 );
466 }
467 return (
468 <div
469 class="user-avatar"
470 style={`width:${size}px;height:${size}px;font-size:${size * 0.4}px`}
471 >
472 {name[0].toUpperCase()}
473 </div>
474 );
475};
476
477export const UserCard: FC<{
478 username: string;
479 displayName?: string | null;
480 bio?: string | null;
481 avatarUrl?: string | null;
482}> = ({ username, displayName, bio, avatarUrl }) => (
483 <div class="user-profile">
484 <Avatar name={displayName || username} url={avatarUrl || undefined} size={96} />
485 <div class="user-info">
486 <h2>{displayName || username}</h2>
487 <div class="username">@{username}</div>
488 {bio && <div class="bio">{bio}</div>}
489 </div>
490 </div>
491);
492
493// ─── Onboarding Components ──────────────────────────────────────────────────
494
495export const StepIndicator: FC<{
496 steps: Array<{ label: string; completed: boolean; active: boolean }>;
497}> = ({ steps }) => (
498 <Flex gap={0} align="center" class="step-indicator">
499 {steps.map((step, i) => (
500 <>
501 {i > 0 && <div class="step-line" data-completed={step.completed || steps[i - 1]?.completed ? "true" : "false"} />}
502 <Flex direction="column" align="center" gap={4}>
503 <div
504 class={`step-circle${step.completed ? " step-completed" : ""}${step.active ? " step-active" : ""}`}
505 >
506 {step.completed ? "\u2713" : i + 1}
507 </div>
508 <Text size={12} muted={!step.active}>{step.label}</Text>
509 </Flex>
510 </>
511 ))}
512 </Flex>
513);
514
515export const WelcomeHero: FC<
516 PropsWithChildren<{ title: string; subtitle?: string }>
517> = ({ children, title, subtitle }) => (
518 <div class="welcome-hero">
519 <h1>{title}</h1>
520 {subtitle && <p class="hero-subtitle">{subtitle}</p>}
521 {children}
522 </div>
523);
524
525export const FeatureCard: FC<{
526 icon: string;
527 title: string;
528 description: string;
529 href?: string;
530}> = ({ icon, title, description, href }) => {
531 const content = (
532 <Card class="feature-card">
533 <div class="feature-icon">{icon}</div>
534 <h3>{title}</h3>
535 <Text size={13} muted>{description}</Text>
536 </Card>
537 );
538 return href ? <a href={href} style="text-decoration:none">{content}</a> : content;
539};
540
541// ─── Search Components ──────────────────────────────────────────────────────
542
543export const SearchBar: FC<{
544 action: string;
545 value?: string;
546 placeholder?: string;
547 name?: string;
548}> = ({ action, value, placeholder = "Search...", name = "q" }) => (
549 <form method="get" action={action} style="margin-bottom:20px">
550 <Flex gap={8}>
551 <input
552 type="text"
553 name={name}
554 value={value}
555 placeholder={placeholder}
556 class="search-input"
557 autocomplete="off"
558 />
559 <Button type="submit" variant="primary">Search</Button>
560 </Flex>
561 </form>
562);
563
564export const SearchResults: FC<{
565 query: string;
566 count: number;
567}> = ({ query, count }) => (
568 <p style="font-size:14px;color:var(--text-muted);margin-bottom:16px">
569 {count} result{count !== 1 ? "s" : ""} for{" "}
570 <strong style="color:var(--text)">"{query}"</strong>
571 </p>
572);
573
574// ─── Markdown Content ───────────────────────────────────────────────────────
575
576export const MarkdownContent: FC<{ html: string }> = ({ html: htmlContent }) => (
577 <div class="markdown-body">
578 {html([htmlContent] as unknown as TemplateStringsArray)}
579 </div>
580);
581
582// ─── Comment Components ─────────────────────────────────────────────────────
583
584export const CommentBox: FC<{
585 author: string;
586 date: string | Date;
587 body: string;
588 isAi?: boolean;
589}> = ({ author, date, body, isAi }) => {
590 const dateStr = typeof date === "string" ? date : date.toISOString();
591 return (
592 <div class={`issue-comment-box${isAi ? " ai-review" : ""}`}>
593 <div class="comment-header">
594 <Flex gap={8} align="center">
595 <strong>{author}</strong>
596 {isAi && <Badge variant="default" style="font-size:11px">AI Review</Badge>}
597 <Text size={13} muted>commented {formatRelative(dateStr)}</Text>
598 </Flex>
599 </div>
600 <MarkdownContent html={body} />
601 </div>
602 );
603};
604
605export const CommentForm: FC<{
606 action: string;
607 csrfToken?: string;
608 placeholder?: string;
609 submitLabel?: string;
610 extraActions?: any;
611}> = ({ action, csrfToken, placeholder = "Leave a comment... (Markdown supported)", submitLabel = "Comment", extraActions }) => (
612 <div style="margin-top:20px">
613 <Form action={action} csrfToken={csrfToken}>
614 <FormGroup>
615 <div class="comment-editor">
616 <div class="editor-tabs">
617 <button type="button" class="editor-tab active" data-tab="write">Write</button>
618 <button type="button" class="editor-tab" data-tab="preview">Preview</button>
619 </div>
620 <TextArea
621 name="body"
622 rows={6}
623 required
624 placeholder={placeholder}
625 mono
626 />
627 <div class="editor-preview" style="display:none" />
628 </div>
629 </FormGroup>
630 <Flex gap={8}>
631 <Button type="submit" variant="primary">{submitLabel}</Button>
632 {extraActions}
633 </Flex>
634 </Form>
635 </div>
636);
637
638// ─── Tooltip Component ──────────────────────────────────────────────────────
639
640export const Tooltip: FC<PropsWithChildren<{ text: string }>> = ({
641 children,
642 text,
643}) => (
644 <span class="tooltip-wrapper" data-tooltip={text}>
645 {children}
646 </span>
647);
648
649// ─── Loading & Progress ─────────────────────────────────────────────────────
650
651export const Spinner: FC<{ size?: number }> = ({ size = 20 }) => (
652 <div
653 class="spinner"
654 style={`width:${size}px;height:${size}px`}
655 />
656);
657
658export const ProgressBar: FC<{ value: number; max?: number; color?: string }> = ({
659 value,
660 max = 100,
661 color,
662}) => (
663 <div class="progress-bar">
664 <div
665 class="progress-fill"
666 style={`width:${(value / max) * 100}%;${color ? `background:${color};` : ""}`}
667 />
668 </div>
669);
670
671// ─── Keyboard Shortcut Hint ─────────────────────────────────────────────────
672
673export const Kbd: FC<PropsWithChildren> = ({ children }) => (
674 <kbd class="kbd">{children}</kbd>
675);
676
677// ─── Utility Functions ──────────────────────────────────────────────────────
678
679export function formatRelative(dateStr: string | Date): string {
680 const date = typeof dateStr === "string" ? new Date(dateStr) : dateStr;
681 const now = new Date();
682 const diffMs = now.getTime() - date.getTime();
683 const diffMins = Math.floor(diffMs / 60000);
684 if (diffMins < 1) return "just now";
685 if (diffMins < 60) return `${diffMins}m ago`;
686 const diffHours = Math.floor(diffMins / 60);
687 if (diffHours < 24) return `${diffHours}h ago`;
688 const diffDays = Math.floor(diffHours / 24);
689 if (diffDays < 30) return `${diffDays}d ago`;
690 return date.toLocaleDateString("en-US", {
691 month: "short",
692 day: "numeric",
693 year: "numeric",
694 });
695}
696
697export function formatSize(bytes: number): string {
698 if (bytes < 1024) return `${bytes} B`;
699 if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
700 return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
701}