feat(theme): ✨ Custom avatars
This commit is contained in:
82
apps/builder/components/theme/ChatSettings/AvatarForm.tsx
Normal file
82
apps/builder/components/theme/ChatSettings/AvatarForm.tsx
Normal file
@ -0,0 +1,82 @@
|
||||
import React from 'react'
|
||||
import { AvatarProps } from 'models'
|
||||
import {
|
||||
Heading,
|
||||
HStack,
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
Stack,
|
||||
Switch,
|
||||
Image,
|
||||
Flex,
|
||||
Box,
|
||||
Portal,
|
||||
} from '@chakra-ui/react'
|
||||
import { ImageUploadContent } from 'components/shared/ImageUploadContent'
|
||||
import { DefaultAvatar } from 'assets/DefaultAvatar'
|
||||
|
||||
type Props = {
|
||||
title: string
|
||||
avatarProps?: AvatarProps
|
||||
isDefaultCheck?: boolean
|
||||
onAvatarChange: (avatarProps: AvatarProps) => void
|
||||
}
|
||||
|
||||
export const AvatarForm = ({
|
||||
title,
|
||||
avatarProps,
|
||||
isDefaultCheck = false,
|
||||
onAvatarChange,
|
||||
}: Props) => {
|
||||
const isChecked = avatarProps ? avatarProps.isEnabled : isDefaultCheck
|
||||
const handleOnCheck = () =>
|
||||
onAvatarChange({ ...avatarProps, isEnabled: !isChecked })
|
||||
const handleImageUrl = (url: string) =>
|
||||
onAvatarChange({ isEnabled: isChecked, url })
|
||||
return (
|
||||
<Stack borderWidth={1} rounded="md" p="4" spacing={4}>
|
||||
<Flex justifyContent="space-between">
|
||||
<HStack>
|
||||
<Heading as="label" fontSize="lg" htmlFor={title} mb="1">
|
||||
{title}
|
||||
</Heading>
|
||||
<Switch isChecked={isChecked} id={title} onChange={handleOnCheck} />
|
||||
</HStack>
|
||||
{isChecked && (
|
||||
<Popover isLazy>
|
||||
<PopoverTrigger>
|
||||
{avatarProps?.url ? (
|
||||
<Image
|
||||
src={avatarProps.url}
|
||||
alt="Website image"
|
||||
cursor="pointer"
|
||||
_hover={{ filter: 'brightness(.9)' }}
|
||||
transition="filter 200ms"
|
||||
rounded="full"
|
||||
boxSize="40px"
|
||||
objectFit="cover"
|
||||
/>
|
||||
) : (
|
||||
<Box>
|
||||
<DefaultAvatar
|
||||
cursor="pointer"
|
||||
_hover={{ filter: 'brightness(.9)' }}
|
||||
/>
|
||||
</Box>
|
||||
)}
|
||||
</PopoverTrigger>
|
||||
<Portal>
|
||||
<PopoverContent p="4">
|
||||
<ImageUploadContent
|
||||
url={avatarProps?.url}
|
||||
onSubmit={handleImageUrl}
|
||||
/>
|
||||
</PopoverContent>
|
||||
</Portal>
|
||||
</Popover>
|
||||
)}
|
||||
</Flex>
|
||||
</Stack>
|
||||
)
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
import { Heading, Stack } from '@chakra-ui/react'
|
||||
import { ChatTheme, ContainerColors, InputColors } from 'models'
|
||||
import { AvatarProps, ChatTheme, ContainerColors, InputColors } from 'models'
|
||||
import React from 'react'
|
||||
import { AvatarForm } from './AvatarForm'
|
||||
import { ButtonsTheme } from './ButtonsTheme'
|
||||
import { GuestBubbles } from './GuestBubbles'
|
||||
import { HostBubbles } from './HostBubbles'
|
||||
@ -21,8 +22,24 @@ export const ChatThemeSettings = ({ chatTheme, onChatThemeChange }: Props) => {
|
||||
const handleInputsChange = (inputs: InputColors) =>
|
||||
onChatThemeChange({ ...chatTheme, inputs })
|
||||
|
||||
const handleHostAvatarChange = (hostAvatar: AvatarProps) =>
|
||||
onChatThemeChange({ ...chatTheme, hostAvatar })
|
||||
const handleGuestAvatarChange = (guestAvatar: AvatarProps) =>
|
||||
onChatThemeChange({ ...chatTheme, guestAvatar })
|
||||
|
||||
return (
|
||||
<Stack spacing={6}>
|
||||
<AvatarForm
|
||||
title="Bot avatar"
|
||||
avatarProps={chatTheme.hostAvatar}
|
||||
isDefaultCheck
|
||||
onAvatarChange={handleHostAvatarChange}
|
||||
/>
|
||||
<AvatarForm
|
||||
title="User avatar"
|
||||
avatarProps={chatTheme.guestAvatar}
|
||||
onAvatarChange={handleGuestAvatarChange}
|
||||
/>
|
||||
<Stack borderWidth={1} rounded="md" p="4" spacing={4}>
|
||||
<Heading fontSize="lg">Bot bubbles</Heading>
|
||||
<HostBubbles
|
||||
|
Reference in New Issue
Block a user