index.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. 'use client'
  2. import type { FC } from 'react'
  3. import { InputNumber } from '../input-number'
  4. import Tooltip from '@/app/components/base/tooltip'
  5. import Slider from '@/app/components/base/slider'
  6. import Switch from '@/app/components/base/switch'
  7. type Props = {
  8. className?: string
  9. id: string
  10. name: string
  11. noTooltip?: boolean
  12. tip?: string
  13. value: number
  14. enable: boolean
  15. step?: number
  16. min?: number
  17. max: number
  18. onChange: (key: string, value: number) => void
  19. hasSwitch?: boolean
  20. onSwitchChange?: (key: string, enable: boolean) => void
  21. }
  22. const ParamItem: FC<Props> = ({ className, id, name, noTooltip, tip, step = 0.1, min = 0, max, value, enable, onChange, hasSwitch, onSwitchChange }) => {
  23. return (
  24. <div className={className}>
  25. <div className="flex items-center justify-between">
  26. <div className="flex h-6 items-center">
  27. {hasSwitch && (
  28. <Switch
  29. size='md'
  30. className='mr-2'
  31. defaultValue={enable}
  32. onChange={async (val) => {
  33. onSwitchChange?.(id, val)
  34. }}
  35. />
  36. )}
  37. <span className="system-sm-semibold mr-1 text-text-secondary">{name}</span>
  38. {!noTooltip && (
  39. <Tooltip
  40. triggerClassName='w-4 h-4 shrink-0'
  41. popupContent={<div className="w-[200px]">{tip}</div>}
  42. />
  43. )}
  44. </div>
  45. </div>
  46. <div className="mt-1 flex items-center">
  47. <div className="mr-3 flex shrink-0 items-center">
  48. <InputNumber
  49. disabled={!enable}
  50. type="number"
  51. min={min}
  52. max={max}
  53. step={step}
  54. amount={step}
  55. size='sm'
  56. value={value}
  57. onChange={(value) => {
  58. onChange(id, value)
  59. }}
  60. className='w-[72px]'
  61. />
  62. </div>
  63. <div className="flex grow items-center">
  64. <Slider
  65. className='w-full'
  66. disabled={!enable}
  67. value={max < 5 ? value * 100 : value}
  68. min={min < 1 ? min * 100 : min}
  69. max={max < 5 ? max * 100 : max}
  70. onChange={value => onChange(id, value / (max < 5 ? 100 : 1))}
  71. />
  72. </div>
  73. </div>
  74. </div>
  75. )
  76. }
  77. export default ParamItem