Skip to content

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

refactor: use flex variants

thecodrracd300337485
diff --git a/apps/web/src/app.js b/apps/web/src/app.js
index 0a1609a56..69379a377 100644
--- a/apps/web/src/app.js
+++ b/apps/web/src/app.js
@@ -34,8 +34,9 @@ function App() {
<ThemeProvider>
<Flex bg="background" height="100%">
<NavigationMenu toggleNavigationContainer={() => setShow(!show)} />
- <Flex flex="1 1 auto">
+ <Flex variant="rowFill">
<Animated.Flex
+ variant="columnFill"
className="RootNavigator"
initial={{ width: "30%", opacity: 1, scaleY: 1 }}
animate={{
@@ -45,8 +46,6 @@ function App() {
zIndex: show ? 0 : -1
}}
transition={{ duration: 0.3, ease: "easeOut" }}
- flex="1 1 auto"
- flexDirection="column"
sx={{
borderRight: "1px solid",
borderColor: "border"
diff --git a/apps/web/src/components/dialogs/dialog.js b/apps/web/src/components/dialogs/dialog.js
index ea7dc725a..280b82f65 100644
--- a/apps/web/src/components/dialogs/dialog.js
+++ b/apps/web/src/components/dialogs/dialog.js
@@ -38,14 +38,14 @@ function Dialog(props) {
}}
>
<Flex flexDirection="column">
- <Flex alignItems="center" justifyContent="center" pb={2}>
+ <Flex variant="rowCenter" pb={2}>
<props.icon size={props.iconSize || 38} color="primary" />
<Text variant="heading" color="primary" mx={1}>
{props.title}
</Text>
</Flex>
{props.children}
- <Flex mt={3} justifyContent="center" alignItems="center">
+ <Flex variant="rowCenter" mt={3}>
{props.positiveButton && (
<RebassButton
variant="primary"
diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.js
index 1ce56f45f..dff7d7103 100644
--- a/apps/web/src/components/editor/index.js
+++ b/apps/web/src/components/editor/index.js
@@ -61,9 +61,8 @@ function Editor() {
}}
>
<Flex
+ variant="columnFill"
className="editor"
- flex="1 1 auto"
- flexDirection="column"
onFocus={() => {
hideProperties();
}}
diff --git a/apps/web/src/components/list-container/index.js b/apps/web/src/components/list-container/index.js
index c485f5820..00eb3f711 100644
--- a/apps/web/src/components/list-container/index.js
+++ b/apps/web/src/components/list-container/index.js
@@ -24,26 +24,15 @@ function ListContainer(props) {
});
}, [setSearchContext, props.item, props.items, props.type, props.noSearch]);
return (
- <Flex flexDirection="column" flex="1 1 auto">
+ <Flex variant="columnFill">
{!props.items.length && props.placeholder ? (
- <Flex
- flexDirection="column"
- alignSelf="center"
- justifyContent="center"
- flex="1 1 auto"
- >
+ <Flex variant="columnCenterFill">
<props.placeholder />
</Flex>
) : (
<>
{!props.noSearch && <Search type={props.type} />}
- <Flex
- flexDirection="column"
- flex="1 1 auto"
- sx={{
- marginTop: 2
- }}
- >
+ <Flex variant="columnFill" mt={2}>
{props.children || (
<List
style={{
diff --git a/apps/web/src/components/list-item/index.js b/apps/web/src/components/list-item/index.js
index 2480eb293..f6f7e1f28 100644
--- a/apps/web/src/components/list-item/index.js
+++ b/apps/web/src/components/list-item/index.js
@@ -121,6 +121,7 @@ function ListItem(props) {
>
{props.pinned && (
<Flex
+ variant="rowCenter"
bg="primary"
sx={{
position: "absolute",
@@ -132,8 +133,6 @@ function ListItem(props) {
boxShadow: "2px 1px 3px #00000066"
}}
mx={2}
- alignItems="center"
- justifyContent="center"
>
<Box
bg="static"
diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.js
index f600c9497..3db3ce810 100644
--- a/apps/web/src/components/note/index.js
+++ b/apps/web/src/components/note/index.js
@@ -107,7 +107,7 @@ function Note(props) {
await editorStore.getState().openSession(note);
}}
info={
- <Flex justifyContent="center" alignItems="center">
+ <Flex variant="rowCenter">
{note.colors.map((item, index) => (
<Box
key={item}
diff --git a/apps/web/src/components/notebook/index.js b/apps/web/src/components/notebook/index.js
index 0f35a18e1..5af56f2a5 100644
--- a/apps/web/src/components/notebook/index.js
+++ b/apps/web/src/components/notebook/index.js
@@ -71,7 +71,7 @@ class Notebook extends React.Component {
</Flex>
}
info={
- <Flex justifyContent="center" alignItems="center">
+ <Flex variant="rowCenter">
{new Date(notebook.dateCreated).toDateString().substring(4)}
<Text as="span" mx={1}>
•
diff --git a/apps/web/src/components/properties/index.js b/apps/web/src/components/properties/index.js
index 987a5a38e..5560a4fdc 100644
--- a/apps/web/src/components/properties/index.js
+++ b/apps/web/src/components/properties/index.js
@@ -34,25 +34,6 @@ function Properties() {
return (
!isFocusModeEnabled && (
<>
- <Box
- onClick={() => showProperties()}
- sx={{
- display: arePropertiesVisible ? "none" : "flex",
- position: "absolute",
- top: "50%",
- right: 0,
- color: "static",
- borderRadius: "100px 0px 0px 100px",
- cursor: "pointer",
- height: [0, 0, 60]
- }}
- alignItems="center"
- justifyContent="center"
- bg="primary"
- >
- <Icon.ChevronLeft color="static" size={32} />
- </Box>
-
<motion.div
animate={{ x: arePropertiesVisible ? 0 : 800 }}
transition={{
@@ -187,9 +168,8 @@ function Properties() {
<Flex flexWrap="wrap" sx={{ marginBottom: 2 }}>
{objectMap(COLORS, (label, code) => (
<Flex
+ variant="rowCenter"
sx={{ position: "relative" }}
- justifyContent="center"
- alignItems="center"
onClick={() => setColor(label)}
key={label}
>
diff --git a/apps/web/src/components/search/index.js b/apps/web/src/components/search/index.js
index 96caf55fe..09821e02c 100644
--- a/apps/web/src/components/search/index.js
+++ b/apps/web/src/components/search/index.js
@@ -11,13 +11,10 @@ function Search(props) {
const search = useStore(store => store.search);
return (
<Flex
+ variant="rowCenter"
px={2}
- flexDirection="row"
- justifyContent="center"
- alignItems="center"
sx={{
- position: "relative",
- marginBottom: 0
+ position: "relative"
}}
>
<Input
diff --git a/apps/web/src/components/theme-provider/index.js b/apps/web/src/components/theme-provider/index.js
index 60034a85e..bbdbd3e78 100644
--- a/apps/web/src/components/theme-provider/index.js
+++ b/apps/web/src/components/theme-provider/index.js
@@ -11,6 +11,7 @@ function ThemeProvider(props) {
const accent = useStore(store => store.accent);
injectCss(factory.transform("css"));
const theme = factory.construct({ theme: themeType, accent, scale: 1 });
+ console.log("theme", theme);
return (
<EmotionThemeProvider theme={theme}>
{props.children instanceof Function
diff --git a/apps/web/src/theme/variants/flex.js b/apps/web/src/theme/variants/flex.js
new file mode 100644
index 000000000..52ae3c185
--- /dev/null
+++ b/apps/web/src/theme/variants/flex.js
@@ -0,0 +1,44 @@
+class FlexFactory {
+ constructor(direction) {
+ const variants = {
+ Center: new Center(direction),
+ Fill: new Fill(direction),
+ CenterFill: new CenterFill(direction)
+ };
+ return Object.fromEntries(
+ Object.entries(variants).map(([key, value]) => {
+ return [`${direction}${key}`, value];
+ })
+ );
+ }
+}
+export default FlexFactory;
+
+class Center {
+ constructor(direction) {
+ return {
+ justifyContent: "center",
+ alignItems: "center",
+ flexDirection: direction
+ };
+ }
+}
+
+class Fill {
+ constructor(direction) {
+ return {
+ flex: "1 1 auto",
+ flexDirection: direction
+ };
+ }
+}
+
+class CenterFill {
+ constructor(direction) {
+ return {
+ variant: `${direction}Center`,
+ flex: "1 1 auto",
+ flexDirection: direction
+ };
+ }
+}
diff --git a/apps/web/src/theme/variants/index.js b/apps/web/src/theme/variants/index.js
index 1b080939b..c7bff13dc 100644
--- a/apps/web/src/theme/variants/index.js
+++ b/apps/web/src/theme/variants/index.js
@@ -1,13 +1,18 @@
import ButtonFactory from "./button";
import InputFactory from "./input";
import TextFactory from "./text";
+import FlexFactory from "./flex";
class VariantFactory {
constructor() {
return {
buttons: new ButtonFactory(),
forms: new InputFactory(),
- text: new TextFactory()
+ text: new TextFactory(),
+ variants: {
+ ...new FlexFactory("row"),
+ ...new FlexFactory("column")
+ }
};
}
}
diff --git a/apps/web/src/views/Account.js b/apps/web/src/views/Account.js
index dfcd6399e..fdbfcbb48 100644
--- a/apps/web/src/views/Account.js
+++ b/apps/web/src/views/Account.js
@@ -3,38 +3,34 @@ import { Flex, Button, Image, Text } from "rebass";
function Account() {
return (
- <Flex flexDirection="column" flex="1 1 auto">
- <Flex flexDirection="column" flex="1 1 auto">
- <Image
- width={1 / 4}
- alignSelf="center"
- mt="20px"
- src={process.env.PUBLIC_URL + "/square.jpg"}
- sx={{ borderRadius: 50 }}
- />
- <Text variant="title" textAlign="center" py="5px">
- {"Alex's Account"}
- </Text>
- <Flex justifyContent="center">
- <Text
- alignSelf="center"
- fontSize="title"
- bg="primary"
- color="static"
- px="5px"
- my="5px"
- sx={{ borderRadius: "5px" }}
- >
- {"Pro"}
- </Text>
- </Flex>
- <Button variant="setting">Backup</Button>
- <Button variant="setting">My Devices</Button>
- <Button variant="setting">Vault</Button>
- <Button variant="setting">My Subscription</Button>
- <Button variant="setting">Change Password</Button>
- <Button variant="setting">Logout</Button>
- </Flex>
+ <Flex variant="columnFill">
+ <Image
+ width={1 / 4}
+ alignSelf="center"
+ mt="20px"
+ src={process.env.PUBLIC_URL + "/square.jpg"}
+ sx={{ borderRadius: 50 }}
+ />
+ <Text variant="title" textAlign="center" py="5px">
+ {"Alex's Account"}
+ </Text>
+ <Text
+ alignSelf="center"
+ fontSize="title"
+ bg="primary"
+ color="static"
+ px="5px"
+ my="5px"
+ sx={{ borderRadius: "5px" }}
+ >
+ Pro
+ </Text>
+ <Button variant="list">Backup</Button>
+ <Button variant="list">My Devices</Button>
+ <Button variant="list">Vault</Button>
+ <Button variant="list">My Subscription</Button>
+ <Button variant="list">Change Password</Button>
+ <Button variant="list">Logout</Button>
</Flex>
);
}
diff --git a/apps/web/src/views/Notebooks.js b/apps/web/src/views/Notebooks.js
index 1c7451a31..e64ff7712 100644
--- a/apps/web/src/views/Notebooks.js
+++ b/apps/web/src/views/Notebooks.js
@@ -69,13 +69,7 @@ function NotebooksContainer() {
NotebookNavigator.navigate("notebooks");
}
}, []);
- return (
- <Flex
- className="NotebookNavigator"
- flexDirection="column"
- flex="1 1 auto"
- />
- );
+ return <Flex variant="columnFill" className="NotebookNavigator" />;
}
export { NotebooksContainer, Notebooks };
diff --git a/apps/web/src/views/Settings.js b/apps/web/src/views/Settings.js
index e44420454..29e59c0a5 100644
--- a/apps/web/src/views/Settings.js
+++ b/apps/web/src/views/Settings.js
@@ -14,9 +14,8 @@ function Settings(props) {
const isLoggedIn = useUserStore(store => store.isLoggedIn);
return (
- <Flex flexDirection="column" flex="1 1 auto">
+ <Flex variant="columnFill">
<Flex
- flexDirection="row"
bg="shade"
mx={2}
p={2}
@@ -24,9 +23,7 @@ function Settings(props) {
onClick={() => props.navigator.navigate("account")}
>
<Flex
- flexDirection="column"
- justifyContent="center"
- alignItems="center"
+ variant="columnCenter"
bg="primary"
mr={2}
sx={{
@@ -37,7 +34,7 @@ function Settings(props) {
>
<Icon.User color="static" />
</Flex>
- <Flex flexDirection="column" justifyContent="center">
+ <Flex variant="columnCenter">
{isLoggedIn ? (
<>
<Text variant="title">{user.username}</Text>
@@ -97,9 +94,8 @@ function Settings(props) {
{ label: "lightpink", code: "#FABEBE" }
].map(color => (
<Flex
+ variant="rowCenter"
sx={{ position: "relative" }}
- justifyContent="center"
- alignItems="center"
onClick={() => {
setAccent(color.code);
}}
@@ -185,13 +181,7 @@ function SettingsContainer() {
SettingsNavigator.navigate("settings");
}
}, []);
- return (
- <Flex
- className="SettingsNavigator"
- flexDirection="column"
- flex="1 1 auto"
- />
- );
+ return <Flex variant="columnFill" className="SettingsNavigator" />;
}
const Titles = {
diff --git a/apps/web/src/views/Tags.js b/apps/web/src/views/Tags.js
index 484a88ce8..ca8fb241c 100644
--- a/apps/web/src/views/Tags.js
+++ b/apps/web/src/views/Tags.js
@@ -59,9 +59,7 @@ function TagsContainer() {
TagNavigator.navigate("tags");
}
}, []);
- return (
- <Flex className="TagNavigator" flexDirection="column" flex="1 1 auto" />
- );
+ return <Flex variant="columnFill" className="TagNavigator" />;
}
export { Tags, TagsContainer };
diff --git a/apps/web/src/views/Trash.js b/apps/web/src/views/Trash.js
index 44d8fb621..f52aef88d 100644
--- a/apps/web/src/views/Trash.js
+++ b/apps/web/src/views/Trash.js
@@ -49,7 +49,7 @@ function Trash() {
body={item.headline}
index={index}
info={
- <Flex justifyContent="center" alignItems="center">
+ <Flex variant="rowCenter">
<TimeAgo datetime={item.dateDeleted || item.dateCreated} />
<Text as="span" mx={1}>
•