coss.com Svelte

Date Picker

A date picker component built with Calendar and Popover.

Loading p-date-picker-1 preview…

About

The Date Picker is built using a composition of the Calendar and Popover components.

Installation

The Date Picker is a composition pattern, not a standalone component. Install the required components:

pnpm dlx shadcn-svelte@latest add https://coss-sv.vercel.app/r/calendar.json https://coss-sv.vercel.app/r/popover.json https://coss-sv.vercel.app/r/button.json

Usage

<script lang="ts">
  import { buttonVariants } from "$lib/components/ui/button/index.js";
  import { Calendar } from "$lib/components/ui/calendar/index.js";
  import * as Popover from "$lib/components/ui/popover/index.js";
  import HugeiconsIcon from "$lib/hugeicons-icon.svelte";
  import Calendar03Icon from "@hugeicons/core-free-icons/Calendar03Icon";

  let date = $state<Date>();
</script>

<Popover.Root>
  <Popover.Trigger class={buttonVariants({ class: "w-[280px] justify-start", variant: "outline" })}>
    <HugeiconsIcon aria-hidden="true" icon={Calendar03Icon} strokeWidth={2} />
    {date ? date.toLocaleDateString() : "Pick a date"}
  </Popover.Trigger>
  <Popover.Popup align="start" class="w-auto p-0">
    <Calendar mode="single" bind:selected={date} />
  </Popover.Popup>
</Popover.Root>

Examples

Date Range Picker

Loading p-date-picker-2 preview…

With Dropdown Navigation

Use captionLayout="dropdown" for date of birth or historical date selection.

Loading p-date-picker-3 preview…

With Presets

Loading p-date-picker-4 preview…

With Input

Loading p-date-picker-5 preview…

Close on Select

Control the popover state to close it when a date is selected.

Loading p-date-picker-6 preview…