index.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import cn from '@/utils/classnames'
  5. type Props = {
  6. className?: string
  7. icon: React.ReactNode
  8. iconBgClassName?: string
  9. title: React.ReactNode
  10. description: string
  11. noRadio?: boolean
  12. isChosen?: boolean
  13. onChosen?: () => void
  14. chosenConfig?: React.ReactNode
  15. chosenConfigWrapClassName?: string
  16. }
  17. const RadioCard: FC<Props> = ({
  18. icon,
  19. iconBgClassName = 'bg-[#F5F3FF]',
  20. title,
  21. description,
  22. noRadio,
  23. isChosen,
  24. onChosen = () => { },
  25. chosenConfig,
  26. chosenConfigWrapClassName,
  27. }) => {
  28. return (
  29. <div
  30. className={cn(
  31. 'border border-components-option-card-option-border bg-components-option-card-option-bg rounded-xl hover:shadow-xs cursor-pointer',
  32. isChosen && 'bg-components-option-card-option-selected-bg border-components-panel-border shadow-xs',
  33. )}
  34. >
  35. <div className='flex py-3 pl-3 pr-4' onClick={onChosen}>
  36. <div className={cn(iconBgClassName, 'mr-3 shrink-0 flex w-8 justify-center h-8 items-center rounded-lg')}>
  37. {icon}
  38. </div>
  39. <div className='grow'>
  40. <div className='leading-5 text-sm font-medium text-gray-900'>{title}</div>
  41. <div className='leading-[18px] text-xs font-normal text-[#667085]'>{description}</div>
  42. </div>
  43. {!noRadio && (
  44. <div className='shrink-0 flex items-center h-8'>
  45. <div className={cn(
  46. 'w-4 h-4 border border-components-radio-border bg-components-radio-bg shadow-xs rounded-full',
  47. isChosen && 'border-[5px] border-components-radio-border-checked',
  48. )}></div>
  49. </div>
  50. )}
  51. </div>
  52. {((isChosen && chosenConfig) || noRadio) && (
  53. <div className={cn(chosenConfigWrapClassName, 'p-3 border-t border-gray-200')}>
  54. {chosenConfig}
  55. </div>
  56. )}
  57. </div>
  58. )
  59. }
  60. export default React.memo(RadioCard)