-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This reverts commit 3641b29.
- Loading branch information
1 parent
2c88758
commit dde36a0
Showing
18 changed files
with
150 additions
and
290 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,70 @@ | ||
import * as RadixAvatar from '@radix-ui/react-avatar' | ||
import { | ||
HTMLAttributes, | ||
ImgHTMLAttributes, | ||
PropsWithChildren, | ||
ReactNode, | ||
} from 'react' | ||
import { | ||
avatar, | ||
AvatarStylesProps, | ||
AvatarSmallImgStyleProps, | ||
AvatarStatusStyleProps, | ||
} from '@mochi-ui/theme' | ||
import { useId } from 'react' | ||
import { avatar, AvatarStylesProps } from '@mochi-ui/theme' | ||
import { boringAvatar } from './util' | ||
|
||
const { avatarCva, avatarImgClsx, avatarSmallImgCva, avatarStatusWrapperCva } = | ||
avatar | ||
const { avatarCva, avatarImgClsx } = avatar | ||
|
||
type AvatarProps = PropsWithChildren<AvatarStylesProps> & { | ||
interface AvatarProps extends AvatarStylesProps { | ||
src: string | ||
smallSrc?: string | ||
fallback?: string | ||
className?: string | ||
onLoadingStatusChange?: RadixAvatar.AvatarImageProps['onLoadingStatusChange'] | ||
delayMs?: RadixAvatar.AvatarFallbackProps['delayMs'] | ||
} & HTMLAttributes<HTMLDivElement> | ||
} | ||
|
||
export default function Avatar({ | ||
size, | ||
src, | ||
smallSrc, | ||
fallback = '', | ||
onLoadingStatusChange, | ||
delayMs, | ||
className, | ||
children, | ||
...props | ||
}: AvatarProps) { | ||
const id = useId() | ||
const fallbackUrl = boringAvatar(fallback) | ||
|
||
if (smallSrc) { | ||
return ( | ||
<div className={avatarCva({ size, className })}> | ||
<svg height="100%" role="none" viewBox="0 0 100 100" width="100%"> | ||
<mask id={`circle-mask-${id}`}> | ||
<circle cx="50%" cy="50%" fill="white" r="50%" /> | ||
<circle cx="80%" cy="80%" fill="black" r="24%" /> | ||
</mask> | ||
<image | ||
height="100%" | ||
mask={`url(#circle-mask-${id})`} | ||
onError={(e) => { | ||
;(e.target as SVGImageElement).setAttribute( | ||
'xlink:href', | ||
fallbackUrl, | ||
) | ||
}} | ||
width="100%" | ||
xlinkHref={src} | ||
className="overflow-hidden" | ||
/> | ||
<image | ||
height="40%" | ||
width="40%" | ||
x="60%" | ||
xlinkHref={smallSrc} | ||
y="60%" | ||
/> | ||
</svg> | ||
</div> | ||
) | ||
} | ||
|
||
return ( | ||
<RadixAvatar.Root className={avatarCva({ size, className })} {...props}> | ||
<RadixAvatar.Image | ||
className={avatarImgClsx} | ||
onLoadingStatusChange={onLoadingStatusChange} | ||
src={src} | ||
/> | ||
{children} | ||
<RadixAvatar.Fallback delayMs={delayMs}> | ||
<RadixAvatar.Root | ||
className={avatarCva({ size, className: `${className} overflow-hidden` })} | ||
> | ||
<RadixAvatar.Image src={src} className={avatarImgClsx} /> | ||
<RadixAvatar.Fallback> | ||
<img alt="fallback" src={fallbackUrl} /> | ||
</RadixAvatar.Fallback> | ||
</RadixAvatar.Root> | ||
) | ||
} | ||
|
||
export type AvatarSmallImageProps = AvatarSmallImgStyleProps & { | ||
src?: string | ||
className?: string | ||
} & ImgHTMLAttributes<HTMLImageElement> | ||
|
||
export const AvatarSmallImage = (props: AvatarSmallImageProps) => { | ||
const { src, position = 'bottom-right', className, alt, ...restProps } = props | ||
return ( | ||
<img | ||
className={avatarSmallImgCva({ position, className })} | ||
src={src} | ||
alt={alt} | ||
{...restProps} | ||
/> | ||
) | ||
} | ||
|
||
export type AvatarStatusProps = AvatarStatusStyleProps & { | ||
className?: string | ||
children?: ReactNode | ||
} & HTMLAttributes<HTMLDivElement> | ||
|
||
export const AvatarStatus = (props: AvatarStatusProps) => { | ||
const { | ||
position = 'bottom-right', | ||
color = 'success', | ||
className, | ||
children, | ||
...restProps | ||
} = props | ||
return ( | ||
<div | ||
className={avatarStatusWrapperCva({ color, className, position })} | ||
{...restProps} | ||
> | ||
{children || ( | ||
<svg height="100%" width="100%"> | ||
<circle r="50%" cx="50%" cy="50%" fill="currentColor" /> | ||
</svg> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export { type AvatarProps } |
Oops, something went wrong.
dde36a0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
websites-mochi – ./apps/mochi-web
websites-mochi.vercel.app
websites-mochi-git-main-consolelabs.vercel.app
websites-mochi-consolelabs.vercel.app
beta.mochi.gg