strategy-item.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 'use client'
  2. import React, { useState } from 'react'
  3. import StrategyDetailPanel from './strategy-detail'
  4. import type {
  5. StrategyDetail,
  6. } from '@/app/components/plugins/types'
  7. import type { Locale } from '@/i18n'
  8. import { useRenderI18nObject } from '@/hooks/use-i18n'
  9. import cn from '@/utils/classnames'
  10. type Props = {
  11. provider: {
  12. author: string
  13. name: string
  14. description: Record<Locale, string>
  15. tenant_id: string
  16. icon: string
  17. label: Record<Locale, string>
  18. tags: string[]
  19. }
  20. detail: StrategyDetail
  21. }
  22. const StrategyItem = ({
  23. provider,
  24. detail,
  25. }: Props) => {
  26. const getValueFromI18nObject = useRenderI18nObject()
  27. const [showDetail, setShowDetail] = useState(false)
  28. return (
  29. <>
  30. <div
  31. 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')}
  32. onClick={() => setShowDetail(true)}
  33. >
  34. <div className='pb-0.5 text-text-secondary system-md-semibold'>{getValueFromI18nObject(detail.identity.label)}</div>
  35. <div className='text-text-tertiary system-xs-regular line-clamp-2' title={getValueFromI18nObject(detail.description)}>{getValueFromI18nObject(detail.description)}</div>
  36. </div>
  37. {showDetail && (
  38. <StrategyDetailPanel
  39. provider={provider}
  40. detail={detail}
  41. onHide={() => setShowDetail(false)}
  42. />
  43. )}
  44. </>
  45. )
  46. }
  47. export default StrategyItem