timepicker-ui
4.6.0GitHub
timepicker-ui
Overview / Installation

Installation

Install @pglejzer/datepicker-ui, the date picker companion of timepicker-ui, and load its CSS.

Package manager

#

The package has no dependencies. Install it with the package manager your project uses:

npm
npm install @pglejzer/datepicker-ui
yarn
yarn add @pglejzer/datepicker-ui
pnpm
pnpm add @pglejzer/datepicker-ui

Import the styles

#

The picker needs its stylesheet. Import index.css to get every theme, or main.css plus the theme files you use.

CSS entry points of the package.
ImportContains
@pglejzer/datepicker-ui/index.cssThe core and every theme
@pglejzer/datepicker-ui/main.cssThe core only, which is enough for basic
@pglejzer/datepicker-ui/theme-m3-green.cssOne theme, to load next to main.css

The theme files are:

  • theme-m3-green.css
  • theme-crane.css
  • theme-crane-straight.css
  • theme-m2.css
  • theme-glassmorphic.css
  • theme-pastel.css
  • theme-ai.css
  • theme-cyberpunk.css
  • theme-blueprint.css
index.ts
import "@pglejzer/datepicker-ui/main.css";
import "@pglejzer/datepicker-ui/theme-m2.css";

Set ui.theme to the matching name, for example "m2". See Themes for the color scheme and custom themes.

CDN

#

The UMD build exposes the class itself as the global DatepickerUI. From unpkg:

index.html
<link
rel="stylesheet"
href="https://unpkg.com/@pglejzer/datepicker-ui/dist/css/index.css"
/>
<script src="https://unpkg.com/@pglejzer/datepicker-ui/dist/umd/index.js"></script>
<script>
new DatepickerUI("#date").create();
</script>

jsDelivr serves the same files:

index.html
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@pglejzer/datepicker-ui/dist/css/index.css"
/>
<script src="https://cdn.jsdelivr.net/npm/@pglejzer/datepicker-ui/dist/umd/index.js"></script>

TypeScript

#

Types ship in the package, so there is nothing else to install. DatepickerUI is the default export and also a named export, and every option, value and event payload has an exported type.

index.ts
import DatepickerUI, {
type DatepickerOptions,
type PickerValue,
} from "@pglejzer/datepicker-ui";
const options: DatepickerOptions = {
calendar: { mode: "range" },
};
const picker = new DatepickerUI("#date", options);
picker.create();
const value: PickerValue | null = picker.getValue();

The full list is on the TypeScript page.

Server rendering

#

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

Frameworks

React, Next.js, Vue, Svelte and Angular setups are on Frameworks and SSR.

Next steps

Quick Start
Create your first picker
Examples
Live demos with code
Esc