-
Notifications
You must be signed in to change notification settings - Fork 832
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add prop to render elements after calendar (#1795)
This allows us to render anything after the calendar (buttons, text…) by passing the renderCalendarInfo props to DateRangePicker.
- Loading branch information
Julien Enselme
committed
Sep 8, 2020
1 parent
91dcbaf
commit 05d8a95
Showing
4 changed files
with
127 additions
and
38 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
docs/pages/demo/daterangepicker/CustomCalendarRender.example.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as React from 'react'; | ||
import { DateRangePicker, DateRange, DateRangeDelimiter, PickersCalendar, PickersCalendarProps } from '@material-ui/pickers'; | ||
import TextField from "@material-ui/core/TextField"; | ||
|
||
interface CalendarWithValidationButtonProps extends PickersCalendarProps<Date> { | ||
validateCustomPeriod: () => void; | ||
} | ||
|
||
function CalendarWithValidationButton ({ validateCustomPeriod, ...pickersCalendarProps }: CalendarWithValidationButtonProps) { | ||
return ( | ||
<React.Fragment> | ||
<PickersCalendar {...pickersCalendarProps} /> | ||
|
||
<button | ||
type="button" | ||
className="button date-dropdown__button--validate button--small button--alert" | ||
onClick={validateCustomPeriod} | ||
> | ||
Validate | ||
</button> | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
export default function CustomCalendarRender() { | ||
const [value, setValue] = React.useState<DateRange<Date>>([null, null]); | ||
|
||
return ( | ||
<DateRangePicker | ||
startText="Check-in" | ||
endText="Check-out" | ||
value={value} | ||
onChange={(newValue) => setValue(newValue)} | ||
slotComponents={{ Calendar: CalendarWithValidationButton }} | ||
// @ts-ignore | ||
slotProps={{ Calendar: { validateCustomPeriod: setValue } }} | ||
renderInput={(startProps, endProps) => ( | ||
<React.Fragment> | ||
<TextField {...startProps} /> | ||
<DateRangeDelimiter> to </DateRangeDelimiter> | ||
<TextField {...endProps} /> | ||
</React.Fragment> | ||
)} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters