11import { consume } from '@lit/context' ;
2- import { html , LitElement , nothing } from 'lit' ;
2+ import { html , LitElement , nothing , type TemplateResult } from 'lit' ;
33import { query , state } from 'lit/decorators.js' ;
44import IgcIconButtonComponent from '../button/icon-button.js' ;
55import IgcChipComponent from '../chip/chip.js' ;
@@ -83,6 +83,67 @@ export default class IgcChatInputComponent extends LitElement {
8383 registerIconFromText ( 'send-message' , sendButtonIcon , 'material' ) ;
8484 }
8585
86+ public get defaultAttachmentsArea ( ) : TemplateResult {
87+ return html `${ this . _chatState ?. inputAttachments ?. map (
88+ ( attachment , index ) => html `
89+ < div part ="attachment-wrapper " role ="listitem ">
90+ < igc-chip removable @igcRemove =${ ( ) => this . removeAttachment ( index ) } >
91+ < span part ="attachment-name "> ${ attachment . name } </ span >
92+ </ igc-chip >
93+ </ div >
94+ `
95+ ) } `;
96+ }
97+
98+ public get defaultTextArea ( ) : TemplateResult {
99+ return html ` < igc-textarea
100+ part ="text-input "
101+ placeholder ="Type a message... "
102+ resize ="auto "
103+ rows ="1 "
104+ .value =${ this . inputValue }
105+ @input =${ this . handleInput }
106+ @keydown=${ this . handleKeyDown }
107+ @focus=${ this . handleFocus }
108+ @blur=${ this . handleBlur }
109+ > </ igc-textarea > ` ;
110+ }
111+
112+ public get defaultFileUploadButton ( ) : TemplateResult {
113+ return html `
114+ < igc-file-input
115+ multiple
116+ .accept =${ this . _chatState ?. options ?. acceptedFiles }
117+ @igcChange =${ this . handleFileUpload }
118+ >
119+ < igc-icon
120+ slot ="file-selector-text "
121+ name ="attachment "
122+ collection ="material "
123+ > </ igc-icon >
124+ </ igc-file-input >
125+ ` ;
126+ }
127+
128+ public get defaultSendButton ( ) : TemplateResult {
129+ return html ` < igc-icon-button
130+ aria-label ="Send message "
131+ name ="send-message "
132+ collection ="material "
133+ variant ="contained "
134+ part ="send-button "
135+ ?disabled =${ ! this . inputValue . trim ( ) &&
136+ this . _chatState ?. inputAttachments . length === 0 }
137+ @click =${ this . sendMessage }
138+ > </ igc-icon-button > ` ;
139+ }
140+
141+ protected * renderDefaultFileUploadTemplate ( ) {
142+ yield html `${ this . _chatState ?. options ?. disableAttachments
143+ ? nothing
144+ : this . defaultFileUploadButton } `;
145+ }
146+
86147 protected override firstUpdated ( ) {
87148 this . setupDragAndDrop ( ) ;
88149 if ( this . _chatState ) {
@@ -243,43 +304,13 @@ export default class IgcChatInputComponent extends LitElement {
243304 this . requestUpdate ( ) ;
244305 }
245306
246- protected * renderDefaultFileUploadTemplate ( ) {
247- yield html `${ this . _chatState ?. options ?. disableAttachments
248- ? nothing
249- : html `
250- < igc-file-input
251- multiple
252- .accept =${ this . _chatState ?. options ?. acceptedFiles }
253- @igcChange =${ this . handleFileUpload }
254- >
255- < igc-icon
256- slot ="file-selector-text "
257- name ="attachment "
258- collection ="material "
259- > </ igc-icon >
260- </ igc-file-input >
261- ` } `;
262- }
263-
264- protected * renderDefaultSendButtonTemplate ( ) {
265- yield html ` < igc-icon-button
266- aria-label ="Send message "
267- name ="send-message "
268- collection ="material "
269- variant ="contained "
270- part ="send-button "
271- ?disabled =${ ! this . inputValue . trim ( ) &&
272- this . _chatState ?. inputAttachments . length === 0 }
273- @click =${ this . sendMessage }
274- > </ igc-icon-button > ` ;
275- }
276-
277307 private renderActionsArea ( ) {
278308 return html `< div part ="buttons-container ">
279309 ${ this . _chatState ?. options ?. templates ?. textAreaActionsTemplate
280310 ? this . _chatState ?. options ?. templates ?. textAreaActionsTemplate
281- : html ` ${ this . renderDefaultFileUploadTemplate ( ) }
282- ${ this . renderDefaultSendButtonTemplate ( ) } ` }
311+ : html `
312+ ${ this . renderDefaultFileUploadTemplate ( ) } ${ this . defaultSendButton }
313+ ` }
283314 </ div > ` ;
284315 }
285316
@@ -289,18 +320,7 @@ export default class IgcChatInputComponent extends LitElement {
289320 ? this . _chatState . options . templates . textAreaAttachmentsTemplate (
290321 this . _chatState ?. inputAttachments
291322 )
292- : html `${ this . _chatState ?. inputAttachments ?. map (
293- ( attachment , index ) => html `
294- < div part ="attachment-wrapper " role ="listitem ">
295- < igc-chip
296- removable
297- @igcRemove =${ ( ) => this . removeAttachment ( index ) }
298- >
299- < span part ="attachment-name "> ${ attachment . name } </ span >
300- </ igc-chip >
301- </ div >
302- `
303- ) } `}
323+ : this . defaultAttachmentsArea }
304324 </ div > ` ;
305325 }
306326
@@ -314,17 +334,7 @@ export default class IgcChatInputComponent extends LitElement {
314334 ? this . _chatState . options . templates . textInputTemplate (
315335 this . _chatState ?. inputValue
316336 )
317- : html ` < igc-textarea
318- part ="text-input "
319- placeholder ="Type a message... "
320- resize ="auto "
321- rows ="1 "
322- .value =${ this . inputValue }
323- @input =${ this . handleInput }
324- @keydown=${ this . handleKeyDown }
325- @focus=${ this . handleFocus }
326- @blur=${ this . handleBlur }
327- > </ igc-textarea > ` }
337+ : this . defaultTextArea }
328338 </ div >
329339 ${ this . renderActionsArea ( ) }
330340 </ div >
0 commit comments