66 lines
1.9 KiB
TypeScript
Raw Normal View History

2022-03-13 14:40:38 +08:00
import { average } from 'color.js'
import { colord } from 'colord'
import SvgIcon from '@/components/SvgIcon'
enum ACTION {
DISLIKE = 'dislike',
PLAY = 'play',
NEXT = 'next',
}
const FMCard = () => {
const coverUrl =
'https://p1.music.126.net/lEzPSOjusKaRXKXT3987lQ==/109951166035876388.jpg?param=512y512'
const [background, setBackground] = useState('')
useEffect(() => {
average(coverUrl, { amount: 1, format: 'hex', sample: 1 }).then(color => {
const to = colord(color as string)
.darken(0.15)
.rotate(-5)
.toHex()
setBackground(`linear-gradient(to bottom right, ${color}, ${to})`)
})
}, [coverUrl])
return (
<div
2022-03-17 19:30:43 +08:00
className='relative flex h-[198px] overflow-hidden rounded-2xl p-4'
2022-03-13 14:40:38 +08:00
style={{ background }}
>
2022-03-17 19:30:43 +08:00
<img className='rounded-lg shadow-2xl' src={coverUrl} />
2022-03-13 14:40:38 +08:00
2022-03-17 19:30:43 +08:00
<div className='ml-5 flex w-full flex-col justify-between text-white'>
2022-03-13 14:40:38 +08:00
{/* Track info */}
<div>
2022-03-17 19:30:43 +08:00
<div className='text-xl font-semibold'>How Can I Make It OK?</div>
<div className='opacity-75'>Wolf Alice</div>
2022-03-13 14:40:38 +08:00
</div>
2022-03-21 02:03:25 +08:00
<div className='-mb-1 flex items-center justify-between'>
2022-03-13 14:40:38 +08:00
{/* Actions */}
<div>
{Object.values(ACTION).map(action => (
<button
key={action}
2022-03-21 02:03:25 +08:00
className='btn-pressed-animation btn-hover-animation mr-1 cursor-default rounded-lg p-1.5 transition duration-200 after:bg-white/10'
2022-03-13 14:40:38 +08:00
>
2022-03-21 02:03:25 +08:00
<SvgIcon name={action} className='h-6 w-6' />
2022-03-13 14:40:38 +08:00
</button>
))}
</div>
{/* FM logo */}
2022-03-17 19:30:43 +08:00
<div className='right-4 bottom-5 flex text-white opacity-20'>
2022-03-21 02:03:25 +08:00
<SvgIcon name='fm' className='mr-1 h-6 w-6' />
2022-03-17 19:30:43 +08:00
<span className='font-semibold'>FM</span>
2022-03-13 14:40:38 +08:00
</div>
</div>
</div>
</div>
)
}
export default FMCard