mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2025-02-11 02:51:43 +08:00
52 lines
1.1 KiB
TypeScript
52 lines
1.1 KiB
TypeScript
import { useNavigate } from 'react-router-dom'
|
|
import cx from 'classnames'
|
|
|
|
const ArtistInline = ({
|
|
artists,
|
|
className,
|
|
disableLink,
|
|
onClick,
|
|
}: {
|
|
artists: Artist[]
|
|
className?: string
|
|
disableLink?: boolean
|
|
onClick?: (artistId: number) => void
|
|
}) => {
|
|
if (!artists) return <div></div>
|
|
|
|
const navigate = useNavigate()
|
|
const handleClick = (id: number) => {
|
|
if (id === 0 || disableLink) return
|
|
if (!onClick) {
|
|
navigate(`/artist/${id}`)
|
|
} else {
|
|
onClick(id)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div
|
|
className={cx(
|
|
!className?.includes('line-clamp') && 'line-clamp-1',
|
|
className
|
|
)}
|
|
>
|
|
{artists.map((artist, index) => (
|
|
<span key={`${artist.id}-${artist.name}`}>
|
|
<span
|
|
onClick={() => handleClick(artist.id)}
|
|
className={cx({
|
|
'hover:underline': !!artist.id && !disableLink,
|
|
})}
|
|
>
|
|
{artist.name}
|
|
</span>
|
|
{index < artists.length - 1 ? ', ' : ''}
|
|
</span>
|
|
))}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default ArtistInline
|