-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
useComposerProps.js
28 lines (23 loc) · 1.26 KB
/
useComposerProps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { useMemo } from 'react';
import { concatMiddleware, defaultStyleOptions } from 'botframework-webchat-component';
import createAdaptiveCardsAttachmentMiddleware from './adaptiveCards/createAdaptiveCardsAttachmentMiddleware';
import createAdaptiveCardsStyleSet from './adaptiveCards/Styles/createAdaptiveCardsStyleSet';
import defaultRenderMarkdown from './renderMarkdown';
export default function useComposerProps({ attachmentMiddleware, renderMarkdown, styleOptions, styleSet }) {
const patchedAttachmentMiddleware = useMemo(
() => concatMiddleware(attachmentMiddleware, createAdaptiveCardsAttachmentMiddleware()),
[attachmentMiddleware]
);
const patchedStyleOptions = useMemo(() => ({ ...defaultStyleOptions, ...styleOptions }), [styleOptions]);
// When styleSet is not specified, the styleOptions will be used to create Adaptive Cards styleSet and merged into useStyleSet.
const extraStyleSet = useMemo(() => (styleSet ? undefined : createAdaptiveCardsStyleSet(patchedStyleOptions)), [
patchedStyleOptions,
styleSet
]);
return {
attachmentMiddleware: patchedAttachmentMiddleware,
extraStyleSet,
renderMarkdown:
typeof renderMarkdown === 'undefined' ? text => defaultRenderMarkdown(text, patchedStyleOptions) : renderMarkdown
};
}