2020-03-16 16:01:05 +01:00
|
|
|
import React, { useState } from "react";
|
|
|
|
import PropTypes from "prop-types";
|
|
|
|
import {
|
|
|
|
Portal,
|
|
|
|
Dialog,
|
|
|
|
Button,
|
|
|
|
TextInput,
|
|
|
|
} from "react-native-paper";
|
|
|
|
|
|
|
|
export default function InputDialog({ visible, onOK, onDismiss, title, label, placeholder }) {
|
|
|
|
const [ text, setText ] = useState("");
|
2020-03-30 10:23:24 +02:00
|
|
|
const [ error, setError ] = useState(false);
|
|
|
|
|
|
|
|
function onChangeText(text) {
|
|
|
|
setText(text);
|
|
|
|
setError(text === "");
|
|
|
|
}
|
|
|
|
|
|
|
|
function onCancel() {
|
|
|
|
onDismiss();
|
|
|
|
setText("");
|
|
|
|
}
|
|
|
|
|
|
|
|
function onDone() {
|
|
|
|
if (text === "") {
|
|
|
|
setError(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
onOK(text);
|
|
|
|
setText("");
|
|
|
|
}
|
2020-03-16 16:01:05 +01:00
|
|
|
return (
|
|
|
|
<Portal>
|
|
|
|
<Dialog
|
|
|
|
visible={visible}
|
|
|
|
onDismiss={() => {onDismiss(); setText("");}}>
|
|
|
|
<Dialog.Title>{title}</Dialog.Title>
|
|
|
|
<Dialog.Content>
|
|
|
|
<TextInput
|
|
|
|
label={label}
|
|
|
|
placeholder={placeholder}
|
|
|
|
value={text}
|
2020-03-30 10:23:24 +02:00
|
|
|
onChangeText={onChangeText}
|
2020-03-16 16:01:05 +01:00
|
|
|
mode="outlined"
|
2020-03-30 10:23:24 +02:00
|
|
|
error={error}
|
2020-03-16 16:01:05 +01:00
|
|
|
/>
|
|
|
|
</Dialog.Content>
|
|
|
|
<Dialog.Actions>
|
2020-03-30 10:23:24 +02:00
|
|
|
<Button onPress={onCancel}>Cancel</Button>
|
|
|
|
<Button onPress={onDone}>Done</Button>
|
2020-03-16 16:01:05 +01:00
|
|
|
</Dialog.Actions>
|
|
|
|
</Dialog>
|
|
|
|
</Portal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
InputDialog.propTypes = {
|
|
|
|
visible: PropTypes.bool,
|
|
|
|
onOK: PropTypes.func,
|
|
|
|
onDismiss: PropTypes.func,
|
|
|
|
title: PropTypes.string,
|
|
|
|
label: PropTypes.string,
|
|
|
|
placeholder: PropTypes.string,
|
|
|
|
};
|