index.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import cn from '@/utils/classnames'
  5. type Option = {
  6. value: string
  7. text: string | React.JSX.Element
  8. }
  9. type ItemProps = {
  10. className?: string
  11. isActive: boolean
  12. onClick: (v: string) => void
  13. option: Option
  14. smallItem?: boolean
  15. }
  16. const Item: FC<ItemProps> = ({
  17. className,
  18. isActive,
  19. onClick,
  20. option,
  21. smallItem,
  22. }) => {
  23. return (
  24. <div
  25. key={option.value}
  26. className={cn(
  27. 'relative pb-2.5 ',
  28. !isActive && 'cursor-pointer',
  29. smallItem ? 'system-sm-semibold-uppercase' : 'system-xl-semibold',
  30. className,
  31. )}
  32. onClick={() => !isActive && onClick(option.value)}
  33. >
  34. <div className={cn(isActive ? 'text-text-primary' : 'text-text-tertiary')}>{option.text}</div>
  35. {isActive && (
  36. <div className='absolute bottom-0 left-0 right-0 h-0.5 bg-util-colors-blue-brand-blue-brand-600'></div>
  37. )}
  38. </div>
  39. )
  40. }
  41. type Props = {
  42. className?: string
  43. value: string
  44. onChange: (v: string) => void
  45. options: Option[]
  46. noBorderBottom?: boolean
  47. smallItem?: boolean
  48. itemClassName?: string
  49. }
  50. const TabSlider: FC<Props> = ({
  51. className,
  52. value,
  53. onChange,
  54. options,
  55. noBorderBottom,
  56. itemClassName,
  57. smallItem,
  58. }) => {
  59. return (
  60. <div className={cn(className, !noBorderBottom && 'border-b border-divider-subtle', 'flex space-x-6')}>
  61. {options.map(option => (
  62. <Item
  63. isActive={option.value === value}
  64. option={option}
  65. onClick={onChange}
  66. key={option.value}
  67. className={itemClassName}
  68. smallItem={smallItem}
  69. />
  70. ))}
  71. </div>
  72. )
  73. }
  74. export default React.memo(TabSlider)