mirror of
https://github.com/ritz078/transform.git
synced 2026-11-21 00:32:56 +03:00
* feat(init): added EditorPanel with prettier, copy and settings support * chore(static): ignore static * feat: added navigator * feat: * feat(settings): added sessionStorage support for settings * feat(message): add messaging support in editors * feat(preview): added support for preview panel * fix(settings): use localstorage for settings instead of session storage * feat: * feat(css-to-js): implemented React section * feat(schema): add json to schema conversions * feat(others): implemented xml, yaml and markdown conversions * feat(babel): added flow to typescript converter * feat(graphql): implemented graphql to typescript * feat(graphql): added some transformations * fix: add support for different default value in one language * feat(graphql): added components, resolver signatures and mongodb * feat: * scala case class * fix(memory): worker-loader patch applied to fix memory overflow crash * feat: added json schema to typescript * icon: <GraphQLIcon />, * feat(navigator): shorter naming and new categories * route fixes * navigator * perf(workers): create separate file and remove fallback * fix(navigator): completed * build(snack): * fixes * fixes * fix(safari): * added json-to-mobx-state tree * fix(native): snacksession * fixes * added logo * navigator * fixes * custom header * fixes * refactor(settings): move settings to left side * feat: set up redirects * feat(seo): added title and description * feat(error): added custom error page * ga-script * feat: * fixes * fixe * fixes * fixes * fix:
105 lines
2.7 KiB
TypeScript
105 lines
2.7 KiB
TypeScript
import React from "react";
|
|
import { Formik, FormikProps } from "formik";
|
|
import { Dialog, Heading, Pane, Switch, TextInput } from "evergreen-ui";
|
|
|
|
export enum InputType {
|
|
SWITCH = 1,
|
|
TEXT_INPUT
|
|
}
|
|
|
|
interface FormProps<T> {
|
|
initialValues: T;
|
|
onSubmit: (values: T) => void;
|
|
title: string;
|
|
formsFields: {
|
|
key: string;
|
|
type: InputType;
|
|
label: string;
|
|
isDisabled?: (values: T) => boolean;
|
|
props?: any;
|
|
}[];
|
|
open: boolean;
|
|
toggle: () => void;
|
|
}
|
|
|
|
const Form = <T extends object>({
|
|
initialValues,
|
|
onSubmit,
|
|
title,
|
|
formsFields,
|
|
open,
|
|
toggle
|
|
}: FormProps<T> & { children?: React.ReactNode }) => {
|
|
return (
|
|
<Formik
|
|
initialValues={initialValues}
|
|
render={(props: FormikProps<T>) => {
|
|
return (
|
|
<Dialog
|
|
title={title}
|
|
isShown={open}
|
|
onCloseComplete={toggle}
|
|
onConfirm={close => {
|
|
props.submitForm();
|
|
close();
|
|
}}
|
|
onCancel={close => {
|
|
props.resetForm();
|
|
close();
|
|
}}
|
|
>
|
|
<>
|
|
{formsFields.map(
|
|
({ type, key, label, isDisabled, props: _props }, i) => {
|
|
let FormField;
|
|
if (type === InputType.TEXT_INPUT) FormField = TextInput;
|
|
else if (type === InputType.SWITCH) FormField = Switch;
|
|
|
|
const _isDisabled = isDisabled
|
|
? isDisabled(props.values)
|
|
: undefined;
|
|
|
|
return (
|
|
<Pane
|
|
display={"flex"}
|
|
alignItems="center"
|
|
flexDirection={"row"}
|
|
paddingY={10}
|
|
key={i}
|
|
justifyContent={"space-between"}
|
|
{..._props}
|
|
>
|
|
<Heading
|
|
flex={1}
|
|
size={400}
|
|
opacity={_isDisabled ? 0.4 : 1}
|
|
textTransform={"capitalize"}
|
|
>
|
|
{label}
|
|
</Heading>
|
|
{FormField && (
|
|
<FormField
|
|
value={props.values[key]}
|
|
checked={props.values[key]}
|
|
onChange={props.handleChange}
|
|
name={key}
|
|
disabled={_isDisabled}
|
|
/>
|
|
)}
|
|
</Pane>
|
|
);
|
|
}
|
|
)}
|
|
</>
|
|
</Dialog>
|
|
);
|
|
}}
|
|
onSubmit={values => {
|
|
onSubmit(values);
|
|
}}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default Form;
|