third party plugins

Tailwind CSS Flatpickr (Datepicker)

Flatpickr is a lightweight JavaScript library for easy date and time picking, offering sleek design and extensive customization options for web applications.

Below are the steps to seamlessly integrate Flatpickr JS into your project.

  • 1
    Step 1: Installation

    Install flatpickr using npm:

    npm i flatpickr

  • 2
    Step 2: Include Flatpickr JavaScript and CSS

    Include the necessary CSS and JavaScript files in the following locations:

    <head>
      <link rel="stylesheet" href="../path/to/flatpickr/dist/flatpickr.css" />
    </head>
    <body>
      <script src="../path/to/flatpickr/flatpickr.js"></script>
    </body>

    Note: A CDN link won't work here because we need to modify the default Vendor CSS to fit FlyonUI's design.


  • 3
    Step 3: Update Tailwind Configuration

    To enable CSS overrides, include the path to the vendor JS files in the content section of your Tailwind configuration file. Additionally, set vendors="true" in the FlyonUI config to ensure the override CSS is generated:

    module.exports = {
      content: [
        '.../path/to/flatpickr/**/*.js', // Include all relevant JS files from Flatpickr
      ],
      flyonui: {
        vendors: true // Enable vendor-specific CSS generation
      }
    }

  • 4
    Step 4: Basic Usage

    The following are valid ways to create a Flatpickr instance:

    // If using Flatpickr in a framework, it's recommended to pass the element directly
    flatpickr(element, {});
    
    // Alternatively, selectors are supported
    flatpickr("#myID", {});
    
    // Create multiple instances
    flatpickr(".anotherSelector");

Basic date picker example.

Basic time picker example.

Default datepicker.

Floating label example.

Success state can be show using is-valid class.

Error state can be show using is-invalid class.

Example showcasing a picker with both date and time selection.

Example demonstrating how to select multiple dates.

Select range of date.

Human Friendly date picker example.

Basic inline picker example.

The example below demonstrates how to disable a specific date range.

The date picker below has been localized to display months and days in Russian. For more information, please refer to the official documentation on localization.

Example displaying week number.