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.
| Import | Contains |
|---|---|
@pglejzer/datepicker-ui/index.css | The core and every theme |
@pglejzer/datepicker-ui/main.css | The core only, which is enough for basic |
@pglejzer/datepicker-ui/theme-m3-green.css | One theme, to load next to main.css |
The theme files are:
theme-m3-green.csstheme-crane.csstheme-crane-straight.csstheme-m2.csstheme-glassmorphic.csstheme-pastel.csstheme-ai.csstheme-cyberpunk.csstheme-blueprint.css
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:
<linkrel="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:
<linkrel="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.
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
Next steps
- Quick Start
- Create your first picker
- Examples
- Live demos with code