4
0
forked from crowetic/commerce
This commit is contained in:
Belen Curcio 2020-10-14 13:13:46 -03:00
parent ced85970f8
commit 45b191c6bb
2 changed files with 23 additions and 8 deletions

View File

@ -1,2 +0,0 @@
.root {
}

View File

@ -1,22 +1,39 @@
import cn from 'classnames' import cn from 'classnames'
import { FC } from 'react' import { FC } from 'react'
import s from './Avatar.module.css' import { random } from 'lodash'
import { useState } from 'react'
interface Props { interface Props {
className?: string className?: string
children?: any children?: any
} }
const Avatar: FC<Props> = ({ className }) => { function getRandomPairOfColors() {
const rootClassName = cn(s.root, className) const colors = ['#f33', '#7928ca', '#50e3c2', '#7928ca', '#7928CA']
const getRandomIdx = () => random(0, colors.length - 1)
let idx = getRandomIdx()
let idx2 = getRandomIdx()
// Has to be a different color
while (idx2 === idx) {
idx2 = getRandomIdx()
}
// Returns a pair of colors
return [colors[idx], colors[idx2]]
}
const Avatar: FC<Props> = ({}) => {
const [bg] = useState(getRandomPairOfColors)
return ( return (
<div <div
className="inline-block h-8 w-8 rounded-full border border-accent" className="inline-block h-8 w-8 rounded-full border border-accent"
style={{ style={{
backgroundImage: 'linear-gradient(160deg, #F9CB28, #FF4D4D 100%)', backgroundImage: `linear-gradient(140deg, ${bg[0]}, ${bg[1]} 100%)`,
}} }}
> >
{/* <img></img> */} {/* Add an image - We're generating a gradient as placeholder
<img></img> */}
</div> </div>
) )
} }