mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 11:16:01 +00:00
add connection modal
This commit is contained in:
29
web/src/modals/ConnectionModal.js
Normal file
29
web/src/modals/ConnectionModal.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import React from 'react';
|
||||
import ModalBase from './ModalBase';
|
||||
import { FormRow, FormLabel, FormValue, FormTextField, FormSubmit } from '../utility/forms';
|
||||
import { TextField } from '../utility/inputs';
|
||||
import { Formik, Form } from 'formik';
|
||||
// import FormikForm from '../utility/FormikForm';
|
||||
|
||||
export default function ConnectionModal({ modalState }) {
|
||||
const handleSubmit = values => {
|
||||
console.log(values);
|
||||
modalState.close();
|
||||
};
|
||||
return (
|
||||
<ModalBase modalState={modalState}>
|
||||
<h2>Add connection</h2>
|
||||
<Formik onSubmit={handleSubmit} initialValues={{ server: 'localhost' }}>
|
||||
<Form>
|
||||
<FormTextField label="Server" name="server" />
|
||||
<FormTextField label="Port" name="port" />
|
||||
<FormTextField label="User" name="user" />
|
||||
<FormTextField label="Password" name="password" />
|
||||
<FormTextField label="Display name" name="displayName" />
|
||||
|
||||
<FormSubmit />
|
||||
</Form>
|
||||
</Formik>
|
||||
</ModalBase>
|
||||
);
|
||||
}
|
||||
40
web/src/modals/ModalBase.js
Normal file
40
web/src/modals/ModalBase.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import React from 'react';
|
||||
import Modal from 'react-modal';
|
||||
import styled from 'styled-components';
|
||||
|
||||
// const StyledModal = styled(Modal)`
|
||||
// position: absolute;
|
||||
// top: 40px;
|
||||
// left: 40px;
|
||||
// right: 40px;
|
||||
// bottom: 40px;
|
||||
// border: 1px solid #ccc;
|
||||
// background: #fff;
|
||||
// overflow: auto;
|
||||
// webkitoverflowscrolling: touch;
|
||||
// borderradius: 4px;
|
||||
// outline: none;
|
||||
// padding: 20px;
|
||||
// `;
|
||||
|
||||
const StyledModal = styled(Modal)`
|
||||
border: 1px solid #ccc;
|
||||
background: #fff;
|
||||
overflow: auto;
|
||||
webkitoverflowscrolling: touch;
|
||||
borderradius: 4px;
|
||||
outline: none;
|
||||
padding: 20px;
|
||||
|
||||
width: 50%;
|
||||
margin: auto;
|
||||
margin-top: 15vh;
|
||||
`;
|
||||
|
||||
export default function ModalBase({ modalState, children }) {
|
||||
return (
|
||||
<StyledModal isOpen={modalState.isOpen} onRequestClose={modalState.close}>
|
||||
{children}
|
||||
</StyledModal>
|
||||
);
|
||||
}
|
||||
8
web/src/modals/useModalState.js
Normal file
8
web/src/modals/useModalState.js
Normal file
@@ -0,0 +1,8 @@
|
||||
import React from 'react';
|
||||
|
||||
export default function useModalState() {
|
||||
const [isOpen, setOpen] = React.useState(false);
|
||||
const close = () => setOpen(false);
|
||||
const open = () => setOpen(true);
|
||||
return { isOpen, open, close };
|
||||
}
|
||||
35
web/src/utility/forms.js
Normal file
35
web/src/utility/forms.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import { TextField } from './inputs';
|
||||
import { Field } from 'formik';
|
||||
|
||||
export const FormRow = styled.div`
|
||||
display: flex;
|
||||
margin: 10px;
|
||||
`;
|
||||
|
||||
export const FormLabel = styled.div`
|
||||
width: 10vw;
|
||||
font-weight: bold;
|
||||
`;
|
||||
|
||||
export const FormValue = styled.div``;
|
||||
|
||||
export function FormTextField({ label, ...other }) {
|
||||
return (
|
||||
<FormRow>
|
||||
<FormLabel>{label}</FormLabel>
|
||||
<FormValue>
|
||||
<Field {...other} as={TextField} />
|
||||
</FormValue>
|
||||
</FormRow>
|
||||
);
|
||||
}
|
||||
|
||||
export function FormSubmit({text}) {
|
||||
return (
|
||||
<FormRow>
|
||||
<input type="submit" value={text}/>
|
||||
</FormRow>
|
||||
);
|
||||
}
|
||||
5
web/src/utility/inputs.js
Normal file
5
web/src/utility/inputs.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import React from 'react';
|
||||
|
||||
export function TextField({ ...other }) {
|
||||
return <input type="text" {...other}></input>;
|
||||
}
|
||||
7
web/src/utility/layout.js
Normal file
7
web/src/utility/layout.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import styled from 'styled-components';
|
||||
|
||||
export const Grid = styled.div``;
|
||||
|
||||
export const Row = styled.div``;
|
||||
|
||||
export const Col = styled.div``;
|
||||
@@ -1,5 +1,13 @@
|
||||
import React from 'react';
|
||||
import useModalState from '../modals/useModalState';
|
||||
import ConnectionModal from '../modals/ConnectionModal';
|
||||
|
||||
export default function DatabaseWidget() {
|
||||
return <button onClick={() => {}}>Add connection</button>;
|
||||
const modalState = useModalState();
|
||||
return (
|
||||
<>
|
||||
<ConnectionModal modalState={modalState} />
|
||||
<button onClick={modalState.open}>Add connection</button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user