-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
92 lines (83 loc) · 2.63 KB
/
index.tsx
File metadata and controls
92 lines (83 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { Feature, Geometry } from 'geojson'
import { Checkbox, Form, Input } from 'antd'
import { useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { BackdropProps } from '../../types'
import './index.css'
export interface BackdropFormProps {
backdrop: Feature<Geometry, BackdropProps>
onChange: (backdrop: Feature<Geometry, BackdropProps>) => void
create?: boolean
}
export const BackdropForm: React.FC<BackdropFormProps> = ({backdrop, onChange, create = false}) => {
const { t } = useTranslation()
const [state, setState] = useState<BackdropProps | null>(null)
const [form] = Form.useForm()
useEffect(() => {
if (backdrop && form) {
const dupe = {...backdrop.properties}
setState(dupe)
form.setFieldsValue(dupe)
}
}, [backdrop, setState, form])
const localChange = (values: Partial<BackdropProps>) => {
const dupe = {...values} as unknown as BackdropProps
const updatedProps= {...state, ...dupe} as BackdropProps
const res = {...backdrop, properties: updatedProps}
onChange(res)
}
if (!state) {
return null
}
const itemStyle = { marginBottom: '0.5em' }
return (
<Form
form={form}
name='backdropForm'
className="propertiesForm"
labelCol={{ span: 7 }}
wrapperCol={{ span: 17 }}
style={{ maxWidth: 400 }}
initialValues={state}
autoComplete='off'
onValuesChange={localChange}
size='small'>
<Form.Item<BackdropProps>
label={t('forms.common.name')}
name='name'
style={itemStyle}
rules={[{ required: true, message: t('forms.common.nameRequired') }]}>
<Input/>
</Form.Item>
<Form.Item<BackdropProps>
label={t('forms.common.visible')}
name={'visible'}
style={itemStyle}
valuePropName="checked" >
<Checkbox />
</Form.Item>
{ create && <><Form.Item<BackdropProps>
label={t('forms.common.url')}
name='url'
style={itemStyle}
rules={[{ required: true, message: t('forms.common.urlRequired') }]}>
<Input.TextArea rows={3}/>
</Form.Item>
<Form.Item<BackdropProps>
label={t('forms.common.maxNativeZoom')}
name= 'maxNativeZoom'
style={itemStyle}
rules={[{ required: true, message: t('forms.common.maxNativeZoomRequired') }]}>
<Input/>
</Form.Item>
<Form.Item<BackdropProps>
label={t('forms.common.maxZoom')}
name='maxZoom'
style={itemStyle}
rules={[{ required: true, message: t('forms.common.maxZoomRequired') }]}>
<Input/>
</Form.Item>
</>}
</Form>
)
}