File size: 2,555 Bytes
801f06c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | import { useEffect, useRef, type ReactNode } from 'react';
import { X, LoaderCircle, AlertCircle, ArrowUpRight, AudioLines } from 'lucide-react';
import type { Character } from '../api/types';
import { assetUrl } from '../api/client';
export function ErrorNotice({ error }: { error: unknown }) {
return error ? (
<div className="notice error" role="alert">
<AlertCircle size={16} />
<span>{error instanceof Error ? error.message : String(error)}</span>
</div>
) : null;
}
export function Loading() {
return (
<div className="loading" role="status">
<LoaderCircle className="spin" size={22} /> Loading your studio…
</div>
);
}
export function Avatar({ character, large = false }: { character: Character; large?: boolean }) {
return (
<div className={`avatar ${large ? 'large' : ''}`} style={{ background: character.color }}>
{character.image_asset_id ? (
<img src={assetUrl(character.image_asset_id)} alt={character.name} />
) : (
<span>
{character.name
.split(/[ .]+/)
.map((n) => n[0])
.slice(0, 2)
.join('')}
</span>
)}
</div>
);
}
export function PageTitle({
eyebrow,
title,
description,
action,
}: {
eyebrow: string;
title: string;
description: string;
action?: ReactNode;
}) {
return (
<header className="page-heading">
<div>
<div className="eyebrow">{eyebrow}</div>
<h1>{title}</h1>
<p>{description}</p>
</div>
{action}
</header>
);
}
export function Empty({ title, children }: { title: string; children: ReactNode }) {
return (
<div className="empty">
<AudioLines size={30} />
<h3>{title}</h3>
<p>{children}</p>
</div>
);
}
export function Modal({
title,
children,
onClose,
}: {
title: string;
children: ReactNode;
onClose: () => void;
}) {
const ref = useRef<HTMLDialogElement>(null);
useEffect(() => {
ref.current?.showModal();
}, []);
return (
<dialog ref={ref} onCancel={onClose} className="modal">
<header>
<h2>{title}</h2>
<button className="icon-button" aria-label="Close dialog" onClick={onClose}>
<X size={20} />
</button>
</header>
{children}
</dialog>
);
}
export function External({ href, children }: { href: string; children: ReactNode }) {
return (
<a href={href} target="_blank" rel="noreferrer" className="text-link">
{children}
<ArrowUpRight size={15} />
</a>
);
}
|