-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add sliding dots typing indicator to Fluent theme #5447
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 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5a0f448
Add sliding dots typing indicator
compulim 46fb758
Update PR number
compulim 7feeae0
Add tests
compulim a974390
Import test IDs from bundle
compulim f815877
Update screenshots
compulim c5daf21
Pause animation
compulim e740c80
Fix ESLint
compulim c2abf67
Add test for layout
compulim f16bf57
Read test IDs from component
compulim 5c7d996
Read test IDs from component
compulim b84e0e3
Add useShouldReduceMotion
compulim 25bfc03
Add doc
compulim dd998ef
Unformat
compulim 1efba38
Simplify
compulim 2b22fdb
Add prefers-reduced-motion
compulim 88a469c
Simplify
compulim 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 |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| <!doctype html> | ||
| <html lang="en-US"> | ||
| <head> | ||
| <link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
| <script crossorigin="anonymous" src="https://unpkg.com/react@16.8.6/umd/react.production.min.js"></script> | ||
| <script crossorigin="anonymous" src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.production.min.js"></script> | ||
| <script crossorigin="anonymous" src="/test-harness.js"></script> | ||
| <script crossorigin="anonymous" src="/test-page-object.js"></script> | ||
| <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script> | ||
| <script crossorigin="anonymous" src="/__dist__/botframework-webchat-fluent-theme.production.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <main id="webchat"></main> | ||
| <script type="importmap"> | ||
| { | ||
| "imports": { | ||
| "@testduet/wait-for": "https://unpkg.com/@testduet/wait-for@main/dist/wait-for.mjs", | ||
| "jest-mock": "https://esm.sh/jest-mock", | ||
| "react-dictate-button/internal": "https://unpkg.com/react-dictate-button@main/dist/react-dictate-button.internal.mjs" | ||
| } | ||
| } | ||
| </script> | ||
| <script type="module"> | ||
| import { waitFor } from '@testduet/wait-for'; | ||
|
|
||
| const isLivestream = new URL(location).searchParams.has('livestream'); | ||
|
|
||
| run(async function () { | ||
| const { | ||
| React: { createElement }, | ||
| ReactDOM: { render }, | ||
| WebChat: { FluentThemeProvider, ReactWebChat } | ||
| } = window; // Imports in UMD fashion. | ||
|
|
||
| // TBD: We cannot pause SMIL animation via reduced motion yet. | ||
| // await host.sendDevToolsCommand('Emulation.setEmulatedMedia', { | ||
| // features: [{ name: 'prefers-reduced-motion', value: 'reduce' }] | ||
| // }); | ||
|
|
||
| const { directLine, store } = testHelpers.createDirectLineEmulator(); | ||
|
|
||
| render( | ||
| createElement(FluentThemeProvider, {}, createElement(ReactWebChat, { directLine, store })), | ||
| document.getElementById('webchat') | ||
| ); | ||
|
|
||
| await pageConditions.uiConnected(); | ||
|
|
||
| // WHEN: Receive a bot message. | ||
| await directLine.emulateIncomingActivity({ | ||
| from: { id: 'u-00001', name: 'Bot', role: 'bot' }, | ||
| id: 'a-00001', | ||
| text: 'Hello, World!', | ||
| type: 'message' | ||
| }); | ||
|
|
||
| // WHEN: Bot send either a contentless livestream or typing activity. | ||
| await directLine.emulateIncomingActivity({ | ||
| ...(isLivestream | ||
| ? { | ||
| channelData: { | ||
| streamSequence: 1, | ||
| streamType: 'streaming' | ||
| } | ||
| } | ||
| : {}), | ||
| from: { id: 'u-00001', name: 'Bot', role: 'bot' }, | ||
| id: 'a-00002', | ||
| type: 'typing' | ||
| }); | ||
|
|
||
| // THEN: Should show typing indicator. | ||
| await waitFor(() => expect(pageElements.typingIndicator()).toBeTruthy()); | ||
|
|
||
| const svg = pageElements.typingIndicator().querySelector('svg'); | ||
|
|
||
| svg?.pauseAnimations(); | ||
| svg?.setCurrentTime(0); | ||
|
|
||
| // THEN: Should match snapshot. | ||
| await host.snapshot('local'); | ||
|
|
||
| // --- | ||
|
|
||
| // WHEN: Bot send either a contentless livestream or typing activity. | ||
| await directLine.emulateIncomingActivity({ | ||
| ...(isLivestream | ||
| ? { | ||
| channelData: { | ||
| streamId: 'a-00002', | ||
| streamType: 'final' | ||
| } | ||
| } | ||
| : { | ||
| channelData: { | ||
| webChat: { | ||
| styleOptions: { typingAnimationDuration: 0 } | ||
| } | ||
| } | ||
| }), | ||
| from: { id: 'u-00001', name: 'Bot', role: 'bot' }, | ||
| id: 'a-00002', | ||
| type: 'typing' | ||
| }); | ||
|
|
||
| // THEN: Should hide typing indicator. | ||
| await waitFor(() => expect(pageElements.typingIndicator()).toBeFalsy()); | ||
|
|
||
| // THEN: Should match snapshot. | ||
| await host.snapshot('local'); | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <script> | ||
| location = './typingIndicator?livestream'; | ||
| </script> | ||
| </head> | ||
| <body></body> | ||
| </html> |
Binary file added
BIN
+10.3 KB
__tests__/html2/fluentTheme/typingIndicator.livestream.html.snap-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.32 KB
__tests__/html2/fluentTheme/typingIndicator.livestream.html.snap-2.png
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
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
176 changes: 176 additions & 0 deletions
176
packages/fluent-theme/src/components/assets/SlidingDots.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,176 @@ | ||
| import React, { memo, useMemo } from 'react'; | ||
|
|
||
| type SlidingDotsProps = Readonly<{ | ||
| className?: string | undefined; | ||
| }>; | ||
|
|
||
| function SlidingDots({ className }: SlidingDotsProps) { | ||
| const id = useMemo(() => `webchat__sliding-dots-asset--${crypto.randomUUID()}`, []); | ||
|
|
||
| return ( | ||
| <svg | ||
| className={className} | ||
| height="20" | ||
| role="presentation" | ||
| viewBox="0 0 400 20" | ||
| width="400" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| > | ||
| <defs> | ||
| {/* eslint-disable-next-line react/forbid-dom-props */} | ||
| <linearGradient gradientUnits="userSpaceOnUse" id={id} x1="0" x2="100%" y1="0" y2="0"> | ||
| <stop offset="0%"> | ||
| <animate | ||
| attributeName="stop-color" | ||
| dur="2s" | ||
| keyTimes="0;0.2;0.33;0.5;0.66;0.8;1" | ||
| repeatCount="indefinite" | ||
| values="#ad5ae1;#ad5ae1;#0E94E1;#0E94E1;#669fc2;#669fc2;#ad5ae1" | ||
| /> | ||
| </stop> | ||
| <stop offset="50%"> | ||
| <animate | ||
| attributeName="stop-color" | ||
| dur="2s" | ||
| keyTimes="0;0.2;0.33;0.5;0.66;0.8;1" | ||
| repeatCount="indefinite" | ||
| values="#e9618d;#e9618d;#57AB82;#57AB82;#6377e0;#6377e0;#e9618d" | ||
| /> | ||
| </stop> | ||
| <stop offset="100%"> | ||
| <animate | ||
| attributeName="stop-color" | ||
| dur="2s" | ||
| keyTimes="0;0.2;0.33;0.5;0.66;0.8;1" | ||
| repeatCount="indefinite" | ||
| values="#fd9e5f;#fd9e5f;#C6C225;#C6C225;#9b80ec;#9b80ec;#fd9e5f" | ||
| /> | ||
| </stop> | ||
| </linearGradient> | ||
| </defs> | ||
| <g fill={`url(#${id})`}> | ||
| <rect height="20" rx="10"> | ||
| <animate attributeName="x" dur="2s" keyTimes="0;0.5;0.66;1" repeatCount="indefinite" values="26;26;0;0" /> | ||
| <animate | ||
| attributeName="width" | ||
| dur="2s" | ||
| keyTimes="0;0.2;0.33;0.5;0.66;1" | ||
| repeatCount="indefinite" | ||
| values="20;20;30;30;20;20" | ||
| /> | ||
| <animate attributeName="opacity" dur="2s" keyTimes="0;0.5;0.66;1" repeatCount="indefinite" values="1;1;0;0" /> | ||
| </rect> | ||
| <rect height="20" rx="10"> | ||
| <animate | ||
| attributeName="x" | ||
| dur="2s" | ||
| keyTimes="0;0.2;0.33;0.5;0.66;0.8;1" | ||
| repeatCount="indefinite" | ||
| values="62;62;72;72;26;26;0" | ||
| /> | ||
| <animate | ||
| attributeName="width" | ||
| dur="2s" | ||
| keyTimes="0;0.2;0.33;0.5;0.66;0.8;1" | ||
| repeatCount="indefinite" | ||
| values="104;104;20;20;70;70;20" | ||
| /> | ||
| <animate attributeName="opacity" dur="2s" keyTimes="0;0.8;1" repeatCount="indefinite" values="1;1;0" /> | ||
| </rect> | ||
| <rect height="20" rx="10"> | ||
| <animate | ||
| attributeName="x" | ||
| dur="2s" | ||
| keyTimes="0;0.2;0.33;0.5;0.66;0.8;1" | ||
| repeatCount="indefinite" | ||
| values="182;182;108;108;112;112;26" | ||
| /> | ||
| <animate | ||
| attributeName="width" | ||
| dur="2s" | ||
| keyTimes="0;0.2;0.33;0.5;0.66;1" | ||
| repeatCount="indefinite" | ||
| values="20;20;60;60;20;20" | ||
| /> | ||
| </rect> | ||
| <rect height="20" rx="10"> | ||
| <animate | ||
| attributeName="x" | ||
| dur="2s" | ||
| keyTimes="0;0.2;0.33;0.5;0.66;0.8;1" | ||
| repeatCount="indefinite" | ||
| values="218;218;184;184;148;148;62" | ||
| /> | ||
| <animate | ||
| attributeName="width" | ||
| dur="2s" | ||
| keyTimes="0;0.2;0.33;0.5;0.66;0.8;1" | ||
| repeatCount="indefinite" | ||
| values="60;60;80;80;40;40;104" | ||
| /> | ||
| </rect> | ||
| <rect height="20" rx="10"> | ||
| <animate | ||
| attributeName="x" | ||
| dur="2s" | ||
| keyTimes="0;0.2;0.33;0.5;0.66;0.8;1" | ||
| repeatCount="indefinite" | ||
| values="294;294;280;280;204;204;182" | ||
| /> | ||
| <animate | ||
| attributeName="width" | ||
| dur="2s" | ||
| keyTimes="0;0.2;0.33;0.5;0.66;0.8;1" | ||
| repeatCount="indefinite" | ||
| values="40;40;20;20;80;80;20" | ||
| /> | ||
| </rect> | ||
| <rect height="20" rx="10"> | ||
| <animate | ||
| attributeName="x" | ||
| dur="2s" | ||
| keyTimes="0;0.2;0.33;0.5;0.66;0.8;1" | ||
| repeatCount="indefinite" | ||
| values="350;350;316;316;300;300;218" | ||
| /> | ||
| <animate | ||
| attributeName="width" | ||
| dur="2s" | ||
| keyTimes="0;0.2;0.33;0.5;0.66;0.8;1" | ||
| repeatCount="indefinite" | ||
| values="20;20;60;60;20;20;60" | ||
| /> | ||
| </rect> | ||
| <rect height="20" rx="10"> | ||
| <animate | ||
| attributeName="x" | ||
| dur="2s" | ||
| keyTimes="0;0.2;0.33;0.5;0.66;0.8;1" | ||
| repeatCount="indefinite" | ||
| values="386;386;392;392;336;336;294" | ||
| /> | ||
| <animate | ||
| attributeName="width" | ||
| dur="2s" | ||
| keyTimes="0;0.5;0.66;1" | ||
| repeatCount="indefinite" | ||
| values="20;20;40;40" | ||
| /> | ||
| <animate attributeName="opacity" dur="2s" keyTimes="0;0.5;0.66;1" repeatCount="indefinite" values="0;0;1;1" /> | ||
| </rect> | ||
| <rect height="20" rx="10" width="20"> | ||
| <animate | ||
| attributeName="x" | ||
| dur="2s" | ||
| keyTimes="0;0.2;0.33;0.5;0.66;0.8;1" | ||
| repeatCount="indefinite" | ||
| values="422;422;428;428;392;392;350" | ||
| /> | ||
| <animate attributeName="opacity" dur="2s" keyTimes="0;0.8;1" repeatCount="indefinite" values="0;0;1" /> | ||
| </rect> | ||
| </g> | ||
| </svg> | ||
| ); | ||
| } | ||
|
|
||
| export default memo(SlidingDots); | ||
11 changes: 11 additions & 0 deletions
11
packages/fluent-theme/src/components/typingIndicator/SlidingDotsTypingIndicator.module.css
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,11 @@ | ||
| :global(.webchat-fluent) .sliding-dots-typing-indicator { | ||
| align-self: start; | ||
| display: flex; | ||
| height: 16px; | ||
| margin: auto var(--webchat-spacingHorizontalMNudge); | ||
| } | ||
|
|
||
| :global(.webchat-fluent) .sliding-dots-typing-indicator__image { | ||
| height: 6px; | ||
| width: auto; | ||
| } |
24 changes: 24 additions & 0 deletions
24
packages/fluent-theme/src/components/typingIndicator/SlidingDotsTypingIndicator.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,24 @@ | ||
| import { testIds } from 'botframework-webchat-component'; | ||
| import { useStyles } from 'botframework-webchat-styles/react'; | ||
| import cx from 'classnames'; | ||
| import React, { memo } from 'react'; | ||
|
|
||
| import { useVariantClassName } from '../../styles'; | ||
| import SlidingDots from '../assets/SlidingDots'; | ||
| import styles from './SlidingDotsTypingIndicator.module.css'; | ||
|
|
||
| function SlidingDotsTypingIndicator() { | ||
| const classNames = useStyles(styles); | ||
| const variantClassName = useVariantClassName(classNames); | ||
|
compulim marked this conversation as resolved.
|
||
|
|
||
| return ( | ||
| <div | ||
| className={cx(classNames['sliding-dots-typing-indicator'], variantClassName)} | ||
| data-testid={testIds.typingIndicator} | ||
| > | ||
| <SlidingDots className={cx(classNames['sliding-dots-typing-indicator__image'])} /> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default memo(SlidingDotsTypingIndicator); | ||
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.