mirror of
https://github.com/vercel/commerce.git
synced 2025-06-30 02:11:21 +00:00
Avatar background
This commit is contained in:
parent
573d274b13
commit
7bf4978ac8
@ -1,5 +1,5 @@
|
|||||||
import { FC, useState, useMemo, useRef, useEffect } from 'react'
|
import { FC, useRef, useEffect } from 'react'
|
||||||
import { getRandomPairOfColors } from '@lib/colors'
|
import { useUserAvatar } from '@lib/hooks/useUserAvatar'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
className?: string
|
className?: string
|
||||||
@ -7,18 +7,13 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const Avatar: FC<Props> = ({}) => {
|
const Avatar: FC<Props> = ({}) => {
|
||||||
const [bg] = useState(useMemo(() => getRandomPairOfColors, []))
|
|
||||||
let ref = useRef() as React.MutableRefObject<HTMLInputElement>
|
let ref = useRef() as React.MutableRefObject<HTMLInputElement>
|
||||||
|
let { userAvatar } = useUserAvatar()
|
||||||
useEffect(() => {
|
|
||||||
if (ref && ref.current) {
|
|
||||||
ref.current.style.backgroundImage = `linear-gradient(140deg, ${bg[0]}, ${bg[1]} 100%)`
|
|
||||||
}
|
|
||||||
}, [bg])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={ref}
|
ref={ref}
|
||||||
|
style={{ backgroundImage: userAvatar }}
|
||||||
className="inline-block h-8 w-8 rounded-full border-2 border-primary hover:border-secondary focus:border-secondary transition linear-out duration-150"
|
className="inline-block h-8 w-8 rounded-full border-2 border-primary hover:border-secondary focus:border-secondary transition linear-out duration-150"
|
||||||
>
|
>
|
||||||
{/* Add an image - We're generating a gradient as placeholder <img></img> */}
|
{/* Add an image - We're generating a gradient as placeholder <img></img> */}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user