import { useState } from "react"; import { Dialog } from "./Dialog"; import { TextField } from "./TextField"; import { MagicIcon, OpenAIIcon } from "./icons"; import { FilledButton } from "./FilledButton"; import { CheckboxItem } from "./CheckboxItem"; import { KEYS } from "../keys"; import { useUIAppState } from "../context/ui-appState"; import { InlineIcon } from "./InlineIcon"; import { Paragraph } from "./Paragraph"; import "./MagicSettings.scss"; import TTDDialogTabs from "./TTDDialog/TTDDialogTabs"; import { TTDDialogTab } from "./TTDDialog/TTDDialogTab"; export const MagicSettings = (props: { openAIKey: string | null; isPersisted: boolean; onChange: (key: string, shouldPersist: boolean) => void; onConfirm: (key: string, shouldPersist: boolean) => void; onClose: () => void; }) => { const [keyInputValue, setKeyInputValue] = useState(props.openAIKey || ""); const [shouldPersist, setShouldPersist] = useState( props.isPersisted, ); const appState = useUIAppState(); const onConfirm = () => { props.onConfirm(keyInputValue.trim(), shouldPersist); }; if (appState.openDialog?.name !== "settings") { return null; } return ( { props.onClose(); props.onConfirm(keyInputValue.trim(), shouldPersist); }} title={
Wireframe to Code (AI){" "}
Experimental
} className="MagicSettings" autofocus={false} > {/*

AI Settings

*/} {/* Text to diagram Wireframe to code */} {/* TODO */} For the diagram-to-code feature we use{" "} OpenAI. While the OpenAI API is in beta, its use is strictly limited — as such we require you use your own API key. You can create an{" "} OpenAI account , add a small credit (5 USD minimum), and{" "} generate your own API key . Your OpenAI key does not leave the browser, and you can also set your own limit in your OpenAI account dashboard if needed. { setKeyInputValue(value); props.onChange(value.trim(), shouldPersist); }} selectOnRender onKeyDown={(event) => event.key === KEYS.ENTER && onConfirm()} /> By default, your API token is not persisted anywhere so you'll need to insert it again after reload. But, you can persist locally in your browser below. Persist API key in browser storage Once API key is set, you can use the {" "} tool to wrap your elements in a frame that will then allow you to turn it into code. This dialog can be accessed using the{" "} AI Settings .
); };