@@ -2,17 +2,75 @@ import { clsx } from 'clsx';
22import ResizeObserver , { type ResizeObserverProps } from '@rc-component/resize-observer' ;
33import * as React from 'react' ;
44import type {
5+ PanelRenderPanelProps ,
56 RangeTimeProps ,
67 SharedPickerProps ,
78 SharedTimeProps ,
89 ValueDate ,
910} from '../../interface' ;
11+ import PickerPanel , { type PickerPanelProps , type PickerPanelRef } from '../../PickerPanel' ;
12+ import { PickerHackContext , type PickerHackContextProps } from '../../PickerPanel/context' ;
1013import { toArray } from '../../utils/miscUtil' ;
1114import PickerContext from '../context' ;
1215import Footer , { type FooterProps } from './Footer' ;
13- import PopupPanel , { type PopupPanelProps } from './PopupPanel' ;
16+ import PopupPanel , {
17+ getPopupPanelPickerProps ,
18+ getPopupPanelSharedContext ,
19+ type PopupPanelProps ,
20+ } from './PopupPanel' ;
1421import PresetPanel from './PresetPanel' ;
1522
23+ interface PanelRenderContextProps < DateType extends object = any > {
24+ pickerProps : PickerPanelProps < DateType > ;
25+ sharedContext : PickerHackContextProps ;
26+ }
27+
28+ const PanelRenderContext = React . createContext < PanelRenderContextProps > ( null ! ) ;
29+
30+ const InternalPanelRenderPanel = React . forwardRef (
31+ < DateType extends object = any > (
32+ props : PanelRenderPanelProps < DateType > ,
33+ ref : React . Ref < PickerPanelRef > ,
34+ ) => {
35+ const context = React . useContext < PanelRenderContextProps < DateType > > ( PanelRenderContext ) ;
36+
37+ if ( ! context ) {
38+ return < PickerPanel ref = { ref } { ...( props as PickerPanelProps < DateType > ) } /> ;
39+ }
40+
41+ const { pickerProps, sharedContext } = context ;
42+ const mergedPicker = props . picker ?? pickerProps . picker ;
43+ const mergedProps = {
44+ ...pickerProps ,
45+ ...props ,
46+ picker : mergedPicker ,
47+ mode : props . mode ?? ( props . picker !== undefined ? mergedPicker : pickerProps . mode ) ,
48+ hideHeader : props . hideHeader ?? mergedPicker === 'time' ,
49+ components : props . components
50+ ? { ...pickerProps . components , ...props . components }
51+ : pickerProps . components ,
52+ classNames : props . classNames
53+ ? { ...pickerProps . classNames , ...props . classNames }
54+ : pickerProps . classNames ,
55+ styles : props . styles ? { ...pickerProps . styles , ...props . styles } : pickerProps . styles ,
56+ } as PickerPanelProps < DateType > ;
57+
58+ return (
59+ < PickerHackContext . Provider value = { sharedContext } >
60+ < PickerPanel ref = { ref } { ...mergedProps } />
61+ </ PickerHackContext . Provider >
62+ ) ;
63+ } ,
64+ ) ;
65+
66+ const PanelRenderPanel = InternalPanelRenderPanel as < DateType extends object = any > (
67+ props : PanelRenderPanelProps < DateType > & React . RefAttributes < PickerPanelRef > ,
68+ ) => React . ReactElement < any > ;
69+
70+ if ( process . env . NODE_ENV !== 'production' ) {
71+ InternalPanelRenderPanel . displayName = 'PanelRenderPanel' ;
72+ }
73+
1674export type PopupShowTimeConfig < DateType extends object = any > = Omit <
1775 RangeTimeProps < DateType > ,
1876 'defaultValue' | 'defaultOpenValue' | 'disabledTime'
@@ -78,6 +136,7 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D
78136 // Change
79137 value,
80138 onSelect,
139+ needConfirm,
81140 isInvalid,
82141 defaultOpenValue,
83142 onOk,
@@ -182,6 +241,11 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D
182241 onSubmit ( ) ;
183242 } ;
184243
244+ const panelRenderContext = {
245+ pickerProps : getPopupPanelPickerProps ( { ...props , value : popupPanelValue } ) ,
246+ sharedContext : getPopupPanelSharedContext ( needConfirm , onSubmit ) ,
247+ } ;
248+
185249 let mergedNodes : React . ReactNode = (
186250 < div className = { `${ prefixCls } -panel-layout` } >
187251 { /* `any` here since PresetPanel is reused for both Single & Range Picker which means return type is not stable */ }
@@ -203,10 +267,16 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D
203267 </ div >
204268 ) ;
205269
206- if ( panelRender ) {
207- mergedNodes = panelRender ( mergedNodes ) ;
270+ if ( typeof panelRender === 'function' ) {
271+ mergedNodes = panelRender ( mergedNodes , { components : { Panel : PanelRenderPanel } } ) ;
208272 }
209273
274+ mergedNodes = (
275+ < PanelRenderContext . Provider value = { panelRenderContext } >
276+ { mergedNodes }
277+ </ PanelRenderContext . Provider >
278+ ) ;
279+
210280 // ======================== Render ========================
211281 const containerPrefixCls = `${ panelPrefixCls } -container` ;
212282
0 commit comments