Netzo Logo

date-picker

A date picker component with range and presets.

shadcn/ui radix-ui Storybook Figma

Usage

After installation components can be imported and used directly.

import { DatePicker } from 'netzo/components/date-picker.tsx'

Examples

Working examples to copy-paste into projects under components/.

Default

import { format } from "netzo/deps/date-fns.ts";
import { useState } from "preact/hooks";
import { cn } from "netzo/components/utils.ts";
import { Button } from "netzo/components/button.tsx";
import { Calendar } from "netzo/components/calendar.tsx";
import {
  Popover,
  PopoverContent,
  PopoverTrigger,
} from "netzo/components/popover.tsx";

export default () => {
  const [date, setDate] = useState<Date>();

  return (
    <Popover>
      <PopoverTrigger asChild>
        <Button
          variant={"outline"}
          className={cn(
            "w-[240px] justify-start text-left font-normal",
            !date && "text-muted-foreground",
          )}
        >
          <i className="mdi-calendar mr-2 h-4 w-4" />
          {date ? format(date, "PPP") : <span>Pick a date</span>}
        </Button>
      </PopoverTrigger>
      <PopoverContent className="w-auto p-0" align="start">
        <Calendar
          mode="single"
          selected={date}
          onSelect={setDate}
          initialFocus
        />
      </PopoverContent>
    </Popover>
  );
};