Files
transform/pages/json-to-flow.tsx
Ritesh Kumar 9f67f97573 2.1.0 (#128)
* HTML to Pug converter (#127)

* feat(pug): add HTML to pug converter

* fix(pug): added package details

* feat(analyze): added webpack bundle analyzer

*  fix(rust): handle special characters and duplicate keys (#131)

* remove duplicate google tag manager (#122)

* Update _app.tsx (#124)

* docs: add timneutkens as a contributor (#125)

* docs: update README.md

* docs: update .all-contributorsrc

* Upgrade Next.js to 9 (#126)

* Upgrade Next.js to 9

* Add back engines key

* Add globalObject

Brings in suggestion from https://github.com/zeit/next.js/issues/7873#issuecomment-512795482

* Add temporary fix for window issue

* fix(font): add fallback font for non mac browsers (#130)

closes #129

* fix(rust): handle special characters and duplicate keys

closes #97

* fix(rust): handle special chars

closes #97, closes #95, closes #89, closes #62

* chore(rust): remove settings

* feat(kotlin): added JSON to kotlin and json schema

* fixes

* fixes

* fixes

* fixes

* fixes

* added favicon

* social media tags
2019-07-25 00:38:09 +05:30

74 lines
1.6 KiB
TypeScript

import ConversionPanel from "@components/ConversionPanel";
import * as React from "react";
import { useCallback } from "react";
import { json2ts } from "json-ts";
import { useSettings } from "@hooks/useSettings";
import Form, { InputType } from "@components/Form";
import { EditorPanelProps } from "@components/EditorPanel";
import { Settings } from "@constants/svgoConfig";
const formFields = [
{
type: InputType.TEXT_INPUT,
key: "namespace",
label: "Namespace"
},
{
type: InputType.TEXT_INPUT,
key: "prefix",
label: "prefix"
},
{
type: InputType.TEXT_INPUT,
key: "rootName",
label: "Root Name"
}
];
const defaultSettings = {
namespace: "",
prefix: "I",
rootName: "RootObject"
};
export default function() {
const name = "json-to-flow";
const [settings, setSettings] = useSettings(name, defaultSettings);
const getSettingsElement = useCallback<EditorPanelProps["settingElement"]>(
({ open, toggle }) => {
return (
<Form<Settings>
title="JSON to Flow"
onSubmit={setSettings}
open={open}
toggle={toggle}
formsFields={formFields}
initialValues={settings}
/>
);
},
[]
);
const transformer = useCallback(
async ({ value }) => {
return json2ts(value, { flow: true, ...settings });
},
[settings]
);
return (
<ConversionPanel
transformer={transformer}
editorTitle="JSON"
editorLanguage="json"
resultTitle="Flow"
resultLanguage={"typescript"}
resultSettingsElement={getSettingsElement}
settings={settings}
/>
);
}