-
Notifications
You must be signed in to change notification settings - Fork 8
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
Create spright-chat-conversation and spright-chat-message components #2529
Open
joseahdz
wants to merge
67
commits into
main
Choose a base branch
from
spright-chat-components-final
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 52 commits
Commits
Show all changes
67 commits
Select commit
Hold shift + click to select a range
8a3e0f7
Component APIs initial pass
jattasNI 53d8a83
Copy rectange and rename ai-chat-text-bubble
jattasNI dde0e41
Fix build
jattasNI ff03a9e
Copy rectangle docs for AI Chat text bubble
jattasNI f318f03
Refactor into single MDX for all AI Chat components
jattasNI 3996846
Start implementing chat bubble
jattasNI f31ed38
Remove "AI" from names
jattasNI 2ba3b86
Rename bubbles to messages
jattasNI 3f94aa5
Slot message content
jattasNI 2837ba3
Markdown example
jattasNI 9b5866c
positioning based on who sent message
jattasNI 20f73fc
Move message under chat folder
jattasNI 0b15993
Initial conversation component
jattasNI badb124
Docs for conversation
jattasNI 5aaf44d
Padding between messages
jattasNI ecddda6
Only outgoing messages in bubbles
jattasNI d232c8e
background color
jattasNI df26a48
More example message types
jattasNI ad64243
Conversation vertical scroll
jattasNI dd13b59
Add window component (initially copied from conversation)
jattasNI 3649d59
Window toolbars
jattasNI 81b81aa
Chat input toolbar
jattasNI 0eb06b5
Type in chat window
jattasNI 2ac76a7
Merge branch 'main' into sprigiht-ai-components
jattasNI a67499c
Padding around conversation
jattasNI 08ad339
Work around theme provider conflict in build
jattasNI e23117e
work around theme provider styles
jattasNI ffe0add
Merge branch 'main' into spright-chat-components
jattasNI 2207d4f
Fixture errors
jattasNI 463a99f
More Fixture build errors
jattasNI a57c934
Fix build
jattasNI cc8a9b2
Productize ChatConversation and ChatMessage elements
joseahdz 5809c06
Delete README.md
joseahdz 1e5b67a
Small tweaks
joseahdz d05c23e
Merge branch 'main' into spright-chat-components-final
joseahdz 0f6ab82
Update chat.stories.ts
joseahdz d3a1010
Change files
joseahdz 4b9ca60
Fix lint and beachball errors
joseahdz 96d9bae
Reverted lock.json files
joseahdz 5c8584b
Implemented feedback
joseahdz 48f39dc
Merge branch 'main' into spright-chat-components-final
joseahdz 3160b95
Simpsons reference
jattasNI 5581ea4
Status table
jattasNI 0232ae3
Improve doc content
jattasNI 761c74a
linting
jattasNI f9558ce
Added chat messages of different sizes
joseahdz 4dfac11
Ran lint tool and added conversation tests
joseahdz 4314626
Fixed typo
joseahdz a9fce4d
Implemented latest feedback.
joseahdz 02f1468
More feedback
joseahdz 75d40cf
Added margins to chat messages in storybook matrix stories
joseahdz 1d87912
Updating margins
joseahdz 5956cd5
Removed usage of png file and started using svg image
joseahdz d798feb
Fixed formatting
joseahdz 3cbe591
Implemented Milan's feedback
joseahdz ab06456
Use nimble icon svg
rajsite 1e91cac
Merge branch 'main' into spright-chat-components-final
joseahdz 7ab321e
Merge branch 'main' into spright-chat-components-final
rajsite 8dd5207
Consistent chat-conversation naming
rajsite ab15b5b
Enable overflow on message content
rajsite df6e01a
Make message stories internal
rajsite 0179425
lint
rajsite de82196
Remove duplicate config for messages
rajsite f80c5bb
Template consistency
rajsite 19dc127
Refactor sizing stories
rajsite 7d8c7aa
lint
rajsite 9ee640b
Move overflow to inner message div
rajsite 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
7 changes: 7 additions & 0 deletions
7
change/@ni-spright-components-6dcca5fc-0353-4ba2-b325-63565d42b95e.json
This file contains 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,7 @@ | ||
{ | ||
"type": "minor", | ||
"comment": "Productize ChatConversation and ChatMessage elements", | ||
"packageName": "@ni/spright-components", | ||
"email": "jose.a.hernandez@ni.com", | ||
"dependentChangeType": "patch" | ||
} |
This file contains 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
25 changes: 25 additions & 0 deletions
25
packages/spright-components/src/chat/conversation/index.ts
This file contains 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,25 @@ | ||
import { DesignSystem, FoundationElement } from '@microsoft/fast-foundation'; | ||
import { styles } from './styles'; | ||
import { template } from './template'; | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'spright-chat-conversation': ChatConversation; | ||
} | ||
} | ||
|
||
/** | ||
* A Spright component for displaying a series of chat messages | ||
*/ | ||
export class ChatConversation extends FoundationElement {} | ||
|
||
const sprightChatConversation = ChatConversation.compose({ | ||
baseName: 'chat-conversation', | ||
template, | ||
styles | ||
}); | ||
|
||
DesignSystem.getOrCreate() | ||
.withPrefix('spright') | ||
.register(sprightChatConversation()); | ||
export const chatConversationTag = 'spright-chat-conversation'; |
20 changes: 20 additions & 0 deletions
20
packages/spright-components/src/chat/conversation/styles.ts
This file contains 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,20 @@ | ||
import { css } from '@microsoft/fast-element'; | ||
import { | ||
applicationBackgroundColor, | ||
mediumPadding, | ||
standardPadding | ||
} from '@ni/nimble-components/dist/esm/theme-provider/design-tokens'; | ||
import { display } from '../../utilities/style/display'; | ||
|
||
export const styles = css` | ||
${display('flex')} | ||
|
||
:host { | ||
flex-direction: column; | ||
justify-content: flex-start; | ||
row-gap: ${standardPadding}; | ||
padding: ${mediumPadding}; | ||
background: ${applicationBackgroundColor}; | ||
overflow-y: scroll; | ||
} | ||
`; |
7 changes: 7 additions & 0 deletions
7
packages/spright-components/src/chat/conversation/template.ts
This file contains 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,7 @@ | ||
import { html } from '@microsoft/fast-element'; | ||
import type { ChatConversation } from '.'; | ||
|
||
/* eslint-disable @typescript-eslint/indent */ | ||
// prettier-ignore | ||
export const template = html<ChatConversation>`<slot></slot>`; | ||
/* eslint-enable @typescript-eslint/indent */ |
34 changes: 34 additions & 0 deletions
34
packages/spright-components/src/chat/conversation/tests/chat-conversation.spec.ts
This file contains 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,34 @@ | ||
import { html } from '@microsoft/fast-element'; | ||
import { ChatConversation, chatConversationTag } from '..'; | ||
import { fixture, type Fixture } from '../../../utilities/tests/fixture'; | ||
|
||
async function setup(): Promise<Fixture<ChatConversation>> { | ||
return await fixture<ChatConversation>( | ||
html`<${chatConversationTag}></${chatConversationTag}>` | ||
); | ||
} | ||
|
||
describe('ChatConversation', () => { | ||
let element: ChatConversation; | ||
let connect: () => Promise<void>; | ||
let disconnect: () => Promise<void>; | ||
|
||
beforeEach(async () => { | ||
({ element, connect, disconnect } = await setup()); | ||
}); | ||
|
||
afterEach(async () => { | ||
await disconnect(); | ||
}); | ||
|
||
it('can construct an element instance', () => { | ||
expect(document.createElement(chatConversationTag)).toBeInstanceOf( | ||
ChatConversation | ||
); | ||
}); | ||
|
||
it('should have a slot element in the shadow DOM', async () => { | ||
await connect(); | ||
expect(element.shadowRoot?.querySelector('SLOT')).not.toBeNull(); | ||
}); | ||
}); |
This file contains 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,34 @@ | ||
import { attr } from '@microsoft/fast-element'; | ||
import { DesignSystem, FoundationElement } from '@microsoft/fast-foundation'; | ||
import { styles } from './styles'; | ||
import { template } from './template'; | ||
import { ChatMessageType } from '../types'; | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'spright-chat-message': ChatMessage; | ||
} | ||
} | ||
|
||
/** | ||
* A Spright component for displaying a chat message | ||
*/ | ||
export class ChatMessage extends FoundationElement { | ||
/** | ||
* @public | ||
* The message type of this message in the chat conversation | ||
* @remarks | ||
* HTML Attribute: message-type | ||
*/ | ||
@attr({ attribute: 'message-type' }) | ||
public readonly messageType: ChatMessageType = ChatMessageType.outbound; | ||
} | ||
|
||
const sprightChatMessage = ChatMessage.compose({ | ||
baseName: 'chat-message', | ||
template, | ||
styles | ||
}); | ||
|
||
DesignSystem.getOrCreate().withPrefix('spright').register(sprightChatMessage()); | ||
export const chatMessageTag = 'spright-chat-message'; |
This file contains 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,50 @@ | ||
import { css } from '@microsoft/fast-element'; | ||
import { | ||
bodyFont, | ||
bodyFontColor, | ||
borderHoverColor, | ||
borderWidth, | ||
fillSelectedColor, | ||
mediumPadding | ||
} from '@ni/nimble-components/dist/esm/theme-provider/design-tokens'; | ||
import { display } from '../../utilities/style/display'; | ||
|
||
export const styles = css` | ||
${display('flex')} | ||
|
||
:host { | ||
min-width: 16px; | ||
min-height: 16px; | ||
|
||
flex-direction: row; | ||
justify-content: center; | ||
flex-shrink: 0; | ||
} | ||
|
||
:host([message-type='outbound']) { | ||
justify-content: flex-end; | ||
} | ||
|
||
:host([message-type='inbound']) { | ||
justify-content: flex-start; | ||
} | ||
|
||
div { | ||
max-width: calc(100% - 200px); | ||
width: fit-content; | ||
height: fit-content; | ||
padding: ${mediumPadding}; | ||
font: ${bodyFont}; | ||
color: ${bodyFontColor}; | ||
joseahdz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
:host([message-type='outbound']) div { | ||
joseahdz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
background: ${fillSelectedColor}; | ||
border: ${borderWidth} solid ${borderHoverColor}; | ||
border-radius: 8px 8px 0px 8px; | ||
} | ||
|
||
:host([message-type='inbound']) div { | ||
border-radius: 8px 8px 8px 0px; | ||
} | ||
`; |
This file contains 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,11 @@ | ||
import { html } from '@microsoft/fast-element'; | ||
import type { ChatMessage } from '.'; | ||
|
||
/* eslint-disable @typescript-eslint/indent */ | ||
// prettier-ignore | ||
export const template = html<ChatMessage>` | ||
<div> | ||
<slot></slot> | ||
</div> | ||
`; | ||
joseahdz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/* eslint-enable @typescript-eslint/indent */ |
43 changes: 43 additions & 0 deletions
43
packages/spright-components/src/chat/message/tests/chat-message.spec.ts
This file contains 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,43 @@ | ||
import { html } from '@microsoft/fast-element'; | ||
import { ChatMessage, chatMessageTag } from '..'; | ||
import { fixture, type Fixture } from '../../../utilities/tests/fixture'; | ||
import { ChatMessageType } from '../../types'; | ||
|
||
async function setup(): Promise<Fixture<ChatMessage>> { | ||
return await fixture<ChatMessage>( | ||
html`<${chatMessageTag}>Some message</${chatMessageTag}>` | ||
); | ||
} | ||
|
||
describe('ChatMessage', () => { | ||
let element: ChatMessage; | ||
let connect: () => Promise<void>; | ||
let disconnect: () => Promise<void>; | ||
|
||
beforeEach(async () => { | ||
({ element, connect, disconnect } = await setup()); | ||
}); | ||
|
||
afterEach(async () => { | ||
await disconnect(); | ||
}); | ||
|
||
it('can construct an element instance', () => { | ||
expect(document.createElement(chatMessageTag)).toBeInstanceOf( | ||
ChatMessage | ||
); | ||
}); | ||
|
||
it('should have a slot element in the shadow DOM', async () => { | ||
joseahdz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await connect(); | ||
expect(element.shadowRoot?.querySelector('SLOT')).not.toBeNull(); | ||
expect( | ||
element?.innerText?.includes('Some message', undefined) | ||
).toBeTrue(); | ||
}); | ||
|
||
it("should initialize 'message-type' to default", async () => { | ||
await connect(); | ||
expect(element.messageType).toBe(ChatMessageType.outbound); | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/spright-components/src/chat/message/tests/types.spec.ts
This file contains 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,9 @@ | ||
import type { ChatMessageType } from '../../types'; | ||
|
||
describe('ChatMessage message type', () => { | ||
it('ChatMessageType fails compile if assigning arbitrary string values', () => { | ||
// @ts-expect-error This expect will fail if the enum-like type is missing "as const" | ||
const messageType: ChatMessageType = 'hello'; | ||
expect(messageType).toEqual('hello'); | ||
}); | ||
}); |
This file contains 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,12 @@ | ||
/** | ||
* A message type in a chat conversation. | ||
* @public | ||
*/ | ||
export const ChatMessageType = { | ||
joseahdz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
outbound: 'outbound', | ||
inbound: 'inbound', | ||
system: 'system' | ||
joseahdz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} as const; | ||
|
||
export type ChatMessageType = | ||
(typeof ChatMessageType)[keyof typeof ChatMessageType]; |
This file contains 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 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 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
4 changes: 4 additions & 0 deletions
4
packages/storybook/src/spright/chat/chat-conversation.react.tsx
This file contains 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,4 @@ | ||
import { ChatConversation } from '../../../../spright-components/src/chat/conversation'; | ||
import { wrap } from '../../utilities/react-wrapper'; | ||
|
||
export const SprightChatConversation = wrap(ChatConversation); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of the changes I pushed:
chat-conversation