2023-05-29 06:37:34 +02:00
|
|
|
import { useState } from 'react';
|
|
|
|
import { useMessages } from 'hooks';
|
2023-06-23 10:19:08 +02:00
|
|
|
import { Button, Form, FormRow, TextField, Flexbox } from 'react-basics';
|
2023-06-03 08:10:59 +02:00
|
|
|
import styles from './UrlAddForm.module.css';
|
2023-07-02 07:02:49 +02:00
|
|
|
import PopupForm from '../PopupForm';
|
2023-05-29 06:37:34 +02:00
|
|
|
|
2023-07-02 07:02:49 +02:00
|
|
|
export function UrlAddForm({ defaultValue = '', element, onAdd, onClose }) {
|
2023-05-29 06:37:34 +02:00
|
|
|
const [url, setUrl] = useState(defaultValue);
|
|
|
|
const { formatMessage, labels } = useMessages();
|
|
|
|
|
2023-07-02 07:02:49 +02:00
|
|
|
const handleSave = () => {
|
|
|
|
onAdd(url);
|
2023-05-29 06:37:34 +02:00
|
|
|
setUrl('');
|
|
|
|
onClose();
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleChange = e => {
|
|
|
|
setUrl(e.target.value);
|
|
|
|
};
|
|
|
|
|
2023-07-02 07:02:49 +02:00
|
|
|
const handleKeyDown = e => {
|
|
|
|
if (e.key === 'Enter') {
|
|
|
|
e.stopPropagation();
|
|
|
|
handleSave();
|
|
|
|
}
|
2023-06-23 10:19:08 +02:00
|
|
|
};
|
|
|
|
|
2023-07-02 07:02:49 +02:00
|
|
|
return (
|
|
|
|
<PopupForm element={element}>
|
|
|
|
<Form>
|
|
|
|
<FormRow label={formatMessage(labels.url)}>
|
|
|
|
<Flexbox gap={10}>
|
|
|
|
<TextField
|
|
|
|
className={styles.input}
|
|
|
|
value={url}
|
|
|
|
onChange={handleChange}
|
|
|
|
autoFocus={true}
|
|
|
|
autoComplete="off"
|
|
|
|
onKeyDown={handleKeyDown}
|
|
|
|
/>
|
|
|
|
<Button variant="primary" onClick={handleSave}>
|
|
|
|
{formatMessage(labels.add)}
|
|
|
|
</Button>
|
|
|
|
</Flexbox>
|
|
|
|
</FormRow>
|
|
|
|
</Form>
|
|
|
|
</PopupForm>
|
2023-05-29 06:37:34 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-06-03 08:10:59 +02:00
|
|
|
export default UrlAddForm;
|