A simple, modular React date picker component
The package can be installed via NPM:
npm i -S react-simple-date-picker
import React from 'react';
import DatePicker from 'react-simple-date-picker';
const MyForm = () => (
<form className="MyForm" onSubmit={(e) => {
const dateInput = e.target.querySelectorAll('input[name$="date"]')[0];
// dateInput.value is formatted as a YYYY-MM-DD string by default
doSomething(dateInput.value);
}}>
<DatePicker />
<button type="submit">Submit</button>
</form>
);
export default MyForm;
This DatePicker component is built simple on purpose. It's intended to be built upon. However, there are some pieces that are customizable right out of the box.
These customizable props include:
dirty
: should the currently selected date be shown on mount [defaults totrue
]inputName
: the html input element's "name" property [defaults to'date'
]showDateReset
: show the reset button [defaults totrue
]showDateSelected
: show the currently selected date in a human readable string [defaults totrue
]showWeekDayName
: show the abbreviated week names at the top of the calendar [defaults totrue
]showMonthChangeButtons
: show the left/right arrow buttons for changing the month [defaults totrue
]showYearChangeButtons
: show the up/down arrow buttons for changing the year [defaults totrue
]initialDate
: the initially selected date (Date) [defaults tonew Date()
]
...
<DatePicker
inputName="MyForm_date"
showDateReset=false
showDateSelected=false
initialDate={new Date('2021-01-20')}
/>
...
If you'd like to build upon the existing component (and you should!), you can
find all the applicable files within the src
directory, with all the React
components located within the components
directory.
Before you begin hacking away, run npm i
at the root level directory.
This will get you setup with webpack and the necessary loaders so you can run a dev server and create a build when the time is right.
npm start
to start a dev server
npm run build
to create a production build
npm run build-dev
to create a dev build