Checklist
Checklist turns independent choices into native checkboxes with one legend. use it for a packing list, ingredients or the small tasks before publishing a reading collection.
usage
<script>
import { Checklist } from '@ciabi/loafkit-ui';
let done = $state([]);
const items = [
{ id: 'titles', label: 'Check the article titles' },
{ id: 'links', label: 'Open each saved link', description: 'Catch moved pages before you share.' },
{ id: 'intro', label: 'Add a short introduction' }
];
</script>
<Checklist legend="Before you share the collection" {items} bind:value={done} summary name="ready" />composition
- Checklist
- items
- content()(optional)
- items
data and value
keep extra item content passive because it is rendered inside the checkbox label.
name is shared by the checkbox inputs, so native FormData contains one entry per checked ID. an item’s required means that particular checkbox must be checked, not that the group needs at least one choice. implement a group rule in your form logic if that’s the task.
submit the checked item IDs
<script lang="ts">
import { Checklist } from '@ciabi/loafkit-ui';
let reviewChecks = $state<string[]>([]);
let reviewSubmitted = $state('');
</script>
{#snippet reviewHint()}<small>check the original page, not just its saved title.</small>{/snippet}
<form onsubmit={event => {
event.preventDefault();
reviewSubmitted = new FormData(event.currentTarget).getAll('review').join(', ') || 'none';
}}>
<Checklist legend="review before sharing" name="review" bind:value={reviewChecks} summary items={[
{id:'links',label:'open every link',required:true,content:reviewHint},
{id:'intro',label:'add an introduction'},
{id:'publish',label:'publish after review',disabled:true}
]} />
<button type="submit">check submission</button>
</form>
{#if reviewSubmitted}<p role="status">submitted review IDs: {reviewSubmitted}</p>{/if}API reference
Checklist
items-
the checkbox definitions.
value- Default:
[]selected item IDs.
name-
shared checkbox name; each checked input submits its item ID.
legend-
the fieldset’s visible group name.
summary- Default:
falseshows a live count of completed items.
onValueChange-
called with the updated value.
style-
inline styles on the fieldset.
class- Default:
''extra classes on the fieldset.
ChecklistItem
one item in Checklist.items.