"use client";
import {
useState,
type ImgHTMLAttributes,
type VideoHTMLAttributes,
type ReactNode,
} from "react";
export function Avatar({
name,
src,
size = 44,
className = "",
}: {
name: string;
src?: string;
size?: number;
className?: string;
}) {
const [failed, setFailed] = useState();
const initials =
name
.trim()
.split(/\s+/)
.slice(0, 2)
.map((n) => Array.from(n)[0])
.join("")
.toUpperCase() || "?";
return (
{src && src !== failed ? (
setFailed(src)} />
) : (
{initials}
)}
);
}
export function ImageFigure({
src,
alt,
caption,
className = "",
...props
}: ImgHTMLAttributes & { caption?: ReactNode }) {
const [failed, setFailed] = useState();
return (
{src && src === failed ? (
Image unavailable
) : (
{
setFailed(String(src));
props.onError?.(e);
}}
/>
)}
{caption && {caption}}
);
}
export function MediaPlayer({
kind = "video",
label,
children,
className = "",
...props
}: VideoHTMLAttributes & {
kind?: "video" | "audio";
label: string;
}) {
return (
{label}
{kind === "audio" ? (
) : (
)}
);
}