-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathBubble.tsx
66 lines (59 loc) · 2.86 KB
/
Bubble.tsx
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { createSignal, Show, splitProps, onMount } from 'solid-js'
import styles from '../../../assets/index.css'
import { BubbleButton } from './BubbleButton'
import { BubbleParams } from '../types'
import { Bot, BotProps } from '../../../components/Bot'
export type BubbleProps = BotProps & BubbleParams
export const Bubble = (props: BubbleProps) => {
const [bubbleProps] = splitProps(props, ['theme'])
const [isBotOpened, setIsBotOpened] = createSignal(false)
const [isBotStarted, setIsBotStarted] = createSignal(false)
const openBot = () => {
if (!isBotStarted()) setIsBotStarted(true)
setIsBotOpened(true)
}
const closeBot = () => {
setIsBotOpened(false)
}
const toggleBot = () => {
isBotOpened() ? closeBot() : openBot()
}
return (
<>
<style>{styles}</style>
<BubbleButton {...bubbleProps.theme?.button} toggleBot={toggleBot} isBotOpened={isBotOpened()} />
<div
part='bot'
style={{
height: bubbleProps.theme?.chatWindow?.height ? `${bubbleProps.theme?.chatWindow?.height.toString()}px` : 'calc(100% - 100px)',
transition: 'transform 200ms cubic-bezier(0, 1.2, 1, 1), opacity 150ms ease-out',
'transform-origin': 'bottom right',
transform: isBotOpened() ? 'scale3d(1, 1, 1)' : 'scale3d(0, 0, 1)',
'box-shadow': 'rgb(0 0 0 / 16%) 0px 5px 40px',
'background-color': bubbleProps.theme?.chatWindow?.backgroundColor || '#ffffff',
'z-index': 42424242
}}
class={
`fixed sm:right-5 rounded-lg w-full sm:w-[400px] max-h-[704px]` +
(isBotOpened() ? ' opacity-1' : ' opacity-0 pointer-events-none') +
(props.theme?.button?.size === 'large' ? ' bottom-24' : ' bottom-20')
}
>
<Show when={isBotStarted()}>
<Bot
badgeBackgroundColor={bubbleProps.theme?.chatWindow?.backgroundColor}
welcomeMessage={bubbleProps.theme?.chatWindow?.welcomeMessage}
poweredByTextColor={bubbleProps.theme?.chatWindow?.poweredByTextColor}
textInput={bubbleProps.theme?.chatWindow?.textInput}
botMessage={bubbleProps.theme?.chatWindow?.botMessage}
userMessage={bubbleProps.theme?.chatWindow?.userMessage}
fontSize={bubbleProps.theme?.chatWindow?.fontSize}
chatflowid={props.chatflowid}
authToken={props.authToken}
chatflowConfig={props.chatflowConfig}
apiHost={props.apiHost} />
</Show>
</div>
</>
)
}