RalphThings's picture
Upload folder using huggingface_hub
c2d7c73 verified
Raw History Blame Contribute Delete
6.64 kB
"use client";
import type { ReactNode } from "react";
export function Panel({
title,
hint,
aside,
children,
className = "",
}: {
title: string;
hint?: string;
aside?: ReactNode;
children: ReactNode;
className?: string;
}) {
return (
<section
className={`rounded-console border border-line bg-panel ${className}`}
>
<header className="flex items-baseline justify-between gap-4 border-b border-line px-5 py-3.5">
<div className="flex items-baseline gap-3">
<h2 className="text-[13px] font-medium tracking-tight text-ink">{title}</h2>
{hint ? <p className="hidden text-[12px] text-ink-faint sm:block">{hint}</p> : null}
</div>
{aside}
</header>
<div className="px-5 py-4">{children}</div>
</section>
);
}
export function Field({
label,
helper,
error,
htmlFor,
children,
}: {
label: string;
helper?: string;
error?: string | null;
htmlFor?: string;
children: ReactNode;
}) {
return (
<div className="flex flex-col gap-2">
<label
htmlFor={htmlFor}
className="text-[11px] font-medium tracking-[0.06em] text-ink-dim uppercase"
>
{label}
</label>
{children}
{helper ? <p className="text-[12px] leading-snug text-ink-faint">{helper}</p> : null}
{error ? <p className="text-[12px] leading-snug text-alarm">{error}</p> : null}
</div>
);
}
const BUTTON_BASE =
"inline-flex items-center justify-center gap-2 rounded-console text-[13px] font-medium transition-colors duration-150 active:translate-y-px disabled:pointer-events-none disabled:opacity-40";
export function Button({
variant = "ghost",
size = "md",
className = "",
...props
}: React.ButtonHTMLAttributes<HTMLButtonElement> & {
variant?: "primary" | "ghost" | "quiet";
size?: "sm" | "md";
}) {
const variants = {
primary: "bg-citron text-void hover:bg-[#d4f066]",
ghost: "border border-line-strong text-ink hover:border-ink-faint hover:bg-raised",
quiet: "text-ink-dim hover:text-ink hover:bg-raised",
} as const;
const sizes = { sm: "h-8 px-3", md: "h-10 px-4" } as const;
return (
<button {...props} className={`${BUTTON_BASE} ${variants[variant]} ${sizes[size]} ${className}`} />
);
}
export function Chip({
active = false,
className = "",
...props
}: React.ButtonHTMLAttributes<HTMLButtonElement> & { active?: boolean }) {
return (
<button
type="button"
{...props}
className={`rounded-console border px-2.5 py-1 text-[12px] transition-colors duration-150 ${
active
? "border-citron bg-citron/15 text-citron"
: "border-line-strong text-ink-dim hover:border-ink-faint hover:text-ink"
} ${className}`}
/>
);
}
export function SegmentedControl<T extends string>({
value,
options,
onChange,
name,
}: {
value: T;
options: { value: T; label: string; hint?: string }[];
onChange: (value: T) => void;
name: string;
}) {
return (
<div role="radiogroup" aria-label={name} className="grid gap-1.5 sm:grid-cols-2">
{options.map((option) => {
const active = option.value === value;
return (
<button
key={option.value}
type="button"
role="radio"
aria-checked={active}
onClick={() => onChange(option.value)}
className={`rounded-console border px-3 py-2.5 text-left transition-colors duration-150 ${
active
? "border-citron bg-citron/10"
: "border-line-strong hover:border-ink-faint hover:bg-raised"
}`}
>
<span className={`block text-[13px] ${active ? "text-citron" : "text-ink"}`}>
{option.label}
</span>
{option.hint ? (
<span className="mt-0.5 block text-[11.5px] leading-snug text-ink-faint">
{option.hint}
</span>
) : null}
</button>
);
})}
</div>
);
}
export function Switch({
checked,
onChange,
label,
disabled = false,
}: {
checked: boolean;
onChange: (checked: boolean) => void;
label: string;
disabled?: boolean;
}) {
return (
<button
type="button"
role="switch"
aria-checked={checked}
disabled={disabled}
onClick={() => onChange(!checked)}
className="flex w-full items-center justify-between gap-4 py-1 text-left disabled:cursor-not-allowed disabled:opacity-45"
>
<span className="text-[13px] text-ink">{label}</span>
<span
className={`relative h-5 w-9 shrink-0 rounded-full border transition-colors duration-150 ${
checked ? "border-citron bg-citron/30" : "border-line-strong bg-raised"
}`}
>
<span
className={`absolute top-0.5 h-3.5 w-3.5 rounded-full transition-all duration-150 ${
checked ? "left-4.5 bg-citron" : "left-0.5 bg-ink-faint"
}`}
/>
</span>
</button>
);
}
export function NumberInput({
id,
value,
onChange,
min,
max,
step = 1,
suffix,
}: {
id: string;
value: number;
onChange: (value: number) => void;
min: number;
max: number;
step?: number;
suffix?: string;
}) {
return (
<div className="flex items-center gap-2">
<input
id={id}
type="number"
value={value}
min={min}
max={max}
step={step}
onChange={(event) => onChange(Number(event.target.value))}
className="h-9 w-full rounded-console border border-line-strong bg-void px-2.5 font-mono text-[13px] text-ink"
/>
{suffix ? <span className="text-[12px] text-ink-faint">{suffix}</span> : null}
</div>
);
}
export function Slider({
id,
label,
value,
display,
min,
max,
step,
onChange,
}: {
id: string;
label: string;
value: number;
display?: string;
min: number;
max: number;
step: number;
onChange: (value: number) => void;
}) {
return (
<div className="flex flex-col gap-1.5">
<div className="flex items-baseline justify-between">
<label htmlFor={id} className="text-[12px] text-ink-dim">
{label}
</label>
<span className="font-mono text-[12px] text-ink">{display ?? value}</span>
</div>
<input
id={id}
type="range"
value={value}
min={min}
max={max}
step={step}
onChange={(event) => onChange(Number(event.target.value))}
className="h-1 w-full cursor-pointer appearance-none rounded-full bg-line-strong accent-citron"
/>
</div>
);
}