Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(client): extract setup form to dedicated component
Elian Dorana02f3c4440f6
diff --git a/apps/client/src/widgets/type_widgets/WebView.css b/apps/client/src/widgets/type_widgets/WebView.cssindex ceeb5ba7af..42ac871cfb 100644--- a/apps/client/src/widgets/type_widgets/WebView.css+++ b/apps/client/src/widgets/type_widgets/WebView.css@@ -16,24 +16,3 @@width: 100%;height: 100%;}--.web-view-setup-form {- height: 100%;- display: flex;- flex-direction: column;- justify-content: center;- padding-inline: 40px;-- .form-icon {- margin-bottom: 12px;- }-- .form-group {- width: 100%;- max-width: 600px;- }-- .tn-link {- margin-top: 1em;- }-}diff --git a/apps/client/src/widgets/type_widgets/WebView.tsx b/apps/client/src/widgets/type_widgets/WebView.tsxindex aeb56d70b2..90db7000d2 100644--- a/apps/client/src/widgets/type_widgets/WebView.tsx+++ b/apps/client/src/widgets/type_widgets/WebView.tsx@@ -12,6 +12,7 @@ import FormGroup from "../react/FormGroup";import FormTextBox from "../react/FormTextBox";import { useNoteLabel } from "../react/hooks";import LinkButton from "../react/LinkButton";+import SetupForm from "./helpers/SetupForm";import { TypeWidgetProps } from "./type_widget";const isElectron = utils.isElectron();@@ -58,55 +59,50 @@ function SetupWebView({note}: {note: FNote}) {}, [ setSrcLabel ]);return (- <div class="web-view-setup-form">- <form class="tn-centered-form" onSubmit={() => submit(src)}>- <span className="bx bx-globe-alt form-icon" />-- <FormGroup name="web-view-src-detail" label={t("web_view_setup.title")}>- <input className="form-control"- type="text"- value={src}- placeholder={t("web_view_setup.url_placeholder")}- onChange={(e) => {setSrc((e.target as HTMLInputElement)?.value);}}- />- </FormGroup>-- <Button- text={t("web_view_setup.create_button")}- primary- keyboardShortcut="Enter"+ <SetupForm+ icon="bx bx-globe-alt"+ onSubmit={() => submit(src)}+ >+ <FormGroup name="web-view-src-detail" label={t("web_view_setup.title")}>+ <input className="form-control"+ type="text"+ value={src}+ placeholder={t("web_view_setup.url_placeholder")}+ onChange={(e) => {setSrc((e.target as HTMLInputElement)?.value);}}/>- </form>- </div>+ </FormGroup>++ <Button+ text={t("web_view_setup.create_button")}+ primary+ keyboardShortcut="Enter"+ />+ </SetupForm>);}function DisabledWebView({ note, url }: { note: FNote, url: string }) {return (- <div class="web-view-setup-form">- <form class="tn-centered-form">- <span className="bx bx-globe-alt form-icon" />-- <FormGroup name="web-view-src-detail" label={t("web_view_setup.disabled_description")}>- <FormTextBox- type="url"- currentValue={url}- disabled- />- </FormGroup>-- <Button- text={t("web_view_setup.disabled_button_enable")}- icon="bx bx-check-shield"- onClick={() => attributes.toggleDangerousAttribute(note, "label", "webViewSrc", true)}- primary+ <SetupForm icon="bx bx-globe-alt">+ <FormGroup name="web-view-src-detail" label={t("web_view_setup.disabled_description")}>+ <FormTextBox+ type="url"+ currentValue={url}+ disabled/>-- <LinkButton- text="Learn more"- onClick={() => openInAppHelpFromUrl("1vHRoWCEjj0L")}- />- </form>- </div>+ </FormGroup>++ <Button+ text={t("web_view_setup.disabled_button_enable")}+ icon="bx bx-check-shield"+ onClick={() => attributes.toggleDangerousAttribute(note, "label", "webViewSrc", true)}+ primary+ />++ <LinkButton+ text="Learn more"+ onClick={() => openInAppHelpFromUrl("1vHRoWCEjj0L")}+ />+ </SetupForm>);}diff --git a/apps/client/src/widgets/type_widgets/helpers/SetupForm.css b/apps/client/src/widgets/type_widgets/helpers/SetupForm.cssnew file mode 100644index 0000000000..205f3a4cde--- /dev/null+++ b/apps/client/src/widgets/type_widgets/helpers/SetupForm.css@@ -0,0 +1,20 @@+.setup-form {+ height: 100%;+ display: flex;+ flex-direction: column;+ justify-content: center;+ padding-inline: 40px;++ .form-icon {+ margin-bottom: 12px;+ }++ .form-group {+ width: 100%;+ max-width: 600px;+ }++ .tn-link {+ margin-top: 1em;+ }+}diff --git a/apps/client/src/widgets/type_widgets/helpers/SetupForm.tsx b/apps/client/src/widgets/type_widgets/helpers/SetupForm.tsxnew file mode 100644index 0000000000..121b4bb692--- /dev/null+++ b/apps/client/src/widgets/type_widgets/helpers/SetupForm.tsx@@ -0,0 +1,22 @@+import "./SetupForm.css";++import clsx from "clsx";+import { ComponentChildren } from "preact";++interface SetupFormProps {+ icon: string;+ onSubmit?: () => void;+ children: ComponentChildren;+}++export default function SetupForm({ icon, children, onSubmit }: SetupFormProps) {+ return (+ <div class="setup-form">+ <form class="tn-centered-form" onSubmit={onSubmit}>+ <span className={clsx(icon, "form-icon")} />++ {children}+ </form>+ </div>+ );+}