Progress
Una barra que se llena para mostrar cuánto de algo está hecho o usado: una importación, el almacenamiento, el límite de un plan.
import { Progress, ProgressSkeleton } from '@sypnia/ui/react'
Una cantidad conocida
Cuatro límites, de holgado a lleno.
Storage3.1 of 5 GB
Team members4 of 5
Requests this month500,000 of 500,000
Columns matched8 of 8
Código
import { Progress } from '@sypnia/ui/react';
// The words say what is measured; the detail gives the numbers.
export default function Known() {
return (
<div className="sy-cols sy-cols--stack">
<Progress label="Storage" value={3.1} max={5} detail="3.1 of 5 GB" />
<Progress label="Team members" value={4} max={5} detail="4 of 5" tone="warn" />
<Progress label="Requests this month" value={500000} max={500000} detail="500,000 of 500,000" tone="fail" />
<Progress label="Columns matched" value={8} max={8} detail="8 of 8" tone="ok" />
</div>
);
} Una tarea en curso
Presiona «Import».
Importing order_items.csv0 of 3,811 rows
Código
import { useEffect, useState } from 'react';
import { Button, Progress } from '@sypnia/ui/react';
const total = 3811;
// Press «Import»: the bar and the numbers move together.
export default function Running() {
const [rows, setRows] = useState(0);
const [running, setRunning] = useState(false);
useEffect(() => {
if (!running) return;
const t = setInterval(() => setRows((r) => { const n = Math.min(total, r + 137); if (n === total) setRunning(false); return n; }), 120);
return () => clearInterval(t);
}, [running]);
return (
<div className="sy-stack">
<Progress label={rows === total ? 'order_items.csv imported' : 'Importing order_items.csv'} value={rows} max={total}
detail={`${rows.toLocaleString('en')} of ${total.toLocaleString('en')} rows`} tone={rows === total ? 'ok' : undefined} />
<div><Button disabled={running} onClick={() => { setRows(0); setRunning(true); }}>{rows === total ? 'Import again' : 'Import'}</Button></div>
</div>
);
} Sin final conocido
Una franja de luz recorre la barra; las palabras dicen qué está pasando.
Restoring the backup of November 16This can take a few minutes
Código
import { Progress } from '@sypnia/ui/react';
// Without a value: work is going on, and nobody promises when it ends.
export default function Unknown() {
return <Progress label="Restoring the backup of November 16" detail="This can take a few minutes" />;
} Skeleton
La pieza real y su skeleton: la misma caja, así nada se mueve cuando llegan los datos.
Storage18 of 50 GB
Código
import { Progress, ProgressSkeleton } from '@sypnia/ui/react';
// How much of the plan is used, before the amount arrives. The skeleton has the same box as the real one, so nothing moves when the data arrives.
export default function Skeleton() {
return (
<div className="sy-stack">
<Progress label="Storage" value={18} max={50} detail="18 of 50 GB" />
<ProgressSkeleton />
</div>
);
} Cuándo usarlo
Úsalo cuando
- Corre una tarea de tamaño conocido: filas importadas, archivos subidos.
- Se está gastando un límite: almacenamiento, miembros, solicitudes. Cambia el tono al acercarse.
- El trabajo no tiene final conocido: deja fuera
valuey di con palabras qué está pasando.
No lo uses cuando
- El contenido está cargando: muestra su skeleton.
- Un botón trabaja un momento: basta con el estado ocupado del botón.
- Es una secuencia de pasos que da la persona: eso es un Stepper.
Para todos
- Es una barra de progreso para los lectores de pantalla, nombrada por su etiqueta, con su porcentaje.
- Los números también se escriben al lado (
detail), así nadie depende del largo de una barra. - Los tonos de advertencia y falla cambian el color; di la consecuencia con palabras cerca.
- La franja que se mueve en el estado sin final se detiene con movimiento reducido.
Props
| Progress | Tipo | Por defecto |
|---|---|---|
labelobligatorio | ReactNode | |
detail | ReactNode | |
max | number | 100 |
tone | "ok" | "warn" | "fail" | |
value | number |
| ProgressSkeleton | Tipo | Por defecto |
|---|---|---|
detail | boolean | true |