Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

ui: fix props not being forwarded to children in form

thecodrrfecded7d38c8
diff --git a/apps/web/src/components/dialogs/logindialog.js b/apps/web/src/components/dialogs/logindialog.js
index a276c032a..cccff1cf8 100644
--- a/apps/web/src/components/dialogs/logindialog.js
+++ b/apps/web/src/components/dialogs/logindialog.js
@@ -1,12 +1,12 @@
import React, { useState } from "react";
-import { Button, Text } from "rebass";
+import { Box, Button, Text } from "rebass";
import Input from "../inputs";
import * as Icon from "../icons";
import Dialog, { showDialog } from "./dialog";
import { showSignUpDialog } from "./signupdialog";
import { useStore } from "../../stores/user-store";
import PasswordInput from "../inputs/password";
-import Form from "../form";
+import Dropper from "../dropper";
function LoginDialog(props) {
const { onClose } = props;
@@ -35,14 +35,16 @@ function LoginDialog(props) {
}
}}
>
- <Form mt={1} gutter={2} form={form}>
- <Input autoFocus name="username" title="Username" />
- <PasswordInput />
+ <Box mt={1}>
+ <Dropper mt={2} form={form}>
+ <Input autoFocus name="username" title="Username" />
+ <PasswordInput />
+ </Dropper>
<Button variant="anchor" onClick={showSignUpDialog}>
Create a New Account
</Button>
{error && <Text variant="error">{error}</Text>}
- </Form>
+ </Box>
</Dialog>
);
}
diff --git a/apps/web/src/components/dialogs/signupdialog.js b/apps/web/src/components/dialogs/signupdialog.js
index 65e72348f..aa14ffbcc 100644
--- a/apps/web/src/components/dialogs/signupdialog.js
+++ b/apps/web/src/components/dialogs/signupdialog.js
@@ -1,12 +1,12 @@
import React, { useState } from "react";
-import { Text } from "rebass";
+import { Text, Box } from "rebass";
import Input from "../inputs";
import * as Icon from "../icons";
import Dialog, { showDialog } from "./dialog";
//import { db } from "../../common";
import EmailInput from "../inputs/email";
import PasswordInput from "../inputs/password";
-import Form from "../form";
+import Dropper from "../dropper";
function SignUpDialog(props) {
const { onClose } = props;
@@ -32,12 +32,14 @@ function SignUpDialog(props) {
}
}}
>
- <Form mt={1} gutter={2} form={form}>
- <Input autoFocus title="Username" name="username" />
- <EmailInput />
- <PasswordInput confirm />
+ <Box mt={1}>
+ <Dropper mt={2} form={form}>
+ <Input autoFocus title="Username" name="username" />
+ <EmailInput />
+ <PasswordInput confirm />
+ </Dropper>
{error && <Text variant="error">{error}</Text>}
- </Form>
+ </Box>
</Dialog>
);
}
diff --git a/apps/web/src/components/dropper/index.js b/apps/web/src/components/dropper/index.js
new file mode 100644
index 000000000..d5c884cb4
--- /dev/null
+++ b/apps/web/src/components/dropper/index.js
@@ -0,0 +1,12 @@
+import React from "react";
+
+function Dropper(props) {
+ const { children } = props;
+ const fillChildren = React.Children.map(children, (child, index) => {
+ if (!child) return;
+ const childProps = { ...props, children: child.props.children };
+ return React.cloneElement(child, childProps);
+ });
+ return <React.Fragment>{fillChildren}</React.Fragment>;
+}
+export default Dropper;
diff --git a/apps/web/src/components/form/index.js b/apps/web/src/components/form/index.js
deleted file mode 100644
index cc2df3021..000000000
--- a/apps/web/src/components/form/index.js
+++ /dev/null
@@ -1,14 +0,0 @@
-import React from "react";
-import { Box } from "rebass";
-
-function Form(props) {
- const { gutter, children, form } = props;
- const childrenWithGutter = React.Children.map(children, (child, index) => {
- if (!child) return;
- const props = { mt: index && gutter, form };
- return React.cloneElement(child, props);
- });
- return <Box {...props}>{childrenWithGutter}</Box>;
-}
-
-export default Form;
diff --git a/apps/web/src/components/inputs/email.js b/apps/web/src/components/inputs/email.js
index 94eee74a6..6a67a4eef 100644
--- a/apps/web/src/components/inputs/email.js
+++ b/apps/web/src/components/inputs/email.js
@@ -2,7 +2,7 @@ import React from "react";
import Input from "./index";
import { isValidEmail } from "../../utils/validation";
-function EmailInput() {
+function EmailInput(props) {
return (
<Input
title="Email"
@@ -10,6 +10,7 @@ function EmailInput() {
type="email"
error="Email is not valid."
validate={isValidEmail}
+ {...props}
/>
);
}
diff --git a/apps/web/src/components/inputs/password.js b/apps/web/src/components/inputs/password.js
index f68616df0..98fba9bdb 100644
--- a/apps/web/src/components/inputs/password.js
+++ b/apps/web/src/components/inputs/password.js
@@ -1,10 +1,11 @@
import React from "react";
import Input from "./index";
+import Dropper from "../dropper";
function PasswordInput(props) {
const { confirm } = props;
return (
- <>
+ <Dropper {...props}>
<Input title="Password" type="password" name="password" />
{confirm && (
<Input
@@ -14,7 +15,8 @@ function PasswordInput(props) {
validate={(password, form) => form.password === password}
/>
)}
- </>
+ </Dropper>
);
}
+
export default PasswordInput;