@@ -27,13 +27,15 @@ import { formatValue, isEqual, parseValue } from './utils/dateUtil';
2727import getDataOrAriaProps , { toArray } from './utils/miscUtil' ;
2828import type { ContextOperationRefProps } from './PanelContext' ;
2929import PanelContext from './PanelContext' ;
30- import type { CustomFormat , PickerMode } from './interface' ;
30+ import type { CustomFormat , PickerMode , PresetDate } from './interface' ;
3131import { getDefaultFormat , getInputSize , elementsContains } from './utils/uiUtil' ;
3232import usePickerInput from './hooks/usePickerInput' ;
3333import useTextValueMapping from './hooks/useTextValueMapping' ;
3434import useValueTexts from './hooks/useValueTexts' ;
3535import useHoverValue from './hooks/useHoverValue' ;
3636import { legacyPropsWarning } from './utils/warnUtil' ;
37+ import usePresets from './hooks/usePresets' ;
38+ import PresetPanel from './PresetPanel' ;
3739
3840export type PickerRefConfig = {
3941 focus : ( ) => void ;
@@ -56,6 +58,8 @@ export type PickerSharedProps<DateType> = {
5658 inputReadOnly ?: boolean ;
5759 id ?: string ;
5860
61+ presets ?: PresetDate < DateType > [ ] ;
62+
5963 // Value
6064 format ?: string | CustomFormat < DateType > | ( string | CustomFormat < DateType > ) [ ] ;
6165
@@ -151,6 +155,7 @@ function InnerPicker<DateType>(props: PickerProps<DateType>) {
151155 use12Hours,
152156 value,
153157 defaultValue,
158+ presets,
154159 open,
155160 defaultOpen,
156161 defaultOpenValue,
@@ -183,6 +188,8 @@ function InnerPicker<DateType>(props: PickerProps<DateType>) {
183188
184189 const needConfirmButton : boolean = ( picker === 'date' && ! ! showTime ) || picker === 'time' ;
185190
191+ const presetList = usePresets ( presets ) ;
192+
186193 // ============================ Warning ============================
187194 if ( process . env . NODE_ENV !== 'production' ) {
188195 legacyPropsWarning ( props ) ;
@@ -393,26 +400,36 @@ function InnerPicker<DateType>(props: PickerProps<DateType>) {
393400 } ;
394401
395402 let panelNode : React . ReactNode = (
396- < PickerPanel < DateType >
397- { ...panelProps }
398- generateConfig = { generateConfig }
399- className = { classNames ( {
400- [ `${ prefixCls } -panel-focused` ] : ! typing ,
401- } ) }
402- value = { selectedValue }
403- locale = { locale }
404- tabIndex = { - 1 }
405- onSelect = { ( date ) => {
406- onSelect ?.( date ) ;
407- setSelectedValue ( date ) ;
408- } }
409- direction = { direction }
410- onPanelChange = { ( viewDate , mode ) => {
411- const { onPanelChange } = props ;
412- onLeave ( true ) ;
413- onPanelChange ?.( viewDate , mode ) ;
414- } }
415- />
403+ < div className = { `${ prefixCls } -panel-layout` } >
404+ < PresetPanel
405+ prefixCls = { prefixCls }
406+ presets = { presetList }
407+ onClick = { ( nextValue ) => {
408+ triggerChange ( nextValue ) ;
409+ triggerOpen ( false ) ;
410+ } }
411+ />
412+ < PickerPanel < DateType >
413+ { ...panelProps }
414+ generateConfig = { generateConfig }
415+ className = { classNames ( {
416+ [ `${ prefixCls } -panel-focused` ] : ! typing ,
417+ } ) }
418+ value = { selectedValue }
419+ locale = { locale }
420+ tabIndex = { - 1 }
421+ onSelect = { ( date ) => {
422+ onSelect ?.( date ) ;
423+ setSelectedValue ( date ) ;
424+ } }
425+ direction = { direction }
426+ onPanelChange = { ( viewDate , mode ) => {
427+ const { onPanelChange } = props ;
428+ onLeave ( true ) ;
429+ onPanelChange ?.( viewDate , mode ) ;
430+ } }
431+ />
432+ </ div >
416433 ) ;
417434
418435 if ( panelRender ) {
@@ -422,6 +439,7 @@ function InnerPicker<DateType>(props: PickerProps<DateType>) {
422439 const panel = (
423440 < div
424441 className = { `${ prefixCls } -panel-container` }
442+ ref = { panelDivRef }
425443 onMouseDown = { ( e ) => {
426444 e . preventDefault ( ) ;
427445 } }
@@ -505,7 +523,6 @@ function InnerPicker<DateType>(props: PickerProps<DateType>) {
505523 value = { {
506524 operationRef,
507525 hideHeader : picker === 'time' ,
508- panelRef : panelDivRef ,
509526 onSelect : onContextSelect ,
510527 open : mergedOpen ,
511528 defaultOpenValue,
0 commit comments