-
Notifications
You must be signed in to change notification settings - Fork 550
feat(chat): add greeting screen component #6965
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
19 commits
Select commit
Hold shift + click to select a range
e96eec7
add greeting component
shaejaz 00f78dc
add props
shaejaz c700e90
export greeting component from packages
shaejaz af1bb91
add tests
shaejaz f240720
fix lint
shaejaz 7031cdb
fix bundlesize
shaejaz a14de97
Merge branch 'master' into feat/chat-greeting-screen
shaejaz 01e72df
add banner
shaejaz 0d12040
rename prop to empty
shaejaz 115f2e8
remove prop prefix
shaejaz 226e1c6
update prop names
shaejaz 41bdb01
fix ci
shaejaz 775596c
fix class name prop
shaejaz 19e8a82
update empty types
shaejaz ab0d184
fix status check
shaejaz ac67e01
fix widget props
shaejaz fe43af1
update examples
shaejaz 8dca27a
fix lint
shaejaz 46ba729
revert examples
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -163,3 +163,8 @@ | |
| rgba(255, 255, 255, 1) 100% | ||
| ); | ||
| } | ||
|
|
||
| .ais-ChatGreeting-banner { | ||
| width: 3rem; | ||
| height: 3rem; | ||
| } | ||
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
|---|---|---|
|
|
@@ -170,3 +170,8 @@ em { | |
| rgba(255, 255, 255, 1) 100% | ||
| ); | ||
| } | ||
|
|
||
| .ais-ChatGreeting-banner { | ||
| width: 3rem; | ||
| height: 3rem; | ||
| } | ||
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
97 changes: 97 additions & 0 deletions
97
packages/instantsearch-ui-components/src/components/chat/ChatGreeting.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,97 @@ | ||
| /** @jsx createElement */ | ||
|
|
||
| import { cx } from '../../lib'; | ||
|
|
||
| import type { ComponentProps, Renderer } from '../../types'; | ||
| import type { ChatEmptyProps } from './types'; | ||
|
|
||
| export type ChatGreetingTranslations = { | ||
| /** | ||
| * Heading text for the empty screen | ||
| */ | ||
| heading: string; | ||
| /** | ||
| * Subheading text for the empty screen | ||
| */ | ||
| subheading: string; | ||
| }; | ||
|
|
||
| export type ChatGreetingClassNames = { | ||
| /** | ||
| * Class names to apply to the root element | ||
| */ | ||
| root?: string | string[]; | ||
| /** | ||
| * Class names to apply to the heading element | ||
| */ | ||
| heading?: string | string[]; | ||
| /** | ||
| * Class names to apply to the subheading element | ||
| */ | ||
| subheading?: string | string[]; | ||
| /** | ||
| * Class names to apply to the banner element | ||
| */ | ||
| banner?: string | string[]; | ||
| }; | ||
|
|
||
| export type ChatGreetingProps = ChatEmptyProps & ComponentProps<'div'> & { | ||
| /** | ||
| * Optional translations | ||
| */ | ||
| translations?: Partial<ChatGreetingTranslations>; | ||
| /** | ||
| * Optional class names | ||
| */ | ||
| classNames?: ChatGreetingClassNames; | ||
| /** | ||
| * Optional banner image URL | ||
| */ | ||
| banner?: string; | ||
| }; | ||
|
|
||
| export function createChatGreetingComponent({ | ||
| createElement, | ||
| }: Pick<Renderer, 'createElement'>) { | ||
| return function ChatGreeting(userProps: ChatGreetingProps) { | ||
| const { | ||
| translations: userTranslations, | ||
| classNames = {}, | ||
| sendMessage: _sendMessage, | ||
| status: _status, | ||
| onClose: _onClose, | ||
| setInput: _setInput, | ||
| banner, | ||
| ...props | ||
| } = userProps; | ||
| const translations: Required<ChatGreetingTranslations> = { | ||
| heading: | ||
| userTranslations?.heading ?? | ||
| 'How can I help you today?', | ||
| subheading: | ||
| userTranslations?.subheading ?? | ||
| "Ask me anything about our products, and I'll do my best to assist you.", | ||
| }; | ||
|
|
||
| return ( | ||
| <div | ||
| {...props} | ||
| className={cx('ais-ChatGreeting', classNames.root, props.className)} | ||
| > | ||
| {banner && ( | ||
| <img | ||
| className={cx('ais-ChatGreeting-banner', classNames.banner)} | ||
| src={banner} | ||
| alt="" | ||
| /> | ||
| )} | ||
| <h2 className={cx('ais-ChatGreeting-heading', classNames.heading)}> | ||
| {translations.heading} | ||
| </h2> | ||
| <p className={cx('ais-ChatGreeting-subheading', classNames.subheading)}> | ||
| {translations.subheading} | ||
| </p> | ||
| </div> | ||
| ); | ||
| }; | ||
| } | ||
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
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
28 changes: 28 additions & 0 deletions
28
packages/instantsearch.css/src/components/chat/_chat-greeting.scss
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,28 @@ | ||
| .ais-ChatGreeting { | ||
| --ais-chat-greeting-padding: 0.5rem; | ||
|
|
||
| display: flex; | ||
| flex-direction: column; | ||
| justify-content: center; | ||
| padding: var(--ais-chat-greeting-padding); | ||
| flex: 1; | ||
| gap: calc(var(--ais-spacing) * 0.5); | ||
| } | ||
|
|
||
| .ais-ChatGreeting-heading { | ||
| font-size: 1.25em; | ||
| font-weight: 700; | ||
| margin: 0; | ||
| } | ||
|
|
||
| .ais-ChatGreeting-subheading { | ||
| font-size: 0.875em; | ||
| opacity: 0.7; | ||
| margin: 0; | ||
| line-height: 1.5; | ||
| } | ||
|
|
||
| .ais-ChatGreeting-banner { | ||
| max-width: 100%; | ||
| height: auto; | ||
| } |
18 changes: 18 additions & 0 deletions
18
packages/instantsearch.js/src/templates/chat-greeting/chat-greeting.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,18 @@ | ||
| /** @jsx h */ | ||
|
|
||
| import { createChatGreetingComponent } from 'instantsearch-ui-components'; | ||
| import { h } from 'preact'; | ||
|
|
||
| import type { ChatGreetingProps } from 'instantsearch-ui-components'; | ||
|
|
||
| const ChatGreetingComponent = createChatGreetingComponent({ | ||
| createElement: h, | ||
| }); | ||
|
|
||
| export function chatGreeting( | ||
| options?: Pick<ChatGreetingProps, 'banner' | 'translations' | 'classNames'> | ||
| ) { | ||
| return function ChatGreetingTemplate(props: ChatGreetingProps) { | ||
| return <ChatGreetingComponent {...props} {...options} />; | ||
| }; | ||
| } |
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
Oops, something went wrong.
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.