2026-08-01 10:54:05 -04:00
|
|
|
|
import { React, ReactNative } from "@vendetta/metro/common";
|
2026-08-03 12:27:33 -04:00
|
|
|
|
import { TableRow, TableRowGroup } from "./table";
|
2026-08-01 10:34:47 -04:00
|
|
|
|
import NoteBox from "./NoteBox";
|
|
|
|
|
|
|
2026-08-01 10:54:05 -04:00
|
|
|
|
const { Text } = ReactNative;
|
2026-08-01 10:34:47 -04:00
|
|
|
|
|
|
|
|
|
|
export interface ListItem {
|
|
|
|
|
|
key: string;
|
|
|
|
|
|
label: string;
|
|
|
|
|
|
subLabel?: string;
|
|
|
|
|
|
onPress?: () => void;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-01 10:54:05 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* A titled section listing tap-able rows, with a friendly note shown in place of an empty list.
|
|
|
|
|
|
* Always pairs onPress with a visible trailing indicator - rows without one have been unreliable
|
|
|
|
|
|
* about actually registering taps in testing.
|
|
|
|
|
|
*/
|
2026-08-01 10:34:47 -04:00
|
|
|
|
export default function ListSection({ title, items, emptyText }: { title: string; items: ListItem[]; emptyText: string }) {
|
|
|
|
|
|
return (
|
2026-08-03 12:27:33 -04:00
|
|
|
|
<TableRowGroup title={title}>
|
2026-08-01 10:34:47 -04:00
|
|
|
|
{items.length === 0 ? (
|
|
|
|
|
|
<NoteBox>{emptyText}</NoteBox>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
items.map((item) => (
|
2026-08-03 12:27:33 -04:00
|
|
|
|
<TableRow
|
2026-08-01 10:54:05 -04:00
|
|
|
|
key={item.key}
|
|
|
|
|
|
label={item.label}
|
|
|
|
|
|
subLabel={item.subLabel}
|
|
|
|
|
|
onPress={item.onPress}
|
|
|
|
|
|
trailing={<Text style={{ color: "#F23F42", fontSize: 20, fontWeight: "700" }}>×</Text>}
|
|
|
|
|
|
/>
|
2026-08-01 10:34:47 -04:00
|
|
|
|
))
|
|
|
|
|
|
)}
|
2026-08-03 12:27:33 -04:00
|
|
|
|
</TableRowGroup>
|
2026-08-01 10:34:47 -04:00
|
|
|
|
);
|
|
|
|
|
|
}
|