dify/web/app/components/plugins/plugin-detail-panel/strategy-item.tsx

53 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-12-25 12:56:36 +08:00
'use client'
import React, { useState } from 'react'
import { useContext } from 'use-context-selector'
2024-12-25 15:15:41 +08:00
import StrategyDetailPanel from './strategy-detail'
2024-12-25 12:56:36 +08:00
import type {
StrategyDetail,
} from '@/app/components/plugins/types'
2024-12-25 15:15:41 +08:00
import type { Locale } from '@/i18n'
2024-12-25 12:56:36 +08:00
import I18n from '@/context/i18n'
import { getLanguage } from '@/i18n/language'
import cn from '@/utils/classnames'
type Props = {
2024-12-25 15:15:41 +08:00
provider: {
author: string
name: string
description: Record<Locale, string>
icon: string
label: Record<Locale, string>
tags: string[]
}
2024-12-25 12:56:36 +08:00
detail: StrategyDetail
}
const StrategyItem = ({
2024-12-25 15:15:41 +08:00
provider,
2024-12-25 12:56:36 +08:00
detail,
}: Props) => {
const { locale } = useContext(I18n)
const language = getLanguage(locale)
const [showDetail, setShowDetail] = useState(false)
return (
<>
<div
className={cn('mb-2 px-4 py-3 bg-components-panel-item-bg rounded-xl border-[0.5px] border-components-panel-border-subtle shadow-xs cursor-pointer hover:bg-components-panel-on-panel-item-bg-hover')}
onClick={() => setShowDetail(true)}
>
<div className='pb-0.5 text-text-secondary system-md-semibold'>{detail.identity.label[language]}</div>
<div className='text-text-tertiary system-xs-regular line-clamp-2' title={detail.description[language]}>{detail.description[language]}</div>
</div>
2024-12-25 15:15:41 +08:00
{showDetail && (
<StrategyDetailPanel
provider={provider}
detail={detail}
onHide={() => setShowDetail(false)}
/>
)}
2024-12-25 12:56:36 +08:00
</>
)
}
export default StrategyItem