@@ -27,12 +27,10 @@ import {
2727 *
2828 * @element igc-message-attachments
2929 *
30- * @slot attachment-icon - Slot to override the attachment icon (image or file).
31- * @slot attachment-name - Slot to override the displayed attachment name.
32- * @slot attachment-content - Slot to override the content shown inside the attachment panel.
33- *
3430 * @csspart attachments-container - Container wrapping all attachments.
35- * @csspart attachment - Wrapper for a single attachment header.
31+ * @csspart attachment - Wrapper for a single attachment.
32+ * @csspart attachment-header - Wrapper for a single attachment header.
33+ * @csspart attachments-content - Part representing the attachment preview.
3634 * @csspart attachment-icon - Icon part representing the attachment type.
3735 * @csspart file-name - Part representing the attachment's file name.
3836 * @csspart actions - Container for header action buttons.
@@ -79,9 +77,8 @@ export default class IgcMessageAttachmentsComponent extends LitElement {
7977 registerIconFromText ( 'more' , moreIcon , 'material' ) ;
8078 }
8179
82- private handleToggle ( e : CustomEvent , attachment : IgcMessageAttachment ) {
80+ private handleHeaderClick ( attachment : IgcMessageAttachment ) {
8381 this . _chatState ?. emitEvent ( 'igcAttachmentClick' , { detail : attachment } ) ;
84- e . preventDefault ( ) ;
8582 }
8683
8784 private getURL ( attachment : IgcMessageAttachment ) : string {
@@ -94,31 +91,36 @@ export default class IgcMessageAttachmentsComponent extends LitElement {
9491 return '' ;
9592 }
9693
94+ private defaulAttachmentContent ( attachment : IgcMessageAttachment ) {
95+ return html `${ attachment . type === 'image' ||
96+ attachment . file ?. type . startsWith ( 'image/' )
97+ ? html `< img
98+ part ="image-attachment "
99+ src =${ this . getURL ( attachment ) }
100+ alt =${ attachment . name }
101+ /> `
102+ : nothing } `;
103+ }
104+
97105 private renderAttachmentHeaderText ( attachment : IgcMessageAttachment ) {
98106 return html `< div part ="details ">
99107 ${ this . _chatState ?. options ?. templates ?. attachmentHeaderTemplate
100108 ? this . _chatState . options . templates . attachmentHeaderTemplate (
101109 this . attachments
102110 )
103- : html `
104- < slot name ="attachment-icon ">
105- ${ attachment . type === 'image' ||
106- attachment . file ?. type . startsWith ( 'image/' )
107- ? html `< igc-icon
108- name ="image "
109- collection ="material "
110- part ="attachment-icon "
111- > </ igc-icon > `
112- : html `< igc-icon
113- name ="file "
114- collection ="material "
115- part ="attachment-icon "
116- > </ igc-icon > ` }
117- </ slot >
118- < slot name ="attachment-name ">
119- < span part ="file-name "> ${ attachment . name } </ span >
120- </ slot >
121- ` }
111+ : html `${ attachment . type === 'image' ||
112+ attachment . file ?. type . startsWith ( 'image/' )
113+ ? html `< igc-icon
114+ name ="image "
115+ collection ="material "
116+ part ="attachment-icon "
117+ > </ igc-icon > `
118+ : html `< igc-icon
119+ name ="file "
120+ collection ="material "
121+ part ="attachment-icon "
122+ > </ igc-icon > ` }
123+ < span part ="file-name "> ${ attachment . name } </ span > ` }
122124 </ div > ` ;
123125 }
124126
@@ -133,43 +135,34 @@ export default class IgcMessageAttachmentsComponent extends LitElement {
133135 }
134136
135137 private renderAttachmentContent ( attachment : IgcMessageAttachment ) {
136- return html ` ${ this . _chatState ?. options ?. templates
137- ?. attachmentContentTemplate
138- ? this . _chatState . options . templates . attachmentContentTemplate (
139- this . attachments
140- )
141- : html `
142- < slot name ="attachment-content ">
143- ${ attachment . type === 'image' ||
144- attachment . file ?. type . startsWith ( 'image/' )
145- ? html ` < img
146- part ="image-attachment "
147- src =${ this . getURL ( attachment ) }
148- alt =${ attachment . name }
149- /> `
150- : nothing }
151- </ slot >
152- ` } `;
138+ return html `< div part ="attachment-content ">
139+ ${ this . _chatState ?. options ?. templates ?. attachmentContentTemplate
140+ ? this . _chatState . options . templates . attachmentContentTemplate (
141+ this . attachments
142+ )
143+ : this . defaulAttachmentContent ( attachment ) }
144+ </ div > ` ;
153145 }
154146
155147 private renderDefaultAttachmentsTemplate ( ) {
156148 return html `${ this . attachments . map (
157149 ( attachment ) =>
158- html `< igc-expansion-panel
159- indicator-position ="none "
160- .open =${ attachment . type === 'image' ||
161- attachment . file ?. type . startsWith ( 'image/' ) ||
162- this . _chatState ?. options ?. templates ?. attachmentContentTemplate }
163- @igcClosing =${ ( ev : CustomEvent ) => this . handleToggle ( ev , attachment ) }
164- @igcOpening=${ ( ev : CustomEvent ) => this . handleToggle ( ev , attachment ) }
165- >
166- < div slot ="title " part ="attachment ">
150+ html `< div part ="attachment ">
151+ < div
152+ part ="attachment-header "
153+ role ="button "
154+ @click =${ ( ) => this . handleHeaderClick ( attachment ) }
155+ >
167156 ${ this . renderAttachmentHeaderText ( attachment ) }
168157 ${ this . renderAttachmentHeaderActions ( ) }
169158 </ div >
170159
171- ${ this . renderAttachmentContent ( attachment ) }
172- </ igc-expansion-panel > `
160+ ${ attachment . type === 'image' ||
161+ attachment . file ?. type . startsWith ( 'image/' ) ||
162+ this . _chatState ?. options ?. templates ?. attachmentContentTemplate
163+ ? this . renderAttachmentContent ( attachment )
164+ : nothing }
165+ </ div > `
173166 ) } `;
174167 }
175168
0 commit comments