2
0

🐛 (js) Fix preview message without avatar

Was showing a broken link instead of nothing
This commit is contained in:
Baptiste Arnaud
2023-03-14 08:15:19 +01:00
parent e4f4d23cae
commit e7132116f4
4 changed files with 56 additions and 46 deletions

View File

@@ -22,19 +22,13 @@ jobs:
if: ${{ contains(steps.main.outputs.tagname, 'v') }} if: ${{ contains(steps.main.outputs.tagname, 'v') }}
uses: EndBug/latest-tag@latest uses: EndBug/latest-tag@latest
- name: 'Create typebot-js tag' - name: 'Create js tag'
uses: Klemensas/action-autotag@stable
with:
package_root: '/packages/typebot-js'
tag_prefix: 'js-lib-v'
- name: 'Create typebot-js tag'
uses: Klemensas/action-autotag@stable uses: Klemensas/action-autotag@stable
with: with:
package_root: '/packages/js' package_root: '/packages/js'
tag_prefix: 'js-v' tag_prefix: 'js-v'
- name: 'Create typebot-js tag' - name: 'Create react tag'
uses: Klemensas/action-autotag@stable uses: Klemensas/action-autotag@stable
with: with:
package_root: '/packages/react' package_root: '/packages/react'

View File

@@ -1,6 +1,6 @@
{ {
"name": "@typebot.io/js", "name": "@typebot.io/js",
"version": "0.0.27", "version": "0.0.28",
"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",

View File

@@ -1,4 +1,4 @@
import { createSignal } from 'solid-js' import { createSignal, Show } from 'solid-js'
import { PreviewMessageParams, PreviewMessageTheme } from '../types' import { PreviewMessageParams, PreviewMessageTheme } from '../types'
export type PreviewMessageProps = Pick< export type PreviewMessageProps = Pick<
@@ -20,7 +20,7 @@ export const PreviewMessage = (props: PreviewMessageProps) => {
return ( return (
<div <div
onClick={() => props.onClick()} onClick={() => props.onClick()}
class="fixed bottom-20 right-4 w-64 rounded-md duration-200 flex items-center gap-4 shadow-md animate-fade-in cursor-pointer hover:shadow-lg p-4" class="fixed bottom-20 right-4 max-w-[256px] rounded-md duration-200 flex items-center gap-4 shadow-md animate-fade-in cursor-pointer hover:shadow-lg p-4"
style={{ style={{
'background-color': 'background-color':
props.previewMessageTheme?.backgroundColor ?? defaultBackgroundColor, props.previewMessageTheme?.backgroundColor ?? defaultBackgroundColor,
@@ -30,14 +30,38 @@ export const PreviewMessage = (props: PreviewMessageProps) => {
onMouseEnter={() => setIsPreviewMessageHovered(true)} onMouseEnter={() => setIsPreviewMessageHovered(true)}
onMouseLeave={() => setIsPreviewMessageHovered(false)} onMouseLeave={() => setIsPreviewMessageHovered(false)}
> >
<CloseButton
isHovered={isPreviewMessageHovered()}
previewMessageTheme={props.previewMessageTheme}
onClick={props.onCloseClick}
/>
<Show when={props.avatarUrl} keyed>
{(avatarUrl) => (
<img
src={avatarUrl}
class="rounded-full w-8 h-8 object-cover"
alt="Bot avatar"
/>
)}
</Show>
<p>{props.message}</p>
</div>
)
}
const CloseButton = (props: {
isHovered: boolean
previewMessageTheme?: PreviewMessageTheme
onClick: () => void
}) => (
<button <button
class={ class={
`absolute -top-3 -right-3 rounded-full w-6 h-6 p-1 hover:brightness-95 active:brightness-90 transition-all ` + `absolute -top-2 -right-2 rounded-full w-6 h-6 p-1 hover:brightness-95 active:brightness-90 transition-all border ` +
(isPreviewMessageHovered() ? 'opacity-100' : 'opacity-0') (props.isHovered ? 'opacity-100' : 'opacity-0')
} }
onClick={(e) => { onClick={(e) => {
e.stopPropagation() e.stopPropagation()
return props.onCloseClick() return props.onClick()
}} }}
style={{ style={{
'background-color': 'background-color':
@@ -60,12 +84,4 @@ export const PreviewMessage = (props: PreviewMessageProps) => {
<line x1="6" y1="6" x2="18" y2="18" /> <line x1="6" y1="6" x2="18" y2="18" />
</svg> </svg>
</button> </button>
<img )
src={props.avatarUrl}
class="rounded-full w-8 h-8 object-cover"
alt="Bot avatar"
/>
<p>{props.message}</p>
</div>
)
}

View File

@@ -1,6 +1,6 @@
{ {
"name": "@typebot.io/react", "name": "@typebot.io/react",
"version": "0.0.27", "version": "0.0.28",
"description": "React library to display typebots on your website", "description": "React library to display typebots on your website",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",