-
Notifications
You must be signed in to change notification settings - Fork 550
feat(ui-components): introduce chat components #6678
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
20 commits
Select commit
Hold shift + click to select a range
40636a0
feat(ui-components): introduce chat components
FabienMotte 6f1ed20
chore: add passphrase input
FabienMotte 0b70363
wip
Haroenv 78ed732
toggle and header part of satellite
Haroenv 62880e9
revert js example
shaejaz 9f83bde
revert react example
shaejaz 13b1e28
remove todo
shaejaz 556c1d0
remove toggle button duplicate
shaejaz 5d2e92b
add tests
shaejaz 6ceffff
update bundlesize
shaejaz dd12b04
fix lint
shaejaz b095c41
Merge branch 'master' into feat/chat-components
shaejaz 040c035
markdown
Haroenv 8adc9ef
add chat component
shaejaz 4b2531e
update chat message
shaejaz deb8c8a
fix polyfill errors
shaejaz 5ca5ec2
update lock file
shaejaz 000f255
add chat test
shaejaz adf7f8f
address comments
shaejaz 95a463e
address comments
shaejaz 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
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
79 changes: 79 additions & 0 deletions
79
packages/instantsearch-ui-components/src/components/chat/Chat.tsx
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,79 @@ | ||
/** @jsx createElement */ | ||
/** @jsxFrag Fragment */ | ||
import { cx } from '../../lib'; | ||
|
||
import { createChatHeaderComponent } from './ChatHeader'; | ||
import { createChatMessagesComponent } from './ChatMessages'; | ||
import { createChatPromptComponent } from './ChatPrompt'; | ||
import { createChatToggleButtonComponent } from './ChatToggleButton'; | ||
|
||
import type { Renderer } from '../../types'; | ||
import type { ChatHeaderProps } from './ChatHeader'; | ||
import type { ChatMessagesProps } from './ChatMessages'; | ||
import type { ChatPromptProps } from './ChatPrompt'; | ||
import type { ChatToggleButtonProps } from './ChatToggleButton'; | ||
|
||
export type ChatClassNames = { | ||
container?: string | string[]; | ||
}; | ||
|
||
export type ChatProps = { | ||
/* | ||
* Whether the chat is open or closed. | ||
*/ | ||
open: boolean; | ||
/* | ||
* Props for the ChatHeader component. | ||
*/ | ||
headerProps: ChatHeaderProps; | ||
/* | ||
* Props for the ChatToggleButton component. | ||
*/ | ||
toggleButtonProps: ChatToggleButtonProps; | ||
/* | ||
* Props for the ChatMessages component. | ||
*/ | ||
messagesProps: ChatMessagesProps; | ||
/* | ||
* Props for the ChatPrompt component. | ||
*/ | ||
promptProps: ChatPromptProps; | ||
/** | ||
* Optional class names for elements | ||
*/ | ||
classNames?: Partial<ChatClassNames>; | ||
}; | ||
|
||
export function createChatComponent({ createElement, Fragment }: Renderer) { | ||
const ChatToggleButton = createChatToggleButtonComponent({ | ||
createElement, | ||
Fragment, | ||
}); | ||
const ChatHeader = createChatHeaderComponent({ createElement, Fragment }); | ||
const ChatMessages = createChatMessagesComponent({ createElement, Fragment }); | ||
const ChatPrompt = createChatPromptComponent({ createElement, Fragment }); | ||
|
||
return function Chat({ | ||
open, | ||
headerProps, | ||
toggleButtonProps, | ||
messagesProps, | ||
promptProps, | ||
classNames = {}, | ||
}: ChatProps) { | ||
return ( | ||
<> | ||
{!open ? ( | ||
<ChatToggleButton {...toggleButtonProps} /> | ||
) : ( | ||
<div className={cx('ais-Chat-container', classNames.container)}> | ||
<ChatHeader {...headerProps} /> | ||
<ChatMessages {...messagesProps} /> | ||
|
||
<ChatPrompt {...promptProps} /> | ||
</div> | ||
)} | ||
</> | ||
); | ||
}; | ||
} |
58 changes: 58 additions & 0 deletions
58
packages/instantsearch-ui-components/src/components/chat/ChatHeader.tsx
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,58 @@ | ||
/** @jsx createElement */ | ||
import { cx } from '../../lib'; | ||
|
||
import type { Renderer, ComponentProps } from '../../types'; | ||
|
||
export type ChatHeaderClassNames = { | ||
root?: string | string[]; | ||
title?: string | string[]; | ||
close?: string | string[]; | ||
}; | ||
|
||
export type ChatHeaderProps = Omit<ComponentProps<'div'>, 'title'> & { | ||
/** | ||
* The title to display in the header | ||
*/ | ||
title?: string; | ||
/** | ||
* Callback when the close button is clicked | ||
*/ | ||
onClose: () => void; | ||
/** | ||
* Accessible label for the close button | ||
*/ | ||
closeLabel?: string; | ||
/** | ||
* Optional class names for elements | ||
*/ | ||
classNames?: Partial<ChatHeaderClassNames>; | ||
}; | ||
|
||
export function createChatHeaderComponent({ createElement }: Renderer) { | ||
return function ChatHeader({ | ||
title = 'Chat', | ||
onClose, | ||
closeLabel = 'Close chat', | ||
classNames = {}, | ||
...props | ||
}: ChatHeaderProps) { | ||
return ( | ||
<div | ||
className={cx('ais-ChatHeader', classNames.root, props.className)} | ||
{...props} | ||
> | ||
<span className={cx('ais-ChatHeader-title', classNames.title)}> | ||
{title} | ||
</span> | ||
<button | ||
className={cx('ais-ChatHeader-close', classNames.close)} | ||
onClick={onClose} | ||
aria-label={closeLabel} | ||
type="button" | ||
> | ||
× | ||
</button> | ||
</div> | ||
); | ||
}; | ||
} |
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.