11import type { Meta , StoryObj } from '@storybook/web-components-vite' ;
22import { html } from 'lit' ;
33
4- import { IgcChatComponent , defineComponents } from 'igniteui-webcomponents' ;
5- import type { IgcMessageAttachment } from '../src/components/chat/types.js' ;
4+ import {
5+ IgcChatComponent ,
6+ defineComponents ,
7+ registerIconFromText ,
8+ } from 'igniteui-webcomponents' ;
9+ import type {
10+ AttachmentTemplate ,
11+ IgcMessageAttachment ,
12+ MessageActionsTemplate ,
13+ } from '../src/components/chat/types.js' ;
614
715defineComponents ( IgcChatComponent ) ;
816
@@ -53,6 +61,10 @@ const metadata: Meta<IgcChatComponent> = {
5361 type : 'AttachmentTemplate' ,
5462 control : 'AttachmentTemplate' ,
5563 } ,
64+ messageActionsTemplate : {
65+ type : 'MessageActionsTemplate' ,
66+ control : 'MessageActionsTemplate' ,
67+ } ,
5668 } ,
5769 args : {
5870 hideAvatar : false ,
@@ -75,11 +87,23 @@ interface IgcChatArgs {
7587 attachmentHeaderTemplate : AttachmentTemplate ;
7688 attachmentActionsTemplate : AttachmentTemplate ;
7789 attachmentContentTemplate : AttachmentTemplate ;
90+ messageActionsTemplate : MessageActionsTemplate ;
7891}
7992type Story = StoryObj < IgcChatArgs > ;
8093
8194// endregion
8295
96+ const thumbUpIcon =
97+ '<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>' ;
98+ const thumbDownIcon =
99+ '<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>' ;
100+ const regenerateIcon =
101+ '<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>' ;
102+
103+ registerIconFromText ( 'thumb_up' , thumbUpIcon , 'material' ) ;
104+ registerIconFromText ( 'thumb_down' , thumbDownIcon , 'material' ) ;
105+ registerIconFromText ( 'regenerate' , regenerateIcon , 'material' ) ;
106+
83107let messages : any [ ] = [
84108 {
85109 id : '1' ,
@@ -89,6 +113,8 @@ let messages: any[] = [
89113 } ,
90114] ;
91115
116+ let isResponseSent = false ;
117+
92118function handleMessageSend ( e : CustomEvent ) {
93119 const newMessage = e . detail ;
94120 messages . push ( newMessage ) ;
@@ -121,10 +147,12 @@ function handleMessageSend(e: CustomEvent) {
121147 } ;
122148 chat . messages = [ ...messages , emptyResponse ] ;
123149
150+ isResponseSent = false ;
124151 setTimeout ( ( ) => {
125152 const responseParts = generateAIResponse ( e . detail . text ) . split ( ' ' ) ;
126153 showResponse ( chat , responseParts ) . then ( ( ) => {
127154 messages = chat . messages ;
155+ isResponseSent = true ;
128156 // TODO: add attachments (if any) to the response message
129157 } ) ;
130158 } , 1000 ) ;
@@ -196,6 +224,34 @@ export const Basic: Story = {
196224 .hideAvatar=${ args . hideAvatar }
197225 .hideUserName=${ args . hideUserName }
198226 @igcMessageSend=${ handleMessageSend }
227+ .messageActionsTemplate=${ ( msg ) =>
228+ msg . isResponse && msg . text . trim ( )
229+ ? isResponseSent
230+ ? html `
231+ < div >
232+ < igc-icon-button
233+ name ="thumb_up "
234+ collection ="material "
235+ variant ="flat "
236+ @click =${ ( ) => alert ( `Liked·message:·${ msg . text } ` ) }
237+ > </ igc-icon-button >
238+ < igc-icon-button
239+ name ="thumb_down "
240+ variant ="flat "
241+ collection ="material "
242+ @click =${ ( ) => alert ( `Disliked·message:·${ msg . text } ` ) }
243+ > </ igc-icon-button >
244+ < igc-icon-button
245+ name ="regenerate "
246+ variant ="flat "
247+ collection ="material "
248+ @click =${ ( ) =>
249+ alert ( `Response·should·be·re-generated:·${ msg . text } ` ) }
250+ > </ igc-icon-button >
251+ </ div >
252+ `
253+ : ''
254+ : '' }
199255 >
200256 </ igc-chat>
201257 ` ,
0 commit comments