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>
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user