Ambient UI

Command Palette

Search for a command to run...

Date Picker

A date picker component with range and presets.

Usage

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

"use client";
 
import * as React from "react";
 
import { Button } from "@smartacteam/ambient-web/button";
import { Calendar } from "@smartacteam/ambient-web/calendar";
import { CentralIcon } from "@smartacteam/ambient-web/icon";
import { Label } from "@smartacteam/ambient-web/label";
import { Popover } from "@smartacteam/ambient-web/popover";
 
export default function DatepickerDemo() {
  const [open, setOpen] = React.useState(false);
  const [date, setDate] = React.useState<Date | undefined>(undefined);
 
  return (
    <div className="flex flex-col gap-3">
      <Label htmlFor="date" className="px-1">
        Pick a date
      </Label>
      <Popover.Root open={open} onOpenChange={setOpen}>
        <Popover.Trigger>
          <Button id="date" className="w-48 justify-between font-normal">
            {date ? date.toLocaleDateString() : "Select date"}
            <CentralIcon
              name="IconChevronDownSmall"
              radius="2"
              stroke="1.5"
              fill="outlined"
            />
          </Button>
        </Popover.Trigger>
        <Popover.Content className="w-auto overflow-hidden p-0" align="start">
          <Calendar
            mode="single"
            selected={date}
            captionLayout="dropdown"
            onSelect={(date) => {
              setDate(date);
              setOpen(false);
            }}
          />
        </Popover.Content>
      </Popover.Root>
    </div>
  );
}

Examples

Date Range Picker

Picker with Input

Picker with Pattern Input

Natural Language Picker