🚸 Better embed button size prop now acception …
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@typebot.io/js",
|
"name": "@typebot.io/js",
|
||||||
"version": "0.2.41",
|
"version": "0.2.42",
|
||||||
"description": "Javascript library to display typebots on your website",
|
"description": "Javascript library to display typebots on your website",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
@ -47,6 +47,13 @@ export const Bubble = (props: BubbleProps) => {
|
|||||||
|
|
||||||
const [isBotOpened, setIsBotOpened] = createSignal(false)
|
const [isBotOpened, setIsBotOpened] = createSignal(false)
|
||||||
const [isBotStarted, setIsBotStarted] = createSignal(false)
|
const [isBotStarted, setIsBotStarted] = createSignal(false)
|
||||||
|
const [buttonSize, setButtonSize] = createSignal(
|
||||||
|
// eslint-disable-next-line solid/reactivity
|
||||||
|
parseButtonSize(bubbleProps.theme?.button?.size ?? 'medium')
|
||||||
|
)
|
||||||
|
createEffect(() => {
|
||||||
|
setButtonSize(parseButtonSize(bubbleProps.theme?.button?.size ?? 'medium'))
|
||||||
|
})
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
window.addEventListener('message', processIncomingEvent)
|
window.addEventListener('message', processIncomingEvent)
|
||||||
@ -145,7 +152,7 @@ export const Bubble = (props: BubbleProps) => {
|
|||||||
{...previewMessage()}
|
{...previewMessage()}
|
||||||
placement={bubbleProps.theme?.placement}
|
placement={bubbleProps.theme?.placement}
|
||||||
previewMessageTheme={bubbleProps.theme?.previewMessage}
|
previewMessageTheme={bubbleProps.theme?.previewMessage}
|
||||||
buttonSize={bubbleProps.theme?.button?.size}
|
buttonSize={buttonSize()}
|
||||||
onClick={handlePreviewMessageClick}
|
onClick={handlePreviewMessageClick}
|
||||||
onCloseClick={hideMessage}
|
onCloseClick={hideMessage}
|
||||||
/>
|
/>
|
||||||
@ -155,6 +162,7 @@ export const Bubble = (props: BubbleProps) => {
|
|||||||
placement={bubbleProps.theme?.placement}
|
placement={bubbleProps.theme?.placement}
|
||||||
toggleBot={toggleBot}
|
toggleBot={toggleBot}
|
||||||
isBotOpened={isBotOpened()}
|
isBotOpened={isBotOpened()}
|
||||||
|
buttonSize={buttonSize()}
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
part="bot"
|
part="bot"
|
||||||
@ -173,13 +181,11 @@ export const Bubble = (props: BubbleProps) => {
|
|||||||
'box-shadow': 'rgb(0 0 0 / 16%) 0px 5px 40px',
|
'box-shadow': 'rgb(0 0 0 / 16%) 0px 5px 40px',
|
||||||
'background-color': bubbleProps.theme?.chatWindow?.backgroundColor,
|
'background-color': bubbleProps.theme?.chatWindow?.backgroundColor,
|
||||||
'z-index': 42424242,
|
'z-index': 42424242,
|
||||||
|
bottom: `calc(${buttonSize()} + 32px)`,
|
||||||
}}
|
}}
|
||||||
class={
|
class={
|
||||||
'fixed rounded-lg w-full' +
|
'fixed rounded-lg w-full' +
|
||||||
(isBotOpened() ? ' opacity-1' : ' opacity-0 pointer-events-none') +
|
(isBotOpened() ? ' opacity-1' : ' opacity-0 pointer-events-none') +
|
||||||
(props.theme?.button?.size === 'large'
|
|
||||||
? ' bottom-24'
|
|
||||||
: ' bottom-20') +
|
|
||||||
(props.theme?.placement === 'left' ? ' left-5' : ' right-5')
|
(props.theme?.placement === 'left' ? ' left-5' : ' right-5')
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@ -194,3 +200,8 @@ export const Bubble = (props: BubbleProps) => {
|
|||||||
</Show>
|
</Show>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const parseButtonSize = (
|
||||||
|
size: NonNullable<NonNullable<BubbleProps['theme']>['button']>['size']
|
||||||
|
): `${number}px` =>
|
||||||
|
size === 'medium' ? '48px' : size === 'large' ? '64px' : size ? size : '48px'
|
||||||
|
@ -8,6 +8,7 @@ type Props = Pick<BubbleTheme, 'placement'> &
|
|||||||
ButtonTheme & {
|
ButtonTheme & {
|
||||||
isBotOpened: boolean
|
isBotOpened: boolean
|
||||||
toggleBot: () => void
|
toggleBot: () => void
|
||||||
|
buttonSize: `${number}px`
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultButtonColor = '#0042DA'
|
const defaultButtonColor = '#0042DA'
|
||||||
@ -22,13 +23,14 @@ export const BubbleButton = (props: Props) => (
|
|||||||
part="button"
|
part="button"
|
||||||
onClick={() => props.toggleBot()}
|
onClick={() => props.toggleBot()}
|
||||||
class={clsx(
|
class={clsx(
|
||||||
'fixed bottom-5 shadow-md rounded-full hover:scale-110 active:scale-95 transition-transform duration-200 flex justify-center items-center animate-fade-in',
|
`fixed bottom-5 shadow-md rounded-full hover:scale-110 active:scale-95 transition-transform duration-200 flex justify-center items-center animate-fade-in`,
|
||||||
props.size === 'large' ? ' w-16 h-16' : ' w-12 h-12',
|
|
||||||
props.placement === 'left' ? ' left-5' : ' right-5'
|
props.placement === 'left' ? ' left-5' : ' right-5'
|
||||||
)}
|
)}
|
||||||
style={{
|
style={{
|
||||||
'background-color': props.backgroundColor ?? defaultButtonColor,
|
'background-color': props.backgroundColor ?? defaultButtonColor,
|
||||||
'z-index': 42424242,
|
'z-index': 42424242,
|
||||||
|
width: props.buttonSize,
|
||||||
|
height: props.buttonSize,
|
||||||
}}
|
}}
|
||||||
aria-label="Open chatbot"
|
aria-label="Open chatbot"
|
||||||
>
|
>
|
||||||
@ -45,9 +47,8 @@ export const BubbleButton = (props: Props) => (
|
|||||||
: defaultLightIconColor),
|
: defaultLightIconColor),
|
||||||
}}
|
}}
|
||||||
class={clsx(
|
class={clsx(
|
||||||
'stroke-2 fill-transparent absolute duration-200 transition',
|
'stroke-2 fill-transparent absolute duration-200 transition w-[60%]',
|
||||||
props.isBotOpened ? 'scale-0 opacity-0' : 'scale-100 opacity-100',
|
props.isBotOpened ? 'scale-0 opacity-0' : 'scale-100 opacity-100'
|
||||||
props.size === 'large' ? 'w-9' : 'w-7'
|
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" />
|
<path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" />
|
||||||
@ -60,11 +61,7 @@ export const BubbleButton = (props: Props) => (
|
|||||||
class={clsx(
|
class={clsx(
|
||||||
'duration-200 transition',
|
'duration-200 transition',
|
||||||
props.isBotOpened ? 'scale-0 opacity-0' : 'scale-100 opacity-100',
|
props.isBotOpened ? 'scale-0 opacity-0' : 'scale-100 opacity-100',
|
||||||
isSvgSrc(props.customIconSrc)
|
isSvgSrc(props.customIconSrc) ? 'w-[60%]' : 'w-full h-full',
|
||||||
? props.size === 'large'
|
|
||||||
? 'w-9 h-9'
|
|
||||||
: 'w-7 h-7'
|
|
||||||
: 'w-[90%] h-[90%]',
|
|
||||||
isSvgSrc(props.customIconSrc) ? '' : 'object-cover rounded-full'
|
isSvgSrc(props.customIconSrc) ? '' : 'object-cover rounded-full'
|
||||||
)}
|
)}
|
||||||
alt="Bubble button icon"
|
alt="Bubble button icon"
|
||||||
@ -98,11 +95,10 @@ export const BubbleButton = (props: Props) => (
|
|||||||
: defaultLightIconColor),
|
: defaultLightIconColor),
|
||||||
}}
|
}}
|
||||||
class={clsx(
|
class={clsx(
|
||||||
'absolute duration-200 transition',
|
'absolute duration-200 transition w-[60%]',
|
||||||
props.isBotOpened
|
props.isBotOpened
|
||||||
? 'scale-100 rotate-0 opacity-100'
|
? 'scale-100 rotate-0 opacity-100'
|
||||||
: 'scale-0 -rotate-180 opacity-0',
|
: 'scale-0 -rotate-180 opacity-0'
|
||||||
props.size === 'large' ? ' w-9' : ' w-7'
|
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<path
|
<path
|
||||||
@ -123,11 +119,7 @@ export const BubbleButton = (props: Props) => (
|
|||||||
props.isBotOpened
|
props.isBotOpened
|
||||||
? 'scale-100 rotate-0 opacity-100'
|
? 'scale-100 rotate-0 opacity-100'
|
||||||
: 'scale-0 -rotate-180 opacity-0',
|
: 'scale-0 -rotate-180 opacity-0',
|
||||||
isSvgSrc(props.customCloseIconSrc)
|
isSvgSrc(props.customCloseIconSrc) ? 'w-[60%]' : 'w-full h-full',
|
||||||
? props.size === 'large'
|
|
||||||
? 'w-9 h-9'
|
|
||||||
: 'w-7 h-7'
|
|
||||||
: 'w-[90%] h-[90%]',
|
|
||||||
isSvgSrc(props.customCloseIconSrc) ? '' : 'object-cover rounded-full'
|
isSvgSrc(props.customCloseIconSrc) ? '' : 'object-cover rounded-full'
|
||||||
)}
|
)}
|
||||||
alt="Bubble button close icon"
|
alt="Bubble button close icon"
|
||||||
|
@ -27,7 +27,6 @@ export const PreviewMessage = (props: PreviewMessageProps) => {
|
|||||||
onClick={() => props.onClick()}
|
onClick={() => props.onClick()}
|
||||||
class={
|
class={
|
||||||
'fixed max-w-[256px] rounded-md duration-200 flex items-center gap-4 shadow-md animate-fade-in cursor-pointer hover:shadow-lg p-4' +
|
'fixed max-w-[256px] rounded-md duration-200 flex items-center gap-4 shadow-md animate-fade-in cursor-pointer hover:shadow-lg p-4' +
|
||||||
(props.buttonSize === 'large' ? ' bottom-24' : ' bottom-20') +
|
|
||||||
(props.placement === 'left' ? ' left-5' : ' right-5')
|
(props.placement === 'left' ? ' left-5' : ' right-5')
|
||||||
}
|
}
|
||||||
style={{
|
style={{
|
||||||
@ -35,6 +34,7 @@ export const PreviewMessage = (props: PreviewMessageProps) => {
|
|||||||
props.previewMessageTheme?.backgroundColor ?? defaultBackgroundColor,
|
props.previewMessageTheme?.backgroundColor ?? defaultBackgroundColor,
|
||||||
color: props.previewMessageTheme?.textColor ?? defaultTextColor,
|
color: props.previewMessageTheme?.textColor ?? defaultTextColor,
|
||||||
'z-index': 42424242,
|
'z-index': 42424242,
|
||||||
|
bottom: `calc(${props.buttonSize} + 32px)`,
|
||||||
}}
|
}}
|
||||||
onMouseEnter={() => setIsPreviewMessageHovered(true)}
|
onMouseEnter={() => setIsPreviewMessageHovered(true)}
|
||||||
onMouseLeave={() => setIsPreviewMessageHovered(false)}
|
onMouseLeave={() => setIsPreviewMessageHovered(false)}
|
||||||
|
@ -18,7 +18,7 @@ export type ChatWindowTheme = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type ButtonTheme = {
|
export type ButtonTheme = {
|
||||||
size?: 'medium' | 'large'
|
size?: 'medium' | 'large' | `${number}px`
|
||||||
backgroundColor?: string
|
backgroundColor?: string
|
||||||
iconColor?: string
|
iconColor?: string
|
||||||
customIconSrc?: string
|
customIconSrc?: string
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@typebot.io/nextjs",
|
"name": "@typebot.io/nextjs",
|
||||||
"version": "0.2.41",
|
"version": "0.2.42",
|
||||||
"description": "Convenient library to display typebots on your Next.js website",
|
"description": "Convenient library to display typebots on your Next.js website",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@typebot.io/react",
|
"name": "@typebot.io/react",
|
||||||
"version": "0.2.41",
|
"version": "0.2.42",
|
||||||
"description": "Convenient library to display typebots on your React app",
|
"description": "Convenient library to display typebots on your React app",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
Reference in New Issue
Block a user