DatePicker
DatePicker is a read-only text field that opens the calendar in a popover (single or range). For an inline calendar with time and toggles, see DatePickerAdvanced.
import { DatePicker } from "phoundry-ui";Single date
Loading interactive example…
View source
<script lang="ts"> import { DatePicker } from "phoundry-ui";
let singleDate = $state<Date | null>(null);
function formatDate(d: Date | null): string { if (!d) return "none"; return d.toLocaleDateString(); }</script>
<DatePicker value={singleDate} onchange={(d: Date) => { singleDate = d; }}/><p class="mt-2 text-xs text-txt-tertiary">Selected: {formatDate(singleDate)}</p>Date range
Loading interactive example…
View source
<script lang="ts"> import { DatePicker } from "phoundry-ui";
let rangeStart = $state<Date | null>(null);
let rangeEnd = $state<Date | null>(null);
function formatDate(d: Date | null): string { if (!d) return "none"; return d.toLocaleDateString(); }</script>
<DatePicker mode="range" {rangeStart} {rangeEnd} onrangechange={(s: Date, e: Date) => { rangeStart = s; rangeEnd = e; }}/><p class="mt-2 text-xs text-txt-tertiary"> Range: {formatDate(rangeStart)} - {formatDate(rangeEnd)}</p>Trigger size
Loading interactive example…
View source
<script lang="ts"> import { DatePicker } from "phoundry-ui";
let singleDate = $state<Date | null>(null);</script>
<div class="flex flex-wrap items-end gap-3"> <DatePicker value={singleDate} onchange={(d: Date) => { singleDate = d; }} inputSize="sm" /> <DatePicker value={singleDate} onchange={(d: Date) => { singleDate = d; }} inputSize="lg" /></div><p class="mt-2 text-xs text-txt-tertiary"> Same selection; <code>inputSize</code> only affects the field height.</p>Bounds, Monday week, placeholder
Loading interactive example…
View source
<script lang="ts"> import { DatePicker } from "phoundry-ui";
let singleDate = $state<Date | null>(null);
let constrainedDate = $state<Date | null>(null);
const minBoundary = new Date(2026, 4, 1);
const maxBoundary = new Date(2026, 4, 31);
function formatDate(d: Date | null): string { if (!d) return "none"; return d.toLocaleDateString(); }</script>
<div class="flex flex-wrap items-end gap-4"> <DatePicker value={constrainedDate} onchange={(d: Date) => { constrainedDate = d; }} minDate={minBoundary} maxDate={maxBoundary} weekStartsOn={1} placeholder="Pick a May 2026 date" /> <DatePicker value={singleDate} onchange={(d: Date) => (singleDate = d)} disabled placeholder="Disabled trigger" /></div><p class="mt-2 text-xs text-txt-tertiary"> Constrained: {formatDate(constrainedDate)}</p>DatePicker props
From phoundry-ui@0.4.21
| Name | Type | Default | Description |
|---|---|---|---|
value | Date | null | null | Selected date (single mode). |
rangeStart | Date | null | null | Range start date (range mode). |
rangeEnd | Date | null | null | Range end date (range mode). |
mode | "single" | "range" | 'single' | Selection mode. |
onchange | (date: Date) => void | — | Called when a single date is selected. |
onrangechange | (start: Date, end: Date) => void | — | Called when a range is completed. |
minDate | Date | — | Earliest selectable date. |
maxDate | Date | — | Latest selectable date. |
disabled | boolean | false | Disable the input and picker. |
weekStartsOn | 0 | 1 | 0 | First day of week: 0 = Sunday, 1 = Monday. |
placeholder | string | 'Select date' | Placeholder when empty. |
inputSize | "sm" | "md" | "lg" | 'md' | Size of the read-only trigger field (passed to TextInput). |
class | string | '' | Additional CSS classes on the wrapper. |
Usage tips
- Use
minDateandmaxDateto constrain selectable dates. - In
rangemode, the first click sets the start and the second click sets the end. - Set
weekStartsOn={1}for Monday-first calendars (ISO standard).
CSS styling
.ph-date-picker is the stable identification hook for DatePicker. Part selectors and --_ph-* properties are internal. Component CSS is scoped and unlayered; Consumer classes remain additive and utility overrides may lose precedence.
inputSize continues to select the nested TextInput control size. Date formatting, range selection, and callbacks are unchanged.
Keep the shared component stylesheet and a named Theme imported. Decorative motion respects reduced-motion preferences.