title-description-input.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import {
  2. memo,
  3. useCallback,
  4. useState,
  5. } from 'react'
  6. import Textarea from 'rc-textarea'
  7. import { useTranslation } from 'react-i18next'
  8. type TitleInputProps = {
  9. value: string
  10. onBlur: (value: string) => void
  11. }
  12. export const TitleInput = memo(({
  13. value,
  14. onBlur,
  15. }: TitleInputProps) => {
  16. const { t } = useTranslation()
  17. const [localValue, setLocalValue] = useState(value)
  18. const handleBlur = () => {
  19. if (!localValue) {
  20. setLocalValue(value)
  21. onBlur(value)
  22. return
  23. }
  24. onBlur(localValue)
  25. }
  26. return (
  27. <input
  28. value={localValue}
  29. onChange={e => setLocalValue(e.target.value)}
  30. className={`
  31. grow mr-2 px-1 h-7 text-text-primary system-xl-semibold rounded-md border border-transparent appearance-none outline-none
  32. focus:shadow-xs min-w-0
  33. `}
  34. placeholder={t('workflow.common.addTitle') || ''}
  35. onBlur={handleBlur}
  36. />
  37. )
  38. })
  39. TitleInput.displayName = 'TitleInput'
  40. type DescriptionInputProps = {
  41. value: string
  42. onChange: (value: string) => void
  43. }
  44. export const DescriptionInput = memo(({
  45. value,
  46. onChange,
  47. }: DescriptionInputProps) => {
  48. const { t } = useTranslation()
  49. const [focus, setFocus] = useState(false)
  50. const handleFocus = useCallback(() => {
  51. setFocus(true)
  52. }, [])
  53. const handleBlur = useCallback(() => {
  54. setFocus(false)
  55. }, [])
  56. return (
  57. <div
  58. className={`
  59. group flex px-2 py-[5px] max-h-[60px] rounded-lg overflow-y-auto
  60. leading-0 bg-components-panel-bg
  61. ${focus && '!shadow-xs'}
  62. `}
  63. >
  64. <Textarea
  65. value={value}
  66. onChange={e => onChange(e.target.value)}
  67. rows={1}
  68. onFocus={handleFocus}
  69. onBlur={handleBlur}
  70. className={`
  71. w-full text-xs text-gray-900 leading-[18px] bg-transparent
  72. appearance-none outline-none resize-none
  73. placeholder:text-gray-400 caret-[#295EFF]
  74. `}
  75. placeholder={t('workflow.common.addDescription') || ''}
  76. autoSize
  77. />
  78. </div>
  79. )
  80. })
  81. DescriptionInput.displayName = 'DescriptionInput'