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: string;
help?: string;
children: ReactNode;
}) {
return (
{title}
{help ? (
{help}
) : null}
{children}
);
}
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 }: { children: ReactNode }) {
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 ObjectStoreValue({
store,
prefix,
}: {
store: ObjectStoreSettings;
prefix: string;
}) {
if (store.type === "s3") {
const target = `s3://${store.bucket}${prefix ? `/${prefix}` : ""}`;
return (
s3
{target}
{store.region}
);
}
const target = `${store.root}${prefix ? `/${prefix}` : ""}`;
return (
local
{target}
);
}
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}
);
}
export function plural(n: number, singular: string, pluralForm: string) {
return n === 1 ? singular : pluralForm;
}