diff --git a/__tests__/html/emoji.enabledCustomMapDefaultRegExp.html b/__tests__/html/emoji.enabledCustomMapDefaultRegExp.html index 9ad080a666..9a488fffe2 100644 --- a/__tests__/html/emoji.enabledCustomMapDefaultRegExp.html +++ b/__tests__/html/emoji.enabledCustomMapDefaultRegExp.html @@ -15,8 +15,7 @@ directLine: window.WebChat.createDirectLine({ token: await token.fetchDirectLineToken() }), store: createStore(), styleOptions: { - emojiAutocorrect: true, - emojiList: { + emojiSet: { ':)': '😊' } } diff --git a/packages/component/src/BasicTranscript.js b/packages/component/src/BasicTranscript.js index 3623fed940..5bfcb9cf58 100644 --- a/packages/component/src/BasicTranscript.js +++ b/packages/component/src/BasicTranscript.js @@ -1,7 +1,7 @@ /* eslint no-magic-numbers: ["error", { "ignore": [-1, 0, 1] }] */ import { css } from 'glamor'; -import { Panel as ScrollToBottomPanel, useAnimating, useSticky } from 'react-scroll-to-bottom'; +import { Panel as ScrollToBottomPanel, useAnimatingToEnd, useSticky } from 'react-scroll-to-bottom'; import classNames from 'classnames'; import PropTypes from 'prop-types'; import React, { useCallback, useMemo, useRef } from 'react'; @@ -97,7 +97,7 @@ const BasicTranscript = ({ className }) => { const [{ activities: activitiesStyleSet, activity: activityStyleSet }] = useStyleSet(); const [{ hideScrollToEndButton }] = useStyleOptions(); const [activities] = useActivities(); - const [animatingToEnd] = useAnimating(); + const [animatingToEnd] = useAnimatingToEnd(); const [direction] = useDirection(); const [sticky] = useSticky(); const focus = useFocus(); diff --git a/packages/component/src/Styles/defaultStyleOptions.js b/packages/component/src/Styles/defaultStyleOptions.js index 23b6b3a213..fa07e715c6 100644 --- a/packages/component/src/Styles/defaultStyleOptions.js +++ b/packages/component/src/Styles/defaultStyleOptions.js @@ -190,8 +190,7 @@ const DEFAULT_OPTIONS = { toastWarnColor: '#3B3A39', // Emoji - emojiAutocorrect: false, - emojiList: undefined + emojiSet: false // true || false || { ':)' : '😊'} }; export default DEFAULT_OPTIONS; diff --git a/packages/component/src/hooks/useEmojiFromStyles.js b/packages/component/src/hooks/useEmojiFromStyles.js index 40e4a21403..1fab5970bc 100644 --- a/packages/component/src/hooks/useEmojiFromStyles.js +++ b/packages/component/src/hooks/useEmojiFromStyles.js @@ -1,56 +1,42 @@ /*eslint require-unicode-regexp: "off" */ -import { useMemo } from 'react'; - import useStyleOptions from './useStyleOptions'; -function escapeRegexp(emoticon) { - return emoticon.replace(/[\\^$*+?.()|[\]{}]/gu, '\\$&'); -} - export default function useEmojiFromStyles() { - const [{ emojiAutocorrect: autocorrect, emojiList: customEmojiList }] = useStyleOptions(); - - const emojiAutocorrect = autocorrect || false; - - const emojiUnicodeMap = customEmojiList || { - ':)': '😊', - ':-)': '😊', - '(:': '😊', - '(-:': '😊', - ':-|': '😐', - ':|': '😐', - ':-(': '☚ī¸', - ':(': '☚ī¸', - ':-D': '😀', - ':D': '😀', - ':-p': '😛', - ':p': '😛', - ':-P': '😛', - ':P': '😛', - ':-o': '😲', - ':o': '😲', - ':O': '😲', - ':-O': '😲', - ':-0': '😲', - ':0': '😲', - ';-)': '😉', - ';)': '😉', - '<3': '❤ī¸', - ' (customEmojiList ? new RegExp(escapedString, 'gmu') : new RegExp(/([:<()\\|/3DPpoO0-]{2,3})/gmu)), - [customEmojiList, escapedString] - ); - - return [{ emojiAutocorrect, emojiUnicodeMap, emojiRegExp }]; + const [{ emojiSet }] = useStyleOptions(); + + const emojiUnicodeMap = + typeof emojiSet === 'object' + ? emojiSet + : emojiSet === true + ? { + ':)': '😊', + ':-)': '😊', + '(:': '😊', + '(-:': '😊', + ':-|': '😐', + ':|': '😐', + ':-(': '☚ī¸', + ':(': '☚ī¸', + ':-D': '😀', + ':D': '😀', + ':-p': '😛', + ':p': '😛', + ':-P': '😛', + ':P': '😛', + ':-o': '😲', + ':o': '😲', + ':O': '😲', + ':-O': '😲', + ':-0': '😲', + ':0': '😲', + ';-)': '😉', + ';)': '😉', + '<3': '❤ī¸', + ' + typeof emojiUnicodeMap === 'object' && + Object.keys(emojiUnicodeMap) + .map(escapeRegexp) + .join('|'), + [emojiUnicodeMap] + ); + + const emojiRegExp = useMemo( + () => + typeof emojiUnicodeMap === 'object' + ? new RegExp(escapedString, 'gmu') + : new RegExp(/([:<()\\|/3DPpoO0-]{2,3})/gmu), + [emojiUnicodeMap, escapedString] + ); + const [value] = useTextBoxValue(); const setEmoji = useCallback( value => { const emoticon = value.match(emojiRegExp); - if (emojiAutocorrect && emoticon && emojiUnicodeMap[emoticon]) { + if (!!emojiUnicodeMap && emoticon && emojiUnicodeMap[emoticon]) { value = value.replace(emoticon, emojiUnicodeMap[emoticon]); } return value; }, - [emojiAutocorrect, emojiUnicodeMap, emojiRegExp] + [emojiUnicodeMap, emojiRegExp] ); return [value, setEmoji];