Skip to content

Commit 4db6d87

Browse files
committed
refactor(chat): use icons from internal registry
1 parent 959ab63 commit 4db6d87

File tree

9 files changed

+150
-93
lines changed

9 files changed

+150
-93
lines changed

src/components/chat/chat-input.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,12 @@ import { registerComponent } from '../common/definitions/register.js';
1414
import { partMap } from '../common/part-map.js';
1515
import { isEmpty } from '../common/util.js';
1616
import IgcIconComponent from '../icon/icon.js';
17-
import { registerIconFromText } from '../icon/icon.registry.js';
1817
import IgcTextareaComponent from '../textarea/textarea.js';
1918
import type { ChatState } from './chat-state.js';
2019
import { styles } from './themes/input.base.css.js';
2120
import { all } from './themes/input.js';
2221
import { styles as shared } from './themes/shared/input/input.common.css.js';
23-
import {
24-
attachmentIcon,
25-
type ChatTemplateRenderer,
26-
fileDocumentIcon,
27-
fileImageIcon,
28-
type IgcMessageAttachment,
29-
sendButtonIcon,
30-
starIcon,
31-
} from './types.js';
22+
import type { ChatTemplateRenderer, IgcMessageAttachment } from './types.js';
3223
import { getChatAcceptedFiles, getIconName } from './utils.js';
3324

3425
type DefaultInputRenderers = {
@@ -117,12 +108,6 @@ export default class IgcChatInputComponent extends LitElement {
117108
constructor() {
118109
super();
119110
addThemingController(this, all);
120-
121-
registerIconFromText('attachment', attachmentIcon, 'material');
122-
registerIconFromText('send-message', sendButtonIcon, 'material');
123-
registerIconFromText('file-document', fileDocumentIcon, 'material');
124-
registerIconFromText('file-image', fileImageIcon, 'material');
125-
registerIconFromText('star-icon', starIcon, 'material');
126111
}
127112

128113
protected override firstUpdated() {
@@ -239,7 +224,6 @@ export default class IgcChatInputComponent extends LitElement {
239224
<igc-icon
240225
slot="prefix"
241226
name=${getIconName(attachment.file?.type ?? attachment.type)}
242-
collection="material"
243227
></igc-icon>
244228
<span part="attachment-name">${attachment.name}</span>
245229
</igc-chip>
@@ -279,8 +263,7 @@ export default class IgcChatInputComponent extends LitElement {
279263
<label for="input_attachments" part="upload-button">
280264
<igc-icon-button
281265
variant="flat"
282-
name="attachment"
283-
collection="material"
266+
name="attach_file"
284267
@click=${() => this._attachmentsButtonInputRef?.value?.click()}
285268
></igc-icon-button>
286269
<input
@@ -305,8 +288,7 @@ export default class IgcChatInputComponent extends LitElement {
305288
return html`
306289
<igc-icon-button
307290
aria-label="Send message"
308-
name="send-message"
309-
collection="material"
291+
name="send_message"
310292
variant="contained"
311293
part="send-button"
312294
?disabled=${!this._chatState?.inputValue.trim() &&

src/components/chat/chat-message.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,15 @@ export default class IgcChatMessageComponent extends LitElement {
128128

129129
return html`
130130
<div @click=${this._handleMessageActionClick}>
131-
${this._renderActionButton('copy', resourceStrings.reactionCopy)}
132-
${this._renderActionButton('like', resourceStrings.reactionLike)}
133-
${this._renderActionButton('dislike', resourceStrings.reactionDislike)}
131+
${this._renderActionButton(
132+
'copy_content',
133+
resourceStrings.reactionCopy
134+
)}
135+
${this._renderActionButton('thumb_up', resourceStrings.reactionLike)}
136+
${this._renderActionButton(
137+
'thumb_down',
138+
resourceStrings.reactionDislike
139+
)}
134140
${this._renderActionButton(
135141
'regenerate',
136142
resourceStrings.reactionRegenerate
@@ -145,7 +151,6 @@ export default class IgcChatMessageComponent extends LitElement {
145151
id=${`${name}-button`}
146152
name=${name}
147153
variant="flat"
148-
collection="material"
149154
@pointerenter=${({ target }: PointerEvent) =>
150155
showChatActionsTooltip(target as Element, tooltipMessage)}
151156
></igc-icon-button>

src/components/chat/chat-state.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
import { createRef, type Ref } from 'lit/directives/ref.js';
22
import { enterKey } from '../common/controllers/key-bindings.js';
33
import { IgcChatResourceStringEN } from '../common/i18n/chat.resources.js';
4-
import { registerIconFromText } from '../icon/icon.registry.js';
54
import type IgcTextareaComponent from '../textarea/textarea.js';
65
import type IgcChatComponent from './chat.js';
76
import type { IgcChatComponentEventMap } from './chat.js';
8-
import {
9-
copyIcon,
10-
type IgcChatOptions,
11-
type IgcMessage,
12-
type IgcMessageAttachment,
13-
regenerateIcon,
14-
thumbDownIcon,
15-
thumbUpIcon,
7+
import type {
8+
IgcChatOptions,
9+
IgcMessage,
10+
IgcMessageAttachment,
1611
} from './types.js';
1712
import { type ChatAcceptedFileTypes, parseAcceptedFileTypes } from './utils.js';
1813

@@ -189,10 +184,6 @@ export class ChatState {
189184
*/
190185
constructor(chat: IgcChatComponent) {
191186
this._host = chat;
192-
registerIconFromText('copy', copyIcon, 'material');
193-
registerIconFromText('like', thumbUpIcon, 'material');
194-
registerIconFromText('dislike', thumbDownIcon, 'material');
195-
registerIconFromText('regenerate', regenerateIcon, 'material');
196187
}
197188

198189
//#region Event handlers

src/components/chat/chat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ export default class IgcChatComponent extends EventEmitterMixin<
373373
private _renderSuggestionPrefix() {
374374
return html`
375375
<span slot="start">
376-
<igc-icon name="star-icon" collection="material"></igc-icon>
376+
<igc-icon name="auto_suggest"></igc-icon>
377377
</span>
378378
`;
379379
}

src/components/chat/message-attachments.ts

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,14 @@ import { registerComponent } from '../common/definitions/register.js';
88
import { partMap } from '../common/part-map.js';
99
import IgcExpansionPanelComponent from '../expansion-panel/expansion-panel.js';
1010
import IgcIconComponent from '../icon/icon.js';
11-
import { registerIconFromText } from '../icon/icon.registry.js';
1211
import type { ChatState } from './chat-state.js';
1312
import { styles } from './themes/message-attachments.base.css.js';
1413
import { styles as shared } from './themes/shared/message-attachments.common.css.js';
15-
import {
16-
type ChatTemplateRenderer,
17-
closeIcon,
18-
fileIcon,
19-
type IgcChatOptions,
20-
type IgcMessage,
21-
type IgcMessageAttachment,
22-
imageIcon,
23-
moreIcon,
24-
previewIcon,
14+
import type {
15+
ChatTemplateRenderer,
16+
IgcChatOptions,
17+
IgcMessage,
18+
IgcMessageAttachment,
2519
} from './types.js';
2620
import { createAttachmentURL, getFileExtension } from './utils.js';
2721

@@ -88,12 +82,6 @@ export default class IgcMessageAttachmentsComponent extends LitElement {
8882

8983
constructor() {
9084
super();
91-
92-
registerIconFromText('close', closeIcon, 'material');
93-
registerIconFromText('file', fileIcon, 'material');
94-
registerIconFromText('image', imageIcon, 'material');
95-
registerIconFromText('preview', previewIcon, 'material');
96-
registerIconFromText('more', moreIcon, 'material');
9785
}
9886

9987
private _handleHeaderClick = (attachment: IgcMessageAttachment) => {
@@ -110,16 +98,12 @@ export default class IgcMessageAttachmentsComponent extends LitElement {
11098
this.message?.sender === this._chatState?.currentUserId;
11199
const iconName =
112100
attachment.type === 'image' || attachment.file?.type.startsWith('image/')
113-
? 'image'
114-
: 'file';
101+
? 'image_thumbnail'
102+
: 'document_thumbnail';
115103

116104
return html`
117105
${!isCurrentUser
118-
? html`<igc-icon
119-
name=${iconName}
120-
collection="material"
121-
part="attachment-icon"
122-
></igc-icon>`
106+
? html`<igc-icon name=${iconName} part="attachment-icon"></igc-icon>`
123107
: nothing}
124108
<span part="file-name">${attachment.name}</span>
125109
`;

src/components/chat/types.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -145,32 +145,3 @@ export type ChatTemplateRenderer<T> = (ctx: {
145145
defaults: Partial<ChatRenderers>;
146146
options?: IgcChatOptions;
147147
}) => unknown;
148-
149-
export const attachmentIcon =
150-
'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M720-330q0 104-73 177T470-80q-104 0-177-73t-73-177v-370q0-75 52.5-127.5T400-880q75 0 127.5 52.5T580-700v350q0 46-32 78t-78 32q-46 0-78-32t-32-78v-370h80v370q0 13 8.5 21.5T470-320q13 0 21.5-8.5T500-350v-350q-1-42-29.5-71T400-800q-42 0-71 29t-29 71v370q-1 71 49 120.5T470-160q70 0 119-49.5T640-330v-390h80v390Z"/></svg>';
151-
export const sendButtonIcon =
152-
'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M120-160v-640l760 320-760 320Zm80-120 474-200-474-200v140l240 60-240 60v140Zm0 0v-400 400Z"/></svg>';
153-
export const closeIcon =
154-
'<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>';
155-
export const fileIcon =
156-
'<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>';
157-
export const imageIcon =
158-
'<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>';
159-
export const moreIcon =
160-
'<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>';
161-
export const previewIcon =
162-
'<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>';
163-
export const fileImageIcon =
164-
'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18"><path d="M6.75 1.5L5.3775 3H3C2.175 3 1.5 3.675 1.5 4.5V13.5C1.5 14.325 2.175 15 3 15H15C15.825 15 16.5 14.325 16.5 13.5V4.5C16.5 3.675 15.825 3 15 3H12.6225L11.25 1.5H6.75ZM9 12.75C6.93 12.75 5.25 11.07 5.25 9C5.25 6.93 6.93 5.25 9 5.25C11.07 5.25 12.75 6.93 12.75 9C12.75 11.07 11.07 12.75 9 12.75Z"/></svg>';
165-
export const fileDocumentIcon =
166-
'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18"><path d="M4.5 1.5C3.675 1.5 3.0075 2.175 3.0075 3L3 15C3 15.825 3.6675 16.5 4.4925 16.5H13.5C14.325 16.5 15 15.825 15 15V6L10.5 1.5H4.5ZM9.75 6.75V2.625L13.875 6.75H9.75Z"/></svg>';
167-
export const copyIcon =
168-
'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M360-240q-33 0-56.5-23.5T280-320v-480q0-33 23.5-56.5T360-880h360q33 0 56.5 23.5T800-800v480q0 33-23.5 56.5T720-240H360Zm0-80h360v-480H360v480ZM200-80q-33 0-56.5-23.5T120-160v-560h80v560h440v80H200Zm160-240v-480 480Z"/></svg>';
169-
export const thumbUpIcon =
170-
'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M720-120H280v-520l280-280 50 50q7 7 11.5 19t4.5 23v14l-44 174h258q32 0 56 24t24 56v80q0 7-2 15t-4 15L794-168q-9 20-30 34t-44 14Zm-360-80h360l120-280v-80H480l54-220-174 174v406Zm0-406v406-406Zm-80-34v80H160v360h120v80H80v-520h200Z"/></svg>';
171-
export const thumbDownIcon =
172-
'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M240-840h440v520L400-40l-50-50q-7-7-11.5-19t-4.5-23v-14l44-174H120q-32 0-56-24t-24-56v-80q0-7 2-15t4-15l120-282q9-20 30-34t44-14Zm360 80H240L120-480v80h360l-54 220 174-174v-406Zm0 406v-406 406Zm80 34v-80h120v-360H680v-80h200v520H680Z"/></svg>';
173-
export const regenerateIcon =
174-
'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M480-160q-134 0-227-93t-93-227q0-134 93-227t227-93q69 0 132 28.5T720-690v-110h80v280H520v-80h168q-32-56-87.5-88T480-720q-100 0-170 70t-70 170q0 100 70 170t170 70q77 0 139-44t87-116h84q-28 106-114 173t-196 67Z"/></svg>';
175-
export const starIcon =
176-
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="25" viewBox="0 0 24 25"><path d="M6.58624 4.76825C6.72103 4.41058 7.23629 4.41058 7.37112 4.76825L7.92907 6.24921C7.94973 6.30414 7.98177 6.35321 8.02248 6.39423C8.06524 6.43719 8.11758 6.47089 8.17626 6.49213L9.6841 7.04022C10.0484 7.17255 10.0484 7.67865 9.6841 7.81097L8.17626 8.35907C8.10738 8.38422 8.04729 8.42621 8.00109 8.48016C7.97045 8.51605 7.94595 8.55707 7.92907 8.60199L7.37112 10.0829C7.23629 10.4409 6.72103 10.4409 6.58624 10.0829L6.02828 8.60199C5.98589 8.48944 5.89559 8.40082 5.78106 8.35907L4.27322 7.81097C3.90893 7.67865 3.90893 7.17255 4.27322 7.04022L5.78106 6.49213C5.89559 6.45062 5.98589 6.36176 6.02828 6.24921L6.58624 4.76825Z" /><path d="M12.2095 8.05023C12.481 7.31659 13.519 7.31659 13.7905 8.05023L14.9144 11.0876C14.9997 11.3183 15.1816 11.5002 15.4123 11.5856L18.4496 12.7094C19.1835 12.9809 19.1835 14.019 18.4496 14.2905L15.4123 15.4142C15.1816 15.4997 14.9997 15.6816 14.9144 15.9123L13.7905 18.9496C13.519 19.6833 12.481 19.6833 12.2095 18.9496L11.0856 15.9123C11.0002 15.6816 10.8183 15.4997 10.5876 15.4142L7.55038 14.2905C6.81652 14.019 6.81652 12.9809 7.55038 12.7094L10.5876 11.5856C10.8183 11.5002 11.0002 11.3183 11.0856 11.0876L12.2095 8.05023Z" /><path d="M6.63354 16.7551C6.75942 16.415 7.24056 16.415 7.36645 16.7551L7.67638 17.5927C7.71597 17.6996 7.80029 17.7839 7.90725 17.8234L8.74487 18.1335C9.08504 18.2595 9.08504 18.7404 8.74487 18.8664L7.90725 19.1765C7.85857 19.1945 7.8146 19.2216 7.7774 19.256C7.73281 19.2973 7.69796 19.3488 7.67638 19.4072L7.36645 20.2448C7.24056 20.5849 6.75942 20.5849 6.63354 20.2448L6.3236 19.4072C6.3055 19.3583 6.27807 19.3141 6.2434 19.2768C6.2022 19.2326 6.15081 19.1979 6.09274 19.1765L5.25512 18.8664C4.91494 18.7404 4.91494 18.2595 5.25512 18.1335L6.09274 17.8234C6.1997 17.7839 6.28402 17.6996 6.3236 17.5927L6.63354 16.7551Z" /><path d="M18.3664 5.75507C18.2406 5.41498 17.7594 5.41498 17.6335 5.75507L17.3236 6.59271C17.284 6.69965 17.1997 6.78387 17.0928 6.82343L16.2551 7.13348C15.915 7.25946 15.915 7.74042 16.2551 7.86639L17.0928 8.17645C17.1997 8.216 17.284 8.30023 17.3236 8.40717L17.6335 9.24481C17.7594 9.5849 18.2406 9.5849 18.3664 9.24481L18.6764 8.40717C18.716 8.30023 18.8003 8.216 18.9072 8.17645L19.7449 7.86639C20.085 7.74042 20.085 7.25946 19.7449 7.13348L18.9072 6.82343C18.8003 6.78387 18.716 6.69965 18.6764 6.59271L18.3664 5.75507Z" /></svg>';

src/components/chat/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function getChatAcceptedFiles(
5757
}
5858

5959
export function getIconName(fileType?: string) {
60-
return fileType?.startsWith('image') ? 'file-image' : 'file-document';
60+
return fileType?.startsWith('image') ? 'attach_image' : 'attach_document';
6161
}
6262

6363
export function createAttachmentURL(attachment: IgcMessageAttachment): string {

src/components/icon/icon-references.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,88 @@ addIcon('expand', {
6363
collection: 'internal',
6464
},
6565
});
66+
addIcon('attach_file', {
67+
default: {
68+
name: 'attach_file',
69+
collection: 'internal',
70+
},
71+
indigo: {
72+
name: 'indigo_attach_file',
73+
collection: 'internal',
74+
},
75+
});
76+
addIcon('attach_document', {
77+
default: {
78+
name: 'document_filled',
79+
collection: 'internal',
80+
},
81+
});
82+
addIcon('attach_image', {
83+
default: {
84+
name: 'document_image',
85+
collection: 'internal',
86+
},
87+
});
88+
addIcon('auto_suggest', {
89+
default: {
90+
name: 'auto_suggest',
91+
collection: 'internal',
92+
},
93+
});
94+
addIcon('send_message', {
95+
default: {
96+
name: 'send',
97+
collection: 'internal',
98+
},
99+
});
100+
addIcon('image_thumbnail', {
101+
default: {
102+
name: 'image',
103+
collection: 'internal',
104+
},
105+
});
106+
addIcon('document_thumbnail', {
107+
default: {
108+
name: 'document_empty',
109+
collection: 'internal',
110+
},
111+
});
112+
addIcon('more_horiz', {
113+
default: {
114+
name: 'more_horiz',
115+
collection: 'internal',
116+
},
117+
});
118+
addIcon('open_in_new', {
119+
default: {
120+
name: 'open_in_new',
121+
collection: 'internal',
122+
},
123+
});
124+
addIcon('thumb_up', {
125+
default: {
126+
name: 'thumb_up',
127+
collection: 'internal',
128+
},
129+
});
130+
addIcon('thumb_down', {
131+
default: {
132+
name: 'thumb_down',
133+
collection: 'internal',
134+
},
135+
});
136+
addIcon('regenerate', {
137+
default: {
138+
name: 'reload',
139+
collection: 'internal',
140+
},
141+
});
142+
addIcon('copy_content', {
143+
default: {
144+
name: 'copy',
145+
collection: 'internal',
146+
},
147+
});
66148
addIcon('collapse', {
67149
default: {
68150
name: 'keyboard_arrow_up',

0 commit comments

Comments
 (0)