|
1 | 1 | import { validateProps } from '@msinternal/botframework-webchat-react-valibot'; |
2 | 2 | import { useStyles } from '@msinternal/botframework-webchat-styles/react'; |
| 3 | +import { ThemeProvider } from 'botframework-webchat/component'; |
3 | 4 | import cx from 'classnames'; |
4 | | -import React, { memo } from 'react'; |
5 | | -import { object, optional, pipe, readonly, string, type InferInput } from 'valibot'; |
| 5 | +import React, { memo, useMemo } from 'react'; |
| 6 | +import { custom, object, optional, pipe, readonly, string, union, type InferInput } from 'valibot'; |
6 | 7 |
|
7 | 8 | import ChatLauncherStylesheet from '../stylesheet/ChatLauncherStylesheet'; |
8 | 9 | import styles from './ChatLauncher.module.css'; |
9 | 10 | import ChatLauncherButton from './private/ChatLauncherButton'; |
10 | 11 |
|
11 | 12 | const chatLauncherPropsSchema = pipe( |
12 | 13 | object({ |
13 | | - nonce: optional(string()) |
| 14 | + nonce: optional(string()), |
| 15 | + stylesRoot: optional( |
| 16 | + union( |
| 17 | + [ |
| 18 | + custom<HTMLLinkElement>(value => value instanceof HTMLLinkElement && value.rel === 'stylesheet'), |
| 19 | + custom<HTMLStyleElement>(value => value instanceof HTMLStyleElement) |
| 20 | + ], |
| 21 | + '"stylesRoot" must be either <link rel="stylesheet"> or <style>' |
| 22 | + ) |
| 23 | + ) |
14 | 24 | }), |
15 | 25 | readonly() |
16 | 26 | ); |
17 | 27 |
|
18 | 28 | type ChatLauncherProps = InferInput<typeof chatLauncherPropsSchema>; |
19 | 29 |
|
20 | 30 | function ChatLauncher(props: ChatLauncherProps) { |
21 | | - const { nonce } = validateProps(chatLauncherPropsSchema, props); |
| 31 | + const { nonce, stylesRoot } = validateProps(chatLauncherPropsSchema, props); |
| 32 | + |
22 | 33 | const classNames = useStyles(styles); |
| 34 | + const styleOptions = useMemo(() => ({ stylesRoot }), [stylesRoot]); |
23 | 35 |
|
24 | 36 | return ( |
25 | 37 | <div className={cx('webchat', classNames['webchat-experience-chat-launcher'])}> |
26 | | - <ChatLauncherStylesheet nonce={nonce} /> |
27 | | - <ChatLauncherButton /> |
| 38 | + <ThemeProvider styleOptions={styleOptions}> |
| 39 | + <ChatLauncherStylesheet nonce={nonce} /> |
| 40 | + <ChatLauncherButton /> |
| 41 | + </ThemeProvider> |
28 | 42 | </div> |
29 | 43 | ); |
30 | 44 | } |
|
0 commit comments