UNPKG

@alauda/doom

Version:

Doctor Doom making docs.

15 lines (14 loc) 944 B
import { jsx as _jsx } from "react/jsx-runtime"; import { useCallback, useMemo } from 'react'; import { normalizeUrl } from 'x-fetch'; import { FormItem } from '../FormItem/index.js'; import { Input } from '../Input/index.js'; import { useTranslation } from '@alauda/doom/runtime'; export const CaptchaInput = ({ Component = Input, origin, captchaId, timestamp, onTimestampChange, ...props }) => { const t = useTranslation(); const captcha = useMemo(() => normalizeUrl(`${origin}/api/v1/captcha`, { captchaId, timestamp }), [origin, captchaId, timestamp]); const onRefresh = useCallback(() => { onTimestampChange(Date.now()); }, [onTimestampChange]); return (_jsx("div", { className: "captcha-input", children: _jsx(FormItem, { suffix: _jsx("img", { className: "captcha-input__captcha", src: captcha, onClick: onRefresh, alt: t('captcha') }), children: _jsx(Component, { name: "captchaValue", ...props }) }) })); };