@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.
- package/DESIGN.md +444 -0
- package/README.md +19 -26
- package/dist/index.cjs +366 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +228 -4
- package/dist/index.d.ts +228 -4
- package/dist/index.js +360 -8
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
- package/recipes/form.md +296 -0
- package/recipes/inbox.md +460 -0
- package/recipes/list-page.md +290 -0
- package/recipes/record-page.md +198 -0
- package/recipes/states.md +78 -0
- package/recipes/work-queue.md +220 -0
- package/styles/light.css +475 -2
- package/styles/theme.css +475 -2
- package/styles/ui.css +475 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@partrunner-ai/ui",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "L1 primitives built on the PartRunner token scale. Plain CSS over --pr-* so it works in Tailwind v3, v4, or no Tailwind at all.",
|
|
5
5
|
"license": "(MIT AND OFL-1.1)",
|
|
6
6
|
"type": "module",
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
"dist",
|
|
12
12
|
"styles",
|
|
13
13
|
"README.md",
|
|
14
|
+
"DESIGN.md",
|
|
15
|
+
"recipes",
|
|
14
16
|
"LICENSE",
|
|
15
17
|
"TRADEMARKS.md"
|
|
16
18
|
],
|
|
@@ -69,6 +71,7 @@
|
|
|
69
71
|
},
|
|
70
72
|
"scripts": {
|
|
71
73
|
"build": "tsup && node scripts/build-css-bundles.mjs",
|
|
74
|
+
"recipes": "node scripts/build-recipes.mjs",
|
|
72
75
|
"dev": "tsup --watch",
|
|
73
76
|
"test": "vitest run",
|
|
74
77
|
"typecheck": "tsc --noEmit",
|
package/recipes/form.md
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
# Recipe: Form
|
|
2
|
+
|
|
3
|
+
The person creates or changes one record.
|
|
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/FormRecipe.tsx. Do not edit. -->
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { useRef, useState } from 'react';
|
|
19
|
+
import { Plus } from 'lucide-react';
|
|
20
|
+
import {
|
|
21
|
+
Button,
|
|
22
|
+
Card,
|
|
23
|
+
ConfirmDialog,
|
|
24
|
+
DatePicker,
|
|
25
|
+
DetailItem,
|
|
26
|
+
DetailList,
|
|
27
|
+
Dialog,
|
|
28
|
+
FormField,
|
|
29
|
+
Input,
|
|
30
|
+
Notice,
|
|
31
|
+
Page,
|
|
32
|
+
PageHeader,
|
|
33
|
+
PageSkeleton,
|
|
34
|
+
SectionHeading,
|
|
35
|
+
Select,
|
|
36
|
+
Stack,
|
|
37
|
+
Textarea,
|
|
38
|
+
ValidationSummary,
|
|
39
|
+
} from '@partrunner-ai/ui';
|
|
40
|
+
import { formatMoney } from './fixtures';
|
|
41
|
+
import { ErrorNotice, ForbiddenState, NoResults, type RecipeProps } from './states';
|
|
42
|
+
|
|
43
|
+
const FLEETS = [
|
|
44
|
+
{ value: 'aguilar', label: 'Transportes Aguilar del Norte' },
|
|
45
|
+
{ value: 'cumbres', label: 'Logística Cumbres' },
|
|
46
|
+
{ value: 'sierra', label: 'Fletes Sierra Madre' },
|
|
47
|
+
{ value: 'dorada', label: 'Ruta Dorada' },
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
const WEEKS = ['4', '6', '8', '12'].map((value) => ({ value, label: `${value} semanas` }));
|
|
51
|
+
|
|
52
|
+
type Field = 'fleet' | 'amount' | 'weeks' | 'start';
|
|
53
|
+
type Errors = Partial<Record<Field, string>>;
|
|
54
|
+
|
|
55
|
+
const LABELS: Record<Field, string> = {
|
|
56
|
+
fleet: 'Flota',
|
|
57
|
+
amount: 'Monto total',
|
|
58
|
+
weeks: 'Plazo',
|
|
59
|
+
start: 'Primer cobro',
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const CONTROL_ID: Record<Field, string> = {
|
|
63
|
+
fleet: 'plan-flota',
|
|
64
|
+
amount: 'plan-monto',
|
|
65
|
+
weeks: 'plan-plazo',
|
|
66
|
+
start: 'plan-inicio',
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
function validate(values: Record<Field, string>): Errors {
|
|
70
|
+
const errors: Errors = {};
|
|
71
|
+
if (!values.fleet) errors.fleet = 'Elige la flota del plan.';
|
|
72
|
+
const amount = Number(values.amount.replace(/,/g, ''));
|
|
73
|
+
if (!values.amount.trim()) errors.amount = 'Escribe el monto total.';
|
|
74
|
+
else if (!Number.isFinite(amount) || amount <= 0) errors.amount = 'El monto debe ser mayor a $0.00.';
|
|
75
|
+
if (!values.weeks) errors.weeks = 'Elige en cuántas semanas se cobra.';
|
|
76
|
+
if (!values.start) errors.start = 'Elige la fecha del primer cobro.';
|
|
77
|
+
return errors;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const EMPTY = { fleet: '', amount: '', weeks: '', start: '', note: '' };
|
|
81
|
+
|
|
82
|
+
/** Recipe 2.4 · Form: a Dialog with FormFields, a ValidationSummary, and a destructive ConfirmDialog. */
|
|
83
|
+
export function FormRecipe({ state, onRetry }: RecipeProps) {
|
|
84
|
+
const [open, setOpen] = useState(false);
|
|
85
|
+
const [confirmOpen, setConfirmOpen] = useState(false);
|
|
86
|
+
const [values, setValues] = useState(EMPTY);
|
|
87
|
+
const [errors, setErrors] = useState<Errors>({});
|
|
88
|
+
const [submitted, setSubmitted] = useState(false);
|
|
89
|
+
const [saving, setSaving] = useState(false);
|
|
90
|
+
const [created, setCreated] = useState(false);
|
|
91
|
+
const [cancelling, setCancelling] = useState(false);
|
|
92
|
+
const [cancelled, setCancelled] = useState(false);
|
|
93
|
+
const openButton = useRef<HTMLButtonElement>(null);
|
|
94
|
+
|
|
95
|
+
const set = (key: keyof typeof EMPTY, value: string) => {
|
|
96
|
+
const next = { ...values, [key]: value };
|
|
97
|
+
setValues(next);
|
|
98
|
+
if (submitted && key !== 'note') setErrors(validate(next));
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const close = () => {
|
|
102
|
+
setOpen(false);
|
|
103
|
+
setValues(EMPTY);
|
|
104
|
+
setErrors({});
|
|
105
|
+
setSubmitted(false);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const submit = () => {
|
|
109
|
+
const found = validate(values);
|
|
110
|
+
setErrors(found);
|
|
111
|
+
setSubmitted(true);
|
|
112
|
+
if (Object.keys(found).length > 0) return;
|
|
113
|
+
setSaving(true);
|
|
114
|
+
window.setTimeout(() => {
|
|
115
|
+
setSaving(false);
|
|
116
|
+
close();
|
|
117
|
+
setCreated(true);
|
|
118
|
+
}, 800);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const summary = (Object.keys(errors) as Field[]).map((key) => ({
|
|
122
|
+
fieldId: CONTROL_ID[key],
|
|
123
|
+
label: LABELS[key],
|
|
124
|
+
message: errors[key] ?? '',
|
|
125
|
+
}));
|
|
126
|
+
|
|
127
|
+
const header = (
|
|
128
|
+
<PageHeader
|
|
129
|
+
title="Plan de pago"
|
|
130
|
+
subtitle="Convierte un saldo a cargo en cobros semanales."
|
|
131
|
+
actions={
|
|
132
|
+
state === 'forbidden' || state === 'loading' ? undefined : (
|
|
133
|
+
<Button ref={openButton} icon={Plus} onClick={() => setOpen(true)}>
|
|
134
|
+
Nuevo plan de pago
|
|
135
|
+
</Button>
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
/>
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
if (state === 'loading') {
|
|
142
|
+
return (
|
|
143
|
+
<Page width="default">
|
|
144
|
+
<PageSkeleton variant="detail" label="Cargando plan de pago" />
|
|
145
|
+
</Page>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
if (state === 'forbidden') {
|
|
149
|
+
return (
|
|
150
|
+
<Page width="default">
|
|
151
|
+
{header}
|
|
152
|
+
<ForbiddenState who="Finanzas" />
|
|
153
|
+
</Page>
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<Page width="default">
|
|
159
|
+
{header}
|
|
160
|
+
{state === 'error' ? <ErrorNotice what="el plan de pago" onRetry={onRetry} /> : null}
|
|
161
|
+
{created ? (
|
|
162
|
+
<Notice tone="success" title="Plan creado" onDismiss={() => setCreated(false)} dismissLabel="Cerrar aviso">
|
|
163
|
+
El primer cobro quedó programado. La flota recibe un aviso en su portal.
|
|
164
|
+
</Notice>
|
|
165
|
+
) : null}
|
|
166
|
+
{cancelled ? (
|
|
167
|
+
<Notice tone="info" title="Plan cancelado" onDismiss={() => setCancelled(false)} dismissLabel="Cerrar aviso">
|
|
168
|
+
El saldo regresa a la cola de saldos a cargo.
|
|
169
|
+
</Notice>
|
|
170
|
+
) : null}
|
|
171
|
+
|
|
172
|
+
{state === 'empty' || cancelled ? (
|
|
173
|
+
<NoResults
|
|
174
|
+
title="Esta flota no tiene un plan vigente"
|
|
175
|
+
description="Crea un plan para cobrar el saldo en pagos semanales."
|
|
176
|
+
action={
|
|
177
|
+
<Button variant="secondary" onClick={() => setOpen(true)}>
|
|
178
|
+
Nuevo plan de pago
|
|
179
|
+
</Button>
|
|
180
|
+
}
|
|
181
|
+
/>
|
|
182
|
+
) : (
|
|
183
|
+
<Card>
|
|
184
|
+
<SectionHeading
|
|
185
|
+
title="Plan vigente"
|
|
186
|
+
description="Logística Cumbres · creado el 17 nov 2026"
|
|
187
|
+
actions={
|
|
188
|
+
<Button size="sm" variant="outline" onClick={() => setConfirmOpen(true)}>
|
|
189
|
+
Cancelar plan
|
|
190
|
+
</Button>
|
|
191
|
+
}
|
|
192
|
+
/>
|
|
193
|
+
<DetailList columns={3}>
|
|
194
|
+
<DetailItem label="Monto total" numeric>
|
|
195
|
+
{formatMoney(18000)}
|
|
196
|
+
</DetailItem>
|
|
197
|
+
<DetailItem label="Cobro semanal" numeric>
|
|
198
|
+
{formatMoney(1500)}
|
|
199
|
+
</DetailItem>
|
|
200
|
+
<DetailItem label="Avance">4 de 12 semanas</DetailItem>
|
|
201
|
+
<DetailItem label="Primer cobro">24 nov 2026</DetailItem>
|
|
202
|
+
<DetailItem label="Próximo cobro">1 dic 2026</DetailItem>
|
|
203
|
+
<DetailItem label="Responsable">Mariana Lozano</DetailItem>
|
|
204
|
+
</DetailList>
|
|
205
|
+
</Card>
|
|
206
|
+
)}
|
|
207
|
+
|
|
208
|
+
<Dialog
|
|
209
|
+
open={open}
|
|
210
|
+
onClose={close}
|
|
211
|
+
title="Nuevo plan de pago"
|
|
212
|
+
description="Define cuánto y en cuántas semanas se cobra el saldo."
|
|
213
|
+
size="md"
|
|
214
|
+
footer={
|
|
215
|
+
<>
|
|
216
|
+
<Button variant="secondary" onClick={close} disabled={saving}>
|
|
217
|
+
Cancelar
|
|
218
|
+
</Button>
|
|
219
|
+
<Button onClick={submit} loading={saving}>
|
|
220
|
+
Crear plan
|
|
221
|
+
</Button>
|
|
222
|
+
</>
|
|
223
|
+
}
|
|
224
|
+
>
|
|
225
|
+
<form
|
|
226
|
+
noValidate
|
|
227
|
+
onSubmit={(event) => {
|
|
228
|
+
event.preventDefault();
|
|
229
|
+
submit();
|
|
230
|
+
}}
|
|
231
|
+
>
|
|
232
|
+
<Stack>
|
|
233
|
+
{summary.length > 0 ? <ValidationSummary errors={summary} /> : null}
|
|
234
|
+
<FormField label="Flota" required error={errors.fleet} controlId={CONTROL_ID.fleet} fullWidth>
|
|
235
|
+
<Select
|
|
236
|
+
options={FLEETS}
|
|
237
|
+
placeholder="Elige una flota"
|
|
238
|
+
value={values.fleet}
|
|
239
|
+
onChange={(event) => set('fleet', event.target.value)}
|
|
240
|
+
/>
|
|
241
|
+
</FormField>
|
|
242
|
+
<FormField
|
|
243
|
+
label="Monto total"
|
|
244
|
+
required
|
|
245
|
+
hint="En pesos mexicanos, con centavos."
|
|
246
|
+
error={errors.amount}
|
|
247
|
+
controlId={CONTROL_ID.amount}
|
|
248
|
+
fullWidth
|
|
249
|
+
>
|
|
250
|
+
<Input
|
|
251
|
+
inputMode="decimal"
|
|
252
|
+
placeholder="$12,400.00"
|
|
253
|
+
value={values.amount}
|
|
254
|
+
onChange={(event) => set('amount', event.target.value)}
|
|
255
|
+
/>
|
|
256
|
+
</FormField>
|
|
257
|
+
<FormField label="Plazo" required error={errors.weeks} controlId={CONTROL_ID.weeks} fullWidth>
|
|
258
|
+
<Select
|
|
259
|
+
options={WEEKS}
|
|
260
|
+
placeholder="Elige el plazo"
|
|
261
|
+
value={values.weeks}
|
|
262
|
+
onChange={(event) => set('weeks', event.target.value)}
|
|
263
|
+
/>
|
|
264
|
+
</FormField>
|
|
265
|
+
<FormField label="Primer cobro" required error={errors.start} controlId={CONTROL_ID.start} fullWidth>
|
|
266
|
+
<DatePicker mode="single" value={values.start} onValueChange={(next) => set('start', next as string)} />
|
|
267
|
+
</FormField>
|
|
268
|
+
<FormField label="Nota interna" hint="Opcional. No la ve la flota." controlId="plan-nota" fullWidth>
|
|
269
|
+
<Textarea rows={3} value={values.note} onChange={(event) => set('note', event.target.value)} />
|
|
270
|
+
</FormField>
|
|
271
|
+
</Stack>
|
|
272
|
+
</form>
|
|
273
|
+
</Dialog>
|
|
274
|
+
|
|
275
|
+
<ConfirmDialog
|
|
276
|
+
open={confirmOpen}
|
|
277
|
+
onOpenChange={setConfirmOpen}
|
|
278
|
+
destructive
|
|
279
|
+
title="¿Cancelar el plan de pago?"
|
|
280
|
+
description="Se detienen los cobros semanales y el saldo de $18,000.00 regresa a la cola. Esta acción no se puede deshacer."
|
|
281
|
+
confirmLabel="Cancelar plan"
|
|
282
|
+
cancelLabel="Conservar plan"
|
|
283
|
+
loading={cancelling}
|
|
284
|
+
onConfirm={() => {
|
|
285
|
+
setCancelling(true);
|
|
286
|
+
window.setTimeout(() => {
|
|
287
|
+
setCancelling(false);
|
|
288
|
+
setConfirmOpen(false);
|
|
289
|
+
setCancelled(true);
|
|
290
|
+
}, 600);
|
|
291
|
+
}}
|
|
292
|
+
/>
|
|
293
|
+
</Page>
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
```
|