Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

1.9 KB
Raw Blame
import type { FC } from 'react'

type InputProps = {
  id?: string
  value?: string
  onChange: (v: string) => void
  onFocus?: () => void
  placeholder?: string
  validated?: boolean
  className?: string
  disabled?: boolean
  type?: string
  min?: number
  max?: number
}

const Input: FC<InputProps> = ({
  id,
  value,
  onChange,
  onFocus,
  placeholder,
  validated,
  className,
  disabled,
  type = 'text',
  min,
  max,
}) => {
  const toLimit = (v: string) => {
    const minNum = Number.parseFloat(`${min}`)
    const maxNum = Number.parseFloat(`${max}`)
    if (!Number.isNaN(minNum) && Number.parseFloat(v) < minNum) {
      onChange(`${min}`)
      return
    }
    if (!Number.isNaN(maxNum) && Number.parseFloat(v) > maxNum) onChange(`${max}`)
  }

  return (
    <div className="relative">
      <input
        id={id}
        tabIndex={0}
        // Do not set autoComplete for security - prevents browser from storing sensitive API keys
        className={`block h-8 w-full appearance-none rounded-lg border border-transparent bg-components-input-bg-normal px-3 text-sm text-components-input-text-filled caret-primary-600 outline-hidden placeholder:text-sm placeholder:text-text-tertiary hover:border-components-input-border-hover hover:bg-components-input-bg-hover focus:border-components-input-border-active focus:bg-components-input-bg-active focus:shadow-xs ${validated ? 'pe-7.5' : ''} ${className || ''} `}
        placeholder={placeholder || ''}
        onChange={(e) => onChange(e.target.value)}
        onBlur={(e) => toLimit(e.target.value)}
        onFocus={onFocus}
        value={value}
        disabled={disabled}
        type={type}
        min={min}
        max={max}
      />
      {validated && (
        <div className="absolute inset-e-2.5 top-2.5">
          <span
            aria-hidden
            className="i-custom-vender-solid-general-check-circle h-4 w-4 text-[#039855]"
          />
        </div>
      )}
    </div>
  )
}

export default Input