Calendar Grid
A monthly calendar grid primitive powered by the native Date API. It renders a month view based on a provided ISO date without internal year or navigation controls, ideal for composable date pickers and multi-month blocks.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | required | The unique identifier for the component wrapper. |
variant | string | '' | User-defined variant name, added to the root element. Style it with a CSS rule that starts from the root. |
currentDate | string | new Date().toISOString().slice(0, 10) | ISO 8601 formatted date string (YYYY-MM-DD) that determines the displayed month. Supports $bindable. |
startDate | string | '' | The start date string in ISO format for range selections. Supports $bindable. |
endDate | string | '' | The end date string in ISO format for range selections. Supports $bindable. |
daySnippet | Snippet<[{ day: string; isCurrentMonth: boolean; isSelected: boolean; isInRange: boolean }]> | undefined | Optional custom snippet for rendering individual day cells. |
headerSnippet | Snippet<[{ weekday: string }]> | undefined | Optional custom snippet for rendering weekday header labels. |
Samples
1. Single Month with External Navigation
Control the displayed month by updating the currentDate prop from outside.
December
Mon
Tue
Wed
Thu
Fri
Sat
Sun
<script> import { CalendarGrid } from 'fluid-ui-svelte/components'; import { Button, Container } from 'fluid-ui-svelte/base'; let currentDate = $state(new Date().toISOString().slice(0, 10)); const changeMonth = (increment: number) => { const [year, month, day] = currentDate.split("-").map(Number); const date = new Date(year, month - 1 + increment, day); currentDate = date.getFullYear() + "-" + String(date.getMonth() + 1).padStart(2, "0") + "-" + String(date.getDate()).padStart(2, "0"); };</script> <Container class="flex flex-col gap-4"> <Container class="flex gap-2"> <Button onclick={() => changeMonth(-1)}>Prev</Button> <Button onclick={() => changeMonth(1)}>Next</Button> </Container> <CalendarGrid {currentDate} id="calendar-single" /></Container>2. Multi Calendar
Connect multiple calendar grids to the same range state variables.
December
Mon
Tue
Wed
Thu
Fri
Sat
Sun
January
Mon
Tue
Wed
Thu
Fri
Sat
Sun
<script> import { CalendarGrid } from 'fluid-ui-svelte/components'; import { Button, Container } from 'fluid-ui-svelte/base'; const addMonthsToIsoDateString = (dateString: string, monthsToAdd: number) => { const [year, month, day] = dateString.split("-").map(Number); const date = new Date(year, month - 1 + monthsToAdd, day); return date.getFullYear() + "-" + String(date.getMonth() + 1).padStart(2, "0") + "-" + String(date.getDate()).padStart(2, "0"); }; const multiCalendarState = $state({ currentDate: new Date().toISOString().slice(0, 10), startDate: '', endDate: '' }); const changeMonthMulti = (increment: number) => { multiCalendarState.currentDate = addMonthsToIsoDateString(multiCalendarState.currentDate, increment); };</script> <Container class="flex flex-col gap-4"> <Container class="flex gap-2"> <Button onclick={() => changeMonthMulti(-1)}>Prev</Button> <Button onclick={() => changeMonthMulti(1)}>Next</Button> </Container> <Container class="flex gap-8 flex-wrap"> <CalendarGrid bind:startDate={multiCalendarState.startDate} bind:endDate={multiCalendarState.endDate} currentDate={multiCalendarState.currentDate} /> <CalendarGrid bind:startDate={multiCalendarState.startDate} bind:endDate={multiCalendarState.endDate} currentDate={addMonthsToIsoDateString(multiCalendarState.currentDate, 1)} /> </Container></Container>