@lotics/ui 7.8.0 → 7.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/AGENTS.md +92 -43
  2. package/examples/tpl_allocate.tsx +6 -6
  3. package/examples/tpl_assistant.tsx +1 -1
  4. package/examples/tpl_attendance.tsx +1 -1
  5. package/examples/tpl_billing.tsx +2 -2
  6. package/examples/tpl_briefing.tsx +1 -1
  7. package/examples/tpl_calendar.tsx +1 -1
  8. package/examples/tpl_compare.tsx +1 -1
  9. package/examples/tpl_crosscheck.tsx +1 -1
  10. package/examples/tpl_dashboard.tsx +1 -1
  11. package/examples/tpl_detail.tsx +1 -1
  12. package/examples/tpl_dieline.tsx +2 -2
  13. package/examples/tpl_directory.tsx +5 -8
  14. package/examples/tpl_draft.tsx +2 -2
  15. package/examples/tpl_extract.tsx +1 -1
  16. package/examples/tpl_intake.tsx +1 -1
  17. package/examples/{tpl_dossier.tsx → tpl_item_list.tsx} +138 -97
  18. package/examples/tpl_lookup.tsx +2 -2
  19. package/examples/tpl_match.tsx +2 -2
  20. package/examples/tpl_order.tsx +1 -1
  21. package/examples/tpl_pick.tsx +64 -68
  22. package/examples/tpl_pivot.tsx +1 -1
  23. package/examples/tpl_quick.tsx +1 -1
  24. package/examples/tpl_ratedesk.tsx +1 -1
  25. package/examples/tpl_record_plain.tsx +121 -16
  26. package/examples/tpl_report.tsx +1 -1
  27. package/examples/tpl_rollup.tsx +1 -1
  28. package/examples/tpl_settings.tsx +1 -1
  29. package/examples/tpl_shifts.tsx +1 -1
  30. package/examples/tpl_stock.tsx +1 -1
  31. package/examples/tpl_task_board.tsx +2 -2
  32. package/examples/tpl_tasks.tsx +1 -1
  33. package/examples/tpl_timeline.tsx +1 -1
  34. package/examples/tpl_tower.tsx +1 -1
  35. package/examples/tpl_triage.tsx +1 -1
  36. package/examples/tpl_wizard.tsx +1 -1
  37. package/package.json +5 -1
  38. package/src/card.tsx +6 -13
  39. package/src/danger_zone.tsx +58 -0
  40. package/src/data_grid.tsx +1 -1
  41. package/src/detail_row.tsx +8 -1
  42. package/src/inline_edit.tsx +14 -4
  43. package/src/inline_select.tsx +9 -8
  44. package/src/inline_static.tsx +63 -0
  45. package/src/kpi_strip.tsx +5 -5
  46. package/src/pressable_row.tsx +22 -10
  47. package/src/sort_header.tsx +9 -4
  48. package/src/summary_line.tsx +76 -0
  49. package/src/table.tsx +27 -11
  50. package/src/use_selection.test.ts +66 -0
  51. package/src/use_selection.ts +75 -0
  52. package/examples/app_orders.tsx +0 -405
  53. package/examples/tpl_approvals.tsx +0 -375
  54. package/examples/tpl_batch.tsx +0 -234
  55. package/examples/tpl_callsheet.tsx +0 -481
  56. package/examples/tpl_convert.tsx +0 -478
  57. package/examples/tpl_crm_desk.tsx +0 -541
  58. package/examples/tpl_dispatch.tsx +0 -289
  59. package/examples/tpl_inventory.tsx +0 -299
  60. package/examples/tpl_pipeline.tsx +0 -400
  61. package/examples/tpl_reconcile.tsx +0 -275
  62. package/examples/tpl_record.tsx +0 -302
  63. package/examples/tpl_run.tsx +0 -235
@@ -1,235 +0,0 @@
1
- import { useState } from "react";
2
- import { ScrollView, View } from "react-native";
3
- import { Text } from "@lotics/ui/text";
4
- import { colors, type ColorName } from "@lotics/ui/colors";
5
- import { Badge } from "@lotics/ui/badge";
6
- import { Button } from "@lotics/ui/button";
7
- import { Card, CardFooter } from "@lotics/ui/card";
8
- import { ChipGroup } from "@lotics/ui/chip_group";
9
- import { CompletionState } from "@lotics/ui/completion_state";
10
- import { DetailRow } from "@lotics/ui/detail_row";
11
- import { Divider } from "@lotics/ui/divider";
12
- import { Drawer, DrawerFooter } from "@lotics/ui/drawer";
13
- import { KPIStrip } from "@lotics/ui/kpi_strip";
14
- import { Table, TableRow, TableCell, type TableColumn } from "@lotics/ui/table";
15
- import { formatMoney } from "@lotics/ui/format_money";
16
-
17
- // ─────────────────────────────────────────────────────────────────────────────
18
- // Template · Run & post — stage a bulk operation, PREVIEW what it will do row by
19
- // row with a validation verdict, then commit the valid and HOLD the errors. Here:
20
- // a billing run (generate the period's invoices); the same shape serves a payroll
21
- // run, period-close postings, an MRP run, depreciation. Each row carries a status
22
- // — ready · needs review (posts, flagged) · blocked (held) — with the reason
23
- // inline; blockers are resolved in the drawer, which moves them back into the
24
- // postable set. The footer "Post" is GATED: you can never post a blocked line, and
25
- // the run can't apply more than it previews. CompletionState closes the run.
26
- // ─────────────────────────────────────────────────────────────────────────────
27
-
28
- type RunStatus = "ready" | "review" | "blocked";
29
-
30
- interface RunLine {
31
- id: string;
32
- customer: string;
33
- ref: string;
34
- amount: number;
35
- status: RunStatus;
36
- /** Why it's flagged / held — shown inline and in the drawer. */
37
- issue?: string;
38
- }
39
-
40
- const STATUS: Record<RunStatus, { label: string; color: ColorName }> = {
41
- ready: { label: "Ready", color: "emerald" },
42
- review: { label: "Needs review", color: "amber" },
43
- blocked: { label: "Blocked", color: "red" },
44
- };
45
-
46
- const LINES: RunLine[] = [
47
- { id: "SO-4021", customer: "ATLAS COMPONENTS", ref: "Order SO-4021", amount: 31_414_670, status: "ready" },
48
- { id: "SO-4024", customer: "Northwind Packaging", ref: "Order SO-4024", amount: 18_900_000, status: "ready" },
49
- { id: "SO-4025", customer: "CRESTLINE FURNITURE", ref: "Order SO-4025", amount: 4_000_000, status: "review", issue: "PO number missing — invoice will post without it" },
50
- { id: "SO-4027", customer: "King Lun Plastics", ref: "Order SO-4027", amount: 23_400_000, status: "ready" },
51
- { id: "SO-4030", customer: "Vittoria Accessories", ref: "Order SO-4030", amount: 22_500_000, status: "review", issue: "Customer over credit limit by ₫8.4M" },
52
- { id: "SO-4031", customer: "Harbor Industries", ref: "Order SO-4031", amount: 13_650_000, status: "blocked", issue: "Customer tax ID missing — cannot issue a tax invoice" },
53
- { id: "SO-4033", customer: "Summit Logistics", ref: "Order SO-4033", amount: 9_180_000, status: "ready" },
54
- { id: "SO-4035", customer: "Beacon Supplies", ref: "Order SO-4035", amount: 28_800_000, status: "blocked", issue: "Customer on credit hold — release the hold to invoice" },
55
- { id: "SO-4036", customer: "Meridian Foods", ref: "Order SO-4036", amount: 16_320_000, status: "ready" },
56
- ];
57
-
58
- const FILTERS: { value: string; label: string }[] = [
59
- { value: "all", label: "All" },
60
- { value: "ready", label: "Ready" },
61
- { value: "review", label: "Needs review" },
62
- { value: "blocked", label: "Blocked" },
63
- ];
64
-
65
- const COLUMNS: TableColumn[] = [
66
- { key: "customer", label: "Customer", flex: 1 },
67
- { key: "amount", label: "Amount", width: 150, align: "right" },
68
- { key: "status", label: "Verdict", width: 230 },
69
- ];
70
-
71
- function RunRow({ line, status, onPress }: { line: RunLine; status: RunStatus; onPress: () => void }) {
72
- const meta = STATUS[status];
73
- return (
74
- <TableRow onPress={onPress} accessibilityLabel={`Inspect ${line.customer}`}>
75
- <TableCell>
76
- <View style={{ gap: 0 }}>
77
- <Text size="sm" weight="medium" numberOfLines={1}>{line.customer}</Text>
78
- <Text size="xs" color="muted" tabular>{line.ref}</Text>
79
- </View>
80
- </TableCell>
81
- <TableCell>
82
- <Text size="sm" tabular>{formatMoney(line.amount)}</Text>
83
- </TableCell>
84
- <TableCell>
85
- <View style={{ gap: 2 }}>
86
- <Badge variant="dot" label={meta.label} color={meta.color} />
87
- {status !== "ready" && line.issue ? (
88
- <Text size="xs" color={status === "blocked" ? "danger" : "muted"} numberOfLines={1}>{line.issue}</Text>
89
- ) : null}
90
- </View>
91
- </TableCell>
92
- </TableRow>
93
- );
94
- }
95
-
96
- function InspectLine({ line, status, onResolve }: { line: RunLine; status: RunStatus; onResolve: () => void }) {
97
- const meta = STATUS[status];
98
- return (
99
- <>
100
- <ScrollView style={{ flex: 1 }} contentContainerStyle={{ padding: 24, gap: 16 }}>
101
- <View style={{ flexDirection: "row", alignItems: "center", gap: 8 }}>
102
- <Badge variant="dot" label={meta.label} color={meta.color} />
103
- <Text size="xs" color="muted" tabular style={{ flex: 1, textAlign: "right" }}>{line.ref}</Text>
104
- </View>
105
- <Text size="md" weight="medium">{line.customer}</Text>
106
- <View style={{ gap: 6 }}>
107
- <DetailRow label="Invoice total"><Text size="sm" weight="semibold" tabular>{formatMoney(line.amount)}</Text></DetailRow>
108
- <Divider />
109
- <DetailRow label="Source"><Text size="sm" tabular>{line.ref}</Text></DetailRow>
110
- </View>
111
- {status !== "ready" && line.issue ? (
112
- <View style={{ gap: 4, padding: 14, borderRadius: 10, backgroundColor: status === "blocked" ? colors.red[50] : colors.amber[50] }}>
113
- <Text size="xs" weight="semibold" color={status === "blocked" ? "danger" : "default"} transform="uppercase">
114
- {status === "blocked" ? "Blocked" : "Needs review"}
115
- </Text>
116
- <Text size="sm">{line.issue}</Text>
117
- </View>
118
- ) : (
119
- <Text size="sm" color="muted">No issues — this invoice will post in the run.</Text>
120
- )}
121
- </ScrollView>
122
- <DrawerFooter>
123
- {status === "blocked" ? (
124
- <Button title="Resolve & include" color="primary" onPress={onResolve} />
125
- ) : (
126
- <Button title="Open order record" color="primary" onPress={() => {}} />
127
- )}
128
- </DrawerFooter>
129
- </>
130
- );
131
- }
132
-
133
- export function TplRun() {
134
- const [resolved, setResolved] = useState<Set<string>>(new Set());
135
- const [filter, setFilter] = useState("all");
136
- const [openId, setOpenId] = useState<string | null>(null);
137
- const [posted, setPosted] = useState(false);
138
-
139
- // A resolved blocker re-enters the run as ready; a review still posts.
140
- const statusOf = (l: RunLine): RunStatus => (resolved.has(l.id) && l.status === "blocked" ? "ready" : l.status);
141
-
142
- const counts = { ready: 0, review: 0, blocked: 0 } as Record<RunStatus, number>;
143
- LINES.forEach((l) => { counts[statusOf(l)] += 1; });
144
-
145
- const postable = LINES.filter((l) => statusOf(l) !== "blocked");
146
- const blocked = LINES.filter((l) => statusOf(l) === "blocked");
147
- const postValue = postable.reduce((s, l) => s + l.amount, 0);
148
-
149
- const visible = LINES.filter((l) => filter === "all" || statusOf(l) === filter);
150
- const open = openId === null ? null : LINES.find((l) => l.id === openId) ?? null;
151
-
152
- if (posted) {
153
- return (
154
- <ScrollView style={{ flex: 1, backgroundColor: colors.zinc[50] }} contentContainerStyle={{ padding: 28 }}>
155
- <View style={{ width: "100%", maxWidth: 1000, alignSelf: "center" }}>
156
- <Card style={{ padding: 0 }}>
157
- <CompletionState
158
- title="Billing run posted"
159
- summary={`${postable.length} invoices · ${formatMoney(postValue)}${blocked.length ? ` · ${blocked.length} held for fixes` : ""}`}
160
- >
161
- <Button title="Start a new run" color="muted" onPress={() => { setPosted(false); setResolved(new Set()); setFilter("all"); }} />
162
- <Button title="View posted invoices" color="primary" onPress={() => {}} />
163
- </CompletionState>
164
- </Card>
165
- </View>
166
- </ScrollView>
167
- );
168
- }
169
-
170
- return (
171
- <ScrollView style={{ flex: 1, backgroundColor: colors.zinc[50] }} contentContainerStyle={{ padding: 28 }}>
172
- <View style={{ width: "100%", maxWidth: 1000, alignSelf: "center", gap: 16 }}>
173
- {/* header */}
174
- <View style={{ gap: 2 }}>
175
- <Text size="xl" weight="semibold">June billing run</Text>
176
- <Text size="sm" color="muted">Preview every invoice the run will create, clear the blockers, then post — blocked lines are held, never posted</Text>
177
- </View>
178
-
179
- {/* the run summary — the verdict breakdown the commit gates on */}
180
- <KPIStrip
181
- items={[
182
- { label: "Ready", value: counts.ready, format: "number" },
183
- { label: "Needs review", value: counts.review, format: "number", tone: counts.review > 0 ? "warning" : "default", info: "Soft issues — these post, but the flag is recorded (missing PO, over credit limit)." },
184
- { label: "Blocked", value: counts.blocked, format: "number", tone: counts.blocked > 0 ? "danger" : "default", info: "Hard blockers — held out of the run until resolved (no tax ID, on credit hold)." },
185
- { label: "Value to post", value: postValue, format: "currency", compact: true, caption: `${postable.length} invoices` },
186
- ]}
187
- />
188
-
189
- {/* preview register — filter to the verdict you're working */}
190
- <Card style={{ padding: 0 }}>
191
- <View style={{ paddingHorizontal: 20, paddingVertical: 12 }}>
192
- <ChipGroup
193
- accessibilityLabel="Filter by verdict"
194
- options={FILTERS.map((f) => ({
195
- label: f.value === "all" ? `All · ${LINES.length}` : `${f.label} · ${counts[f.value as RunStatus]}`,
196
- value: f.value,
197
- }))}
198
- value={filter}
199
- onValueChange={setFilter}
200
- />
201
- </View>
202
- <Table columns={COLUMNS}>
203
- {visible.map((l) => (
204
- <RunRow key={l.id} line={l} status={statusOf(l)} onPress={() => setOpenId(l.id)} />
205
- ))}
206
- </Table>
207
- <CardFooter>
208
- <Text size="xs" color={blocked.length > 0 ? "danger" : "muted"} style={{ flex: 1 }}>
209
- {blocked.length > 0
210
- ? `${blocked.length} blocked held back — resolve to include them`
211
- : "All lines clear — nothing held back"}
212
- </Text>
213
- <Button
214
- title={`Post ${postable.length} invoices`}
215
- color="primary"
216
- disabled={postable.length === 0}
217
- onPress={() => setPosted(true)}
218
- />
219
- </CardFooter>
220
- </Card>
221
- </View>
222
-
223
- {open !== null ? (
224
- <Drawer open onOpenChange={(o) => !o && setOpenId(null)} title={open.customer} width={440}>
225
- <InspectLine
226
- key={open.id}
227
- line={open}
228
- status={statusOf(open)}
229
- onResolve={() => { setResolved((prev) => new Set(prev).add(open.id)); setOpenId(null); }}
230
- />
231
- </Drawer>
232
- ) : null}
233
- </ScrollView>
234
- );
235
- }