form buttons styling

This commit is contained in:
Jan Prochazka 2020-04-26 08:11:36 +02:00
parent 4e0770d1ab
commit d2887f9869
7 changed files with 96 additions and 17 deletions

View File

@ -1,12 +1,14 @@
import React from 'react'; import React from 'react';
import axios from '../utility/axios'; import axios from '../utility/axios';
import ModalBase from './ModalBase'; import ModalBase from './ModalBase';
import { FormRow, FormButton, FormTextField, FormSelectField, FormSubmit } from '../utility/forms'; import { FormRow, FormButtonRow, FormTextField, FormSelectField, FormSubmit } from '../utility/forms';
import FormStyledButton from '../widgets/FormStyledButton';
import { TextField } from '../utility/inputs'; import { TextField } from '../utility/inputs';
import { Formik, Form } from 'formik'; import { Formik, Form } from 'formik';
import SqlEditor from '../sqleditor/SqlEditor'; import SqlEditor from '../sqleditor/SqlEditor';
// import FormikForm from '../utility/FormikForm'; // import FormikForm from '../utility/FormikForm';
import styled from 'styled-components'; import styled from 'styled-components';
import keycodes from '../utility/keycodes';
const SqlWrapper = styled.div` const SqlWrapper = styled.div`
position: relative; position: relative;
@ -15,24 +17,30 @@ const SqlWrapper = styled.div`
`; `;
export default function ConfirmSqlModal({ modalState, sql, engine, onConfirm }) { export default function ConfirmSqlModal({ modalState, sql, engine, onConfirm }) {
const handleKeyDown = (data, hash, keyString, keyCode, event) => {
if (keyCode == keycodes.enter) {
event.preventDefault();
modalState.close();
onConfirm();
}
};
return ( return (
<ModalBase modalState={modalState}> <ModalBase modalState={modalState}>
<h2>Save changes</h2> <h2>Save changes</h2>
<SqlWrapper> <SqlWrapper>
<SqlEditor value={sql} engine={engine} readOnly /> <SqlEditor value={sql} engine={engine} focusOnCreate onKeyDown={handleKeyDown} readOnly />
</SqlWrapper> </SqlWrapper>
<FormRow> <FormButtonRow>
<input <FormStyledButton
type="button"
value="OK" value="OK"
onClick={() => { onClick={() => {
modalState.close(); modalState.close();
onConfirm(); onConfirm();
}} }}
/> />
<input type="button" value="Close" onClick={modalState.close} /> <FormStyledButton type="button" value="Close" onClick={modalState.close} />
</FormRow> </FormButtonRow>
</ModalBase> </ModalBase>
); );
} }

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import axios from '../utility/axios'; import axios from '../utility/axios';
import ModalBase from './ModalBase'; import ModalBase from './ModalBase';
import { FormRow, FormButton, FormTextField, FormSelectField, FormSubmit } from '../utility/forms'; import { FormButtonRow, FormButton, FormTextField, FormSelectField, FormSubmit } from '../utility/forms';
import { TextField } from '../utility/inputs'; import { TextField } from '../utility/inputs';
import { Formik, Form } from 'formik'; import { Formik, Form } from 'formik';
// import FormikForm from '../utility/FormikForm'; // import FormikForm from '../utility/FormikForm';
@ -37,10 +37,10 @@ export default function ConnectionModal({ modalState, connection = undefined })
<FormTextField label="Password" name="password" /> <FormTextField label="Password" name="password" />
<FormTextField label="Display name" name="displayName" /> <FormTextField label="Display name" name="displayName" />
<FormRow> <FormButtonRow>
<FormButton text="Test" onClick={handleTest} /> <FormButton text="Test" onClick={handleTest} />
<FormSubmit text="Save" /> <FormSubmit text="Save" />
</FormRow> </FormButtonRow>
</Form> </Form>
</Formik> </Formik>
<div>Connect result: {sqlConnectResult}</div> <div>Connect result: {sqlConnectResult}</div>

View File

@ -27,6 +27,7 @@ const StyledModal = styled(Modal)`
padding: 20px; padding: 20px;
width: 50%; width: 50%;
max-width: 900px;
margin: auto; margin: auto;
margin-top: 15vh; margin-top: 15vh;
`; `;

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import axios from '../utility/axios'; import axios from '../utility/axios';
import ModalBase from './ModalBase'; import ModalBase from './ModalBase';
import { FormRow, FormButton, FormTextField, FormSelectField, FormSubmit } from '../utility/forms'; import { FormButtonRow, FormButton, FormTextField, FormSelectField, FormSubmit } from '../utility/forms';
import { TextField } from '../utility/inputs'; import { TextField } from '../utility/inputs';
import { Formik, Form } from 'formik'; import { Formik, Form } from 'formik';
import { useSetSavedSqlFiles } from '../utility/globalState'; import { useSetSavedSqlFiles } from '../utility/globalState';
@ -28,9 +28,9 @@ export default function SaveSqlFileModal({ storageKey, modalState, name, onSave
<Form> <Form>
<FormTextField label="File name" name="name" /> <FormTextField label="File name" name="name" />
<FormRow> <FormButtonRow>
<FormSubmit text="Save" /> <FormSubmit text="Save" />
</FormRow> </FormButtonRow>
</Form> </Form>
</Formik> </Formik>
</ModalBase> </ModalBase>

View File

@ -25,6 +25,7 @@ export default function SqlEditor({
tabVisible = false, tabVisible = false,
onKeyDown = undefined, onKeyDown = undefined,
editorRef = undefined, editorRef = undefined,
focusOnCreate = false,
}) { }) {
const [containerRef, { height, width }] = useDimensions(); const [containerRef, { height, width }] = useDimensions();
const ownEditorRef = React.useRef(null); const ownEditorRef = React.useRef(null);
@ -32,8 +33,9 @@ export default function SqlEditor({
const currentEditorRef = editorRef || ownEditorRef; const currentEditorRef = editorRef || ownEditorRef;
React.useEffect(() => { React.useEffect(() => {
if (tabVisible && currentEditorRef.current && currentEditorRef.current.editor) currentEditorRef.current.editor.focus(); if ((tabVisible || focusOnCreate) && currentEditorRef.current && currentEditorRef.current.editor)
}, [tabVisible]); currentEditorRef.current.editor.focus();
}, [tabVisible, focusOnCreate]);
React.useEffect(() => { React.useEffect(() => {
if (onKeyDown && currentEditorRef.current) { if (onKeyDown && currentEditorRef.current) {

View File

@ -2,12 +2,19 @@ import React from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import { TextField, SelectField } from './inputs'; import { TextField, SelectField } from './inputs';
import { Field, useFormikContext } from 'formik'; import { Field, useFormikContext } from 'formik';
import FormStyledButton from '../widgets/FormStyledButton';
export const FormRow = styled.div` export const FormRow = styled.div`
display: flex; display: flex;
margin: 10px; margin: 10px;
`; `;
export const FormButtonRow = styled.div`
display: flex;
// justify-content: flex-end;
margin: 10px;
`;
export const FormLabel = styled.div` export const FormLabel = styled.div`
width: 10vw; width: 10vw;
font-weight: bold; font-weight: bold;
@ -40,10 +47,10 @@ export function FormSelectField({ label, children, ...other }) {
} }
export function FormSubmit({ text }) { export function FormSubmit({ text }) {
return <input type="submit" value={text} />; return <FormStyledButton type="submit" value={text} />;
} }
export function FormButton({ text, onClick, ...other }) { export function FormButton({ text, onClick, ...other }) {
const { values } = useFormikContext(); const { values } = useFormikContext();
return <input type="button" value={text} onClick={() => onClick(values)} {...other} />; return <FormStyledButton type="button" value={text} onClick={() => onClick(values)} {...other} />;
} }

View File

@ -0,0 +1,61 @@
// @ts-nocheck
import React from 'react';
import styled from 'styled-components';
import theme from '../theme';
const ButtonInput = styled.input`
// height: ${theme.toolBar.height - 5}px;
border: 1px solid #2e6da4;
padding: 5px;
margin: 2px;
width: 100px;
//background-color: #777;
background-color: #337ab7;
// border-color: #2e6da4;
color: white;
border-radius: 2px;
${(props) =>
!props.disabled &&
`
&:hover {
background-color: #286090;
}
&:active:hover {
background-color: #204d74;
}
`}
${(props) =>
props.disabled &&
`
background-color: #ccc;
color: gray;
`}
`;
export default function FormStyledButton({
onClick = undefined,
type = 'button',
value,
disabled = undefined,
...other
}) {
return (
<ButtonInput
type={type}
onClick={
onClick
? () => {
if (!disabled && onClick) onClick();
}
: undefined
}
disabled={disabled}
value={value}
{...other}
/>
);
}