timepicker-ui
4.6.0GitHub
timepicker-ui
Guides / Frameworks and SSR

Date Picker with React, Vue, Svelte and Angular

@pglejzer/datepicker-ui, the companion of timepicker-ui, has a plain JS API. Create the picker on mount and call destroy() on unmount in any framework.

Server rendering

#

Importing the package does not touch window or document, so it is safe on the server. The constructor needs a document and throws without one, so create the picker on the client after the input is mounted, and call destroy() on unmount.

Create on mount, destroy on unmount

#

Every framework follows the same pattern: wait until the input exists, create the picker, and destroy it when the component goes away.

date-field.tsx
"use client";
import { useEffect, useRef } from "react";
import DatepickerUI from "@pglejzer/datepicker-ui";
import "@pglejzer/datepicker-ui/index.css";
export function DateField() {
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!inputRef.current) return;
const picker = new DatepickerUI(inputRef.current, {
calendar: { minDate: "today" },
});
picker.create();
return () => picker.destroy();
}, []);
return <input ref={inputRef} />;
}

Angular styles

Add node_modules/@pglejzer/datepicker-ui/dist/css/index.css to the styles array of angular.json, or import @pglejzer/datepicker-ui/index.css from your global stylesheet.

Next.js App Router

#

Pages and layouts are Server Components by default. Put the picker in a file that starts with "use client", as in the React tab, and render it from the page:

page.tsx
import { DateField } from "./date-field";
export default function Page() {
return (
<form>
<DateField />
</form>
);
}

Options that contain functions, such as isDateDisabled or callbacks, have to be defined inside the client component. A server component cannot pass functions to a client component.

From a CDN

#

The UMD build exposes the class itself as the global DatepickerUI. jsDelivr serves the same files from https://cdn.jsdelivr.net/npm/@pglejzer/datepicker-ui/dist/.

#
Esc