2025-02-19 10:56:18 +08:00
|
|
|
import React, { type FC, useEffect, useRef } from 'react'
|
|
|
|
import cn from '@/utils/classnames'
|
|
|
|
|
|
|
|
type OptionListItemProps = {
|
|
|
|
isSelected: boolean
|
|
|
|
onClick: () => void
|
|
|
|
} & React.LiHTMLAttributes<HTMLLIElement>
|
|
|
|
|
|
|
|
const OptionListItem: FC<OptionListItemProps> = ({
|
|
|
|
isSelected,
|
|
|
|
onClick,
|
|
|
|
children,
|
|
|
|
}) => {
|
|
|
|
const listItemRef = useRef<HTMLLIElement>(null)
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (isSelected)
|
|
|
|
listItemRef.current?.scrollIntoView({ behavior: 'instant' })
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
return (
|
|
|
|
<li
|
|
|
|
ref={listItemRef}
|
|
|
|
className={cn(
|
2025-03-21 17:41:03 +08:00
|
|
|
'system-xs-medium flex cursor-pointer items-center justify-center rounded-md px-1.5 py-1 text-components-button-ghost-text',
|
2025-02-19 10:56:18 +08:00
|
|
|
isSelected ? 'bg-components-button-ghost-bg-hover' : 'hover:bg-components-button-ghost-bg-hover',
|
|
|
|
)}
|
|
|
|
onClick={() => {
|
|
|
|
listItemRef.current?.scrollIntoView({ behavior: 'smooth' })
|
|
|
|
onClick()
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</li>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default React.memo(OptionListItem)
|