select-plan-range.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import cn from '@/utils/classnames'
  6. export enum PlanRange {
  7. monthly = 'monthly',
  8. yearly = 'yearly',
  9. }
  10. type Props = {
  11. value: PlanRange
  12. onChange: (value: PlanRange) => void
  13. }
  14. const ITem: FC<{ isActive: boolean; value: PlanRange; text: string; onClick: (value: PlanRange) => void }> = ({ isActive, value, text, onClick }) => {
  15. return (
  16. <div
  17. className={cn(isActive ? 'bg-[#155EEF] text-white' : 'text-gray-900', 'flex items-center px-8 h-11 rounded-[32px] cursor-pointer text-[15px] font-medium')}
  18. onClick={() => onClick(value)}
  19. >
  20. {text}
  21. </div>
  22. )
  23. }
  24. const ArrowIcon = (
  25. <svg xmlns="http://www.w3.org/2000/svg" width="26" height="38" viewBox="0 0 26 38" fill="none">
  26. <path d="M20.5005 3.49991C23.5 18 18.7571 25.2595 2.92348 31.9599" stroke="#F26725" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
  27. <path d="M2.21996 32.2756L8.37216 33.5812" stroke="#F26725" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
  28. <path d="M2.22168 32.2764L3.90351 27.4459" stroke="#F26725" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
  29. </svg>
  30. )
  31. const SelectPlanRange: FC<Props> = ({
  32. value,
  33. onChange,
  34. }) => {
  35. const { t } = useTranslation()
  36. return (
  37. <div>
  38. <div className='mb-4 leading-[18px] text-sm font-medium text-[#F26725]'>{t('billing.plansCommon.yearlyTip')}</div>
  39. <div className='inline-flex relative p-1 rounded-full bg-[#F5F8FF] border border-black/5'>
  40. <ITem isActive={value === PlanRange.monthly} value={PlanRange.monthly} text={t('billing.plansCommon.planRange.monthly') as string} onClick={onChange} />
  41. <ITem isActive={value === PlanRange.yearly} value={PlanRange.yearly} text={t('billing.plansCommon.planRange.yearly') as string} onClick={onChange} />
  42. <div className='absolute right-0 top-[-16px] '>
  43. {ArrowIcon}
  44. </div>
  45. </div>
  46. </div>
  47. )
  48. }
  49. export default React.memo(SelectPlanRange)