ComponentesComponents

DiálogoDialog

Ventana modal para una tarea corta o una confirmación.Modal window for a short task or a confirmation.

DiseñoDesign: coss ui (MIT) · dialog.tsxMITambos · densidaddensity media · sobriaMarkdownJSON

CódigoCode

<button class="c-btn c-btn--outline" type="button" commandfor="dlg-profile" command="show-modal">Editar perfil</button>
<button class="c-btn c-btn--destructive" type="button" commandfor="dlg-delete" command="show-modal">Eliminar cuenta</button>

<dialog class="c-dialog" id="dlg-profile" aria-labelledby="dlg-profile-title" aria-describedby="dlg-profile-desc" closedby="any">
  <form class="c-dialog__form" method="dialog">
    <div class="c-dialog__header">
      <h2 class="c-dialog__title" id="dlg-profile-title">Editar perfil</h2>
      <p class="c-dialog__description" id="dlg-profile-desc">Cambia tus datos y guarda cuando termines.</p>
    </div>
    <div class="c-dialog__panel">
      <div class="c-field"><label class="c-label" for="dlg-name">Nombre</label><span class="c-input"><input class="c-input__field" id="dlg-name" value="Ada Lovelace" autofocus></span></div>
    </div>
    <div class="c-dialog__footer">
      <button class="c-btn c-btn--ghost" value="cancel" formnovalidate>Cancelar</button>
      <button class="c-btn c-btn--primary" value="save">Guardar</button>
    </div>
    <button class="c-btn c-btn--ghost c-btn--icon c-dialog__close" type="button" commandfor="dlg-profile" command="close" aria-label="Cerrar"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg></button>
  </form>
</dialog>

<dialog class="c-dialog" id="dlg-delete" role="alertdialog" aria-labelledby="dlg-delete-title" aria-describedby="dlg-delete-desc">
  <form class="c-dialog__form" method="dialog">
    <div class="c-dialog__header">
      <h2 class="c-dialog__title" id="dlg-delete-title">¿Eliminar tu cuenta?</h2>
      <p class="c-dialog__description" id="dlg-delete-desc">Se borran tus proyectos y no se puede deshacer.</p>
    </div>
    <div class="c-dialog__footer">
      <button class="c-btn c-btn--outline" value="cancel" autofocus>Cancelar</button>
      <button class="c-btn c-btn--destructive" value="delete">Eliminar</button>
    </div>
  </form>
</dialog>

«Todo» trae tokens, dependencias y componente en un solo archivo, listo para abrir o dárselo a un agente.“All” bundles tokens, dependencies and the component in one file, ready to open or hand to an agent.

InstalaciónInstallation

  1. Agrega una vezAdd once tokens.css (colores, radios, tema oscuro).(colors, radii, dark theme).
  2. Agrega también:Also add: BotónButton, Campo de textoText field.
  3. Copia los archivos:Copy the files: dialog.html, dialog.css, dialog.js.
  4. Para el tema oscuro, pon la claseFor the dark theme, add the class dark ento <html>.

Cuándo usarloWhen to use it

ÚsaloUse it

  • Para confirmar algo irreversible.
  • Para una tarea corta.
  • To confirm something irreversible.
  • For a short task.

Mejor noAvoid

  • Para avisar que algo salió bien: usa un aviso.
  • To say something worked: use a toast.

AccesibilidadAccessibility

dialogalertdialog
EscCierraCloses
TabRecorre solo el diálogoCycles within the dialog
  • <dialog> con showModal(): el resto de la página queda inerte.
  • El foco vuelve al botón que lo abrió.
  • Se abre con commandfor; dialog.js da respaldo donde no existe.
  • <dialog> with showModal(): the rest of the page is inert.
  • Focus returns to the opening button.
  • Opens with commandfor; dialog.js is the fallback.

Cómo probarloHow to test it

  • Abre «Editar perfil» y pulsa Esc: el foco vuelve al botón.
  • Open “Edit profile” and press Esc: focus returns to the button.

CréditosCredits