A Tailwindcss/Flowbite datepicker component built as a React component with types based on the original datepicker from Flowbite. This component can also be used as a plugin using the Flowbite React library.
Date logic from VanillaJS-datepicker.
npm install tailwind-datepicker-react
yarn add tailwind-datepicker-react
tailwind.config.js
filemodule.exports = {
...
content: [
...
"./node_modules/tailwind-datepicker-react/dist/**/*.js", // <--- Add this line
],
};
import Datepicker from "tailwind-datepicker-react"
const options = {
title: "Demo Title",
autoHide: true,
todayBtn: false,
clearBtn: true,
clearBtnText: "Clear",
maxDate: new Date("2030-01-01"),
minDate: new Date("1950-01-01"),
theme: {
background: "bg-gray-700 dark:bg-gray-800",
todayBtn: "",
clearBtn: "",
icons: "",
text: "",
disabledText: "bg-red-500",
input: "",
inputIcon: "",
selected: "",
},
icons: {
// () => ReactElement | JSX.Element
prev: () => <span>Previous</span>,
next: () => <span>Next</span>,
},
datepickerClassNames: "top-12",
defaultDate: new Date("2022-01-01"),
language: "en",
disabledDates: [],
weekDays: ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
inputNameProp: "date",
inputIdProp: "date",
inputPlaceholderProp: "Select Date",
inputDateFormatProp: {
day: "numeric",
month: "long",
year: "numeric"
}
}
const DemoComponent = () => {
const [show, setShow] = useState < boolean > false
const handleChange = (selectedDate: Date) => {
console.log(selectedDate)
}
const handleClose = (state: boolean) => {
setShow(state)
}
return (
<div>
<Datepicker options={options} onChange={handleChange} show={show} setShow={handleClose} />
</div>
)
}
const options = {
title: "Demo Title",
autoHide: true,
todayBtn: false,
clearBtn: true,
clearBtnText: "Clear",
maxDate: new Date("2030-01-01"),
minDate: new Date("1950-01-01"),
theme: {
background: "bg-gray-700 dark:bg-gray-800",
todayBtn: "",
clearBtn: "",
icons: "",
text: "",
disabledText: "bg-red-500",
input: "",
inputIcon: "",
selected: "",
},
icons: {
// () => ReactElement | JSX.Element
prev: () => <span>Previous</span>,
next: () => <span>Next</span>,
},
datepickerClassNames: "top-12",
defaultDate: new Date("2022-01-01"),
language: "en",
disabledDates: [],
weekDays: ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
inputNameProp: "date",
inputIdProp: "date",
inputPlaceholderProp: "Select Date",
inputDateFormatProp: {
day: "numeric",
month: "long",
year: "numeric"
}
}
const DemoComponent = () => {
const [show, setShow] = useState < boolean > false
const [selectedDate, setSelectedDate] = (useState < Date) | (null > null)
const handleChange = (selectedDate: Date) => {
setSelectedDate(selectedDate)
console.log(selectedDate)
}
const handleClose = (state: boolean) => {
setShow(state)
}
return (
<div>
<Datepicker options={options} onChange={handleChange} show={show} setShow={handleClose}>
<div className="...">
<div className="...">
<CalendarIcon />
</div>
<input type="text" className="..." placeholder="Select Date" value={selectedDate} onFocus={() => setShow(true)} readOnly />
</div>
</Datepicker>
</div>
)
}
disabled
true
true
Today
true
Clear
disabled
disabled
As seen on demo page
As seen on demo page
""
new Date()
en
[]
["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"] - Start at Monday even with another language
date
Same as "inputNameProp"
Select Date
{day: "numeric", month: "long", year: "numeric"}
This project is open-source under the MIT License.
After clone, you can run (separated):