Skip to content

Commit 909aee0

Browse files
committed
Add stylesRoot
1 parent 6d6f5ca commit 909aee0

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

packages/experience-chat-launcher/src/private/ChatLauncher.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
11
import { validateProps } from '@msinternal/botframework-webchat-react-valibot';
22
import { useStyles } from '@msinternal/botframework-webchat-styles/react';
3+
import { ThemeProvider } from 'botframework-webchat/component';
34
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';
67

78
import ChatLauncherStylesheet from '../stylesheet/ChatLauncherStylesheet';
89
import styles from './ChatLauncher.module.css';
910
import ChatLauncherButton from './private/ChatLauncherButton';
1011

1112
const chatLauncherPropsSchema = pipe(
1213
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+
)
1424
}),
1525
readonly()
1626
);
1727

1828
type ChatLauncherProps = InferInput<typeof chatLauncherPropsSchema>;
1929

2030
function ChatLauncher(props: ChatLauncherProps) {
21-
const { nonce } = validateProps(chatLauncherPropsSchema, props);
31+
const { nonce, stylesRoot } = validateProps(chatLauncherPropsSchema, props);
32+
2233
const classNames = useStyles(styles);
34+
const styleOptions = useMemo(() => ({ stylesRoot }), [stylesRoot]);
2335

2436
return (
2537
<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>
2842
</div>
2943
);
3044
}

0 commit comments

Comments
 (0)