2026-06-29 00:04:45 +02:00
|
|
|
import type { ReactNode } from "react";
|
|
|
|
|
import Tooltip from "../Tooltip";
|
|
|
|
|
|
|
|
|
|
// Shared form/settings primitives, factored out of the many panels that each re-declared
|
|
|
|
|
// them (Settings, Config, Stats, admin pages, Setup wizard). Visual contract unchanged.
|
|
|
|
|
|
2026-07-04 19:13:11 +02:00
|
|
|
/** Pill on/off switch — the bare control; compose it with your own label/row. Pass `label` for
|
|
|
|
|
* the accessible name (the visible row text) since the control itself has no inner text. */
|
2026-06-29 00:04:45 +02:00
|
|
|
export function Switch({
|
|
|
|
|
checked,
|
|
|
|
|
onChange,
|
2026-07-04 19:13:11 +02:00
|
|
|
label,
|
2026-07-09 15:18:19 +02:00
|
|
|
disabled,
|
2026-06-29 00:04:45 +02:00
|
|
|
}: {
|
|
|
|
|
checked: boolean;
|
|
|
|
|
onChange: (v: boolean) => void;
|
2026-07-04 19:13:11 +02:00
|
|
|
label?: string;
|
2026-07-09 15:18:19 +02:00
|
|
|
disabled?: boolean;
|
2026-06-29 00:04:45 +02:00
|
|
|
}) {
|
|
|
|
|
return (
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
2026-07-04 19:13:11 +02:00
|
|
|
role="switch"
|
|
|
|
|
aria-checked={checked}
|
|
|
|
|
aria-label={label}
|
2026-07-09 15:18:19 +02:00
|
|
|
disabled={disabled}
|
2026-06-29 00:04:45 +02:00
|
|
|
onClick={() => onChange(!checked)}
|
2026-07-09 15:18:19 +02:00
|
|
|
className={`w-9 h-5 rounded-full transition relative shrink-0 disabled:opacity-50 disabled:cursor-not-allowed ${checked ? "bg-accent" : "bg-border"}`}
|
2026-06-29 00:04:45 +02:00
|
|
|
>
|
|
|
|
|
<span
|
|
|
|
|
className={`absolute top-0.5 w-4 h-4 rounded-full bg-white shadow transition-all ${
|
|
|
|
|
checked ? "left-[18px]" : "left-0.5"
|
|
|
|
|
}`}
|
|
|
|
|
/>
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** A titled settings block. Default = a plain block with an uppercase caption; `card` wraps it
|
|
|
|
|
* in a glass card (the admin pages' style). */
|
|
|
|
|
export function Section({
|
|
|
|
|
title,
|
|
|
|
|
card,
|
|
|
|
|
children,
|
|
|
|
|
}: {
|
|
|
|
|
title: string;
|
|
|
|
|
card?: boolean;
|
|
|
|
|
children: ReactNode;
|
|
|
|
|
}) {
|
|
|
|
|
return (
|
|
|
|
|
<div className={card ? "glass rounded-2xl p-4 mb-4" : "mb-6"}>
|
|
|
|
|
<div className={`text-xs uppercase tracking-wide text-muted ${card ? "mb-3" : "mb-2"}`}>
|
|
|
|
|
{title}
|
|
|
|
|
</div>
|
|
|
|
|
{children}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** A label that reveals an explanatory caption on hover (dotted underline) when `hint` is set.
|
|
|
|
|
* No-op styling when there's no hint, so it's safe to use unconditionally. */
|
2026-07-11 04:47:08 +02:00
|
|
|
function HintLabel({ hint, children }: { hint?: string; children: ReactNode }) {
|
2026-06-29 00:04:45 +02:00
|
|
|
return (
|
|
|
|
|
<Tooltip hint={hint ?? ""}>
|
|
|
|
|
<span
|
|
|
|
|
className={
|
|
|
|
|
hint
|
|
|
|
|
? "underline decoration-dotted decoration-muted/40 underline-offset-4 cursor-help"
|
|
|
|
|
: ""
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{children}
|
|
|
|
|
</span>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** A settings row: a (hint-able) label on the left, a control on the right. */
|
|
|
|
|
export function SettingRow({
|
|
|
|
|
label,
|
|
|
|
|
hint,
|
|
|
|
|
children,
|
|
|
|
|
}: {
|
|
|
|
|
label: string;
|
|
|
|
|
hint?: string;
|
|
|
|
|
children: ReactNode;
|
|
|
|
|
}) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex items-center justify-between gap-3 py-1.5 text-sm">
|
|
|
|
|
<HintLabel hint={hint}>{label}</HintLabel>
|
|
|
|
|
{children}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|