11import { ContextProvider } from '@lit/context' ;
22import { html , LitElement } from 'lit' ;
3- import { property } from 'lit/decorators.js' ;
3+ import { property , state } from 'lit/decorators.js' ;
44import IgcButtonComponent from '../button/button.js' ;
55import { chatContext } from '../common/context.js' ;
66import { watch } from '../common/decorators/watch.js' ;
@@ -20,9 +20,11 @@ export interface IgcChatComponentEventMap {
2020 igcMessageCreated : CustomEvent < IgcMessage > ;
2121 igcAttachmentClick : CustomEvent < IgcMessageAttachment > ;
2222 igcAttachmentChange : CustomEvent < IgcMessageAttachment > ;
23+ igcAttachmentDrag : CustomEvent < any > ;
24+ igcAttachmentDrop : CustomEvent < any > ;
2325 igcTypingChange : CustomEvent < boolean > ;
24- igcInputFocus : CustomEvent < void > ;
25- igcInputBlur : CustomEvent < void > ;
26+ igcInputFocus : CustomEvent < any > ;
27+ igcInputBlur : CustomEvent < any > ;
2628 igcInputChange : CustomEvent < string > ;
2729 igcMessageCopied : CustomEvent < IgcMessage > ;
2830}
@@ -55,6 +57,10 @@ export default class IgcChatComponent extends EventEmitterMixin<
5557 context : chatContext ,
5658 initialValue : this ,
5759 } ) ;
60+
61+ @state ( )
62+ private inputAttachments : IgcMessageAttachment [ ] = [ ] ;
63+
5864 @property ( { type : String , reflect : true , attribute : 'current-user-id' } )
5965 public currentUserId = 'user' ;
6066
@@ -101,6 +107,16 @@ export default class IgcChatComponent extends EventEmitterMixin<
101107 this . emitEvent ( 'igcAttachmentClick' , { detail : attachmentArgs } ) ;
102108 }
103109
110+ private handleAttachmentChange ( e : CustomEvent ) {
111+ const allowed = this . emitEvent ( 'igcAttachmentChange' , {
112+ detail : e . detail ,
113+ cancelable : true ,
114+ } ) ;
115+ if ( allowed ) {
116+ this . inputAttachments = [ ...e . detail ] ;
117+ }
118+ }
119+
104120 private addMessage ( message : {
105121 id ?: string ;
106122 text : string ;
@@ -122,6 +138,7 @@ export default class IgcChatComponent extends EventEmitterMixin<
122138
123139 if ( allowed ) {
124140 this . messages = [ ...this . messages , newMessage ] ;
141+ this . inputAttachments = [ ] ;
125142 }
126143 }
127144
@@ -158,16 +175,17 @@ export default class IgcChatComponent extends EventEmitterMixin<
158175 </ slot >
159176 </ div >
160177 < igc-chat-input
178+ .attachments =${ this . inputAttachments }
161179 @message-created =${ this . handleSendMessage }
162180 @typing-change=${ ( e : CustomEvent ) => {
163181 this . emitEvent ( 'igcTypingChange' , { detail : e . detail } ) ;
164182 } }
165183 @input-change=${ ( e : CustomEvent ) => {
166184 this . emitEvent ( 'igcInputChange' , { detail : e . detail } ) ;
167185 } }
168- @attachment-change=${ ( e : CustomEvent ) => {
169- this . emitEvent ( 'igcAttachmentChange' , { detail : e . detail } ) ;
170- } }
186+ @attachment-change=${ this . handleAttachmentChange }
187+ @drop-attachment= ${ ( ) => this . emitEvent ( 'igcAttachmentDrop' ) }
188+ @drag-attachment= ${ ( ) => this . emitEvent ( 'igcAttachmentDrag' ) }
171189 @focus-input=${ ( ) => {
172190 this . emitEvent ( 'igcInputFocus' ) ;
173191 } }
0 commit comments