mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
Adding gradient on the clientside
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
import cn from 'classnames'
|
||||
import { FC, useState } from 'react'
|
||||
import {
|
||||
FC,
|
||||
useState,
|
||||
useMemo,
|
||||
useRef,
|
||||
useEffect,
|
||||
HTMLInputElement,
|
||||
} from 'react'
|
||||
import { getRandomPairOfColors } from '@lib/colors'
|
||||
|
||||
interface Props {
|
||||
@@ -8,14 +15,19 @@ interface Props {
|
||||
}
|
||||
|
||||
const Avatar: FC<Props> = ({}) => {
|
||||
const [bg] = useState(getRandomPairOfColors)
|
||||
const [bg] = useState(useMemo(() => getRandomPairOfColors, []))
|
||||
const ref = useRef(null) as React.MutableRefObject<HTMLInputElement>
|
||||
|
||||
useEffect(() => {
|
||||
if (ref && ref.current) {
|
||||
ref.current.style.backgroundImage = `linear-gradient(140deg, ${bg[0]}, ${bg[1]} 100%)`
|
||||
}
|
||||
}, [bg])
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
className="inline-block h-8 w-8 rounded-full border-2 border-primary hover:border-secondary focus:border-secondary transition linear-out duration-150"
|
||||
style={{
|
||||
backgroundImage: `linear-gradient(140deg, ${bg[0]}, ${bg[1]} 100%)`,
|
||||
}}
|
||||
>
|
||||
{/* Add an image - We're generating a gradient as placeholder <img></img> */}
|
||||
</div>
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { FC } from 'react'
|
||||
import Link from 'next/link'
|
||||
import { getCategoryPath, getDesignerPath } from '@lib/search'
|
||||
import { Grid } from '@components/ui'
|
||||
import { ProductCard } from '@components/product'
|
||||
import s from './HomeAllProductsGrid.module.css'
|
||||
import { getCategoryPath, getDesignerPath } from '@lib/search'
|
||||
|
||||
interface Props {
|
||||
categories?: any
|
||||
|
Reference in New Issue
Block a user