Files
dify/web/app/device/components/code-input.tsx
Yunlu Wen a728e0ac69 feat: adding dify cli (#36348)
Co-authored-by: GareArc <garethcxy@dify.ai>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: L1nSn0w <l1nsn0w@qq.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: gigglewang <gigglewang@dify.ai>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Xiyuan Chen <52963600+GareArc@users.noreply.github.com>
2026-05-26 01:12:36 +00:00

46 lines
1.3 KiB
TypeScript

'use client'
import type { FC } from 'react'
import { useCallback } from 'react'
import { normaliseUserCodeInput } from '../utils/user-code'
type Props = {
value: string
onChange: (normalised: string) => void
disabled?: boolean
autoFocus?: boolean
}
/**
* CodeInput renders the user_code text field with live normalisation
* (uppercase, reduced alphabet, XXXX-XXXX hyphenation).
*
* The onChange callback receives the normalised value only — the parent does
* not need to run validation itself.
*/
const CodeInput: FC<Props> = ({ value, onChange, disabled, autoFocus }) => {
const handle = useCallback((raw: string) => {
onChange(normaliseUserCodeInput(raw))
}, [onChange])
return (
<input
type="text"
inputMode="text"
autoCapitalize="characters"
autoComplete="off"
spellCheck={false}
placeholder="ABCD-1234"
maxLength={9}
aria-label="one-time code"
className="border-components-input-border-normal w-full rounded-lg border bg-components-input-bg-normal px-4 py-3 text-center font-mono text-2xl tracking-wider text-text-primary focus:border-components-input-border-active focus:outline-none"
value={value}
disabled={disabled}
autoFocus={autoFocus}
onChange={e => handle(e.target.value)}
/>
)
}
export default CodeInput