ComponentesComponents

Checkbox

Casillas con el diseño de coss ui sobre un checkbox nativo. Incluye «Todo» con estado intermedio.coss ui checkboxes over a native checkbox. Includes “All” with a mixed state.

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

CódigoCode

<fieldset class="c-checkbox-group" data-c-checkall>
  <legend class="c-checkbox-group__legend">Exportar</legend>
  <label class="c-label">
    <span class="c-checkbox"><input class="c-checkbox__input" type="checkbox" data-c-all><span class="c-checkbox__indicator"><svg class="c-checkbox__check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5.252 12.7 10.2 18.63 18.748 5.37"/></svg><svg class="c-checkbox__dash" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" aria-hidden="true"><path d="M5.252 12h13.496"/></svg></span></span>
    Todo
  </label>
  <div class="c-checkbox-group__items">
    <label class="c-label"><span class="c-checkbox"><input class="c-checkbox__input" type="checkbox" name="export" value="png" checked><span class="c-checkbox__indicator"><svg class="c-checkbox__check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5.252 12.7 10.2 18.63 18.748 5.37"/></svg><svg class="c-checkbox__dash" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" aria-hidden="true"><path d="M5.252 12h13.496"/></svg></span></span> Póster en PNG</label>
    <label class="c-label"><span class="c-checkbox"><input class="c-checkbox__input" type="checkbox" name="export" value="json"><span class="c-checkbox__indicator"><svg class="c-checkbox__check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5.252 12.7 10.2 18.63 18.748 5.37"/></svg><svg class="c-checkbox__dash" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" aria-hidden="true"><path d="M5.252 12h13.496"/></svg></span></span> Receta JSON</label>
    <label class="c-label"><span class="c-checkbox"><input class="c-checkbox__input" type="checkbox" name="export" value="palette"><span class="c-checkbox__indicator"><svg class="c-checkbox__check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5.252 12.7 10.2 18.63 18.748 5.37"/></svg><svg class="c-checkbox__dash" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" aria-hidden="true"><path d="M5.252 12h13.496"/></svg></span></span> Paleta de colores</label>
  </div>
</fieldset>
<label class="c-label c-label--top">
  <span class="c-checkbox"><input class="c-checkbox__input" type="checkbox" checked><span class="c-checkbox__indicator"><svg class="c-checkbox__check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5.252 12.7 10.2 18.63 18.748 5.37"/></svg><svg class="c-checkbox__dash" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" aria-hidden="true"><path d="M5.252 12h13.496"/></svg></span></span>
  <span class="c-label__text">Acepto los términos <span class="c-label__description">Al marcarla aceptas la licencia MIT.</span></span>
</label>
<label class="c-label"><span class="c-checkbox"><input class="c-checkbox__input" type="checkbox" disabled><span class="c-checkbox__indicator"><svg class="c-checkbox__check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5.252 12.7 10.2 18.63 18.748 5.37"/></svg><svg class="c-checkbox__dash" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" aria-hidden="true"><path d="M5.252 12h13.496"/></svg></span></span> Deshabilitado</label>

«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. Copia los archivos:Copy the files: checkbox.html, checkbox.css, checkbox.js.
  3. 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 elegir varias opciones.
  • Para una aceptación.
  • To choose several options.
  • For a single agreement.

Mejor noAvoid

  • Si solo se puede una: usa radios.
  • Para algo que se aplica al instante: usa un switch.
  • If only one is allowed: use radios.
  • For instant settings: use a switch.

AccesibilidadAccessibility

checkboxgroup
Espacio SpaceMarca o desmarcaChecks or unchecks
  • El input real está encima, invisible: el lector y los agentes usan un checkbox de verdad.
  • «Todo» usa indeterminate, que se anuncia como «mixta».
  • The real input sits on top, invisible: screen readers and agents use a real checkbox.
  • “All” uses indeterminate, announced as “mixed”.

Cómo probarloHow to test it

  • Marca una exportación: «Todo» queda intermedio.
  • Check one export: “All” becomes mixed.

CréditosCredits