import type { ReactNode } from "react";
import type { ObjectStoreSettings } from "@qltysh/fabro-api-client";
export type SettingsView = "settings" | "json";
export function Panel({ title, children }: { title: string; children: ReactNode }) {
return (
);
}
export function PanelSkeleton() {
return (
);
}
export function Row({
title,
help,
children,
}: {
title: ReactNode;
help?: ReactNode;
children: ReactNode;
}) {
return (
{title}
{help ? (
{help}
) : null}
{children}
);
}
export function Label({
children,
required,
optional,
}: {
children: ReactNode;
required?: boolean;
optional?: boolean;
}) {
return (
{children}
{required ? (
*
) : null}
{optional ? Optional : null}
);
}
export function SettingsPageIntro({
description,
action,
view,
setView,
}: {
description: ReactNode;
action?: ReactNode;
view?: SettingsView;
setView?: (v: SettingsView) => void;
}) {
const trailing =
action ??
(view !== undefined && setView ? (
) : null);
return (
{description}
{trailing ?
{trailing}
: null}
);
}
export function ViewToggle({
view,
setView,
}: {
view: SettingsView;
setView: (v: SettingsView) => void;
}) {
const btn = "rounded px-3 py-1.5 text-xs font-medium transition-colors";
return (
);
}
export function Mono({
children,
title,
}: {
children: ReactNode;
title?: string;
}) {
return (
{children}
);
}
export function Muted({ children }: { children: ReactNode }) {
return {children};
}
export function Badge({ children }: { children: ReactNode }) {
return (
{children}
);
}
export function NumberValue({ value }: { value: number }) {
return {value};
}
export function Dot({ on }: { on: boolean }) {
return (
);
}
export function Toggle({ on }: { on: boolean }) {
return (
{on ? "Enabled" : "Disabled"}
);
}
export function UrlValue({ url }: { url: string }) {
return (
{url}
);
}
export function ObjectStoreRows({
store,
prefix,
}: {
store: ObjectStoreSettings;
prefix: string;
}) {
const prefixRow = (
{prefix ? {prefix} : None}
);
if (store.type === "s3") {
return (
<>
s3
{store.bucket}
{store.region}
{store.endpoint ? (
{store.endpoint}
) : null}
{store.path_style ? (
) : null}
{prefixRow}
>
);
}
return (
<>
local
{store.root}
{prefixRow}
>
);
}
export function UsernameList({ names }: { names: string[] }) {
const visible = names.slice(0, 3);
const remaining = names.length - visible.length;
return (
{visible.map((n) => (
{n}
))}
{remaining > 0 ? (
+{remaining} more
) : null}
);
}
export function Count({
n,
singular,
plural: pluralLabel,
suffix,
}: {
n: number;
singular: string;
plural: string;
suffix?: string;
}) {
if (n === 0) return None;
return (
{n}{" "}
{n === 1 ? singular : pluralLabel}
{suffix ? {suffix} : null}
);
}