index.tsx 2.5 KB

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