Zubra UI
Code for
GitHub

check-box

A checkbox with a label and an optional description, on a native <input type="checkbox">: it submits value under its name when checked, takes required, and the whole label is the target. indeterminate shows the mixed state (for a "select all" over a partial selection). checked is two-way.

Try it: events appear here (checkedchange).

Source: check-box.zb, and its registry item.

Install

Compiled (any project)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/check-box.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/check-box.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/check-box.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/check-box.json
One file, no dependencies (3.2 KB gzipped)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/check-box.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/check-box.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/check-box.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/check-box.json
.zb source (to edit it with Zubra)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/check-box.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/check-box.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/check-box.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/check-box.json
No build: a script tag, straight from this site
HTML
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/check-box.js"></script>

The compiled install writes src/components/zubra/check-box.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.

Usage

index.html
<check-box
  label="Send me product updates"
  description="About once a month. Unsubscribe any time."
  name="updates"
></check-box>

<script type="module">
  import './components/zubra/check-box.js';

  const element = document.querySelector('check-box');
  element.checked = true;
  element.addEventListener('checkedchange', (event) => console.log('checkedchange', event.detail));
</script>
Example.jsx
import './components/zubra/check-box.js';

const checked = true;

export function CheckBoxExample() {
  return (
    <check-box
      label="Send me product updates"
      description="About once a month. Unsubscribe any time."
      name="updates"
      checked={checked}
      oncheckedchange={(event) => console.log('checkedchange', event.detail)}
    ></check-box>
  );
}
Example.vue
<script setup>
import './components/zubra/check-box.js';
const checked = true;
const onCheckedchange = (event) => console.log('checkedchange', event.detail);
</script>

<template>
  <check-box
    label="Send me product updates"
    description="About once a month. Unsubscribe any time."
    name="updates"
    :checked.prop="checked"
    @checkedchange="onCheckedchange"
  ></check-box>
</template>

<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) -->
Example.svelte
<script>
  import './components/zubra/check-box.js';
  const checked = true;
</script>

<check-box
  label="Send me product updates"
  description="About once a month. Unsubscribe any time."
  name="updates"
  {checked}
  oncheckedchange={(event) => console.log('checkedchange', event.detail)}
></check-box>
example.component.ts
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/check-box.js';

@Component({
  selector: 'app-check-box-example',
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `
    <check-box
      label="Send me product updates"
      description="About once a month. Unsubscribe any time."
      name="updates"
      [checked]="checked"
      (checkedchange)="onCheckedchange($event)"
    ></check-box>
  `,
})
export class CheckBoxExample {
  checked = true;

  onCheckedchange(event: Event) {
    console.log('checkedchange', (event as CustomEvent).detail);
  }
}

API

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
checkedbooleanfalse
indeterminatebooleanfalse
labelstring""
descriptionstring""
namestring""
valuestring"on"
requiredbooleanfalse
disabledbooleanfalse
Events
EventWhen
checkedchangeIt was checked or unchecked; detail is the new state.

Size

1.4 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 18.1 KB.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour