React Datepicker
react-datepicker
is a third-party library. Please refer to its official documentation for more details.
Date Picker
- TSX
- JS
// React Imports
import { useState } from 'react'
// MUI Imports
import Grid from '@mui/material/Grid2'
// Component Imports
import CustomInput from './PickersCustomInput'
import AppReactDatepicker from '@/libs/styles/AppReactDatepicker'
const PickersBasic = () => {
// States
const [date, setDate] = useState<Date | null | undefined>(new Date())
return (
<Grid container spacing={6}>
<Grid size={{ xs: 12, md: 4 }}>
<AppReactDatepicker
selected={date}
id='basic-input'
onChange={(date: Date | null) => setDate(date)}
placeholderText='Click to select a date'
customInput={<CustomInput label='Basic' />}
/>
</Grid>
<Grid size={{ xs: 12, md: 4 }}>
<AppReactDatepicker
disabled
selected={date}
id='disabled-input'
onChange={(date: Date | null) => setDate(date)}
placeholderText='Click to select a date'
customInput={<CustomInput label='Disabled' />}
/>
</Grid>
<Grid size={{ xs: 12, md: 4 }}>
<AppReactDatepicker
readOnly
selected={date}
id='read-only-input'
onChange={(date: Date | null) => setDate(date)}
placeholderText='Click to select a date'
customInput={<CustomInput readOnly label='Readonly' />}
/>
</Grid>
</Grid>
)
}
export default PickersBasic
// React Imports
import { useState } from 'react'
// MUI Imports
import Grid from '@mui/material/Grid2'
// Component Imports
import CustomInput from './PickersCustomInput'
import AppReactDatepicker from '@/libs/styles/AppReactDatepicker'
const PickersBasic = () => {
// States
const [date, setDate] = useState(new Date())
return (
<Grid container spacing={6}>
<Grid size={{ xs: 12, md: 4 }}>
<AppReactDatepicker
selected={date}
id='basic-input'
onChange={date => setDate(date)}
placeholderText='Click to select a date'
customInput={<CustomInput label='Basic' />}
/>
</Grid>
<Grid size={{ xs: 12, md: 4 }}>
<AppReactDatepicker
disabled
selected={date}
id='disabled-input'
onChange={date => setDate(date)}
placeholderText='Click to select a date'
customInput={<CustomInput label='Disabled' />}
/>
</Grid>
<Grid size={{ xs: 12, md: 4 }}>
<AppReactDatepicker
readOnly
selected={date}
id='read-only-input'
onChange={date => setDate(date)}
placeholderText='Click to select a date'
customInput={<CustomInput readOnly label='Readonly' />}
/>
</Grid>
</Grid>
)
}
export default PickersBasic
Time Pickers
- TSX
- JS
// React Imports
import { useState } from 'react'
// MUI Imports
import Grid from '@mui/material/Grid2'
// Component Imports
import CustomInput from './PickersCustomInput'
import AppReactDatepicker from '@/libs/styles/AppReactDatepicker'
const PickersTime = () => {
// States
const [time, setTime] = useState<Date | null | undefined>(new Date())
const [dateTime, setDateTime] = useState<Date | null | undefined>(new Date())
return (
<Grid container spacing={6}>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
showTimeSelect
selected={time}
timeIntervals={15}
showTimeSelectOnly
dateFormat='h:mm aa'
id='time-only-picker'
onChange={(date: Date | null) => setTime(date)}
customInput={<CustomInput label='Time Only' />}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
showTimeSelect
timeFormat='HH:mm'
timeIntervals={15}
selected={dateTime}
id='date-time-picker'
dateFormat='MM/dd/yyyy h:mm aa'
onChange={(date: Date | null) => setDateTime(date)}
customInput={<CustomInput label='Date & Time' />}
/>
</Grid>
</Grid>
)
}
export default PickersTime
// React Imports
import { useState } from 'react'
// MUI Imports
import Grid from '@mui/material/Grid2'
// Component Imports
import CustomInput from './PickersCustomInput'
import AppReactDatepicker from '@/libs/styles/AppReactDatepicker'
const PickersTime = () => {
// States
const [time, setTime] = useState(new Date())
const [dateTime, setDateTime] = useState(new Date())
return (
<Grid container spacing={6}>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
showTimeSelect
selected={time}
timeIntervals={15}
showTimeSelectOnly
dateFormat='h:mm aa'
id='time-only-picker'
onChange={date => setTime(date)}
customInput={<CustomInput label='Time Only' />}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
showTimeSelect
timeFormat='HH:mm'
timeIntervals={15}
selected={dateTime}
id='date-time-picker'
dateFormat='MM/dd/yyyy h:mm aa'
onChange={date => setDateTime(date)}
customInput={<CustomInput label='Date & Time' />}
/>
</Grid>
</Grid>
)
}
export default PickersTime
Min & Max Pickers
- TSX
- JS
// React Imports
import { useState } from 'react'
// MUI Imports
import Grid from '@mui/material/Grid2'
// Third-party Imports
import { subDays, addDays } from 'date-fns'
// Component Imports
import CustomInput from './PickersCustomInput'
import AppReactDatepicker from '@/libs/styles/AppReactDatepicker'
const PickersMinMax = () => {
// States
const [minDate, setMinDate] = useState<Date | null | undefined>(new Date())
const [maxDate, setMaxDate] = useState<Date | null | undefined>(new Date())
return (
<Grid container spacing={6}>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
id='min-date'
selected={minDate}
minDate={subDays(new Date(), 5)}
onChange={(date: Date | null) => setMinDate(date)}
customInput={<CustomInput label='Min Date' />}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
id='max-date'
selected={maxDate}
maxDate={addDays(new Date(), 5)}
onChange={(date: Date | null) => setMaxDate(date)}
customInput={<CustomInput label='Max Date' />}
/>
</Grid>
</Grid>
)
}
export default PickersMinMax
// React Imports
import { useState } from 'react'
// MUI Imports
import Grid from '@mui/material/Grid2'
// Third-party Imports
import { subDays, addDays } from 'date-fns'
// Component Imports
import CustomInput from './PickersCustomInput'
import AppReactDatepicker from '@/libs/styles/AppReactDatepicker'
const PickersMinMax = () => {
// States
const [minDate, setMinDate] = useState(new Date())
const [maxDate, setMaxDate] = useState(new Date())
return (
<Grid container spacing={6}>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
id='min-date'
selected={minDate}
minDate={subDays(new Date(), 5)}
onChange={date => setMinDate(date)}
customInput={<CustomInput label='Min Date' />}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
id='max-date'
selected={maxDate}
maxDate={addDays(new Date(), 5)}
onChange={date => setMaxDate(date)}
customInput={<CustomInput label='Max Date' />}
/>
</Grid>
</Grid>
)
}
export default PickersMinMax
Date Range Pickers
- TSX
- JS
// React Imports
import { useState, forwardRef } from 'react'
// MUI Imports
import Grid from '@mui/material/Grid2'
import TextField from '@mui/material/TextField'
import type { TextFieldProps } from '@mui/material/TextField'
// Third-party Imports
import { format, addDays } from 'date-fns'
// Component Imports
import AppReactDatepicker from '@/libs/styles/AppReactDatepicker'
type CustomInputProps = TextFieldProps & {
label: string
end: Date | number
start: Date | number
}
const PickersRange = () => {
// States
const [startDate, setStartDate] = useState<Date | null | undefined>(new Date())
const [endDate, setEndDate] = useState<Date | null | undefined>(addDays(new Date(), 15))
const [startDateRange, setStartDateRange] = useState<Date | null | undefined>(new Date())
const [endDateRange, setEndDateRange] = useState<Date | null | undefined>(addDays(new Date(), 45))
const handleOnChange = (dates: any) => {
const [start, end] = dates
setStartDate(start)
setEndDate(end)
}
const handleOnChangeRange = (dates: any) => {
const [start, end] = dates
setStartDateRange(start)
setEndDateRange(end)
}
const CustomInput = forwardRef((props: CustomInputProps, ref) => {
const { label, start, end, ...rest } = props
const startDate = format(start, 'MM/dd/yyyy')
const endDate = end !== null ? ` - ${format(end, 'MM/dd/yyyy')}` : null
const value = `${startDate}${endDate !== null ? endDate : ''}`
return <TextField fullWidth inputRef={ref} {...rest} label={label} value={value} />
})
return (
<Grid container spacing={6}>
<Grid size={{ xs: 12 }}>
<AppReactDatepicker
selectsRange
endDate={endDate as Date}
selected={startDate}
startDate={startDate as Date}
id='date-range-picker'
onChange={handleOnChange}
shouldCloseOnSelect={false}
customInput={
<CustomInput label='Date Range' start={startDate as Date | number} end={endDate as Date | number} />
}
/>
</Grid>
<Grid size={{ xs: 12 }}>
<AppReactDatepicker
selectsRange
monthsShown={2}
endDate={endDateRange as Date}
selected={startDateRange}
startDate={startDateRange as Date}
shouldCloseOnSelect={false}
id='date-range-picker-months'
onChange={handleOnChangeRange}
customInput={
<CustomInput
label='Multiple Months'
end={endDateRange as Date | number}
start={startDateRange as Date | number}
/>
}
/>
</Grid>
</Grid>
)
}
export default PickersRange
// React Imports
import { useState, forwardRef } from 'react'
// MUI Imports
import Grid from '@mui/material/Grid2'
import TextField from '@mui/material/TextField'
// Third-party Imports
import { format, addDays } from 'date-fns'
// Component Imports
import AppReactDatepicker from '@/libs/styles/AppReactDatepicker'
const PickersRange = () => {
// States
const [startDate, setStartDate] = useState(new Date())
const [endDate, setEndDate] = useState(addDays(new Date(), 15))
const [startDateRange, setStartDateRange] = useState(new Date())
const [endDateRange, setEndDateRange] = useState(addDays(new Date(), 45))
const handleOnChange = dates => {
const [start, end] = dates
setStartDate(start)
setEndDate(end)
}
const handleOnChangeRange = dates => {
const [start, end] = dates
setStartDateRange(start)
setEndDateRange(end)
}
const CustomInput = forwardRef((props, ref) => {
const { label, start, end, ...rest } = props
const startDate = format(start, 'MM/dd/yyyy')
const endDate = end !== null ? ` - ${format(end, 'MM/dd/yyyy')}` : null
const value = `${startDate}${endDate !== null ? endDate : ''}`
return <TextField fullWidth inputRef={ref} {...rest} label={label} value={value} />
})
return (
<Grid container spacing={6}>
<Grid size={{ xs: 12 }}>
<AppReactDatepicker
selectsRange
endDate={endDate}
selected={startDate}
startDate={startDate}
id='date-range-picker'
onChange={handleOnChange}
shouldCloseOnSelect={false}
customInput={<CustomInput label='Date Range' start={startDate} end={endDate} />}
/>
</Grid>
<Grid size={{ xs: 12 }}>
<AppReactDatepicker
selectsRange
monthsShown={2}
endDate={endDateRange}
selected={startDateRange}
startDate={startDateRange}
shouldCloseOnSelect={false}
id='date-range-picker-months'
onChange={handleOnChangeRange}
customInput={<CustomInput label='Multiple Months' end={endDateRange} start={startDateRange} />}
/>
</Grid>
</Grid>
)
}
export default PickersRange
Specific Range
- TSX
- JS
// React Imports
import { useState } from 'react'
// MUI Imports
import Grid from '@mui/material/Grid2'
// Third-party Imports
import { addDays, setHours, setMinutes } from 'date-fns'
// Component Imports
import CustomInput from './PickersCustomInput'
import AppReactDatepicker from '@/libs/styles/AppReactDatepicker'
const PickersSpecificRange = () => {
// States
const [date, setDate] = useState<Date | null | undefined>(new Date())
const [time, setTime] = useState<Date | null | undefined>(new Date())
return (
<Grid container spacing={6}>
<Grid size={{ xs: 12 }}>
<AppReactDatepicker
selected={date}
id='specific-date'
minDate={new Date()}
maxDate={addDays(new Date(), 5)}
onChange={(date: Date | null) => setDate(date)}
customInput={<CustomInput label='Specific Date Range' />}
/>
</Grid>
<Grid size={{ xs: 12 }}>
<AppReactDatepicker
showTimeSelect
selected={time}
id='specific-time'
dateFormat='MM/dd/yyyy h:mm aa'
onChange={(date: Date | null) => setTime(date)}
minTime={setHours(setMinutes(new Date(), 0), 17)}
maxTime={setHours(setMinutes(new Date(), 30), 20)}
customInput={<CustomInput label='Specific Time' />}
/>
</Grid>
</Grid>
)
}
export default PickersSpecificRange
// React Imports
import { useState } from 'react'
// MUI Imports
import Grid from '@mui/material/Grid2'
// Third-party Imports
import { addDays, setHours, setMinutes } from 'date-fns'
// Component Imports
import CustomInput from './PickersCustomInput'
import AppReactDatepicker from '@/libs/styles/AppReactDatepicker'
const PickersSpecificRange = () => {
// States
const [date, setDate] = useState(new Date())
const [time, setTime] = useState(new Date())
return (
<Grid container spacing={6}>
<Grid size={{ xs: 12 }}>
<AppReactDatepicker
selected={date}
id='specific-date'
minDate={new Date()}
maxDate={addDays(new Date(), 5)}
onChange={date => setDate(date)}
customInput={<CustomInput label='Specific Date Range' />}
/>
</Grid>
<Grid size={{ xs: 12 }}>
<AppReactDatepicker
showTimeSelect
selected={time}
id='specific-time'
dateFormat='MM/dd/yyyy h:mm aa'
onChange={date => setTime(date)}
minTime={setHours(setMinutes(new Date(), 0), 17)}
maxTime={setHours(setMinutes(new Date(), 30), 20)}
customInput={<CustomInput label='Specific Time' />}
/>
</Grid>
</Grid>
)
}
export default PickersSpecificRange
Include & Exclude
- TSX
- JS
// React Imports
import { useState } from 'react'
// MUI Imports
import Grid from '@mui/material/Grid2'
// Third-party Imports
import { addDays, subDays, setHours, setMinutes } from 'date-fns'
// Component Imports
import CustomInput from './PickersCustomInput'
import AppReactDatepicker from '@/libs/styles/AppReactDatepicker'
const PickersIncludeExclude = () => {
// States
const [date, setDate] = useState<Date | null | undefined>(new Date())
const [dateExclude, setDateExclude] = useState<Date | null | undefined>(new Date())
const [time, setTime] = useState<Date | null | undefined>(setHours(setMinutes(new Date(), 0), 18))
const [timeExclude, setTimeExclude] = useState<Date | null | undefined>(setHours(setMinutes(new Date(), 0), 18))
return (
<Grid container spacing={6}>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
selected={date}
id='include-dates'
onChange={(date: Date | null) => setDate(date)}
customInput={<CustomInput label='Include Dates' />}
includeDates={[new Date(), addDays(new Date(), 1)]}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
id='exclude-dates'
selected={dateExclude}
onChange={(date: Date | null) => setDateExclude(date)}
customInput={<CustomInput label='Exclude Dates' />}
excludeDates={[subDays(new Date(), 1), subDays(new Date(), 2)]}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
showTimeSelect
selected={time}
id='include-time'
dateFormat='MM/dd/yyyy h:mm aa'
onChange={(date: Date | null) => setTime(date)}
customInput={<CustomInput label='Include Time' />}
includeTimes={[
setHours(setMinutes(new Date(), 0), 17),
setHours(setMinutes(new Date(), 30), 18),
setHours(setMinutes(new Date(), 30), 19),
setHours(setMinutes(new Date(), 30), 17)
]}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
showTimeSelect
id='exclude-time'
selected={timeExclude}
dateFormat='MM/dd/yyyy h:mm aa'
onChange={(date: Date | null) => setTimeExclude(date)}
customInput={<CustomInput label='Exclude Time' />}
excludeTimes={[
setHours(setMinutes(new Date(), 0), 17),
setHours(setMinutes(new Date(), 30), 18),
setHours(setMinutes(new Date(), 30), 19),
setHours(setMinutes(new Date(), 30), 17)
]}
/>
</Grid>
</Grid>
)
}
export default PickersIncludeExclude
// React Imports
import { useState } from 'react'
// MUI Imports
import Grid from '@mui/material/Grid2'
// Third-party Imports
import { addDays, subDays, setHours, setMinutes } from 'date-fns'
// Component Imports
import CustomInput from './PickersCustomInput'
import AppReactDatepicker from '@/libs/styles/AppReactDatepicker'
const PickersIncludeExclude = () => {
// States
const [date, setDate] = useState(new Date())
const [dateExclude, setDateExclude] = useState(new Date())
const [time, setTime] = useState(setHours(setMinutes(new Date(), 0), 18))
const [timeExclude, setTimeExclude] = useState(setHours(setMinutes(new Date(), 0), 18))
return (
<Grid container spacing={6}>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
selected={date}
id='include-dates'
onChange={date => setDate(date)}
customInput={<CustomInput label='Include Dates' />}
includeDates={[new Date(), addDays(new Date(), 1)]}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
id='exclude-dates'
selected={dateExclude}
onChange={date => setDateExclude(date)}
customInput={<CustomInput label='Exclude Dates' />}
excludeDates={[subDays(new Date(), 1), subDays(new Date(), 2)]}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
showTimeSelect
selected={time}
id='include-time'
dateFormat='MM/dd/yyyy h:mm aa'
onChange={date => setTime(date)}
customInput={<CustomInput label='Include Time' />}
includeTimes={[
setHours(setMinutes(new Date(), 0), 17),
setHours(setMinutes(new Date(), 30), 18),
setHours(setMinutes(new Date(), 30), 19),
setHours(setMinutes(new Date(), 30), 17)
]}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
showTimeSelect
id='exclude-time'
selected={timeExclude}
dateFormat='MM/dd/yyyy h:mm aa'
onChange={date => setTimeExclude(date)}
customInput={<CustomInput label='Exclude Time' />}
excludeTimes={[
setHours(setMinutes(new Date(), 0), 17),
setHours(setMinutes(new Date(), 30), 18),
setHours(setMinutes(new Date(), 30), 19),
setHours(setMinutes(new Date(), 30), 17)
]}
/>
</Grid>
</Grid>
)
}
export default PickersIncludeExclude
Month & Year Dropdowns
- TSX
- JS
// React Imports
import { useState } from 'react'
// MUI Imports
import Grid from '@mui/material/Grid2'
// Component Imports
import CustomInput from './PickersCustomInput'
import AppReactDatepicker from '@/libs/styles/AppReactDatepicker'
const PickersMonthYearDropdowns = () => {
// States
const [year, setYear] = useState<Date | null | undefined>(new Date())
const [month, setMonth] = useState<Date | null | undefined>(new Date())
const [monthYear, setMonthYear] = useState<Date | null | undefined>(new Date())
return (
<Grid container spacing={6}>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
selected={month}
showMonthDropdown
id='month-dropdown'
placeholderText='MM-DD-YYYY'
onChange={(date: Date | null) => setMonth(date)}
customInput={<CustomInput label='Month Dropdown' />}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
selected={year}
showYearDropdown
id='year-dropdown'
placeholderText='MM-DD-YYYY'
onChange={(date: Date | null) => setYear(date)}
customInput={<CustomInput label='Year Dropdown' />}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
showYearDropdown
showMonthDropdown
selected={monthYear}
id='month-year-dropdown'
placeholderText='MM-DD-YYYY'
onChange={(date: Date | null) => setMonthYear(date)}
customInput={<CustomInput label='Month & Year Dropdown' />}
/>
</Grid>
</Grid>
)
}
export default PickersMonthYearDropdowns
// React Imports
import { useState } from 'react'
// MUI Imports
import Grid from '@mui/material/Grid2'
// Component Imports
import CustomInput from './PickersCustomInput'
import AppReactDatepicker from '@/libs/styles/AppReactDatepicker'
const PickersMonthYearDropdowns = () => {
// States
const [year, setYear] = useState(new Date())
const [month, setMonth] = useState(new Date())
const [monthYear, setMonthYear] = useState(new Date())
return (
<Grid container spacing={6}>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
selected={month}
showMonthDropdown
id='month-dropdown'
placeholderText='MM-DD-YYYY'
onChange={date => setMonth(date)}
customInput={<CustomInput label='Month Dropdown' />}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
selected={year}
showYearDropdown
id='year-dropdown'
placeholderText='MM-DD-YYYY'
onChange={date => setYear(date)}
customInput={<CustomInput label='Year Dropdown' />}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
showYearDropdown
showMonthDropdown
selected={monthYear}
id='month-year-dropdown'
placeholderText='MM-DD-YYYY'
onChange={date => setMonthYear(date)}
customInput={<CustomInput label='Month & Year Dropdown' />}
/>
</Grid>
</Grid>
)
}
export default PickersMonthYearDropdowns
Month, Year & Quarter
- TSX
- JS
// React Imports
import { useState } from 'react'
// MUI Imports
import Grid from '@mui/material/Grid2'
// Component Imports
import CustomInput from './PickersCustomInput'
import AppReactDatepicker from '@/libs/styles/AppReactDatepicker'
const PickersMonthYear = () => {
// States
const [year, setYear] = useState<Date | null | undefined>(new Date())
const [month, setMonth] = useState<Date | null | undefined>(new Date())
const [quarter, setQuarter] = useState<Date | null | undefined>(new Date())
return (
<Grid container spacing={6}>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
selected={month}
id='month-picker'
showMonthYearPicker
dateFormat='MM/yyyy'
onChange={(date: Date | null) => setMonth(date)}
customInput={<CustomInput label='Month Picker' />}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
showYearPicker
selected={year}
id='year-picker'
dateFormat='MM/yyyy'
onChange={(date: Date | null) => setYear(date)}
customInput={<CustomInput label='Year Picker' />}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
selected={quarter}
id='quarter-picker'
showQuarterYearPicker
dateFormat='yyyy, QQQ'
onChange={(date: Date | null) => setQuarter(date)}
customInput={<CustomInput label='Quarter Picker' />}
/>
</Grid>
</Grid>
)
}
export default PickersMonthYear
// React Imports
import { useState } from 'react'
// MUI Imports
import Grid from '@mui/material/Grid2'
// Component Imports
import CustomInput from './PickersCustomInput'
import AppReactDatepicker from '@/libs/styles/AppReactDatepicker'
const PickersMonthYear = () => {
// States
const [year, setYear] = useState(new Date())
const [month, setMonth] = useState(new Date())
const [quarter, setQuarter] = useState(new Date())
return (
<Grid container spacing={6}>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
selected={month}
id='month-picker'
showMonthYearPicker
dateFormat='MM/yyyy'
onChange={date => setMonth(date)}
customInput={<CustomInput label='Month Picker' />}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
showYearPicker
selected={year}
id='year-picker'
dateFormat='MM/yyyy'
onChange={date => setYear(date)}
customInput={<CustomInput label='Year Picker' />}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
selected={quarter}
id='quarter-picker'
showQuarterYearPicker
dateFormat='yyyy, QQQ'
onChange={date => setQuarter(date)}
customInput={<CustomInput label='Quarter Picker' />}
/>
</Grid>
</Grid>
)
}
export default PickersMonthYear
Options
- TSX
- JS
// React Imports
import { useState } from 'react'
// MUI Imports
import Grid from '@mui/material/Grid2'
// Component Imports
import CustomInput from './PickersCustomInput'
import AppReactDatepicker from '@/libs/styles/AppReactDatepicker'
const PickersOptions = () => {
// States
const [dateOpen, setDateOpen] = useState<Date | null | undefined>(null)
const [dateClear, setDateClear] = useState<Date | null | undefined>(new Date())
const [dateFilter, setDateFilter] = useState<Date | null | undefined>(new Date())
const [dateWeekNum, setDateWeekNum] = useState<Date | null | undefined>(new Date())
const [dateTodayBtn, setDateTodayBtn] = useState<Date | null | undefined>(new Date())
const isWeekday = (date: Date) => {
const day = new Date(date).getDay()
return day !== 0 && day !== 6
}
return (
<Grid container spacing={6}>
<Grid size={{ xs: 12, lg: 4 }}>
<AppReactDatepicker
isClearable
id='picker-clear'
selected={dateClear}
customInput={<CustomInput label='Clear' />}
onChange={(date: Date | null) => setDateClear(date)}
/>
</Grid>
<Grid size={{ xs: 12, lg: 4 }}>
<AppReactDatepicker
weekLabel='Wk'
showWeekNumbers
id='picker-week-num'
selected={dateWeekNum}
onChange={(date: Date | null) => setDateWeekNum(date)}
customInput={<CustomInput label='Week Numbers' />}
/>
</Grid>
<Grid size={{ xs: 12, lg: 4 }}>
<AppReactDatepicker
id='picker-filter'
selected={dateFilter}
filterDate={isWeekday}
onChange={(date: Date | null) => setDateFilter(date)}
customInput={<CustomInput label='Filter Dates' />}
/>
</Grid>
<Grid size={{ xs: 12, lg: 4 }}>
<AppReactDatepicker
showYearDropdown
showMonthDropdown
selected={dateOpen}
id='picker-open-date'
openToDate={new Date('1993/09/28')}
onChange={(date: Date | null) => setDateOpen(date)}
customInput={<CustomInput label='Open To Date' />}
/>
</Grid>
<Grid size={{ xs: 12, lg: 4 }}>
<AppReactDatepicker
todayButton='Today'
selected={dateTodayBtn}
id='picker-date-today-btn'
onChange={(date: Date | null) => setDateTodayBtn(date)}
customInput={<CustomInput label='Date Today Button' />}
/>
</Grid>
</Grid>
)
}
export default PickersOptions
// React Imports
import { useState } from 'react'
// MUI Imports
import Grid from '@mui/material/Grid2'
// Component Imports
import CustomInput from './PickersCustomInput'
import AppReactDatepicker from '@/libs/styles/AppReactDatepicker'
const PickersOptions = () => {
// States
const [dateOpen, setDateOpen] = useState(null)
const [dateClear, setDateClear] = useState(new Date())
const [dateFilter, setDateFilter] = useState(new Date())
const [dateWeekNum, setDateWeekNum] = useState(new Date())
const [dateTodayBtn, setDateTodayBtn] = useState(new Date())
const isWeekday = date => {
const day = new Date(date).getDay()
return day !== 0 && day !== 6
}
return (
<Grid container spacing={6}>
<Grid size={{ xs: 12, lg: 4 }}>
<AppReactDatepicker
isClearable
id='picker-clear'
selected={dateClear}
customInput={<CustomInput label='Clear' />}
onChange={date => setDateClear(date)}
/>
</Grid>
<Grid size={{ xs: 12, lg: 4 }}>
<AppReactDatepicker
weekLabel='Wk'
showWeekNumbers
id='picker-week-num'
selected={dateWeekNum}
onChange={date => setDateWeekNum(date)}
customInput={<CustomInput label='Week Numbers' />}
/>
</Grid>
<Grid size={{ xs: 12, lg: 4 }}>
<AppReactDatepicker
id='picker-filter'
selected={dateFilter}
filterDate={isWeekday}
onChange={date => setDateFilter(date)}
customInput={<CustomInput label='Filter Dates' />}
/>
</Grid>
<Grid size={{ xs: 12, lg: 4 }}>
<AppReactDatepicker
showYearDropdown
showMonthDropdown
selected={dateOpen}
id='picker-open-date'
openToDate={new Date('1993/09/28')}
onChange={date => setDateOpen(date)}
customInput={<CustomInput label='Open To Date' />}
/>
</Grid>
<Grid size={{ xs: 12, lg: 4 }}>
<AppReactDatepicker
todayButton='Today'
selected={dateTodayBtn}
id='picker-date-today-btn'
onChange={date => setDateTodayBtn(date)}
customInput={<CustomInput label='Date Today Button' />}
/>
</Grid>
</Grid>
)
}
export default PickersOptions
Callbacks
- TSX
- JS
// React Imports
import { useState } from 'react'
// MUI Imports
import Grid from '@mui/material/Grid2'
// Third-party Imports
import { toast } from 'react-toastify'
// Component Imports
import CustomInput from './PickersCustomInput'
import AppReactDatepicker from '@/libs/styles/AppReactDatepicker'
const PickersCallbacks = () => {
// States
const [date, setDate] = useState<Date | null | undefined>(new Date())
const handlePickerCallback = (msg: string) => {
toast(msg, { autoClose: 2000 })
}
return (
<Grid container spacing={6}>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
selected={date}
id='callback-open'
dateFormat='MM/dd/yyyy'
onChange={(date: Date | null) => setDate(date)}
customInput={<CustomInput label='Open & Closed' />}
onCalendarOpen={() => handlePickerCallback(`Selected Date: ${new Date(date || '').toLocaleDateString()}`)}
onCalendarClose={() => handlePickerCallback(`Selected Date: ${new Date(date || '').toLocaleDateString()}`)}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
selected={date}
id='callback-blur'
onChange={(date: Date | null) => setDate(date)}
customInput={<CustomInput label='Blur' />}
onBlur={() => handlePickerCallback('Picker Closed')}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
selected={date}
id='callback-change'
customInput={<CustomInput label='onChange' />}
onChange={(date: Date | null) => {
setDate(date)
handlePickerCallback(`Selected Date: ${new Date(date || '').toLocaleDateString()}`)
}}
/>
</Grid>
</Grid>
)
}
export default PickersCallbacks
// React Imports
import { useState } from 'react'
// MUI Imports
import Grid from '@mui/material/Grid2'
// Third-party Imports
import { toast } from 'react-toastify'
// Component Imports
import CustomInput from './PickersCustomInput'
import AppReactDatepicker from '@/libs/styles/AppReactDatepicker'
const PickersCallbacks = () => {
// States
const [date, setDate] = useState(new Date())
const handlePickerCallback = msg => {
toast(msg, { autoClose: 2000 })
}
return (
<Grid container spacing={6}>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
selected={date}
id='callback-open'
dateFormat='MM/dd/yyyy'
onChange={date => setDate(date)}
customInput={<CustomInput label='Open & Closed' />}
onCalendarOpen={() => handlePickerCallback(`Selected Date: ${new Date(date || '').toLocaleDateString()}`)}
onCalendarClose={() => handlePickerCallback(`Selected Date: ${new Date(date || '').toLocaleDateString()}`)}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
selected={date}
id='callback-blur'
onChange={date => setDate(date)}
customInput={<CustomInput label='Blur' />}
onBlur={() => handlePickerCallback('Picker Closed')}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
selected={date}
id='callback-change'
customInput={<CustomInput label='onChange' />}
onChange={date => {
setDate(date)
handlePickerCallback(`Selected Date: ${new Date(date || '').toLocaleDateString()}`)
}}
/>
</Grid>
</Grid>
)
}
export default PickersCallbacks
Customization
- TSX
- JS
// React Imports
import { useState } from 'react'
// MUI Imports
import Grid from '@mui/material/Grid2'
// Third-party Imports
import { subDays, addDays } from 'date-fns'
// Component Imports
import CustomInput from './PickersCustomInput'
import AppReactDatepicker from '@/libs/styles/AppReactDatepicker'
const PickersCustomization = () => {
// States
const [dateFormat, setDateFormat] = useState<Date | null | undefined>(new Date())
const [dateHighlight, setDateHighlight] = useState<Date | null | undefined>(new Date())
return (
<Grid container spacing={6}>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
id='custom-format'
selected={dateFormat}
dateFormat='MMMM d, yyyy'
onChange={(date: Date | null) => setDateFormat(date)}
customInput={<CustomInput label='Custom Date Format' />}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
id='highlight-dates'
selected={dateHighlight}
onChange={(date: Date | null) => setDateHighlight(date)}
customInput={<CustomInput label='Highlight Dates' />}
highlightDates={[subDays(new Date(), 7), addDays(new Date(), 7)]}
/>
</Grid>
</Grid>
)
}
export default PickersCustomization
// React Imports
import { useState } from 'react'
// MUI Imports
import Grid from '@mui/material/Grid2'
// Third-party Imports
import { subDays, addDays } from 'date-fns'
// Component Imports
import CustomInput from './PickersCustomInput'
import AppReactDatepicker from '@/libs/styles/AppReactDatepicker'
const PickersCustomization = () => {
// States
const [dateFormat, setDateFormat] = useState(new Date())
const [dateHighlight, setDateHighlight] = useState(new Date())
return (
<Grid container spacing={6}>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
id='custom-format'
selected={dateFormat}
dateFormat='MMMM d, yyyy'
onChange={date => setDateFormat(date)}
customInput={<CustomInput label='Custom Date Format' />}
/>
</Grid>
<Grid size={{ xs: 12, lg: 6 }}>
<AppReactDatepicker
id='highlight-dates'
selected={dateHighlight}
onChange={date => setDateHighlight(date)}
customInput={<CustomInput label='Highlight Dates' />}
highlightDates={[subDays(new Date(), 7), addDays(new Date(), 7)]}
/>
</Grid>
</Grid>
)
}
export default PickersCustomization