YesPlayMusic/packages/renderer/src/components/Cover.tsx

56 lines
1.9 KiB
TypeScript
Raw Normal View History

2022-03-13 14:40:38 +08:00
import SvgIcon from '@/components/SvgIcon'
const Cover = ({
isRounded,
imageUrl,
onClick,
}: {
imageUrl: string
isRounded?: boolean
onClick?: () => void
}) => {
const [isError, setIsError] = useState(false)
return (
2022-03-17 19:30:43 +08:00
<div onClick={onClick} className='group relative z-0'>
2022-03-13 14:40:38 +08:00
{/* Neon shadow */}
<div
className={classNames(
'absolute top-2 z-[-1] h-full w-full scale-x-[.92] scale-y-[.96] rounded-xl bg-cover opacity-0 blur-lg filter transition duration-300 group-hover:opacity-60',
isRounded && 'rounded-full',
!isRounded && 'rounded-xl'
)}
style={{
backgroundImage: `url("${imageUrl}")`,
}}
></div>
{/* Cover */}
{isError ? (
2022-03-17 19:30:43 +08:00
<div className='box-content flex aspect-square h-full w-full items-center justify-center rounded-xl border border-black border-opacity-5 bg-gray-800 text-gray-300'>
<SvgIcon name='music-note' className='h-1/2 w-1/2' />
2022-03-13 14:40:38 +08:00
</div>
) : (
<img
className={classNames(
'box-content aspect-square h-full w-full border border-black border-opacity-5 dark:border-white dark:border-opacity-[.03]',
isRounded && 'rounded-full',
!isRounded && 'rounded-xl'
)}
src={imageUrl}
onError={() => setIsError(true)}
/>
)}
{/* Play button */}
2022-03-17 19:30:43 +08:00
<div className='absolute top-0 hidden h-full w-full place-content-center group-hover:grid'>
<button className='btn-pressed-animation grid h-11 w-11 cursor-default place-content-center rounded-full border border-white border-opacity-[.08] bg-white bg-opacity-[.14] text-white backdrop-blur backdrop-filter transition-all hover:bg-opacity-[.44]'>
2022-03-21 02:03:25 +08:00
<SvgIcon className='ml-0.5 h-6 w-6' name='play-fill' />
2022-03-13 14:40:38 +08:00
</button>
</div>
</div>
)
}
export default Cover