1.0.19 • Published 2 months ago

react-daterangeselector v1.0.19

Weekly downloads
38
License
Apache 2.0
Repository
github
Last release
2 months ago

react-daterangeselector

A React component for choosing date ranges, dates and times.

Getting Started

To get started

import React from 'react';
import DateRangeSelector from 'react-daterangeselector';
import 'react-daterangeselector/dist/styles.min.css';

function App() {
	function callback(start, end) {
		console.log(start, end);
	}
	return (
		<>
			<h2>Date Range Selector</h2>
			<DateRangeSelector
				inputComponent={<input type='text' name='dates' className='form-control pull-right' />}
				options={{
					opens: 'left',
					buttonClasses: ['btn btn-sm'],
					applyClass: 'btn-primary',
					separator: ' to ',
					format: 'L',
					dateLimit: { days: 90 },
					ranges: {
						'Last 7 Days': [new Date('2019-10-13T00:00:00.000Z'), new Date('2019-10-19T23:59:59.999Z')],
						'Last 28 Days': [new Date('2019-09-22T00:00:00.000Z'), new Date('2019-10-19T23:59:59.999Z')],
						'October 2019': [new Date('2019-10-01T00:00:00.000Z'), new Date('2019-10-31T23:59:59.999Z')],
						'September 2019': [new Date('2019-09-01T00:00:00.000Z'), new Date('2019-09-30T23:59:59.999Z')],
						'August 2019': [new Date('2019-08-01T00:00:00.000Z'), new Date('2019-08-31T23:59:59.999Z')],
						'July 2019': [new Date('2019-07-01T00:00:00.000Z'), new Date('2019-07-31T23:59:59.999Z')],
						'June 2019': [new Date('2019-06-01T00:00:00.000Z'), new Date('2019-06-30T23:59:59.999Z')]
					},
					locale: {
						applyLabel: 'Update',
						cancelLabel: 'Clear',
						fromLabel: 'Start date',
						toLabel: 'End date',
						customRangeLabel: 'Custom'
					},
					minDate: new Date('2013-10-01T00:00:00.000Z'),
					alwaysShowCalendars: true
				}}
				callback={callback}
			/>
		</>
	);
}

export default App;

Options

NameTypeRequiredDescription
inputComponent(HTMLElement)trueA Component for render react-datetimeselector.
selectedComponent(function)trueA function which return a string ( arguments are startDate,selector,endDate ).
updateOnOutsideClick(boolean)trueOption to control update calender component when click outside
callback(function)trueA function which returns updated date.
hideOnScroll(true or false)falseThe component will hide on scroll body
state(function)falseA callback function to get component open state (boolean)
fixedScroll(true or false)falseThe component will block scroll while opening
title(string)falseTitle of the component
rangeBoundaryLabel(object)falseTitle of the calender {left : 'Start Date', right: 'End Date' }
dateLimit(object)falseOption to controll maximum selectable date limit. ex: option = {{dateLimit: { days: 90 }}}
startDate(Date or string)falseThe beginning date of the initially selected date range. If you provide a string, it must match the date format string set in your locale setting.
endDate(Date or string)falseThe end date of the initially selected date range.
minDate(Date or string)falseThe earliest date a user may select.
maxDate(Date or string)falseThe latest date a user may select.
maxSpan(object)falsee maximum span between the selected start and end dates. Check off maxSpan in the configuration generator for an example of how to use this. You can provide any object the moment library would let you add to a date.
showDropdowns(true/false)falseShow year and month select boxes above calendars to jump to a specific month and year.
minYear(number)falseThe minimum year shown in the dropdowns when showDropdowns is set to true.
maxYear(number)falseThe maximum year shown in the dropdowns when showDropdowns is set to true.
showWeekNumbers(true/false)falseShow localized week numbers at the start of each week on the calendars.
showISOWeekNumbers(true/false)falseShow ISO week numbers at the start of each week on the calendars.
timePicker(true/false)falseAdds select boxes to choose times in addition to dates.
timePickerIncrement(number)falseIncrement of the minutes selection list for times (i.e. 30 to allow only selection of times ending in 0 or 30).
timePicker24Hour(true/false)falseUse 24-hour instead of 12-hour times, removing the AM/PM selection.
timePickerSeconds(true/false)falseShow seconds in the timePicker.
ranges(object)falseSet predefined date ranges the user can select from. Each key is the label for the range, and its value an array with two dates representing the bounds of the range.
showCustomRangeLabel(true/false)falseDisplays "Custom Range" at the end of the list of predefined ranges, when the ranges option is used. This option will be highlighted whenever the current date range selection does not match one of the predefined ranges. Clicking it will display the calendars to select a new range.
alwaysShowCalendars(true/false)falseNormally, if you use the ranges option to specify pre-defined date ranges, calendars for choosing a custom date range are not shown until the user clicks "Custom Range". When this option is set to true, the calendars for choosing a custom date range are always shown instead.
opens('left'/'right'/'center')falseWhether the picker appears aligned to the left, to the right, or centered under the HTML element it's attached to.
drops('down'/'up')falseWhether the picker appears below (default) or above the HTML element it's attached to.
buttonClasses(string)falseCSS class names that will be added to both the apply and cancel buttons.
applyButtonClasses(string)falseCSS class names that will be added only to the apply button.
cancelButtonClasses(string)falseCSS class names that will be added only to the cancel button.
locale(object)falseAllows you to provide localized strings for buttons and labels, customize the date format, and change the first day of week for the calendars.
singleDatePicker(true/false)falseShow only a single calendar to choose one date, instead of a range picker with two calendars. The start and end dates provided to your callback will be the same single date chosen.
autoApply(true/false)falseHide the apply and cancel buttons, and automatically apply a new date range as soon as two dates are clicked.
linkedCalendars(true/false)falseWhen enabled, the two calendars displayed will always be for two sequential months (i.e. January and February), and both will be advanced when clicking the left or right arrows above the calendars. When disabled, the two calendars can be individually advanced and display any month/year.
isInvalidDate(function)falseA function that is passed each date in the two calendars before they are displayed, and may return true or false to indicate whether that date should be available for selection or not.
isCustomDate(function)falseA function that is passed each date in the two calendars before they are displayed, and may return a string or array of CSS class names to apply to that date's calendar cell.
autoUpdateInput(true/false)falseIndicates whether the date range picker should automatically update the value of the element it's attached to at initialization and when the selected dates change.
parentEl(string)falsehtml selector of the parent element that the date range picker will be added to, if not provided this will be 'body'
class(string)falseA custom class which append in root level (for overide css properties)

Screenshot

Preview

Licence

Apache 2.0

1.0.19

2 months ago

1.0.18

2 months ago

1.0.17

2 months ago

1.0.16

2 months ago

1.0.15

2 months ago

1.0.14

2 months ago

1.0.13

2 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago