index.tsx 2.2 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 items-center h-6">
  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="mr-1 text-text-secondary system-sm-semibold">{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. size='sm'
  55. value={value}
  56. onChange={(value) => {
  57. onChange(id, value)
  58. }}
  59. className='w-[72px]'
  60. />
  61. </div>
  62. <div className="flex items-center grow">
  63. <Slider
  64. className='w-full'
  65. disabled={!enable}
  66. value={max < 5 ? value * 100 : value}
  67. min={min < 1 ? min * 100 : min}
  68. max={max < 5 ? max * 100 : max}
  69. onChange={value => onChange(id, value / (max < 5 ? 100 : 1))}
  70. />
  71. </div>
  72. </div>
  73. </div>
  74. )
  75. }
  76. export default ParamItem