@@ -7,6 +7,7 @@ import getValue from 'rc-util/lib/utils/get';
7
7
import React from 'react' ;
8
8
import useXComponentConfig from '../_util/hooks/use-x-component-config' ;
9
9
import { useXProviderContext } from '../x-provider' ;
10
+ import SenderHeader , { SendHeaderContext } from './SenderHeader' ;
10
11
import { ActionButtonContext } from './components/ActionButton' ;
11
12
import ClearButton from './components/ClearButton' ;
12
13
import LoadingButton from './components/LoadingButton' ;
@@ -46,18 +47,22 @@ export interface SenderProps extends Pick<TextareaProps, 'placeholder' | 'onKeyP
46
47
onKeyDown ?: React . KeyboardEventHandler < any > ;
47
48
components ?: SenderComponents ;
48
49
styles ?: {
50
+ prefix ?: React . CSSProperties ;
49
51
input ?: React . CSSProperties ;
50
52
actions ?: React . CSSProperties ;
51
53
} ;
52
54
rootClassName ?: string ;
53
55
classNames ?: {
56
+ prefix ?: string ;
54
57
input ?: string ;
55
58
actions ?: string ;
56
59
} ;
57
60
style ?: React . CSSProperties ;
58
61
className ?: string ;
59
62
actions ?: React . ReactNode | ActionsRender ;
60
63
allowSpeech ?: boolean ;
64
+ prefix ?: React . ReactNode ;
65
+ header ?: React . ReactNode ;
61
66
}
62
67
63
68
function getComponent < T > (
@@ -68,7 +73,9 @@ function getComponent<T>(
68
73
return getValue ( components , path ) || defaultComponent ;
69
74
}
70
75
71
- const Sender : React . FC < SenderProps > = ( props ) => {
76
+ const Sender : React . FC < SenderProps > & {
77
+ Header : typeof SenderHeader ;
78
+ } = ( props ) => {
72
79
const {
73
80
prefixCls : customizePrefixCls ,
74
81
styles = { } ,
@@ -89,6 +96,8 @@ const Sender: React.FC<SenderProps> = (props) => {
89
96
onKeyDown,
90
97
disabled,
91
98
allowSpeech,
99
+ prefix,
100
+ header,
92
101
...rest
93
102
} = props ;
94
103
@@ -243,46 +252,72 @@ const Sender: React.FC<SenderProps> = (props) => {
243
252
style = { { ...contextConfig . style , ...style } }
244
253
onMouseDown = { onInternalMouseDown }
245
254
>
246
- < InputTextArea
247
- { ...inputProps }
248
- disabled = { disabled }
249
- style = { { ...contextConfig . styles . input , ...styles . input } }
250
- className = { classnames ( inputCls , contextConfig . classNames . input , classNames . input ) }
251
- autoSize = { { maxRows : 8 } }
252
- value = { innerValue }
253
- onChange = { ( e ) => {
254
- triggerValueChange ( ( e . target as HTMLTextAreaElement ) . value ) ;
255
- } }
256
- onPressEnter = { onInternalKeyPress }
257
- onCompositionStart = { onInternalCompositionStart }
258
- onCompositionEnd = { onInternalCompositionEnd }
259
- onKeyDown = { onKeyDown }
260
- readOnly = { loading }
261
- variant = "borderless"
262
- />
263
-
264
- { /* Action List */ }
265
- < div
266
- className = { classnames ( actionListCls , contextConfig . classNames . actions , classNames . actions ) }
267
- style = { { ...contextConfig . styles . actions , ...styles . actions } }
268
- >
269
- < ActionButtonContext . Provider
270
- value = { {
271
- prefixCls : actionBtnCls ,
272
- onSend : triggerSend ,
273
- onSendDisabled : ! innerValue ,
274
- onClear : triggerClear ,
275
- onClearDisabled : ! innerValue ,
276
- onCancel,
277
- onCancelDisabled : ! loading ,
278
- onSpeech : triggerSpeech ,
279
- onSpeechDisabled : ! speechPermission ,
280
- speechRecording,
281
- disabled,
255
+ { /* Header */ }
256
+ { header && (
257
+ < SendHeaderContext . Provider value = { { prefixCls } } > { header } </ SendHeaderContext . Provider >
258
+ ) }
259
+
260
+ < div className = { `${ prefixCls } -content` } >
261
+ { /* Prefix */ }
262
+ { prefix && (
263
+ < div
264
+ className = { classnames (
265
+ `${ prefixCls } -prefix` ,
266
+ contextConfig . classNames . prefix ,
267
+ classNames . prefix ,
268
+ ) }
269
+ style = { { ...contextConfig . styles . prefix , ...styles . prefix } }
270
+ >
271
+ { prefix }
272
+ </ div >
273
+ ) }
274
+
275
+ { /* Input */ }
276
+ < InputTextArea
277
+ { ...inputProps }
278
+ disabled = { disabled }
279
+ style = { { ...contextConfig . styles . input , ...styles . input } }
280
+ className = { classnames ( inputCls , contextConfig . classNames . input , classNames . input ) }
281
+ autoSize = { { maxRows : 8 } }
282
+ value = { innerValue }
283
+ onChange = { ( e ) => {
284
+ triggerValueChange ( ( e . target as HTMLTextAreaElement ) . value ) ;
282
285
} }
286
+ onPressEnter = { onInternalKeyPress }
287
+ onCompositionStart = { onInternalCompositionStart }
288
+ onCompositionEnd = { onInternalCompositionEnd }
289
+ onKeyDown = { onKeyDown }
290
+ readOnly = { loading }
291
+ variant = "borderless"
292
+ />
293
+
294
+ { /* Action List */ }
295
+ < div
296
+ className = { classnames (
297
+ actionListCls ,
298
+ contextConfig . classNames . actions ,
299
+ classNames . actions ,
300
+ ) }
301
+ style = { { ...contextConfig . styles . actions , ...styles . actions } }
283
302
>
284
- { actionNode }
285
- </ ActionButtonContext . Provider >
303
+ < ActionButtonContext . Provider
304
+ value = { {
305
+ prefixCls : actionBtnCls ,
306
+ onSend : triggerSend ,
307
+ onSendDisabled : ! innerValue ,
308
+ onClear : triggerClear ,
309
+ onClearDisabled : ! innerValue ,
310
+ onCancel,
311
+ onCancelDisabled : ! loading ,
312
+ onSpeech : triggerSpeech ,
313
+ onSpeechDisabled : ! speechPermission ,
314
+ speechRecording,
315
+ disabled,
316
+ } }
317
+ >
318
+ { actionNode }
319
+ </ ActionButtonContext . Provider >
320
+ </ div >
286
321
</ div >
287
322
</ div > ,
288
323
) ;
@@ -292,4 +327,6 @@ if (process.env.NODE_ENV !== 'production') {
292
327
Sender . displayName = 'Sender' ;
293
328
}
294
329
330
+ Sender . Header = SenderHeader ;
331
+
295
332
export default Sender ;
0 commit comments