npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bootstrap5-multiple-react-datepicker

v1.0.21

Published

Single or Multiple Bootstrap Date Picker for React

Downloads

1,395

Readme

npm

Instructions for Using the Multiple Date Selection Component

Step1 Intstall Datepicker package npm install bootstrap5-multiple-react-datepicker Step2: Install Bootstrap & Add it to your Project This package requires Bootstrap for styling. Depending on your setup, follow the appropriate instructions:

Step2 Option A If You’re Using Plain Bootstrap** Install Bootstrap and import its CSS file in your main JavaScript or SCSS file. npm install bootstrap@^5.3.2 Then, in your main file (e.g., index.js or App.js), add import 'bootstrap/dist/css/bootstrap.min.css';

Step2 Option B For SCSS-based imports (if using custom Bootstrap styles): Add this to your main SCSS file: @import '~bootstrap/scss/bootstrap'; Add Your Global SCSS Import: In your main JavaScript file (e.g., index.js or App.js), import the global SCSS file to apply Bootstrap styles across your application. import '../styles/globals.scss'; // Ensure this file imports Bootstrap 2 Option C If You’re Using React-Bootstrap: import 'bootstrap/dist/css/bootstrap.min.css';

Step3 Import the Date Picker

  • Import the necessary React hooks (useState and useRef) and styles to use the Datepicker component in your app.
  • Your import statements should look like this:
    import { useState, useRef } from 'react';
import Datepicker from 'bootstrap5-multiple-react-datepicker';

**Step4. Define State Variables The datepicker needs these three usestates where you import it. Example:

const [multiple, setMultiple] = useState(''); // Empty for single date selection, 'yes' for multiple
const [selecteddate, setSelecteddate] = useState('');
const [selecteddatesMulti, setSelecteddatesMulti] = useState([]);
  • Use multiple to determine if multiple dates are allowed -leave empty for single or write 'yes' for multiple
  • selecteddate will hold the value of the date if you choose single date
  • selecteddatesMulti will hold an array of multiple dates, if you choose multiple yes
  1. Create a Callback Function for Date Changes

    • Define the handleDateChange function to handle date changes. This function will receive newdate as an argument. Copy and Paste this: ```javascript const handleDateChange = (newdate) => { if (typeof newdate === 'object') { setSelecteddatesMulti(newdate); // Update multi-date state } else { setSelecteddate(newdate); // Update single date state } };
  2. Use the Datepicker Component

    • Add the Datepicker component within the return statement of your component function You can only change the format, the rest leave as is
      • format: Specify the date format, e.g.,
      • YYYYMMDD
      • DDMMYYYY
      • MMDDYYYY

    Example: COPY AND PASTE THIS , and only change the format if you want

    return (
        <Datepicker 
            onDateChange={handleDateChange}
            dateprop={multiple === 'yes' ? selecteddatesMulti : selecteddate}
            multiple={multiple}
            format="MMDDYYYY"
        />
    );
  3. Run the App

    • Start your development server to test the component.
  4. Optional: Toggle between Single and Multiple Date Selection

    • You can add a button or input element to toggle the multiple state between '' (single) and 'yes' (multiple) based on user preference.