Checkbox
A native checkbox, restyled. Supports v-model and an indeterminate state.
Install
If this is the first component in the project, set up once. This writes ermine.json and copies the theme stylesheet. The installation guide covers Vue, Nuxt and Astro.
npx ermineui initpnpm dlx ermineui inityarn dlx ermineui initbunx ermineui initThen add the component:
npx ermineui add checkboxpnpm dlx ermineui add checkboxyarn dlx ermineui add checkboxbunx ermineui add checkboxThat copies 2 files into src/components/ui/checkbox/. Files you already have are kept.
Use
import { Checkbox } from '@/components/ui/checkbox'<script setup lang="ts">
import { Checkbox } from '@/components/ui/checkbox'
</script>
<template>
<Checkbox />
</template>In Nuxt, with the auto-import setting, the tags work in templates without the import. In Astro, use it inside a Vue island. The props are documented in the source below, on each one.
What gets copied
| File | Where it goes |
|---|---|
Checkbox.vue | src/components/ui/checkbox/Checkbox.vue |
index.ts | src/components/ui/checkbox/index.ts |
The folders are the suggested ones. ermine.json says where yours are.
Source
This is exactly what the command copies. To install by hand, create each file below and the helpers listed above.
Checkbox.vue 76 lines
<script setup lang="ts">
defineProps<{
/** Show the "partially selected" dash, e.g. for a select-all box. */
indeterminate?: boolean
}>()
const model = defineModel<boolean>()
</script>
<template>
<input v-model="model" type="checkbox" class="er-checkbox" :indeterminate.prop="indeterminate" />
</template>
<style>
@layer components {
/* A real checkbox, restyled — so forms, labels and the keyboard all work as usual. */
.er-checkbox {
appearance: none;
display: inline-grid;
place-content: center;
flex-shrink: 0;
width: 1rem;
height: 1rem;
margin: 0;
border: 1px solid var(--er-input);
border-radius: 4px;
background: var(--er-input-background);
box-shadow: var(--er-shadow-xs);
cursor: pointer;
transition:
background-color var(--er-duration),
border-color var(--er-duration);
}
.er-checkbox::before {
content: '';
width: 0.75rem;
height: 0.75rem;
background: var(--er-primary-foreground);
mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E")
center / contain no-repeat;
transform: scale(0);
transition: transform var(--er-duration) var(--er-ease);
}
.er-checkbox:indeterminate::before {
mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3.5' stroke-linecap='round'%3E%3Cpath d='M5 12h14'/%3E%3C/svg%3E");
}
.er-checkbox:checked,
.er-checkbox:indeterminate {
border-color: var(--er-primary);
background: var(--er-primary);
}
.er-checkbox:checked::before,
.er-checkbox:indeterminate::before {
transform: scale(1);
}
.er-checkbox:focus-visible {
outline: 2px solid var(--er-ring);
outline-offset: 2px;
}
.er-checkbox:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.er-checkbox[aria-invalid='true'] {
border-color: var(--er-destructive);
}
}
</style>index.ts 3 lines
/** Checkbox — a native checkbox, restyled. Supports v-model and an indeterminate state. */
export { default as Checkbox } from './Checkbox.vue'