diff --git a/web/src/components/editor/AccountDot.tsx b/web/src/components/editor/AccountDot.tsx new file mode 100644 index 0000000..7d9925f --- /dev/null +++ b/web/src/components/editor/AccountDot.tsx @@ -0,0 +1,30 @@ +import styles from './Editor.module.css'; + +/** Chart colours for accounts (design-spec §2.4): `--chart-cat-(position mod 8 + 1)`. */ +const CHART_COLOURS = 8; + +/** An account's colour position: its index among the household's accounts in created order (then id). */ +export function accountColorIndex(accountId: string, accounts: Iterable<{ id: string; created_at: string }>): number { + const ordered = [...accounts].sort((a, b) => + a.created_at < b.created_at ? -1 : a.created_at > b.created_at ? 1 : a.id < b.id ? -1 : a.id > b.id ? 1 : 0, + ); + return Math.max( + 0, + ordered.findIndex((a) => a.id === accountId), + ); +} + +/** The account chip's leading dot (design-spec §3.7): a 12 px circle in the account's chart colour. Decorative. */ +export function AccountDot({ colorIndex, size = 12 }: { colorIndex: number; size?: number }) { + return ( +