This commit is contained in:
Anton 2023-08-22 19:42:06 +02:00
parent a68d4951af
commit 24e8c984d8

View File

@ -4,8 +4,8 @@ import { Popup as LeafletPopup, useMap } from 'react-leaflet'
import { useEffect, useRef, useState } from 'react' import { useEffect, useRef, useState } from 'react'
import { useAddItem, useUpdateItem } from '../hooks/useItems' import { useAddItem, useUpdateItem } from '../hooks/useItems'
import { Geometry, LayerProps, Item, ItemsApi } from '../../../types' import { Geometry, LayerProps, Item, ItemsApi } from '../../../types'
import {TextAreaInput} from '../../Input/TextAreaInput' import { TextAreaInput } from '../../Input/TextAreaInput'
import {TextInput} from '../../Input/TextInput' import { TextInput } from '../../Input/TextInput'
export interface ItemFormPopupProps { export interface ItemFormPopupProps {
position: LatLng, position: LatLng,
@ -76,25 +76,28 @@ export function ItemFormPopup(props: ItemFormPopupProps) {
<LeafletPopup minWidth={275} maxWidth={275} autoPanPadding={[20, 5]} <LeafletPopup minWidth={275} maxWidth={275} autoPanPadding={[20, 5]}
eventHandlers={{ eventHandlers={{
remove: () => { remove: () => {
setTimeout(function() { setTimeout(function () {
resetPopup() resetPopup()
}, 100); }, 100);
} }
}} }}
position={props.position}> position={props.position}>
<form ref={formRef} onReset={resetPopup} onSubmit={e => handleSubmit(e)}> <form ref={formRef} onReset={resetPopup} onSubmit={e => handleSubmit(e)}>
<div className='tw-flex tw-justify-center'><b className="tw-text-xl tw-font-bold">New {props.layer.name}</b></div> {props.item ? <div className='tw-h-2'></div>
<TextInput type="text" placeholder="Name" dataField="name" defaultValue={props.item ? props.item.name : ""} inputStyle=''/> :
<div className='tw-flex tw-justify-center'><b className="tw-text-xl tw-font-bold">New {props.layer.name}</b></div>
}
<TextInput type="text" placeholder="Name" dataField="name" defaultValue={props.item ? props.item.name : ""} inputStyle='' />
{props.children ? {props.children ?
React.Children.toArray(props.children).map((child) => React.Children.toArray(props.children).map((child) =>
React.isValidElement<{ item: Item, test: string }>(child) ? React.isValidElement<{ item: Item, test: string }>(child) ?
React.cloneElement(child, { item: props.item}) : "" React.cloneElement(child, { item: props.item }) : ""
) )
: :
<> <>
<TextAreaInput placeholder="Text" dataField="text" defaultValue={props.item ? props.item.text : ""} inputStyle='tw-h-40 tw-mt-5' /> <TextAreaInput placeholder="Text" dataField="text" defaultValue={props.item ? props.item.text : ""} inputStyle='tw-h-40 tw-mt-5' />
</> </>