mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-05-26 08:08:17 +08:00

Co-authored-by: NFish <douxc512@gmail.com> Co-authored-by: zxhlyh <jasonapring2015@outlook.com> Co-authored-by: twwu <twwu@dify.ai> Co-authored-by: jZonG <jzongcode@gmail.com>
39 lines
987 B
TypeScript
39 lines
987 B
TypeScript
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(
|
|
'system-xs-medium flex cursor-pointer items-center justify-center rounded-md px-1.5 py-1 text-components-button-ghost-text',
|
|
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)
|