@partrunner-ai/ui 2.4.4 → 2.5.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.
@@ -0,0 +1,290 @@
1
+ # Recipe: List page
2
+
3
+ The person finds records, then acts on one.
4
+
5
+ This is the full source of a screen that compiles and is tested. Copy the structure and
6
+ the props. Replace the sample data with the data of the app.
7
+
8
+ - `./fixtures` is sample data and two format helpers (`formatMoney`, `formatDate`). Use the
9
+ app's own data and its shared format helpers.
10
+ - `./states` is in `states.md`.
11
+ - The `state` prop exists only to show each state in the catalogue. In an app, the state
12
+ comes from the data request.
13
+ - The rules are in `../DESIGN.md`.
14
+
15
+ <!-- Generated from packages/showcase/src/recipes/ListPageRecipe.tsx. Do not edit. -->
16
+
17
+ ```tsx
18
+ import { useMemo, useState } from 'react';
19
+ import { CheckCircle2, Clock, Download, Plus, Truck, Timer } from 'lucide-react';
20
+ import {
21
+ Badge,
22
+ Button,
23
+ DateRangeFilter,
24
+ EMPTY_DATE_RANGE,
25
+ FilterChip,
26
+ FilterChipRow,
27
+ MultiSelect,
28
+ Page,
29
+ PageHeader,
30
+ Pagination,
31
+ SearchField,
32
+ Skeleton,
33
+ StatTile,
34
+ StatTileGrid,
35
+ Table,
36
+ TableFrame,
37
+ TableSkeleton,
38
+ Toolbar,
39
+ ToolbarGroup,
40
+ type DateRange,
41
+ } from '@partrunner-ai/ui';
42
+ import {
43
+ PLACEMENTS,
44
+ PLACEMENT_STATUS,
45
+ PROJECTS,
46
+ formatDate,
47
+ formatMoney,
48
+ type Placement,
49
+ type PlacementStatus,
50
+ } from './fixtures';
51
+ import { ErrorNotice, ForbiddenState, NoResults, type RecipeProps } from './states';
52
+
53
+ const PAGE_SIZE = 8;
54
+
55
+ const DATE_LABELS = {
56
+ allTime: 'Todo el tiempo',
57
+ custom: 'Rango personalizado',
58
+ from: 'Desde',
59
+ to: 'Hasta',
60
+ apply: 'Aplicar',
61
+ clear: 'Limpiar',
62
+ dialog: 'Filtrar por fechas',
63
+ };
64
+
65
+ const DATE_PRESETS = [
66
+ { id: '7d', label: 'Últimos 7 días', range: { from: '2026-11-18', to: '2026-11-24' } },
67
+ { id: 'month', label: 'Este mes', range: { from: '2026-11-01', to: '2026-11-30' } },
68
+ ];
69
+
70
+ const PROJECT_OPTIONS = PROJECTS.map((project) => ({ value: project, label: project }));
71
+
72
+ const COLUMNS = [
73
+ {
74
+ key: 'driver',
75
+ header: 'Conductor',
76
+ render: (row: Placement) => row.driver,
77
+ },
78
+ { key: 'plate', header: 'Placa', render: (row: Placement) => row.plate, hideOnMobile: true },
79
+ { key: 'fleet', header: 'Flota', render: (row: Placement) => row.fleet, hideOnMobile: true },
80
+ { key: 'project', header: 'Proyecto', render: (row: Placement) => row.project, hideOnMobile: true },
81
+ { key: 'date', header: 'Fecha', render: (row: Placement) => formatDate(row.date), hideOnMobile: true },
82
+ {
83
+ key: 'rate',
84
+ header: 'Tarifa semanal',
85
+ align: 'right' as const,
86
+ render: (row: Placement) => formatMoney(row.weeklyRate),
87
+ },
88
+ {
89
+ key: 'status',
90
+ header: 'Estado',
91
+ render: (row: Placement) => (
92
+ <Badge tone={PLACEMENT_STATUS[row.status].tone}>{PLACEMENT_STATUS[row.status].label}</Badge>
93
+ ),
94
+ },
95
+ ];
96
+
97
+ /** Recipe 2.1 · List page: header, stat tiles, status chips, toolbar, table, pagination. */
98
+ export function ListPageRecipe({ state, onRetry }: RecipeProps) {
99
+ const [status, setStatus] = useState<'all' | PlacementStatus>('all');
100
+ const [query, setQuery] = useState('');
101
+ const [projects, setProjects] = useState<string[]>([]);
102
+ const [range, setRange] = useState<DateRange>(EMPTY_DATE_RANGE);
103
+ const [page, setPage] = useState(1);
104
+
105
+ const source = useMemo(() => (state === 'empty' ? [] : PLACEMENTS), [state]);
106
+
107
+ const counts = useMemo(() => {
108
+ const result = { all: source.length, pending: 0, placed: 0, cancelled: 0 };
109
+ for (const row of source) result[row.status] += 1;
110
+ return result;
111
+ }, [source]);
112
+
113
+ const rows = useMemo(() => {
114
+ const needle = query.trim().toLowerCase();
115
+ return source.filter((row) => {
116
+ if (status !== 'all' && row.status !== status) return false;
117
+ if (projects.length > 0 && !projects.includes(row.project)) return false;
118
+ if (range.from && row.date < range.from) return false;
119
+ if (range.to && row.date > range.to) return false;
120
+ if (!needle) return true;
121
+ return [row.driver, row.plate, row.fleet].some((value) => value.toLowerCase().includes(needle));
122
+ });
123
+ }, [source, status, projects, range, query]);
124
+
125
+ const pageRows = rows.slice((page - 1) * PAGE_SIZE, page * PAGE_SIZE);
126
+ const filtered = status !== 'all' || query !== '' || projects.length > 0 || range.from !== '';
127
+
128
+ const header = (
129
+ <PageHeader
130
+ title="Colocadas"
131
+ subtitle="Conductores asignados a una flota y a un proyecto esta semana."
132
+ actions={
133
+ state === 'forbidden' ? undefined : (
134
+ <Button icon={Plus} disabled={state === 'loading'}>
135
+ Nueva colocada
136
+ </Button>
137
+ )
138
+ }
139
+ />
140
+ );
141
+
142
+ if (state === 'forbidden') {
143
+ return (
144
+ <Page width="wide">
145
+ {header}
146
+ <ForbiddenState who="el equipo de Operaciones" />
147
+ </Page>
148
+ );
149
+ }
150
+
151
+ if (state === 'loading') {
152
+ return (
153
+ <Page width="wide">
154
+ {header}
155
+ <StatTileGrid columns={4}>
156
+ {[0, 1, 2, 3].map((item) => (
157
+ <Skeleton key={item} shape="block" height={96} />
158
+ ))}
159
+ </StatTileGrid>
160
+ <TableSkeleton rows={8} columns={7} label="Cargando colocadas" />
161
+ </Page>
162
+ );
163
+ }
164
+
165
+ return (
166
+ <Page width="wide">
167
+ {header}
168
+ {state === 'error' ? <ErrorNotice what="las colocadas" onRetry={onRetry} /> : null}
169
+ <StatTileGrid columns={4}>
170
+ <StatTile label="Colocadas del mes" value={counts.all} icon={Truck} tone="neutral" hint="24 nov 2026" />
171
+ <StatTile label="Confirmadas" value={counts.placed} icon={CheckCircle2} tone="green" />
172
+ <StatTile label="Pendientes" value={counts.pending} icon={Clock} tone="amber" hint="Esperan confirmación" />
173
+ <StatTile label="Tiempo promedio" value={counts.all === 0 ? '—' : '2.4 días'} icon={Timer} tone="neutral" hint="De solicitud a colocada" />
174
+ </StatTileGrid>
175
+
176
+ <FilterChipRow aria-label="Filtrar por estado">
177
+ <FilterChip active={status === 'all'} count={counts.all} onClick={() => { setStatus('all'); setPage(1); }}>
178
+ Todas
179
+ </FilterChip>
180
+ {(Object.keys(PLACEMENT_STATUS) as PlacementStatus[]).map((key) => (
181
+ <FilterChip
182
+ key={key}
183
+ active={status === key}
184
+ count={counts[key]}
185
+ onClick={() => { setStatus(key); setPage(1); }}
186
+ >
187
+ {PLACEMENT_STATUS[key].label}
188
+ </FilterChip>
189
+ ))}
190
+ </FilterChipRow>
191
+
192
+ <Toolbar aria-label="Filtros de colocadas">
193
+ <ToolbarGroup>
194
+ <SearchField
195
+ aria-label="Buscar colocada"
196
+ placeholder="Buscar conductor o placa"
197
+ value={query}
198
+ onChange={(event) => { setQuery(event.target.value); setPage(1); }}
199
+ />
200
+ </ToolbarGroup>
201
+ <ToolbarGroup>
202
+ <DateRangeFilter
203
+ aria-label="Ventana de fechas"
204
+ value={range}
205
+ onChange={(next) => { setRange(next); setPage(1); }}
206
+ presets={DATE_PRESETS}
207
+ labels={DATE_LABELS}
208
+ locale="es-MX"
209
+ size="sm"
210
+ />
211
+ <MultiSelect
212
+ variant="filter"
213
+ aria-label="Filtrar por proyecto"
214
+ placeholder="Proyecto"
215
+ clearLabel="Quitar filtro"
216
+ options={PROJECT_OPTIONS}
217
+ value={projects}
218
+ onChange={(next) => { setProjects(next); setPage(1); }}
219
+ />
220
+ </ToolbarGroup>
221
+ </Toolbar>
222
+
223
+ <TableFrame
224
+ title="Colocadas"
225
+ count={rows.length}
226
+ countLabel={(count) => `${count} registros`}
227
+ actions={
228
+ <Button size="sm" variant="secondary" icon={Download}>
229
+ Exportar CSV
230
+ </Button>
231
+ }
232
+ footer={
233
+ rows.length > PAGE_SIZE ? (
234
+ <Pagination
235
+ aria-label="Paginación de colocadas"
236
+ page={page}
237
+ pageSize={PAGE_SIZE}
238
+ totalItems={rows.length}
239
+ onPageChange={setPage}
240
+ labels={{
241
+ previous: 'Página anterior',
242
+ next: 'Página siguiente',
243
+ summary: ({ start, end, totalItems }) => `${start}–${end} de ${totalItems}`,
244
+ }}
245
+ />
246
+ ) : undefined
247
+ }
248
+ >
249
+ <Table
250
+ bare
251
+ label="Colocadas"
252
+ columns={COLUMNS}
253
+ rows={pageRows}
254
+ getRowKey={rowId}
255
+ empty={
256
+ filtered ? (
257
+ <NoResults
258
+ title="Ninguna colocada coincide"
259
+ description="Cambia o quita los filtros para ver más registros."
260
+ action={
261
+ <Button
262
+ variant="secondary"
263
+ onClick={() => {
264
+ setStatus('all');
265
+ setQuery('');
266
+ setProjects([]);
267
+ setRange(EMPTY_DATE_RANGE);
268
+ }}
269
+ >
270
+ Quitar filtros
271
+ </Button>
272
+ }
273
+ />
274
+ ) : (
275
+ <NoResults
276
+ title="Aún no hay colocadas"
277
+ description="Cuando asignes un conductor a una flota, aparecerá aquí."
278
+ />
279
+ )
280
+ }
281
+ />
282
+ </TableFrame>
283
+ </Page>
284
+ );
285
+ }
286
+
287
+ function rowId(row: { id: string }): string {
288
+ return row.id;
289
+ }
290
+ ```
@@ -0,0 +1,198 @@
1
+ # Recipe: Record page
2
+
3
+ The person reads one record and acts on it.
4
+
5
+ This is the full source of a screen that compiles and is tested. Copy the structure and
6
+ the props. Replace the sample data with the data of the app.
7
+
8
+ - `./fixtures` is sample data and two format helpers (`formatMoney`, `formatDate`). Use the
9
+ app's own data and its shared format helpers.
10
+ - `./states` is in `states.md`.
11
+ - The `state` prop exists only to show each state in the catalogue. In an app, the state
12
+ comes from the data request.
13
+ - The rules are in `../DESIGN.md`.
14
+
15
+ <!-- Generated from packages/showcase/src/recipes/RecordPageRecipe.tsx. Do not edit. -->
16
+
17
+ ```tsx
18
+ import { Pencil, Plus } from 'lucide-react';
19
+ import {
20
+ Badge,
21
+ Button,
22
+ Card,
23
+ DetailItem,
24
+ DetailList,
25
+ Notice,
26
+ Page,
27
+ PageHeader,
28
+ PageSkeleton,
29
+ SectionHeading,
30
+ Table,
31
+ TableFrame,
32
+ Tabs,
33
+ TabsContent,
34
+ TabsList,
35
+ TabsTrigger,
36
+ } from '@partrunner-ai/ui';
37
+ import {
38
+ FLEET_CHARGES,
39
+ FLEET_PAYMENTS,
40
+ FLEET_RECORD,
41
+ FLEET_ROUTES,
42
+ formatDate,
43
+ formatMoney,
44
+ } from './fixtures';
45
+ import { ErrorNotice, ForbiddenState, NoResults, type RecipeProps } from './states';
46
+
47
+ const ROUTE_COLUMNS = [
48
+ { key: 'route', header: 'Ruta', render: (row: (typeof FLEET_ROUTES)[number]) => row.route },
49
+ { key: 'project', header: 'Proyecto', render: (row: (typeof FLEET_ROUTES)[number]) => row.project, hideOnMobile: true },
50
+ { key: 'date', header: 'Fecha', render: (row: (typeof FLEET_ROUTES)[number]) => formatDate(row.date), hideOnMobile: true },
51
+ { key: 'units', header: 'Unidades', align: 'right' as const, render: (row: (typeof FLEET_ROUTES)[number]) => row.units, hideOnMobile: true },
52
+ { key: 'amount', header: 'Importe', align: 'right' as const, render: (row: (typeof FLEET_ROUTES)[number]) => formatMoney(row.amount) },
53
+ {
54
+ key: 'status',
55
+ header: 'Estado',
56
+ render: (row: (typeof FLEET_ROUTES)[number]) => (
57
+ <Badge tone={row.status === 'done' ? 'success' : 'neutral'}>{row.status === 'done' ? 'Cerrada' : 'En curso'}</Badge>
58
+ ),
59
+ },
60
+ ];
61
+
62
+ const CHARGE_COLUMNS = [
63
+ { key: 'concept', header: 'Concepto', render: (row: (typeof FLEET_CHARGES)[number]) => row.concept },
64
+ { key: 'week', header: 'Semana', render: (row: (typeof FLEET_CHARGES)[number]) => row.week, hideOnMobile: true },
65
+ { key: 'date', header: 'Fecha', render: (row: (typeof FLEET_CHARGES)[number]) => formatDate(row.date), hideOnMobile: true },
66
+ { key: 'amount', header: 'Monto', align: 'right' as const, render: (row: (typeof FLEET_CHARGES)[number]) => formatMoney(row.amount) },
67
+ {
68
+ key: 'status',
69
+ header: 'Estado',
70
+ render: (row: (typeof FLEET_CHARGES)[number]) => (
71
+ <Badge tone={row.status === 'applied' ? 'success' : 'warning'}>{row.status === 'applied' ? 'Aplicado' : 'Pendiente'}</Badge>
72
+ ),
73
+ },
74
+ ];
75
+
76
+ const PAYMENT_COLUMNS = [
77
+ { key: 'week', header: 'Semana', render: (row: (typeof FLEET_PAYMENTS)[number]) => row.week },
78
+ { key: 'date', header: 'Fecha de pago', render: (row: (typeof FLEET_PAYMENTS)[number]) => formatDate(row.date), hideOnMobile: true },
79
+ { key: 'amount', header: 'Monto', align: 'right' as const, render: (row: (typeof FLEET_PAYMENTS)[number]) => formatMoney(row.amount) },
80
+ {
81
+ key: 'status',
82
+ header: 'Estado',
83
+ render: (row: (typeof FLEET_PAYMENTS)[number]) => (
84
+ <Badge tone={row.status === 'paid' ? 'success' : 'warning'}>{row.status === 'paid' ? 'Pagado' : 'Retenido'}</Badge>
85
+ ),
86
+ },
87
+ ];
88
+
89
+ /** Recipe 2.2 · Record page: header, notice, summary card, tabs with tables. */
90
+ export function RecordPageRecipe({ state, onRetry }: RecipeProps) {
91
+ const fleet = FLEET_RECORD;
92
+
93
+ if (state === 'loading') {
94
+ return (
95
+ <Page width="wide">
96
+ <PageSkeleton variant="detail" label="Cargando flota" />
97
+ </Page>
98
+ );
99
+ }
100
+ if (state === 'forbidden') {
101
+ return (
102
+ <Page width="wide">
103
+ <PageHeader title="Ficha de flota" />
104
+ <ForbiddenState who="Finanzas y Soporte a flotas" />
105
+ </Page>
106
+ );
107
+ }
108
+ if (state === 'empty') {
109
+ return (
110
+ <Page width="wide">
111
+ <PageHeader title="Ficha de flota" />
112
+ <NoResults
113
+ title="No encontramos esta flota"
114
+ description="El enlace puede estar incompleto o la flota ya no existe."
115
+ action={<Button variant="secondary">Ver todas las flotas</Button>}
116
+ />
117
+ </Page>
118
+ );
119
+ }
120
+
121
+ return (
122
+ <Page width="wide">
123
+ <PageHeader
124
+ eyebrow="Flotas"
125
+ title={fleet.name}
126
+ subtitle={`${fleet.rfc} · ${fleet.city}`}
127
+ actions={
128
+ <>
129
+ <Button variant="secondary" icon={Pencil}>
130
+ Editar datos
131
+ </Button>
132
+ <Button icon={Plus}>Crear plan de pago</Button>
133
+ </>
134
+ }
135
+ />
136
+ {state === 'error' ? <ErrorNotice what="la ficha de la flota" onRetry={onRetry} /> : null}
137
+ <Notice
138
+ tone="warning"
139
+ title="Pago de la semana 47 retenido"
140
+ actions={
141
+ <Button size="sm" variant="secondary">
142
+ Ver pagos
143
+ </Button>
144
+ }
145
+ >
146
+ Falta la constancia de situación fiscal vigente. Se libera cuando Finanzas la valide.
147
+ </Notice>
148
+
149
+ <Card>
150
+ <SectionHeading title="Datos generales" description={fleet.note} />
151
+ <DetailList columns={3}>
152
+ <DetailItem label="RFC">{fleet.rfc}</DetailItem>
153
+ <DetailItem label="Régimen fiscal">{fleet.regime}</DetailItem>
154
+ <DetailItem label="Código postal">{fleet.zip}</DetailItem>
155
+ <DetailItem label="Unidades activas" numeric>
156
+ {fleet.units}
157
+ </DetailItem>
158
+ <DetailItem label="Saldo a cargo" numeric>
159
+ {formatMoney(fleet.balance)}
160
+ </DetailItem>
161
+ <DetailItem label="Cliente desde">{formatDate(fleet.since)}</DetailItem>
162
+ <DetailItem label="CLABE">{fleet.clabe}</DetailItem>
163
+ <DetailItem label="Contacto" span={2}>
164
+ {fleet.contact}
165
+ </DetailItem>
166
+ </DetailList>
167
+ </Card>
168
+
169
+ <Tabs defaultValue="routes">
170
+ <TabsList>
171
+ <TabsTrigger value="routes">Rutas</TabsTrigger>
172
+ <TabsTrigger value="charges">Cargos</TabsTrigger>
173
+ <TabsTrigger value="payments">Pagos</TabsTrigger>
174
+ </TabsList>
175
+ <TabsContent value="routes">
176
+ <TableFrame title="Rutas de la semana" count={FLEET_ROUTES.length} countLabel={(count) => `${count} rutas`}>
177
+ <Table bare label="Rutas" columns={ROUTE_COLUMNS} rows={FLEET_ROUTES} getRowKey={rowId} />
178
+ </TableFrame>
179
+ </TabsContent>
180
+ <TabsContent value="charges">
181
+ <TableFrame title="Cargos y descuentos" count={FLEET_CHARGES.length} countLabel={(count) => `${count} cargos`}>
182
+ <Table bare label="Cargos" columns={CHARGE_COLUMNS} rows={FLEET_CHARGES} getRowKey={rowId} />
183
+ </TableFrame>
184
+ </TabsContent>
185
+ <TabsContent value="payments">
186
+ <TableFrame title="Historial de pagos" count={FLEET_PAYMENTS.length} countLabel={(count) => `${count} pagos`}>
187
+ <Table bare label="Pagos" columns={PAYMENT_COLUMNS} rows={FLEET_PAYMENTS} getRowKey={rowId} />
188
+ </TableFrame>
189
+ </TabsContent>
190
+ </Tabs>
191
+ </Page>
192
+ );
193
+ }
194
+
195
+ function rowId(row: { id: string }): string {
196
+ return row.id;
197
+ }
198
+ ```
@@ -0,0 +1,78 @@
1
+ # Recipe: State helpers
2
+
3
+ The error, no-permission and no-results blocks that the recipes share.
4
+
5
+ This is the full source of a screen that compiles and is tested. Copy the structure and
6
+ the props. Replace the sample data with the data of the app.
7
+
8
+ - `./fixtures` is sample data and two format helpers (`formatMoney`, `formatDate`). Use the
9
+ app's own data and its shared format helpers.
10
+ - `./states` is in `states.md`.
11
+ - The `state` prop exists only to show each state in the catalogue. In an app, the state
12
+ comes from the data request.
13
+ - The rules are in `../DESIGN.md`.
14
+
15
+ <!-- Generated from packages/showcase/src/recipes/states.tsx. Do not edit. -->
16
+
17
+ ```tsx
18
+ import { type ReactNode } from 'react';
19
+ import { Lock, SearchX } from 'lucide-react';
20
+ import { Button, EmptyState, Notice } from '@partrunner-ai/ui';
21
+
22
+ export type RecipeState = 'data' | 'loading' | 'empty' | 'error' | 'forbidden';
23
+
24
+ export const STATE_OPTIONS: Array<{ value: RecipeState; label: string }> = [
25
+ { value: 'data', label: 'Datos' },
26
+ { value: 'loading', label: 'Cargando' },
27
+ { value: 'empty', label: 'Vacío' },
28
+ { value: 'error', label: 'Error' },
29
+ { value: 'forbidden', label: 'Sin permiso' },
30
+ ];
31
+
32
+ export interface RecipeProps {
33
+ state: RecipeState;
34
+ /** Called by «Reintentar» in the error state. */
35
+ onRetry: () => void;
36
+ }
37
+
38
+ /** Error state: a danger Notice with one retry action. The page frame stays. */
39
+ export function ErrorNotice({ what, onRetry }: { what: string; onRetry: () => void }) {
40
+ return (
41
+ <Notice
42
+ tone="danger"
43
+ title={`No se pudo cargar ${what}`}
44
+ actions={
45
+ <Button size="sm" variant="secondary" onClick={onRetry}>
46
+ Reintentar
47
+ </Button>
48
+ }
49
+ >
50
+ Revisa tu conexión e inténtalo de nuevo. Si el problema sigue, avisa al equipo de plataforma.
51
+ </Notice>
52
+ );
53
+ }
54
+
55
+ /** No-permission state: no data, no tabs, no actions. Says who can see it. */
56
+ export function ForbiddenState({ who }: { who: string }) {
57
+ return (
58
+ <EmptyState
59
+ icon={Lock}
60
+ title="No tienes acceso a esta sección"
61
+ description={`Solo ${who} puede verla. Pide acceso a tu administrador.`}
62
+ />
63
+ );
64
+ }
65
+
66
+ /** Empty state with an optional single action. */
67
+ export function NoResults({
68
+ title,
69
+ description,
70
+ action,
71
+ }: {
72
+ title: string;
73
+ description: string;
74
+ action?: ReactNode;
75
+ }) {
76
+ return <EmptyState icon={SearchX} title={title} description={description} action={action} />;
77
+ }
78
+ ```