# Checkbox Indicator

## Usage

Indicators are the selection pictures shared by a checkbox, a radio, a selector, and a Markdown task list. They are decorative. The owning control keeps the input, the role, the accessible name, the focus, and the keyboard. The indicator only turns state into a picture. That split is what makes them themeable: restyle one through its class, or replace the component by name.

```vue
<script setup lang="ts">
import { CheckboxIndicator } from '@astryx-vue/core/CheckboxIndicator'
</script>

<template>
  <CheckboxIndicator state="indeterminate" size="sm" />
</template>
```

The box draws in every state. Unchecked is an empty box, not an empty gap. A mixed state draws a short bar.

For a control the user can operate, use [CheckboxInput](/en/components/checkbox-input). The check and the circle are [Check Indicator](/en/components/check-indicator) and [Radio Indicator](/en/components/radio-indicator).

## Anatomy

| Element | Description |
| --- | --- |
| Chrome (checkbox, radio) | Required. The persistent box or circle drawn by the checkbox and radio indicators in every state. The check indicator is the state mark itself and has no chrome of its own. |
| State mark | The checkmark, the indeterminate bar, or the radio dot shown inside the chrome for the current state. |

## Best practices

| Guidance | Practices |
| --- | --- |
| Do | Restyle the stable class first. Replacing the component is the heavier path, for when the shape itself is wrong. |
| Do | Decide whether slot content replaces the mark with isRenderable, not a null check. The helper is shallow: it excludes null, undefined, booleans, and the empty string. An element still counts when its descendants later render nothing. A host writes a spinner with v-if="busy". When that condition is false, a null check deletes the state mark. |
| Do | A replacement must set aria-hidden. The owning control provides the role and the accessible name. A visible indicator would be announced twice. |
| Do | Use theme tokens for every color, radius, and border width in a replacement. |
| Do | Render a single root element, and let it keep the border radius the focus ring should follow. The control paints that ring onto the indicator when the real input is visually hidden. The ring is never missing. It is only the wrong shape if the root has no radius of its own. Do not draw a second ring. |
| Don't | Pass hover or pressed state in as props. Hover reaches the graphic through the ancestor class astryx-indicator-scope, so hovering the row tints the control with no props involved. |
| Don't | Assume the graphic is mounted only when it is selected. The host renders it in every state and passes state. That is what lets a replacement draw where the default draws nothing, such as an empty circle on an unchosen row. Drawing nothing in a state is the indicator's decision. |

## Examples

### States

The box at sm and md, including unchecked, checked, mixed, and disabled.

```vue
<script setup lang="ts">
import { CheckboxIndicator } from '@astryx-vue/core/CheckboxIndicator'
</script>

<template>
  <div class="checkbox-indicator-preview">
    <div v-for="size in (['sm', 'md'] as const)" :key="size" class="checkbox-indicator-preview-row">
      <span class="checkbox-indicator-preview-size">{{ size }}</span>
      <span v-for="state in (['unchecked', 'checked', 'indeterminate'] as const)" :key="state" class="checkbox-indicator-preview-item">
        <CheckboxIndicator :state="state" :size="size" />
        <span>{{ state }}</span>
      </span>
    </div>
    <div class="checkbox-indicator-preview-row">
      <span>Disabled</span>
      <CheckboxIndicator state="unchecked" is-disabled />
      <CheckboxIndicator state="checked" is-disabled />
      <CheckboxIndicator state="indeterminate" is-disabled />
    </div>
  </div>
</template>
```

### Cycle the state

The buttons cycle the box, the check, and the circle. The check and the circle share the single-selection state.

```vue
<script setup lang="ts">
import type { IndicatorState } from '@astryx-vue/core/Indicator'
import { Button } from '@astryx-vue/core/Button'
import { CheckboxIndicator } from '@astryx-vue/core/CheckboxIndicator'
import { RadioIndicator, useIndicator } from '@astryx-vue/core/Indicator'
import { ref } from 'vue'

const checkbox = ref<IndicatorState<'multiSelection'>>('unchecked')
const chosen = ref<IndicatorState<'singleSelection'>>('unchecked')
const Mark = useIndicator('check')

function cycleCheckbox(): void {
  checkbox.value = checkbox.value === 'unchecked'
    ? 'checked'
    : checkbox.value === 'checked'
      ? 'indeterminate'
      : 'unchecked'
}

function cycleChosen(): void {
  chosen.value = chosen.value === 'checked' ? 'unchecked' : 'checked'
}
</script>

<template>
  <div class="indicator-board">
    <div class="indicator-board-row">
      <span class="indicator-board-item">
        <CheckboxIndicator :state="checkbox" />
        <Button size="sm" variant="secondary" label="Checkbox" @click="cycleCheckbox" />
      </span>
      <span class="indicator-board-item">
        <component :is="Mark" :state="chosen" />
        <Button size="sm" variant="secondary" label="Check" @click="cycleChosen" />
      </span>
      <span class="indicator-board-item">
        <RadioIndicator :state="chosen" />
        <Button size="sm" variant="secondary" label="Radio" @click="cycleChosen" />
      </span>
    </div>
  </div>
</template>
```

### Replace the mark while loading

A spinner in the default slot replaces the mark. Turning it off restores the box's check, and an unchosen check stops reserving space.

```vue
<script setup lang="ts">
import { Button } from '@astryx-vue/core/Button'
import { CheckboxIndicator } from '@astryx-vue/core/CheckboxIndicator'
import { CheckIndicator } from '@astryx-vue/core/Indicator'
import { ref } from 'vue'

const busy = ref(true)
</script>

<template>
  <div class="indicator-board">
    <div class="indicator-board-row">
      <span class="indicator-board-item">
        <CheckboxIndicator state="checked">
          <span v-if="busy" class="indicator-spinner" />
        </CheckboxIndicator>
        <span>Checkbox</span>
      </span>
      <span class="indicator-board-item">
        <CheckIndicator state="unchecked">
          <span v-if="busy" class="indicator-spinner" />
        </CheckIndicator>
        <span>Check</span>
      </span>
      <Button size="sm" variant="secondary" :label="busy ? 'Show marks' : 'Show spinner'" @click="busy = !busy" />
    </div>
  </div>
</template>
```

## Props

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `state` | `'unchecked' \| 'checked' \| 'indeterminate'` | — | Required. The visual state. |
| `size` | `'sm' \| 'md'` | `'md'` | Indicator size. |
| `isDisabled` | `boolean` | false | Shows disabled styling. |

## Slots

- The default slot replaces the checkmark and the dash, drawn inside the box.
- An empty slot, including a condition that is false, keeps the marks. Use isRenderable rather than a null check.
- Slot content is decorative. Do not put a focusable control in the slot.

## Accessibility

- The root always has `aria-hidden="true"`.
- The component has no interactive role.
- It ignores `role`, `tabindex` and `contenteditable` attributes.
- It provides no click or keyboard behavior.
- The exposed `element` is `HTMLSpanElement | null`.

## Theme

The indicator shares color variables with [CheckboxInput](/en/components/checkbox-input/props#theme).

- `.astryx-checkbox-indicator`: outer box.
- `.astryx-checkbox-indicator-check`: checkmark.
- `.astryx-checkbox-indicator-dash`: indeterminate mark.
- `data-state`: current visual state.
- `data-size`: current size.
- `data-disabled`: disabled state.
