index.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. 'use client'
  2. import type { FC } from 'react'
  3. import { HelpCircle } from '@/app/components/base/icons/src/vender/line/general'
  4. import Tooltip from '@/app/components/base/tooltip-plus'
  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 h-8 justify-between">
  26. <div className="flex items-center">
  27. {hasSwitch && (
  28. <Switch
  29. size='md'
  30. defaultValue={enable}
  31. onChange={async (val) => {
  32. onSwitchChange?.(id, val)
  33. }}
  34. />
  35. )}
  36. <span className="mx-1 text-gray-900 text-[13px] leading-[18px] font-medium">{name}</span>
  37. {!noTooltip && (
  38. <Tooltip popupContent={<div className="w-[200px]">{tip}</div>}>
  39. <HelpCircle className='w-[14px] h-[14px] text-gray-400' />
  40. </Tooltip>
  41. )}
  42. </div>
  43. <div className="flex items-center"></div>
  44. </div>
  45. <div className="mt-2 flex items-center">
  46. <div className="mr-4 flex shrink-0 items-center">
  47. <input disabled={!enable} type="number" min={min} max={max} step={step} className="block w-[48px] h-7 text-xs leading-[18px] rounded-lg border-0 pl-1 pl py-1.5 bg-gray-50 text-gray-900 placeholder:text-gray-400 focus:ring-1 focus:ring-inset focus:ring-primary-600 disabled:opacity-60" value={value} onChange={(e) => {
  48. const value = parseFloat(e.target.value)
  49. if (value < min || value > max)
  50. return
  51. onChange(id, value)
  52. }} />
  53. </div>
  54. <div className="flex items-center h-7 grow">
  55. <Slider
  56. className='w-full'
  57. disabled={!enable}
  58. value={max < 5 ? value * 100 : value}
  59. min={min < 1 ? min * 100 : min}
  60. max={max < 5 ? max * 100 : max}
  61. onChange={value => onChange(id, value / (max < 5 ? 100 : 1))}
  62. />
  63. </div>
  64. </div>
  65. </div>
  66. )
  67. }
  68. export default ParamItem