jot-datepicker
v0.1.1
Published
[Youtube](https://www.youtube.com/c/JackofTraits) | [Github](https://github.com/jackoftraits) The jot-datepicker is a react js datepicker component that lets you customize the look of your calendar.
Downloads
4
Maintainers
Readme
JOT-DATEPICKER by Jack of Traits
Youtube | Github The jot-datepicker is a react js datepicker component that lets you customize the look of your calendar.
Reasons to use jot-datepicker
- Easy to use.
- No-brainer configurations are easily passed through the props.
Installation
The jot-datepicker requires Node.js v10+ and moment-js.
$ cd react-js-app
$ npm install jot-datepicker moment
Basic Usage
import Datepicker from "jot-datepicker";
import moment from "moment";
export defaults function App() {
return (
<Datepicker
showCalendar={true}
value={new Date()}
width="400px" // Just css width i.e. 300px, 50%
dateFormat="MMMM DD, Y" // Any moment-js format
closeTimeOut={200} // Closes the calendar after 200ms
onDatechange={(value) => {
// value returns native javascript date object
console.log(moment(value).format("YYYY-MM-DD"));
}}
/>
);
}
Adding custom styles to Weekdays
In this example, I am using Tailwind CSS. However you can use any CSS frameworks that you are comfortable with.
import Datepicker from "jot-datepicker";
import moment from "moment";
export defaults function App() {
return (
<Datepicker
showCalendar={true}
value={new Date()}
width="400px" // Just css width i.e. 300px, 50%
dateFormat="MMMM DD, Y" // any moment-js format
closeTimeOut={200}
weekDays={
<div>
<div className="font-semibold">Sun</div>
<div className="font-semibold">Mon</div>
<div className="font-semibold">Tue</div>
<div className="font-semibold">Wed</div>
<div className="font-semibold">Thur</div>
<div className="font-semibold">Fri</div>
<div className="font-semibold">Sat</div>
<div/>
}
onDatechange={(value) => {
// value returns native javascript date object
console.log(moment(value).format("YYYY-MM-DD"));
}}
/>
);
}
Overriding previous and next month buttons
import Datepicker from "jot-datepicker";
import moment from "moment";
export defaults function App() {
return (
<Datepicker
showCalendar={true}
value={new Date()}
width="400px" // Just css width i.e. 300px, 50%
dateFormat="MMMM DD, Y" // any moment-js format
closeTimeOut={200}
customPreviousMonthButton={(previousMonthAction) => {
return (
<button
className="text-sm cursor-pointer"
onClick={previousMonthAction}
>
←
</button>
);
}}
customNextMonthButton={(nextMonthAction) => {
return (
<button
className="text-sm cursor-pointer"
onClick={nextMonthAction}
>
→
</button>
);
}}
onDatechange={(value) => {
// value returns native javascript date object
console.log(moment(value).format("YYYY-MM-DD"));
}}
/>
);
}
Overriding the appearance of your calendar
The "view" props accepts two objects, the container and element.
The container has ** [calendar, closeButton, inputField] ** properties.
The element has ** [calendarTitle, inputField, dateBox, dateBoxSelected] ** properties.
The container and element are just CSS properties. You can try experimenting the appearance by changing the CSS properties.
import Datepicker from "jot-datepicker"; import moment from "moment"; export defaults function App() { return ( <Datepicker showCalendar={true} value={new Date()} width="400px" // Just css width i.e. 300px, 50% dateFormat="MMMM DD, Y" // any moment-js format closeTimeOut={200} view={{ container: { calendar: { border: "2px solid #4481cc", }, closeButton: { border: "1px solid green", backgroundColor: "#4481cc", color: "yellow", }, inputField: { border: "2px dashed #4481cc", }, }, element: { calendarTitle: { backgroundColor: "#4481cc", color: "#fff", }, inputField: { padding: "4px", border: "1px solid black", }, dateBox: { backgroundColor: "#e6dcff", }, dateBoxSelected: { backgroundColor: "#15C39A", border: "1px solid green", color: "#fff", }, }, }} onDatechange={(value) => { // value returns native javascript date object console.log(moment(value).format("YYYY-MM-DD")); }} /> );
}
Full Configuration with Tailwind
If have installed tailwind in your react project. You can also do the ones as shown in the example below. You can also use other css frameworks such as bootstrap.
import Datepicker from "jot-datepicker";
import moment from "moment";
export defaults function App() {
return (
<Datepicker
showCalendar={false}
value={new Date()}
width="400px"
dateFormat="MMMM DD, Y"
closeTimeOut={200}
customPreviousMonthButton={(previousMonthAction) => {
return (
<button
className="text-sm cursor-pointer focus:outline-none hover:bg-gray-100 btn px-2 py-1"
onClick={previousMonthAction}
>
←
</button>
);
}}
customNextMonthButton={(nextMonthAction) => {
return (
<button
className="text-sm cursor-pointer focus:outline-none hover:bg-gray-100 btn px-2 py-1"
onClick={nextMonthAction}
>
→
</button>
);
}}
weekDays={
<>
<div className="font-semibold bg-green-200">
Sun
</div>
<div className="font-semibold bg-blue-200">Mon</div>
<div className="font-semibold bg-blue-200">Tue</div>
<div className="font-semibold bg-blue-200">Wed</div>
<div className="font-semibold bg-blue-200">
Thur
</div>
<div className="font-semibold bg-blue-200">Fri</div>
<div className="font-semibold bg-green-200">
Sat
</div>
</>
}
customCalendarTitle={(
currentMonth,
currentYear,
monthArray
) => {
return (
<div className="font-semibold">
{monthArray[currentMonth] + " " + currentYear}
</div>
);
}}
view={{
container: {
calendar: {
border: "2px solid #4481cc",
},
closeButton: {
border: "1px solid green",
backgroundColor: "#4481cc",
color: "yellow",
},
inputField: {
border: "2px dashed #4481cc",
},
},
element: {
calendarTitle: {
backgroundColor: "#4481cc",
color: "#fff",
},
inputField: {
padding: "4px",
border: "1px solid black",
},
dateBox: {
backgroundColor: "#e6dcff",
},
dateBoxSelected: {
backgroundColor: "#15C39A",
border: "1px solid green",
color: "#fff",
},
},
}}
onDatechange={(value) => {
// value returns native javascript date object
console.log(moment(value).format("YYYY-MM-DD"));
}}
/>
);
}
License
MIT
Copyright (c) 2021 jackoftraits
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.