Scripts2026年6月3日·1 分钟阅读

Flatpickr — Lightweight DateTime Picker with No Dependencies

A lightweight, dependency-free datetime picker that provides date, time, and range selection with localization support, mobile-friendly design, and extensive configuration options.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Flatpickr Overview
直接安装命令
npx -y tokrepo@latest install d8fee6e4-5ee2-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

Flatpickr is a lightweight datetime picker that works without any external dependencies. It supports date selection, time picking, date ranges, and multiple date selection with a clean UI that is touch-friendly and accessible. At under 6 KB gzipped, it provides extensive functionality while keeping bundle size small.

What Flatpickr Does

  • Renders an interactive calendar dropdown for date selection on any input element
  • Supports time picking, date ranges, and multi-date selection through configuration flags
  • Provides over 60 locale files for internationalized date formatting and calendar display
  • Allows disabling specific dates, date ranges, or weekdays for scheduling applications
  • Works with form libraries and frameworks through native input element binding

Architecture Overview

Flatpickr creates a calendar DOM element that is positioned relative to the bound input. All date calculations use the native JavaScript Date object without external date libraries. The picker maintains internal state for the current view (days, months, years), selected dates, and configuration. Plugins extend functionality by hooking into lifecycle events (onChange, onOpen, onClose). The CSS is modular, with a base theme and optional theme overrides.

Self-Hosting & Configuration

  • Install via npm, Yarn, or include from a CDN (both JS and CSS files)
  • Bind to an input element with flatpickr(selector, options) or use the data-flatpickr attribute for declarative setup
  • Set mode to "single", "multiple", or "range" to control selection behavior
  • Import locale files to display the calendar in different languages: import { French } from "flatpickr/dist/l10n/fr.js"
  • Apply themes by importing alternative CSS files (dark, material, airbnb) or write custom styles

Key Features

  • Zero dependencies and under 6 KB gzipped for fast page loads
  • Date range selection mode with visual highlighting between start and end dates
  • Plugins system for extras like month select, week select, confirm button, and scroll-based input
  • Mobile-friendly with an option to fall back to native date inputs on touch devices
  • Hooks and callbacks (onChange, onOpen, onClose, onReady) for custom logic integration

Comparison with Similar Tools

  • Pikaday — another lightweight date picker but lacks time selection and range mode; Flatpickr covers more use cases
  • date-fns/date picker libraries — React/Vue date pickers built on date-fns provide deeper framework integration; Flatpickr is framework-agnostic
  • Air Datepicker — jQuery-based date picker with similar features; Flatpickr has no jQuery dependency and a smaller footprint
  • Litepicker — modern lightweight range picker with no dependencies; Flatpickr offers more features (time, multi-select, plugins)
  • Native HTML date input — built into browsers but offers no customization of appearance or behavior; Flatpickr provides a consistent cross-browser experience

FAQ

Q: Does Flatpickr work with React or Vue? A: Yes. Community wrappers like react-flatpickr and vue-flatpickr-component provide idiomatic bindings. You can also initialize Flatpickr on a ref in lifecycle hooks.

Q: How do I disable specific dates? A: Use the disable option with an array of date strings, Date objects, or a function that returns true for dates that should be disabled.

Q: Can Flatpickr handle timezones? A: Flatpickr works with local dates by default. For timezone-aware behavior, parse and format dates using a library like date-fns-tz or Luxon before passing them to Flatpickr.

Q: Is Flatpickr still maintained? A: The library is stable and continues to receive community contributions. Its small scope and zero-dependency design mean it requires minimal ongoing maintenance.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产