Back to Woocommerce

DatePicker and DateRange

packages/js/components/src/calendar/README.md

10.8.0-dev3.3 KB
Original Source

DatePicker and DateRange

DatePicker

Usage

jsx
<DatePicker
	date={ date }
	text={ text }
	error={ error }
	onUpdate={ ( { date, text, error } ) => setState( { date, text, error } ) }
	dateFormat="MM/DD/YYYY"
/>

Props

NameTypeDefaultDescription
dateObjectnullA moment date object representing the selected date. null for no selection
disabledBooleannullWhether the input is disabled
textStringnullThe date in human-readable format. Displayed in the text input
errorStringnullA string error message, shown to the user
onUpdateFunctionnull(required) A function called upon selection of a date or input change
dateFormatStringnull(required) The date format in moment.js-style tokens
isInvalidDateFunctionnullA function to determine if a day on the calendar is not valid
popoverPropsObject{}Props that will be sent to the Dropdown component

DateRange

This is wrapper for a react-dates powered calendar.

Usage

jsx
<DateRange
	after={ after }
	afterText={ afterText }
	before={ before }
	beforeText={ beforeText }
	onUpdate={ ( update ) => setState( update ) }
	shortDateFormat="MM/DD/YYYY"
	focusedInput="startDate"
	isInvalidDate={ ( date ) =>
		// not a future date
		moment().isBefore( moment( date ), 'date' )
	}
/>

Props

NameTypeDefaultDescription
afterObjectnullA moment date object representing the selected start. null for no selection
afterErrorStringnullA string error message, shown to the user
afterTextStringnullThe start date in human-readable format. Displayed in the text input
beforeObjectnullA moment date object representing the selected end. null for no selection
beforeErrorStringnullA string error message, shown to the user
beforeTextStringnullThe end date in human-readable format. Displayed in the text input
focusedInputStringnullString identifying which is the currently focused input (start or end)
isInvalidDateFunctionnullA function to determine if a day on the calendar is not valid
onUpdateFunctionnull(required) A function called upon selection of a date
shortDateFormatStringnull(required) The date format in moment.js-style tokens