Skip to content

Commit

Permalink
feat: blur profile image
Browse files Browse the repository at this point in the history
  • Loading branch information
stakbucks committed Aug 23, 2024
1 parent 12a0dcd commit b9c93b6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
22 changes: 22 additions & 0 deletions apps/bottle/src/components/avatar/avatarStyle.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { colors } from '@bottlesteam/ui';
import { style } from '@vanilla-extract/css';
import { recipe } from '@vanilla-extract/recipes';

export const avatarStyle = recipe({
base: {
borderRadius: '50%',
},
variants: {
blur: {
true: {
filter: 'blur(2px)',
},
false: {},
},
},
});

export const placeholderStyle = style({
borderRadius: '50%',
backgroundColor: colors.neutral200,
});
16 changes: 10 additions & 6 deletions apps/bottle/src/components/avatar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import { colors } from '@bottlesteam/ui';
import Image from 'next/image';
import type { ImageProps } from 'next/image';
import { avatarStyle, placeholderStyle } from './avatarStyle.css';

export interface AvatarProps extends Omit<ImageProps, 'alt' | 'width' | 'height'> {
size: 'sm' | 'lg';
blur?: boolean;
}

export function Avatar({ size: _size, ...props }: AvatarProps) {
export function Avatar({ size: _size, blur, ...props }: AvatarProps) {
const size = _size === 'sm' ? 48 : 80;

return (
<>
{props.src != null ? (
<Image {...props} alt="user profile image" width={size} height={size} style={{ borderRadius: '50%' }} />
<Image {...props} alt="user profile image" width={size} height={size} className={avatarStyle({ blur })} />
) : (
<div
style={{ width: `${size}px`, height: `${size}px`, borderRadius: '50%', backgroundColor: colors.neutral200 }}
/>
<Placeholder size={size} />
)}
</>
);
}

function Placeholder({ size }: { size: number }) {
return <div style={{ width: `${size}px`, height: `${size}px` }} className={placeholderStyle} />;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function BasicInformationArea(props: Props) {
return (
<section className={basicInformationAreaStyle}>
{props.likeMessage && <Bubble style={{ marginBottom: spacings.sm }}>{props.likeMessage}</Bubble>}
<Avatar src={isCurrentUser(props) ? props.imageUrl : props.userImageUrl} size="lg" />
<Avatar blur src={isCurrentUser(props) ? props.imageUrl : props.userImageUrl} size="lg" />
<div className={nameAndAgeContainerStyle}>
<Paragraph typography="st1" color="neutral900">
{props.userName}
Expand Down

0 comments on commit b9c93b6

Please sign in to comment.