Skip to content

Commit 6c27d41

Browse files
committed
feat(chat): display attachments in expansion panel
1 parent c5f00c5 commit 6c27d41

3 files changed

Lines changed: 82 additions & 31 deletions

File tree

src/components/chat/message-attachments.ts

Lines changed: 66 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@ import { LitElement, html } from 'lit';
22
import { property } from 'lit/decorators.js';
33
import IgcIconButtonComponent from '../button/icon-button.js';
44
import { registerComponent } from '../common/definitions/register.js';
5+
import IgcExpansionPanelComponent from '../expansion-panel/expansion-panel.js';
56
import IgcIconComponent from '../icon/icon.js';
67
import { registerIconFromText } from '../icon/icon.registry.js';
78
import { styles } from './themes/message-attachments.base.css';
8-
import { type IgcMessageAttachment, closeIcon, fileIcon } from './types.js';
9+
import {
10+
type IgcMessageAttachment,
11+
closeIcon,
12+
fileIcon,
13+
imageIcon,
14+
moreIcon,
15+
previewIcon,
16+
} from './types.js';
917

1018
/**
1119
*
@@ -23,7 +31,8 @@ export class IgcMessageAttachmentsComponent extends LitElement {
2331
registerComponent(
2432
IgcMessageAttachmentsComponent,
2533
IgcIconComponent,
26-
IgcIconButtonComponent
34+
IgcIconButtonComponent,
35+
IgcExpansionPanelComponent
2736
);
2837
}
2938
@property({ type: Array })
@@ -36,6 +45,9 @@ export class IgcMessageAttachmentsComponent extends LitElement {
3645
super();
3746
registerIconFromText('close', closeIcon, 'material');
3847
registerIconFromText('file', fileIcon, 'material');
48+
registerIconFromText('image', imageIcon, 'material');
49+
registerIconFromText('preview', previewIcon, 'material');
50+
registerIconFromText('more', moreIcon, 'material');
3951
}
4052

4153
private formatFileSize(bytes = 0): string {
@@ -52,41 +64,64 @@ export class IgcMessageAttachmentsComponent extends LitElement {
5264
this.previewImage = '';
5365
}
5466

67+
private preventToggle(e: CustomEvent) {
68+
e.preventDefault();
69+
}
70+
5571
protected override render() {
5672
return html`
5773
<div class="attachments-container">
58-
${this.attachments.map((attachment) =>
59-
attachment.type === 'image'
60-
? html`
61-
<div class="attachment-preview">
62-
<img
74+
${this.attachments.map(
75+
(attachment) => html`
76+
<igc-expansion-panel
77+
indicator-position="none"
78+
.open=${attachment.type === 'image'}
79+
@igcClosing=${this.preventToggle}
80+
@igcOpening=${this.preventToggle}
81+
>
82+
<div slot="title" class="attachment">
83+
<div class="details">
84+
${attachment.type === 'image'
85+
? html`<igc-icon
86+
name="image"
87+
collection="material"
88+
class="medium"
89+
></igc-icon>`
90+
: html`<igc-icon
91+
name="file"
92+
collection="material"
93+
class="medium"
94+
></igc-icon>`}
95+
<span class="file-name">${attachment.name}</span>
96+
</div>
97+
<div class="actions">
98+
${attachment.type === 'image'
99+
? html` <igc-icon-button
100+
name="preview"
101+
collection="material"
102+
variant="flat"
103+
class="small"
104+
@click=${() => this.openImagePreview(attachment.url)}
105+
></igc-icon-button>`
106+
: ''}
107+
<igc-icon-button
108+
name="more"
109+
collection="material"
110+
variant="flat"
111+
class="small"
112+
></igc-icon-button>
113+
</div>
114+
</div>
115+
116+
${attachment.type === 'image'
117+
? html` <img
63118
class="image-attachment"
64119
src=${attachment.url}
65120
alt=${attachment.name}
66-
@click=${() => this.openImagePreview(attachment.url)}
67-
/>
68-
</div>
69-
`
70-
: html`
71-
<a
72-
class="file-attachment"
73-
href=${attachment.url}
74-
target="_blank"
75-
download=${attachment.name}
76-
>
77-
<igc-icon
78-
name="file"
79-
collection="material"
80-
class="large"
81-
></igc-icon>
82-
<div class="file-info">
83-
<div class="file-name">${attachment.name}</div>
84-
<div class="file-size">
85-
${this.formatFileSize(attachment.size)}
86-
</div>
87-
</div>
88-
</a>
89-
`
121+
/>`
122+
: ''}
123+
</igc-expansion-panel>
124+
`
90125
)}
91126
</div>
92127

src/components/chat/themes/message-attachments.base.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,14 @@
9696

9797
.large {
9898
--ig-size: var(--ig-size-large);
99+
}
100+
101+
.actions {
102+
display: flex;
103+
}
104+
105+
.attachment {
106+
display: flex;
107+
justify-content: space-between;
108+
gap: 2rem;
99109
}

src/components/chat/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,9 @@ export const closeIcon =
4444
'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="m256-200-56-56 224-224-224-224 56-56 224 224 224-224 56 56-224 224 224 224-56 56-224-224-224 224Z"/></svg>';
4545
export const fileIcon =
4646
'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M240-80q-33 0-56.5-23.5T160-160v-640q0-33 23.5-56.5T240-880h320l240 240v480q0 33-23.5 56.5T720-80H240Zm280-520v-200H240v640h480v-440H520ZM240-800v200-200 640-640Z"/></svg>';
47+
export const imageIcon =
48+
'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Zm40-80h480L570-480 450-320l-90-120-120 160Zm-40 80v-560 560Z"/></svg>';
49+
export const moreIcon =
50+
'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M240-400q-33 0-56.5-23.5T160-480q0-33 23.5-56.5T240-560q33 0 56.5 23.5T320-480q0 33-23.5 56.5T240-400Zm240 0q-33 0-56.5-23.5T400-480q0-33 23.5-56.5T480-560q33 0 56.5 23.5T560-480q0 33-23.5 56.5T480-400Zm240 0q-33 0-56.5-23.5T640-480q0-33 23.5-56.5T720-560q33 0 56.5 23.5T800-480q0 33-23.5 56.5T720-400Z"/></svg>';
51+
export const previewIcon =
52+
'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h280v80H200v560h560v-280h80v280q0 33-23.5 56.5T760-120H200Zm188-212-56-56 372-372H560v-80h280v280h-80v-144L388-332Z"/></svg>';

0 commit comments

Comments
 (0)