Ir al contenido

Split

Dos paneles con un divisor que se puede arrastrar, o mover con las flechas. Una lista y su detalle, el código y su resultado.

import { Split } from '@sypnia/ui/react'

En esta página
  1. Una lista y su detalle
  2. Uno encima del otro
  3. En Astro
  4. Cuándo usarlo
  5. Para todos
  6. Props

Una lista y su detalle

Arrastra la línea, o llega a ella con Tab y usa las flechas (Shift para pasos grandes, Inicio y Fin para los límites). En el celular los paneles se apilan.

Service
api
Region
us-east
Uptime
99.98%
List width
38%
Código
import { useState } from 'react';
import { KeyValue, Split, Status } from '@sypnia/ui/react';

const rows = [
  { id: 'api', name: 'api', state: 'ok', region: 'us-east', uptime: '99.98%' },
  { id: 'worker', name: 'worker', state: 'warn', region: 'eu-west', uptime: '99.20%' },
  { id: 'web', name: 'web', state: 'ok', region: 'us-east', uptime: '100%' },
] as const;
export default function ListDetail() {
  const [size, setSize] = useState(38);
  const [chosen, setChosen] = useState<string>('api');
  const row = rows.find((r) => r.id === chosen)!;
  return (
    <Split size={size} onSizeChange={setSize} min={25} max={70} label="Resize the list of services" height="16rem">
      {[
        <ul key="list" className="sy-stack" style={{ '--gap': '2px', padding: 'var(--s-2)', margin: 0, listStyle: 'none' } as React.CSSProperties}>
          {rows.map((r) => (
            <li key={r.id}>
              <button type="button" className="sy-nav-item" aria-current={r.id === chosen ? 'true' : undefined} onClick={() => setChosen(r.id)} style={{ width: '100%' }}>
                <span>{r.name}</span><Status tone={r.state}>{r.state === 'ok' ? 'Well' : 'Slow'}</Status>
              </button>
            </li>
          ))}
        </ul>,
        <div key="detail" style={{ padding: 'var(--s-4)' }}>
          <KeyValue items={[['Service', row.name], ['Region', row.region], ['Uptime', row.uptime], ['List width', `${Math.round(size)}%`]]} />
        </div>,
      ]}
    </Split>
  );
}

Uno encima del otro

orientation="vertical", y keepOnPhones para que siga dividido también en pantallas pequeñas.

select id, email
from users
where created_at > now() - interval '7 days';

128 rows. The result goes here; drag the line or use the arrow keys.

Código
import { Split } from '@sypnia/ui/react';

export default function Vertical() {
  return (
    <Split orientation="vertical" defaultSize={55} label="Resize the editor" height="18rem" keepOnPhones>
      {[
        <pre key="code" style={{ margin: 0, padding: 'var(--s-4)' }}><code>{'select id, email\nfrom users\nwhere created_at > now() - interval \'7 days\';'}</code></pre>,
        <p key="out" style={{ padding: 'var(--s-4)' }} className="sy-text--muted">128 rows. The result goes here; drag the line or use the arrow keys.</p>,
      ]}
    </Split>
  );
}

En Astro

El mismo Split sin React: <sy-split> le da el comportamiento, y remember guarda el tamaño en el navegador.

The first pane. Its size is kept in this browser (remember).

The second pane. Behaviour comes from <sy-split>.

Código
---
import Split from '@sypnia/ui/astro/Split.astro';
---
<Split size={40} label="Resize the menu" height="10rem" remember="docs-example">
  <p slot="first" style="padding: var(--s-4)">The first pane. Its size is kept in this browser (<code>remember</code>).</p>
  <p slot="second" style="padding: var(--s-4)" class="sy-text--muted">The second pane. Behaviour comes from <code>&lt;sy-split&gt;</code>.</p>
</Split>

Cuándo usarlo

Úsalo cuando

  • La persona compara o trabaja en dos cosas a la vez y decide cuánto espacio tiene cada una.
  • Una lista principal y el detalle del elemento elegido.

No lo uses cuando

  • Los tamaños nunca cambian: usa Columns.
  • En el celular los dos paneles importan a la vez: muestra uno y pasa al otro.

Para todos

  • El divisor es un separador enfocable con su valor en porcentaje (patrón window splitter de WAI-ARIA): las flechas lo mueven, Inicio y Fin van a los límites.
  • Su nombre dice qué cambia de tamaño: «Cambiar el tamaño de la lista de servicios».
  • Arrastrar también funciona con el dedo y con lápiz.

Props

SplitTipoPor defecto
childrenobligatorio

The two panes, in order.

[ReactNode, ReactNode]
className string
defaultSize

Size of the first pane at the start, in percent.

number 50
height

Height of the whole split, as CSS.

string
keepOnPhones

Keep the two panes side by side on phones too (they stack by default).

boolean
label

Name of the divider for screen readers: what it resizes.

string
max number 85
min

Limits of the first pane, in percent.

number 15
onSizeChange ((size: number) => void)
orientation

'horizontal': side by side. 'vertical': one above the other.

"horizontal" | "vertical" horizontal
size

Size of the first pane, when the parent keeps it.

number
  1. Una lista y su detalle
  2. Uno encima del otro
  3. En Astro
  4. Cuándo usarlo
  5. Para todos
  6. Props

    Busca páginas, secciones y términos