2
0

🐛 (embed) Fix custom close icon placement in bubble button

This commit is contained in:
Baptiste Arnaud
2023-07-31 09:39:30 +02:00
parent f8af76d347
commit 81c2e5022b
5 changed files with 58 additions and 52 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@typebot.io/js", "name": "@typebot.io/js",
"version": "0.1.11", "version": "0.1.12",
"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",
@@ -29,6 +29,7 @@
"@typebot.io/tsconfig": "workspace:*", "@typebot.io/tsconfig": "workspace:*",
"autoprefixer": "10.4.14", "autoprefixer": "10.4.14",
"babel-preset-solid": "1.7.7", "babel-preset-solid": "1.7.7",
"clsx": "2.0.0",
"eslint": "8.44.0", "eslint": "8.44.0",
"eslint-config-custom": "workspace:*", "eslint-config-custom": "workspace:*",
"eslint-plugin-solid": "0.12.1", "eslint-plugin-solid": "0.12.1",

View File

@@ -2,6 +2,7 @@ import { Show } from 'solid-js'
import { isNotDefined, isSvgSrc } from '@typebot.io/lib' import { isNotDefined, isSvgSrc } from '@typebot.io/lib'
import { BubbleTheme, ButtonTheme } from '../types' import { BubbleTheme, ButtonTheme } from '../types'
import { isLight } from '@typebot.io/lib/hexToRgb' import { isLight } from '@typebot.io/lib/hexToRgb'
import { clsx } from 'clsx'
type Props = Pick<BubbleTheme, 'placement'> & type Props = Pick<BubbleTheme, 'placement'> &
ButtonTheme & { ButtonTheme & {
@@ -20,11 +21,11 @@ export const BubbleButton = (props: Props) => (
<button <button
part="button" part="button"
onClick={() => props.toggleBot()} onClick={() => props.toggleBot()}
class={ 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.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,
@@ -40,11 +41,11 @@ export const BubbleButton = (props: Props) => (
? defaultDarkIconColor ? defaultDarkIconColor
: defaultLightIconColor), : defaultLightIconColor),
}} }}
class={ class={clsx(
`stroke-2 fill-transparent absolute duration-200 transition ` + 'stroke-2 fill-transparent absolute duration-200 transition',
(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') 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" />
</svg> </svg>
@@ -53,27 +54,25 @@ export const BubbleButton = (props: Props) => (
<img <img
part="button-icon" part="button-icon"
src={props.customIconSrc} src={props.customIconSrc}
class={ class={clsx(
'duration-200 transition' + 'duration-200 transition',
(props.isBotOpened props.isBotOpened ? 'scale-0 opacity-0' : 'scale-100 opacity-100',
? ' scale-0 opacity-0' isSvgSrc(props.customIconSrc)
: ' scale-100 opacity-100') +
(isSvgSrc(props.customIconSrc)
? props.size === 'large' ? props.size === 'large'
? ' w-9 h-9' ? 'w-9 h-9'
: ' w-7 h-7' : 'w-7 h-7'
: ' w-[90%] h-[90%]') + : '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"
/> />
</Show> </Show>
<Show when={props.customIconSrc && !isImageSrc(props.customIconSrc)}> <Show when={props.customIconSrc && !isImageSrc(props.customIconSrc)}>
<span <span
class={ class={clsx(
'text-4xl duration-200 transition' + 'text-4xl duration-200 transition',
(props.isBotOpened ? ' scale-0 opacity-0' : ' scale-100 opacity-100') props.isBotOpened ? 'scale-0 opacity-0' : 'scale-100 opacity-100'
} )}
style={{ style={{
'font-family': 'font-family':
"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'", "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'",
@@ -92,13 +91,13 @@ export const BubbleButton = (props: Props) => (
? defaultDarkIconColor ? defaultDarkIconColor
: defaultLightIconColor), : defaultLightIconColor),
}} }}
class={ class={clsx(
`absolute duration-200 transition ` + 'absolute duration-200 transition',
(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') props.size === 'large' ? ' w-9' : ' w-7'
} )}
> >
<path <path
fill-rule="evenodd" fill-rule="evenodd"
@@ -113,33 +112,31 @@ export const BubbleButton = (props: Props) => (
<img <img
part="button-icon" part="button-icon"
src={props.customCloseIconSrc} src={props.customCloseIconSrc}
class={ class={clsx(
'duration-200 transition' + 'absolute duration-200 transition',
(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)
? props.size === 'large' ? props.size === 'large'
? ' w-9 h-9' ? 'w-9 h-9'
: ' w-7 h-7' : 'w-7 h-7'
: ' w-[90%] h-[90%]') + : 'w-[90%] h-[90%]',
(isSvgSrc(props.customCloseIconSrc) isSvgSrc(props.customCloseIconSrc) ? '' : 'object-cover rounded-full'
? '' )}
: ' object-cover rounded-full') alt="Bubble button close icon"
}
alt="Bubble button clost icon"
/> />
</Show> </Show>
<Show <Show
when={props.customCloseIconSrc && !isImageSrc(props.customCloseIconSrc)} when={props.customCloseIconSrc && !isImageSrc(props.customCloseIconSrc)}
> >
<span <span
class={ class={clsx(
'text-4xl duration-200 transition' + 'absolute text-4xl duration-200 transition',
(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'
} )}
style={{ style={{
'font-family': 'font-family':
"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'", "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@typebot.io/nextjs", "name": "@typebot.io/nextjs",
"version": "0.1.11", "version": "0.1.12",
"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",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@typebot.io/react", "name": "@typebot.io/react",
"version": "0.1.11", "version": "0.1.12",
"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",

8
pnpm-lock.yaml generated
View File

@@ -851,6 +851,9 @@ importers:
babel-preset-solid: babel-preset-solid:
specifier: 1.7.7 specifier: 1.7.7
version: 1.7.7(@babel/core@7.22.9) version: 1.7.7(@babel/core@7.22.9)
clsx:
specifier: 2.0.0
version: 2.0.0
eslint: eslint:
specifier: 8.44.0 specifier: 8.44.0
version: 8.44.0 version: 8.44.0
@@ -12633,6 +12636,11 @@ packages:
engines: {node: '>=6'} engines: {node: '>=6'}
dev: false dev: false
/clsx@2.0.0:
resolution: {integrity: sha512-rQ1+kcj+ttHG0MKVGBUXwayCCF1oh39BF5COIpRzuCEv8Mwjv0XucrI2ExNTOn9IlLifGClWQcU9BrZORvtw6Q==}
engines: {node: '>=6'}
dev: true
/co-body@6.1.0: /co-body@6.1.0:
resolution: {integrity: sha512-m7pOT6CdLN7FuXUcpuz/8lfQ/L77x8SchHCF4G0RBTJO20Wzmhn5Sp4/5WsKy8OSpifBSUrmg83qEqaDHdyFuQ==} resolution: {integrity: sha512-m7pOT6CdLN7FuXUcpuz/8lfQ/L77x8SchHCF4G0RBTJO20Wzmhn5Sp4/5WsKy8OSpifBSUrmg83qEqaDHdyFuQ==}
dependencies: dependencies: