-
Notifications
You must be signed in to change notification settings - Fork 7
feat(chat): add chat component #1688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 18 commits
Commits
Show all changes
329 commits
Select commit
Hold shift + click to select a range
c92a8f3
Merge branch 'master' of https://github.com/IgniteUI/igniteui-webcomp…
teodosiah c3f5e30
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
gedinakova dd3fed1
refactor(chat): move common logic into chat state class
teodosiah 78b4e4d
feat(chat): expose message template
teodosiah e4c9314
fix(chat): export correct type in index.ts
teodosiah 72ca424
Merge branch 'master' into dmdimitrov/chat-ai-component
teodosiah 5259098
feat(chat): add DOMPurify sanitizer
igdmdimitrov adf894e
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
igdmdimitrov 0079d34
feat(chat): add support for custom markdown renderer
igdmdimitrov 7df3050
feat(chat): expose draftMessage prop & input area templates
teodosiah 7976d72
Merge branch 'master' of https://github.com/IgniteUI/igniteui-webcomp…
teodosiah bcb49c3
Merge branch 'master' of https://github.com/IgniteUI/igniteui-webcomp…
teodosiah a381855
feat(chat): add initial KB nav between messages
teodosiah 6e5f0f1
feat(chat): expand input textarea on long input
igdmdimitrov 05df856
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
igdmdimitrov d325646
chore(*): update input wrapper prop in tests
igdmdimitrov 39d443d
test(chat): add input focus & KB arrow up/down tests
teodosiah 99320a4
feat(chat): add aria attributes to the chat elements
teodosiah fe31e84
feat(chat): add slot for empty message list area
teodosiah b9ecb52
Merge branch 'master' of https://github.com/IgniteUI/igniteui-webcomp…
teodosiah 3c6c454
test(chat): fix tests after exposing empty message list slot
teodosiah 1d6d140
chore(chat): remove default attachment action buttons & fix duplicate…
teodosiah e57787e
test(chat): fix attachment header actions test
teodosiah b335c29
Merge branch 'master' of https://github.com/IgniteUI/igniteui-webcomp…
teodosiah 6839f7d
feat(chat): add home/end KB nav & additional tests
teodosiah 212711b
refactor(chat): change action button and attachments places in the in…
teodosiah 4ddd539
Merge branch 'master' into dmdimitrov/chat-ai-component
teodosiah da400be
Merge branch 'master' into dmdimitrov/chat-ai-component
teodosiah 8a03d6e
feat(chat): initial styling
SisIvanova 4a296aa
chore(*): JSDoc for all types in types.ts
gedinakova 4032567
fix(chat): failing tests
SisIvanova 6735e65
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
gedinakova e614203
chore(*): JSDoc for chat components
gedinakova 5a50f60
refactor(chat): use key binding controller instead of handling keydow…
teodosiah 701e9ea
fix(chat): fix merge issues
teodosiah e92820c
feat(chat): expose suggestions header slot
teodosiah fbfa82e
chore(*): Adding JSDoc to igc-chat-input
gedinakova 598a378
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
gedinakova f160851
feat(chat): expose getters for the default input area elements
teodosiah f688b53
refactor(chat): remove containers when they are empty
teodosiah b3d7800
feat(chat): expose inputPlaceholder option
teodosiah 618943d
Merge branch 'master' into dmdimitrov/chat-ai-component
teodosiah 0d78411
refactor(chat): fix using classes in tests, add undefined checks
teodosiah 4b9355a
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
teodosiah 45ccac3
refactor(chat): apply dragging part
teodosiah 9a65e96
Merge branch 'master' of https://github.com/IgniteUI/igniteui-webcomp…
teodosiah dec1240
fix(chat): fix file drag&drop
teodosiah dcda60f
chore(chat): component styling
SisIvanova aa8d71e
fix(chat): lint errors
SisIvanova 87a52f4
fix(chat): fix calculating active message index
teodosiah b80c175
chore(chat): add story with templates
teodosiah 0ca9772
refactor(chat): header should be displayed only if it has content
teodosiah 87a2862
refactor(chat): remove the expansion panel usage as default attachmen…
teodosiah 0078251
feat(chat): focus styles and improvements
SisIvanova b2095e0
Update chat.base.scss
SisIvanova dfb73eb
feat(chat): return unknown instead of TemplateResult for templates
igdmdimitrov 7a80cef
chore(*): remove leftover props
igdmdimitrov 62a8879
refactor(chat): separate message & attachment template, provide the e…
teodosiah 9aa705f
Adding an option for positioning the suggestions (#1803)
gedinakova f8daf04
Merge branch 'master' of https://github.com/IgniteUI/igniteui-webcomp…
teodosiah 8d28a31
build(deps): Bumped to fixed theming package
rkaraivanov a10f321
fix(chat): clear file input after attaching and avoid duplicated atta…
igdmdimitrov 6bfd5ae
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
igdmdimitrov e984b07
feat(chat): use input type=file instead of igc-file-input
igdmdimitrov 45dc235
feat(chat): add prefix icon in attachments chips
igdmdimitrov 3572374
refactor(chat): styling improvements
SisIvanova c2b25b3
feat(chat): address some PR comments and improve typing change
igdmdimitrov b565409
refactor(chat): chip icons and typing dots animation
SisIvanova f79f356
feat(chat): use slot controller
igdmdimitrov 7ec9588
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
igdmdimitrov e835efd
refactor(chat): remove message grouping
teodosiah cc96e63
refactor(chat): rename isComposing to isTyping
teodosiah b0c0c16
Merge branch 'master' of https://github.com/IgniteUI/igniteui-webcomp…
teodosiah 8bfa538
build(deps): Bumped to latest beta theming package
SisIvanova 4bc7fdf
refactor(chat): remove message active styles
SisIvanova 63e4907
feat(chat): update tests
igdmdimitrov e4787ed
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
igdmdimitrov d0abb54
Update chat.base.scss
SisIvanova 7b7a4a1
refactor(chat): use keybinidng controller for textarea enter keydown
teodosiah 2566b0a
fix(chat): textarea keydown should be handled for any key
teodosiah 8f2c25a
feat(chat): fixed failing tests
igdmdimitrov 310c645
fix(chat): move max-width to `sent` part in order to make the respons…
desig9stein 10a91ac
feat(chat): Add customizable chat height via `--igc-chat-height` vari…
desig9stein c5de30e
chore(*): expose scrollToMessage method
teodosiah e002594
feat(chat): add message reactions buttons for responses
igdmdimitrov 04206fb
chore(*): fix lint
igdmdimitrov 8349174
refactor(chat): use list component for suggestions
SisIvanova 41f8116
feat(chat): fix upload file button and test fixes
igdmdimitrov 46c7a6f
fix(chat): horizontal & vertical scrollbar issues
SisIvanova 190dbff
Update message.base.scss
SisIvanova 4f91b2e
chore(*): Exporting all relevant parts.
gedinakova c201da2
chore(*): Restored accidentally removed message-text part
gedinakova 1e704e3
feat(chat): generate suggestions in ai story
igdmdimitrov 4194e8f
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
igdmdimitrov e02457d
refactor(chat): styling improvements
SisIvanova 860fb63
fix(*): Adding images for file attachments.
gedinakova 5058940
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
gedinakova cb8cef1
chore(*): Add marked to dev dependencies.
gedinakova 1be97ff
feat(chat): add default suggestions header and reaction tooltips
igdmdimitrov 599d283
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
igdmdimitrov 3d18e25
fix(*); Updated build script to copy chat assets
gedinakova 12c2334
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
gedinakova 87d63d7
fix(*): Fixed png images imports.
gedinakova 8d4da70
fix(*): Adding a slot in message component
gedinakova b60b857
feat(chat): add sent to attachment-header part for current user
igdmdimitrov ac0185d
feat(chat): add template for suggestion prefix
igdmdimitrov a649390
feat(chat): improve reactions tooltip
igdmdimitrov 22d88da
refactor(chat): udate attachments styling
SisIvanova 295b729
Adding renderers + default templates (#1821)
gedinakova 65ea59d
chore(*): Fixed chat state methods
gedinakova 8ed9190
fix(*): Fixed templates in test setup
gedinakova ee2e5a9
feat(chat): fixed reaction icons and suggestions generation in AI story
igdmdimitrov efab918
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
gedinakova ea314ef
fix(*): Fix Tooltip targets
gedinakova b0f89fe
chore(*): update stories
igdmdimitrov ba740ed
fix(*): Fixing failing tests.
gedinakova d49e099
fix(*): Polishing on stories.
gedinakova 79acef9
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
gedinakova 27af099
fix(*): Fixed input actions template and tests.
gedinakova 6951915
fix(*): Fixed message content in template test
gedinakova 22522ec
fix(*): Adding a default sanitizer and an option for custom one.
gedinakova 1de788e
chore(*): Added Dompurify to dev & peer deps.
gedinakova f701b47
refactor(chat): remove unnecessary part
SisIvanova 0725bc7
feat(chat): moved div with parts outside of default attachment conten…
igdmdimitrov 580e916
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
igdmdimitrov ac4c6ce
Merge branch 'master' into dmdimitrov/chat-ai-component
igdmdimitrov b9e3d68
chore(*): address PR comments
igdmdimitrov 7802431
chore(*): address PR comments
igdmdimitrov f684e3d
feat(chat): add template for message author
igdmdimitrov f82afbd
chore(*): removed only from test
igdmdimitrov 87facf2
fix(chat-message): Adopt page stylesheets in chat message ShadowRoot
rkaraivanov f1da11d
fix(*): Moved rendering logic back to components
gedinakova 25af43c
feat(chat): renamed message header template and other
igdmdimitrov b78a951
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
igdmdimitrov 68e4521
chore(*): renamed template
igdmdimitrov e2ab0cb
feat(chat): create igniteui-webcomponents/extras with markdown renderer
igdmdimitrov 7fb8f58
refactor: Cleaned up chat state and smaller components
rkaraivanov 9f1e235
fix(*): Added template renderers for all templatable areas
gedinakova 442d664
feat(chat): remove igc-chat-message-list and move messages in igc-chat
igdmdimitrov 73cb4e8
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
igdmdimitrov b995826
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
gedinakova feda411
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
gedinakova e91517d
fix(*): Updated stories to use renderers
gedinakova 60efb94
Merge branch 'master' into dmdimitrov/chat-ai-component
gedinakova 44ea247
fix(chat): message list styles
SisIvanova d72dc5b
fix(*); Simplify ChatTemplateRenderers.
gedinakova 4165ba7
fix(*): Fixing renderers updates & tests.
gedinakova 7eb8913
fix(*):Delegate the click to action buttons container
gedinakova 5f6aa41
text(*): Exclude an irrelevant keyboard test.
gedinakova 1bf8948
Merge branch 'master' into dmdimitrov/chat-ai-component
rkaraivanov 9d3cb0f
fix(chat): render header if headerText is provided
igdmdimitrov 4077b24
chore(*): fix chat headerText test
igdmdimitrov 94cc25d
refactor(chat-message): Simplified renderers
rkaraivanov 6c6fdd9
refactor(chat-input): Drag handlers bindings
rkaraivanov a264bcf
fix(*): Update input & attachments renderers.
gedinakova 64b0b4e
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
gedinakova c14f1cb
fix(*): Adding file extensions for the planned svgs
gedinakova 7ab0225
refactor(chat): Cache message renderer and cleaned some templates
rkaraivanov dfc2b65
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
rkaraivanov 6d7731a
chore(*): update templates story with markdown message renderer
igdmdimitrov 0421b58
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
igdmdimitrov 7766630
refactor(test): Changed query expectation to not null.
gedinakova e642e3d
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
gedinakova 02571ee
fix(chat): Autoscroll behavior
rkaraivanov 103a8a8
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
rkaraivanov 64af197
fix(tests): Show typing indicator when there are no messages; Updated…
gedinakova 35dfc16
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
gedinakova 7a636be
refactor(chat): Scroll to `end` boundry and code cleanup
rkaraivanov b12a229
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
rkaraivanov 2c078d5
feat(chat): renamed message actions icons and tooltips
igdmdimitrov 8e73294
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
igdmdimitrov 2a2ebbb
test(*): Updated slots tests
gedinakova 83de405
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
gedinakova 959ab63
chore(*): enabled markdown for AI story
igdmdimitrov 4db6d87
refactor(chat): use icons from internal registry
simeonoff c6f3157
refactor(*): Changed renderAttachment signature
gedinakova facb259
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
gedinakova c139b7c
refactor(*): Removed highlighter prop from MarkdownRendererOptions
gedinakova 91c3ffe
feat(chat): refactor layout to use CSS Grid for improved structure an…
desig9stein ae4d4e6
refactor(chat): replace png assets with svg icons
simeonoff 3c82640
feat(chat): tests adjustments
igdmdimitrov f11668c
feat(chat): styling improvements
SisIvanova 5ecce9c
refactor(chat): update thumb active icons
simeonoff 8794409
feat(chat): support for toggled like/dislike message actions
igdmdimitrov 599f9e2
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
igdmdimitrov f01ce78
chore(*): update dislike active icon name
igdmdimitrov 9382e23
Merge remote-tracking branch 'origin/master' into dmdimitrov/chat-ai-…
rkaraivanov 95ab978
refactor(chat): Simplify markdown renderer
rkaraivanov 6814780
refactor(chat): Streamline rendering
rkaraivanov 73294bb
refactor: Starting to clear up internal chat state model
rkaraivanov 7a65bdc
chore(*): adding all file type icons
gedinakova 6ce1588
refactor(chat): textarea height
SisIvanova 3d99d05
fix(chat): code snippets font
SisIvanova 570a3e4
refactor(chat): textarea size
SisIvanova f5ac4de
chore(*): Adding file preview icons. (#1843)
gedinakova 5caf2aa
feat(chat): add suggestion prefix renderer
igdmdimitrov f370c0a
Merge branch 'master' into dmdimitrov/chat-ai-component
gedinakova 000922f
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
igdmdimitrov c387091
fix(chat): header fixes
SisIvanova bdac4b8
chore(*): adjust chat tests
igdmdimitrov ba82fb6
refactor(chat): Reorganized template renderers and types
rkaraivanov 7c0882a
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
rkaraivanov 10d31be
fix(*): Render actions for message with attachments only.
gedinakova b9f17da
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
gedinakova 14870b8
refactor: Removed default renderers from template context
rkaraivanov 867cfc1
chore: Adjusted chat stories
rkaraivanov 8cc770f
chore(*): Copy message content to clipboard (#1846)
gedinakova 58fc80f
feat(chat): export sent css part
igdmdimitrov ed68030
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
igdmdimitrov 42412b8
refactor(*): Moved show tooltip & toast functions to ChatState.
gedinakova c48300e
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
gedinakova f06f9c1
chore(*): renamed renderer contexts
igdmdimitrov 7545f95
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
igdmdimitrov 674a5e0
chore(*): Added input area start and end renderers
gedinakova 67ff710
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
gedinakova 9af4c9d
refactor(*): Renamed message and message attachment interfaces
gedinakova 88cd56d
Merge remote-tracking branch 'origin/master' into dmdimitrov/chat-ai-…
rkaraivanov 1b0a763
chore: Fix chat stylelint errors
rkaraivanov 72c3ae6
feat(chat): add message-actions part
igdmdimitrov 8b2d30e
chore(*): tests adjustment
igdmdimitrov ad0e2eb
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
igdmdimitrov da4733d
refactor: Cleaned up chat state model
rkaraivanov 2838753
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
rkaraivanov 5a6c266
fix(*): Scroll typing indicator/suggestions into view. (#1848)
gedinakova d87f63a
refactor: Cleaned-up auto-scroll handler
rkaraivanov 88848af
test: Fixed DOM structure for the typing indicator container
rkaraivanov 15d6214
refactor: Moved state functionality to appropriate inner components
rkaraivanov 7d34591
feat: Split attachments event into explciit types
rkaraivanov ad879b1
fix(*): Removed unnecessary timeouts
gedinakova 5bcea88
refactor: API docs and moved adoptRootStyles as optional
rkaraivanov 40a07cb
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
rkaraivanov 5415b9c
docs: Enhance adoptRootStyles API docs
rkaraivanov 96569e3
docs: Updated adoptRootStyle API docs
rkaraivanov c703225
fix(*): Fixed failing interaction & events tests
gedinakova ad57339
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
gedinakova 5be4ebc
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
gedinakova 9bbf2ed
refactor(*): Further fixes & updates of events tests.
gedinakova 625ab14
refactor(*): Adding wrapping containers for some renderers
gedinakova d5dd419
deps(theming): bump to theming version with dark chat schemas
simeonoff 258e457
fix(chat): hide empty parts
SisIvanova 4b6f657
fix: Strip significant whitespace from empty template containers
rkaraivanov aa6746f
test(*): Small tweak for custom content
gedinakova c98cb22
refactor(*): Updated all parts & export
gedinakova 210d391
test: Fixed typing state test
rkaraivanov 0a8b8b6
fix: Flaky test and auto-scroll behavior
rkaraivanov 8b1b965
Merge branch 'master' into dmdimitrov/chat-ai-component
gedinakova 8654bb4
deps(theming): bump theming package to latest release
simeonoff af26fdc
refactor(chat): styling improvements
SisIvanova 1f06be1
feat: Pinned dependencies and updated release package.json
rkaraivanov a276dbf
Merge branch 'dmdimitrov/chat-ai-component' of https://github.com/Ign…
rkaraivanov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
import { LitElement, html } from 'lit'; | ||
import { property, query, state } from 'lit/decorators.js'; | ||
import IgcIconButtonComponent from '../button/icon-button.js'; | ||
import IgcChipComponent from '../chip/chip.js'; | ||
import { registerComponent } from '../common/definitions/register.js'; | ||
import IgcFileInputComponent from '../file-input/file-input.js'; | ||
import IgcIconComponent from '../icon/icon.js'; | ||
import { registerIconFromText } from '../icon/icon.registry.js'; | ||
import IgcTextareaComponent from '../textarea/textarea.js'; | ||
import { styles } from './themes/input.base.css.js'; | ||
import { | ||
type IgcMessageAttachment, | ||
attachmentIcon, | ||
sendButtonIcon, | ||
} from './types.js'; | ||
|
||
/** | ||
* | ||
* @element igc-chat | ||
* | ||
*/ | ||
export default class IgcChatInputComponent extends LitElement { | ||
/** @private */ | ||
public static readonly tagName = 'igc-chat-input'; | ||
|
||
public static override styles = styles; | ||
|
||
/* blazorSuppress */ | ||
public static register() { | ||
registerComponent( | ||
IgcChatInputComponent, | ||
IgcTextareaComponent, | ||
IgcIconButtonComponent, | ||
IgcChipComponent, | ||
IgcFileInputComponent, | ||
IgcIconComponent | ||
); | ||
} | ||
|
||
@property({ type: Boolean, attribute: 'disable-attachments' }) | ||
public disableAttachments = false; | ||
|
||
@property({ type: Boolean }) | ||
public isAiResponding = false; | ||
|
||
@query('textarea') | ||
private textInputElement!: HTMLTextAreaElement; | ||
|
||
@state() | ||
private inputValue = ''; | ||
|
||
@state() | ||
private attachments: IgcMessageAttachment[] = []; | ||
|
||
constructor() { | ||
super(); | ||
registerIconFromText('attachment', attachmentIcon, 'material'); | ||
registerIconFromText('send-message', sendButtonIcon, 'material'); | ||
} | ||
|
||
private handleInput(e: Event) { | ||
const target = e.target as HTMLTextAreaElement; | ||
this.inputValue = target.value; | ||
this.adjustTextareaHeight(); | ||
} | ||
|
||
private handleKeyDown(e: KeyboardEvent) { | ||
if (e.key === 'Enter' && !e.shiftKey) { | ||
e.preventDefault(); | ||
this.sendMessage(); | ||
} | ||
} | ||
|
||
private adjustTextareaHeight() { | ||
const textarea = this.textInputElement; | ||
if (!textarea) return; | ||
|
||
textarea.style.height = 'auto'; | ||
const newHeight = Math.min(textarea.scrollHeight, 120); | ||
textarea.style.height = `${newHeight}px`; | ||
} | ||
|
||
private sendMessage() { | ||
if (!this.inputValue.trim() && this.attachments.length === 0) return; | ||
|
||
const messageEvent = new CustomEvent('message-send', { | ||
detail: { text: this.inputValue, attachments: this.attachments }, | ||
}); | ||
|
||
this.dispatchEvent(messageEvent); | ||
this.inputValue = ''; | ||
this.attachments = []; | ||
|
||
if (this.textInputElement) { | ||
this.textInputElement.style.height = 'auto'; | ||
} | ||
|
||
setTimeout(() => { | ||
this.textInputElement?.focus(); | ||
}, 0); | ||
} | ||
|
||
private handleFileUpload(e: Event) { | ||
const input = (e.target as any).input as HTMLInputElement; | ||
if (!input.files || input.files.length === 0) return; | ||
|
||
const files = Array.from(input.files); | ||
const newAttachments: IgcMessageAttachment[] = []; | ||
files.forEach((file) => { | ||
const isImage = file.type.startsWith('image/'); | ||
newAttachments.push({ | ||
id: `attach_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`, | ||
type: isImage ? 'image' : 'file', | ||
url: URL.createObjectURL(file), | ||
name: file.name, | ||
size: file.size, | ||
thumbnail: isImage ? URL.createObjectURL(file) : undefined, | ||
}); | ||
}); | ||
this.attachments = [...this.attachments, ...newAttachments]; | ||
} | ||
|
||
private removeAttachment(index: number) { | ||
this.attachments = this.attachments.filter((_, i) => i !== index); | ||
} | ||
|
||
protected override render() { | ||
return html` | ||
<div class="input-container"> | ||
${this.disableAttachments | ||
? '' | ||
: html` | ||
<igc-file-input multiple @igcChange=${this.handleFileUpload}> | ||
<igc-icon | ||
slot="file-selector-text" | ||
name="attachment" | ||
collection="material" | ||
></igc-icon> | ||
</igc-file-input> | ||
`} | ||
|
||
<div class="input-wrapper"> | ||
<igc-textarea | ||
class="text-input" | ||
placeholder="Type a message..." | ||
rows="1" | ||
.value=${this.inputValue} | ||
@input=${this.handleInput} | ||
@keydown=${this.handleKeyDown} | ||
></igc-textarea> | ||
</div> | ||
|
||
<div class="buttons-container"> | ||
<igc-icon-button | ||
name="send-message" | ||
collection="material" | ||
variant="contained" | ||
class="small" | ||
?disabled=${!this.inputValue.trim() && | ||
this.attachments.length === 0} | ||
@click=${this.sendMessage} | ||
></igc-icon-button> | ||
</div> | ||
</div> | ||
<div> | ||
${this.attachments?.map( | ||
(attachment, index) => html` | ||
<div class="attachment-wrapper"> | ||
<igc-chip | ||
removable | ||
@igcRemove=${() => this.removeAttachment(index)} | ||
> | ||
<span class="attachment-name">${attachment.name}</span> | ||
</igc-chip> | ||
</div> | ||
` | ||
)} | ||
</div> | ||
`; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'igc-chat-input': IgcChatInputComponent; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import { LitElement, html } from 'lit'; | ||
import { property } from 'lit/decorators.js'; | ||
import { repeat } from 'lit/directives/repeat.js'; | ||
import { registerComponent } from '../common/definitions/register.js'; | ||
import IgcChatMessageComponent from './chat-message.js'; | ||
import { styles } from './themes/message-list.base.css.js'; | ||
import type { IgcMessage } from './types.js'; | ||
|
||
/** | ||
* | ||
* @element igc-chat-message-list | ||
* | ||
*/ | ||
export default class IgcChatMessageListComponent extends LitElement { | ||
/** @private */ | ||
public static readonly tagName = 'igc-chat-message-list'; | ||
|
||
public static override styles = styles; | ||
|
||
/* blazorSuppress */ | ||
public static register() { | ||
registerComponent(IgcChatMessageListComponent, IgcChatMessageComponent); | ||
} | ||
igdmdimitrov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
@property({ reflect: true, attribute: false }) | ||
public messages: IgcMessage[] = []; | ||
|
||
@property({ reflect: true, attribute: false }) | ||
public isAiResponding = false; | ||
|
||
@property({ type: Boolean, attribute: 'disable-auto-scroll' }) | ||
public disableAutoScroll = false; | ||
|
||
private formatDate(date: Date): string { | ||
const today = new Date(); | ||
const yesterday = new Date(today); | ||
yesterday.setDate(yesterday.getDate() - 1); | ||
|
||
if (date.toDateString() === today.toDateString()) { | ||
return 'Today'; | ||
} | ||
|
||
if (date.toDateString() === yesterday.toDateString()) { | ||
return 'Yesterday'; | ||
} | ||
|
||
return date.toLocaleDateString('en-US', { | ||
weekday: 'long', | ||
month: 'short', | ||
day: 'numeric', | ||
}); | ||
} | ||
teodosiah marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
private groupMessagesByDate( | ||
messages: IgcMessage[] | ||
): { date: string; messages: IgcMessage[] }[] { | ||
const grouped: { [key: string]: IgcMessage[] } = {}; | ||
|
||
messages.forEach((message) => { | ||
const dateStr = this.formatDate(message.timestamp); | ||
if (!grouped[dateStr]) { | ||
grouped[dateStr] = []; | ||
} | ||
grouped[dateStr].push(message); | ||
}); | ||
|
||
return Object.keys(grouped).map((date) => ({ | ||
date, | ||
messages: grouped[date], | ||
})); | ||
} | ||
teodosiah marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
private scrollToBottom() { | ||
requestAnimationFrame(() => { | ||
const container = this.shadowRoot?.host as HTMLElement; | ||
if (container) { | ||
container.scrollTop = container.scrollHeight; | ||
} | ||
}); | ||
} | ||
|
||
protected override updated() { | ||
if (!this.disableAutoScroll) { | ||
this.scrollToBottom(); | ||
} | ||
} | ||
|
||
protected override firstUpdated() { | ||
if (!this.disableAutoScroll) { | ||
this.scrollToBottom(); | ||
} | ||
} | ||
|
||
protected override render() { | ||
const groupedMessages = this.groupMessagesByDate(this.messages); | ||
|
||
return html` | ||
<div class='message-container'></div> | ||
<div class="message-list"> | ||
${repeat( | ||
groupedMessages, | ||
(group) => group.date, | ||
(group) => html` | ||
<div class="day-separator">${group.date}</div> | ||
${repeat( | ||
group.messages, | ||
(message) => message.id, | ||
(message) => html` | ||
<igc-chat-message | ||
.message=${message} | ||
.isResponse=${message.isResponse} | ||
></igc-chat-message> | ||
` | ||
)} | ||
` | ||
)} | ||
${ | ||
this.isAiResponding | ||
? html` | ||
<div class="typing-indicator"> | ||
<div class="typing-dot"></div> | ||
<div class="typing-dot"></div> | ||
<div class="typing-dot"></div> | ||
</div> | ||
` | ||
: '' | ||
} | ||
</div> | ||
</div> | ||
`; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'igc-chat-message-list': IgcChatMessageListComponent; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.