domain-watchdog/assets/components/search/DomainSearchBar.tsx

50 lines
1.5 KiB
TypeScript
Raw Permalink Normal View History

2024-12-30 23:50:15 +01:00
import {Form, Input} from 'antd'
import {t} from 'ttag'
import {SearchOutlined} from '@ant-design/icons'
2025-01-01 14:10:23 +01:00
import React, {useState} from 'react'
2024-12-30 23:50:15 +01:00
export interface FieldType {
ldhName: string
2025-01-01 14:10:23 +01:00
isRefreshForced: boolean
}
2024-12-30 23:50:15 +01:00
export function DomainSearchBar({onFinish, initialValue}: {
onFinish: (values: FieldType) => void,
initialValue?: string
}) {
2025-01-01 14:10:23 +01:00
const [isRefreshForced, setRefreshForced] = useState(false)
2024-12-30 23:50:15 +01:00
return (
<Form
2025-01-01 14:10:23 +01:00
onFinish={({ldhName}: FieldType) => onFinish({ldhName, isRefreshForced})}
2024-12-30 23:50:15 +01:00
autoComplete='off'
style={{width: '100%'}}
>
2024-12-30 23:50:15 +01:00
<Form.Item<FieldType>
name='ldhName'
initialValue={initialValue}
rules={[{
required: true,
message: t`Required`
}, {
pattern: /^(?=.*\.)?\S*[^.\s]$/,
message: t`This domain name does not appear to be valid`,
max: 63,
min: 2
}]}
>
<Input
style={{textAlign: 'center'}}
size='large'
2025-01-01 14:10:23 +01:00
onKeyDown={e => setRefreshForced(e.shiftKey)}
onKeyUp={e => setRefreshForced(e.shiftKey)}
2024-12-30 23:50:15 +01:00
prefix={<SearchOutlined/>}
placeholder='example.com'
autoComplete='off'
autoFocus
/>
</Form.Item>
</Form>
)
}