@@ -7,6 +7,7 @@ import IgcIconComponent from '../icon/icon.js';
77import { registerIconFromText } from '../icon/icon.registry.js' ;
88import { styles } from './themes/message-attachments.base.css' ;
99import {
10+ type AttachmentTemplate ,
1011 type IgcMessageAttachment ,
1112 closeIcon ,
1213 fileIcon ,
@@ -41,6 +42,18 @@ export class IgcMessageAttachmentsComponent extends LitElement {
4142 @property ( { type : String } )
4243 previewImage = '' ;
4344
45+ @property ( { type : Function } )
46+ attachmentTemplate : AttachmentTemplate | undefined ;
47+
48+ @property ( { type : Function } )
49+ attachmentHeaderTemplate : AttachmentTemplate | undefined ;
50+
51+ @property ( { type : Function } )
52+ attachmentActionsTemplate : AttachmentTemplate | undefined ;
53+
54+ @property ( { type : Function } )
55+ attachmentContentTemplate : AttachmentTemplate | undefined ;
56+
4457 constructor ( ) {
4558 super ( ) ;
4659 registerIconFromText ( 'close' , closeIcon , 'material' ) ;
@@ -50,12 +63,6 @@ export class IgcMessageAttachmentsComponent extends LitElement {
5063 registerIconFromText ( 'more' , moreIcon , 'material' ) ;
5164 }
5265
53- private formatFileSize ( bytes = 0 ) : string {
54- if ( bytes < 1024 ) return `${ bytes } B` ;
55- if ( bytes < 1024 * 1024 ) return `${ ( bytes / 1024 ) . toFixed ( 1 ) } KB` ;
56- return `${ ( bytes / ( 1024 * 1024 ) ) . toFixed ( 1 ) } MB` ;
57- }
58-
5966 private openImagePreview ( url : string ) {
6067 this . previewImage = url ;
6168 }
@@ -82,60 +89,82 @@ export class IgcMessageAttachmentsComponent extends LitElement {
8289 protected override render ( ) {
8390 return html `
8491 < div class ="attachments-container ">
85- ${ this . attachments . map (
86- ( attachment ) => html `
87- < igc-expansion-panel
88- indicator-position ="none "
89- .open =${ attachment . type === 'image' }
90- @igcClosing =${ ( ev : CustomEvent ) =>
91- this . handleToggle ( ev , attachment ) }
92- @igcOpening=${ ( ev : CustomEvent ) =>
93- this . handleToggle ( ev , attachment ) }
94- >
95- < div slot ="title " class ="attachment ">
96- < div class ="details ">
97- ${ attachment . type === 'image'
98- ? html `< igc-icon
99- name ="image "
100- collection ="material "
101- class ="medium "
102- > </ igc-icon > `
103- : html `< igc-icon
104- name ="file "
105- collection ="material "
106- class ="medium "
107- > </ igc-icon > ` }
108- < span class ="file-name "> ${ attachment . name } </ span >
109- </ div >
110- < div class ="actions ">
111- ${ attachment . type === 'image'
112- ? html ` < igc-icon-button
113- name ="preview "
114- collection ="material "
115- variant ="flat "
116- class ="small "
117- @click =${ ( ) => this . openImagePreview ( attachment . url ) }
118- > </ igc-icon-button > `
119- : '' }
120- < igc-icon-button
121- name ="more "
122- collection ="material "
123- variant ="flat "
124- class ="small "
125- > </ igc-icon-button >
126- </ div >
127- </ div >
128-
129- ${ attachment . type === 'image'
130- ? html ` < img
131- class ="image-attachment "
132- src =${ attachment . url }
133- alt =${ attachment . name }
134- /> `
135- : '' }
136- </ igc-expansion-panel >
137- `
138- ) }
92+ ${ this . attachmentTemplate
93+ ? this . attachmentTemplate ( this . attachments )
94+ : html ` ${ this . attachments . map (
95+ ( attachment ) =>
96+ html ` < igc-expansion-panel
97+ indicator-position ="none "
98+ .open =${ attachment . type === 'image' }
99+ @igcClosing =${ ( ev : CustomEvent ) =>
100+ this . handleToggle ( ev , attachment ) }
101+ @igcOpening=${ ( ev : CustomEvent ) =>
102+ this . handleToggle ( ev , attachment ) }
103+ >
104+ < div slot ="title " class ="attachment ">
105+ < div class ="details ">
106+ ${ this . attachmentHeaderTemplate
107+ ? this . attachmentHeaderTemplate ( this . attachments )
108+ : html `
109+ < slot name ="attachment-icon ">
110+ ${ attachment . type === 'image'
111+ ? html `< igc-icon
112+ name ="image "
113+ collection ="material "
114+ class ="medium "
115+ > </ igc-icon > `
116+ : html `< igc-icon
117+ name ="file "
118+ collection ="material "
119+ class ="medium "
120+ > </ igc-icon > ` }
121+ </ slot >
122+ < slot name ="attachment-name ">
123+ < span class ="file-name "> ${ attachment . name } </ span >
124+ </ slot >
125+ ` }
126+ </ div >
127+ < div class ="actions ">
128+ ${ this . attachmentActionsTemplate
129+ ? this . attachmentActionsTemplate ( this . attachments )
130+ : html `
131+ < slot name ="attachment-actions ">
132+ ${ attachment . type === 'image'
133+ ? html ` < igc-icon-button
134+ name ="preview "
135+ collection ="material "
136+ variant ="flat "
137+ class ="small "
138+ @click =${ ( ) =>
139+ this . openImagePreview ( attachment . url ) }
140+ > </ igc-icon-button > `
141+ : '' }
142+ < igc-icon-button
143+ name ="more "
144+ collection ="material "
145+ variant ="flat "
146+ class ="small "
147+ > </ igc-icon-button >
148+ </ slot >
149+ ` }
150+ </ div >
151+ </ div >
152+
153+ ${ this . attachmentContentTemplate
154+ ? this . attachmentContentTemplate ( this . attachments )
155+ : html `
156+ < slot name ="attachment-content ">
157+ ${ attachment . type === 'image'
158+ ? html ` < img
159+ class ="image-attachment "
160+ src =${ attachment . url }
161+ alt =${ attachment . name }
162+ /> `
163+ : '' }
164+ </ slot >
165+ ` }
166+ </ igc-expansion-panel > `
167+ ) } `}
139168 </ div >
140169
141170 ${ this . previewImage
0 commit comments