Componentes · Interacción
Diálogo <Dialog>
Ventana modal nativa: bloquea el scroll, atrapa el foco y se cierra con Esc.
import Dialog from '@vivla-cms/ds/primitives/Dialog.astro'Ejemplos
Cuatro tamaños
Cualquier elemento con data-ds-dialog-open="<id>" abre el diálogo con ese id. sm es el ancho de lectura, md 48rem, lg el ancho de página y full toda la pantalla. Se cierra con la X, con Esc o pulsando fuera; el foco vuelve al botón que lo abrió y la página de detrás no se mueve.
---
import Button from '@vivla-cms/ds/primitives/Button.astro'
import Dialog from '@vivla-cms/ds/primitives/Dialog.astro'
import Media from '@vivla-cms/ds/primitives/Media.astro'
import Text from '@vivla-cms/ds/primitives/Text.astro'
const sizes = ['sm', 'md', 'lg'] as const
---
{
sizes.map((size) => (
<>
<Button variant="secondary" data-ds-dialog-open={`ejemplo-dialogo-${size}`} aria-haspopup="dialog">
Abrir {size}
</Button>
<Dialog id={`ejemplo-dialogo-${size}`} title="Todo lo que incluye la casa" size={size}>
<Text>Piscina, jardín, chimenea, cocina abierta, wifi, aire acondicionado y parking para dos coches.</Text>
<Text tone="muted" class="mt-4">Limpieza y mantenimiento los hace VIVLA entre estancia y estancia.</Text>
</Dialog>
</>
))
}
<Button variant="secondary" data-ds-dialog-open="ejemplo-dialogo-full" aria-haspopup="dialog">Abrir full</Button>
<Dialog id="ejemplo-dialogo-full" label="Foto de la casa" size="full" theme="dark">
<Media src="/assets/home/hero-1024.avif" alt="Salón de la casa con vistas al mar" aspect="16/9" class="w-[min(90vw,64rem)]" />
</Dialog> El tema del panel
theme pinta el panel, no hereda el de la banda: un diálogo abierto desde una banda terracota sigue siendo claro salvo que pidas otro. dark es el de las galerías y vídeos. Sin título visible, pon label para que tenga nombre accesible.
---
import Button from '@vivla-cms/ds/primitives/Button.astro'
import Dialog from '@vivla-cms/ds/primitives/Dialog.astro'
import Text from '@vivla-cms/ds/primitives/Text.astro'
const themes = [
{ theme: 'light', label: 'Claro' },
{ theme: 'paper', label: 'Papel' },
{ theme: 'dark', label: 'Oscuro' },
{ theme: 'accent', label: 'Terracota' },
{ theme: 'invest', label: 'Cobalto' },
] as const
---
{
themes.map(({ theme, label }) => (
<>
<Button variant="secondary" data-ds-dialog-open={`ejemplo-dialogo-tema-${theme}`} aria-haspopup="dialog">
{label}
</Button>
<Dialog id={`ejemplo-dialogo-tema-${theme}`} title={`Panel ${label.toLowerCase()}`} theme={theme}>
<Text>Compra de 1/8 a 1/2 de una casa y disfrútala unas seis semanas al año por cada octavo.</Text>
</Dialog>
</>
))
} Botones propios para cerrar
Cualquier elemento con data-ds-dialog-close dentro del diálogo lo cierra. Con closeOnBackdrop={false} un clic fuera no lo cierra: úsalo cuando cerrar por accidente haga perder algo.
---
import Button from '@vivla-cms/ds/primitives/Button.astro'
import Dialog from '@vivla-cms/ds/primitives/Dialog.astro'
import Text from '@vivla-cms/ds/primitives/Text.astro'
---
<Button data-ds-dialog-open="ejemplo-dialogo-confirmar" aria-haspopup="dialog">Enviar solicitud</Button>
<Dialog id="ejemplo-dialogo-confirmar" title="¿Enviamos tu solicitud?" closeOnBackdrop={false}>
<Text tone="muted">Te llamaremos en menos de 24 horas para contarte qué casas hay disponibles.</Text>
<div class="mt-8 flex flex-wrap gap-3">
<Button data-ds-dialog-close>Sí, enviar</Button>
<Button variant="secondary" data-ds-dialog-close>Volver</Button>
</div>
</Dialog> Modal de lead
size="lead" es el modal de los formularios cortos del hand-off (ficha «Especificaciones», /listings «¿Qué casa buscas?»): panel blanco de 640, padding 40 · 40 · 48 · 48, el aspa de 32 sola en su fila arriba a la derecha y velo espresso al 50 %. El título va a 40/42 y el contenido 16 por debajo. En el móvil ocupa toda la pantalla.
---
import Button from '@vivla-cms/ds/primitives/Button.astro'
import Dialog from '@vivla-cms/ds/primitives/Dialog.astro'
import Text from '@vivla-cms/ds/primitives/Text.astro'
import TextField from '@vivla-cms/ds/primitives/TextField.astro'
---
<Button data-ds-dialog-open="ejemplo-dialogo-lead" aria-haspopup="dialog">Obtener especificaciones</Button>
<Dialog id="ejemplo-dialogo-lead" size="lead" title="Recibe las especificaciones">
<Text>Déjanos tus datos y te enviamos la ficha completa de Casa Taula: planos, calidades y amenities.</Text>
<div class="mt-8 flex flex-col gap-8">
<TextField label="Nombre completo*" name="name" placeholder="Tu nombre y apellidos" />
<TextField label="Email*" name="email" type="email" placeholder="tu@email.com" />
</div>
<Button class="mt-8" disabled>Recibir especificaciones</Button>
</Dialog> Props
| Prop | Valores | Por defecto | Para qué |
|---|---|---|---|
| id * | string | — | Element id; triggers point at it with data-ds-dialog-open="<id>". |
| title | string | — | Visible heading (h2 element at h3 size); also the accessible name. |
| label | string | — | Accessible name when there is no visible title. |
| description | string | — | A muted line under the title; also the dialog's description (aria-describedby). |
| size | smmdlgfullleadside | 'sm' | — |
| theme | lightdarkaccentinvestpapersoft | — | Default light; paper (white) for size="lead" and size="side". |
| closeOnBackdrop | boolean | true | Close on a click outside the panel (default true). |
| scrim | defaultlead | 'default' | The veil: default 60 % espresso (90 % surface when dark) · lead = the lead modals' 50 % espresso (always on size="lead" and size="side"). |
| data-* | string | undefined | — | Se pasan tal cual al elemento. |
| aria-* | string | undefined | — | Se pasan tal cual al elemento. |
Slots: contenido
Notas del código
El comentario de cabecera de Dialog.astro, tal cual (en inglés, como el código): si cambia el código, cambia esto.
modal window on the native <dialog> (showModal), roles only. Shared by the video lightboxes (testimonials, FAQ videos), the ficha amenities list and the gallery lightbox.
<Button variant="ghost" data-ds-dialog-open="amenities" aria-haspopup="dialog">Ver todos</Button>
<Dialog id="amenities" title="Todo lo que incluye la casa">…</Dialog> Opening: any element with data-ds-dialog-open="<id>" (delegated, so it also works for content added later; a modified click on a link trigger keeps the browser's new-tab behaviour), or dialog.showModal() from a script. Both paths get the same behaviour:
- Focus: the browser moves focus into the dialog (the close button comes
first; put `autofocus` on another control to start there). Tab and
Shift+Tab cycle inside the dialog. On close, focus returns to the
element that opened it: the trigger, or for a script opener the control
the visitor last pressed or focused (recorded on pointerdown, click and
focusin, so Safari, which does not focus a clicked button, gets it too). - Esc closes (native
cancel). A click on the backdrop closes it too
(press AND release outside the panel, so a text selection that ends
outside does not), unless `closeOnBackdrop={false}`. - Scroll lock: the page behind does not scroll while any Dialog is open
(`overflow: hidden` on <html>, scrollbar gutter kept so nothing shifts).
It comes from `lib/scroll-lock.ts`, shared with the site menu's own
<dialog>, and counts locks — overlapping overlays release the page once. - Close button: top-right (bottom-right belongs to the cookie consent
button), 44 px, named by `uiLabel('dialogClose')`. It stays in view: a
sticky corner in sm/md/lg (it follows long content down), fixed to the
viewport corner in `full`. It is a plain `type="button"` (no nested
<form method="dialog">), so a Dialog can live inside a filter <form>
without the X submitting it. Any element with `data-ds-dialog-close`
inside the dialog closes it too (only its own dialog when nested). - Events:
ds-dialog:open(bubbles) fires on the <dialog> once it is open;
the native `close` event fires when it closes (clear a player's src there). Name: title renders a visible h2 (h3 size) and labels the dialog; without a visible title pass label (e.g. a lightbox). The close corner is kept clear either way: the title leaves room on its right, and a label-only sm/md/lg dialog starts its content below the button. In full the button floats over the content's top-right corner. theme sets the palette of the panel (default light, so a dialog opened from a terracotta band does not turn terracotta); dark suits media lightboxes.
Sizes: sm = prose (--container-prose, 36.5625rem = 585 px, five Figma columns) · md = 48rem · lg = --container-shell (1432, the content of the 1512 canvas; a dialog keeps that size on wider screens, the page column does not) · full = the whole viewport with no panel padding (the panel shrinks to its content and the empty area around it is backdrop). class goes on the panel.
lead = the lead modals of the 30/10 hand-off (ficha «Especificaciones» 1612:3342 / 3732 / 4049, listings «¿Qué casa buscas?» 1606:3072 / 1610:3003 / 1610:3299): a 640 px white panel (paper theme unless theme says otherwise), padding 40 top · 40 right · 48 bottom · 48 left, a bare line/close 32 in its own row at the top right (no disc) with the content right under it, and a 50 % espresso scrim (on-surface/50). Its title is typography-01-2XL (title, 40/42) with the slot 16 below. Phones (not drawn): the panel fills the screen, px-gutter, the same row on top.
scrim="lead" gives another size that same 50 % veil: the ficha's «¿Hablamos?» card (LeadDialog look="card", 1721:7538) is a full dialog drawn over a 50 % espresso page, not the default 60 %.
<Dialog id="listing-specs" size="lead" title="Recibe las especificaciones">
<Text>Déjanos tus datos y te enviamos la ficha completa…</Text>
<LeadForm … />
</Dialog> side = the side panel of the 06/11 hand-off (ficha «Calidades y amenities», «PDP — Amenities · Sidebar · Desktop» 1917:6547, panel 1917:6633): a white panel (paper unless theme says otherwise) docked to the right edge, full height, 560 px from md, over the lead modals' 50 % espresso scrim. Its header — title (typography-01-2XL, 40/42) with the bare 32 px line/close on the same row, then description — stays put while the slot scrolls under it. Padding 64 · 40 · 24 over the header, 16 · 40 · 40 around the slot. It slides in from the right (still with reduced motion). Phones (not drawn): the whole screen, px-gutter.
<Dialog id="listing-amenities" size="side" title="Calidades y amenities" description="16 amenities en esta casa">…</Dialog> description is a line in the muted body under the title (any size); it also describes the dialog (aria-describedby).
Dónde se usa
17 veces en 13 archivos de la web y los bloques del CMS.
Ver los archivos
- apps/web/src/pages/dev/kit.astro ×5
- apps/web/src/layouts/chrome/ContactDock.astro ×1
- apps/web/src/layouts/chrome/LandingCta.astro ×1
- apps/web/src/layouts/chrome/LandingMenu.astro ×1
- apps/web/src/pages/dev/kit/handoff.astro ×1
- apps/web/src/sections/listing/ListingGallery.astro ×1
- apps/web/src/sections/listing/ListingHighlights.astro ×1
- apps/web/src/sections/listing/ListingIntro.astro ×1
- apps/web/src/sections/listing/ListingNearby.astro ×1
- packages/cms-blocks/src/renderers/MediaCollage/orbital.astro ×1
- packages/cms-blocks/src/renderers/parts/LeadDialog.astro ×1
- packages/cms-blocks/src/renderers/parts/YouTubeDialog.astro ×1
- packages/cms-blocks/src/renderers/StepPanel/wide.astro ×1