YesPlayMusic/src/renderer/components/Cover.tsx

65 lines
2.1 KiB
TypeScript
Raw Normal View History

2022-04-09 00:28:37 +08:00
import SvgIcon from '@/renderer/components/SvgIcon'
2022-03-13 14:40:38 +08:00
const Cover = ({
imageUrl,
onClick,
2022-03-29 00:11:05 +08:00
roundedClass = 'rounded-xl',
showPlayButton = false,
showHover = true,
2022-04-08 01:02:25 +08:00
alwaysShowShadow = false,
2022-03-13 14:40:38 +08:00
}: {
imageUrl: string
onClick?: () => void
2022-03-29 00:11:05 +08:00
roundedClass?: string
showPlayButton?: boolean
showHover?: boolean
2022-04-08 01:02:25 +08:00
alwaysShowShadow?: boolean
2022-03-13 14:40:38 +08:00
}) => {
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 */}
2022-03-29 00:11:05 +08:00
{showHover && (
<div
className={classNames(
2022-04-08 01:02:25 +08:00
'absolute top-2 z-[-1] h-full w-full scale-x-[.92] scale-y-[.96] bg-cover blur-lg filter transition duration-300 ',
roundedClass,
!alwaysShowShadow && 'opacity-0 group-hover:opacity-60'
2022-03-29 00:11:05 +08:00
)}
style={{
backgroundImage: `url("${imageUrl}")`,
}}
></div>
)}
2022-03-13 14:40:38 +08:00
{/* Cover */}
{isError ? (
2022-04-08 01:02:25 +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 '>
2022-03-17 19:30:43 +08:00
<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]',
2022-03-29 00:11:05 +08:00
roundedClass
2022-03-13 14:40:38 +08:00
)}
src={imageUrl}
2022-03-29 00:11:05 +08:00
onError={() => imageUrl && setIsError(true)}
2022-03-13 14:40:38 +08:00
/>
)}
{/* Play button */}
2022-03-29 00:11:05 +08:00
{showPlayButton && (
<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]'>
<SvgIcon className='ml-0.5 h-6 w-6' name='play-fill' />
</button>
</div>
)}
2022-03-13 14:40:38 +08:00
</div>
)
}
export default Cover