From 5ce52976f3b528b431ef6837f565cf3fc67b48a3 Mon Sep 17 00:00:00 2001 From: Cobular <22972550+Cobular@users.noreply.github.com> Date: Thu, 31 Dec 2020 16:58:58 -0800 Subject: [PATCH] Masonry works pretty good --- .eslintcache | 2 +- src/components/ProjectGrid.scss | 77 +++++++++-- src/components/ProjectGrid.tsx | 227 ++++++++++++++++++++++---------- src/cusotmHooks.ts | 33 +++++ 4 files changed, 256 insertions(+), 83 deletions(-) create mode 100644 src/cusotmHooks.ts diff --git a/.eslintcache b/.eslintcache index bc84d0c..650f66e 100644 --- a/.eslintcache +++ b/.eslintcache @@ -1 +1 @@ -[{"C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\index.tsx":"1","C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\reportWebVitals.ts":"2","C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\App.tsx":"3","C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\Header.tsx":"4","C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\Home.tsx":"5","C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\Main.tsx":"6","C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\Contact.tsx":"7","C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\Resume.tsx":"8","C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\ProjectGrid.tsx":"9"},{"size":560,"mtime":1609455390298,"results":"10","hashOfConfig":"11"},{"size":440,"mtime":1609445337674,"results":"12","hashOfConfig":"11"},{"size":262,"mtime":1609448057026,"results":"13","hashOfConfig":"11"},{"size":885,"mtime":1609448882867,"results":"14","hashOfConfig":"11"},{"size":402,"mtime":1609452953574,"results":"15","hashOfConfig":"11"},{"size":424,"mtime":1609448271170,"results":"16","hashOfConfig":"11"},{"size":142,"mtime":1609448138377,"results":"17","hashOfConfig":"11"},{"size":132,"mtime":1609448124025,"results":"18","hashOfConfig":"11"},{"size":2612,"mtime":1609456026589,"results":"19","hashOfConfig":"11"},{"filePath":"20","messages":"21","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"lcbj9u",{"filePath":"22","messages":"23","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"24"},{"filePath":"25","messages":"26","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"24"},{"filePath":"27","messages":"28","errorCount":0,"warningCount":2,"fixableErrorCount":0,"fixableWarningCount":0,"source":"29","usedDeprecatedRules":"24"},{"filePath":"30","messages":"31","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"24"},{"filePath":"32","messages":"33","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"24"},{"filePath":"34","messages":"35","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"24"},{"filePath":"36","messages":"37","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"24"},{"filePath":"38","messages":"39","errorCount":0,"warningCount":2,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\index.tsx",[],"C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\reportWebVitals.ts",[],["40","41"],"C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\App.tsx",[],"C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\Header.tsx",["42","43"],"import React from \"react\";\nimport \"./Header.scss\";\nimport {Button, Space, Typography} from \"antd\";\nimport {Link} from \"react-router-dom\";\n\nconst {Title} = Typography;\n\nexport const Header = () => {\n return (\n
\n \n

Jake Cover

\n \n\n \n \n

Home

\n \n\n \n

Contact

\n \n \n

Resume

\n \n \n

GitHub

\n
\n
\n
\n );\n};\n","C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\Home.tsx",[],"C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\Main.tsx",[],"C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\Contact.tsx",[],"C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\Resume.tsx",[],"C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\ProjectGrid.tsx",["44","45"],{"ruleId":"46","replacedBy":"47"},{"ruleId":"48","replacedBy":"49"},{"ruleId":"50","severity":1,"message":"51","line":3,"column":9,"nodeType":"52","messageId":"53","endLine":3,"endColumn":15},{"ruleId":"50","severity":1,"message":"54","line":6,"column":8,"nodeType":"52","messageId":"53","endLine":6,"endColumn":13},{"ruleId":"50","severity":1,"message":"55","line":44,"column":7,"nodeType":"52","messageId":"53","endLine":44,"endColumn":11},{"ruleId":"50","severity":1,"message":"56","line":45,"column":7,"nodeType":"52","messageId":"53","endLine":45,"endColumn":12},"no-native-reassign",["57"],"no-negated-in-lhs",["58"],"@typescript-eslint/no-unused-vars","'Button' is defined but never used.","Identifier","unusedVar","'Title' is assigned a value but never used.","'elem' is assigned a value but never used.","'msnry' is assigned a value but never used.","no-global-assign","no-unsafe-negation"] \ No newline at end of file +[{"C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\index.tsx":"1","C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\reportWebVitals.ts":"2","C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\App.tsx":"3","C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\Header.tsx":"4","C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\Home.tsx":"5","C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\Main.tsx":"6","C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\Contact.tsx":"7","C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\Resume.tsx":"8","C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\ProjectGrid.tsx":"9","C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\cusotmHooks.ts":"10"},{"size":560,"mtime":1609455390298,"results":"11","hashOfConfig":"12"},{"size":440,"mtime":1609445337674,"results":"13","hashOfConfig":"12"},{"size":262,"mtime":1609448057026,"results":"14","hashOfConfig":"12"},{"size":885,"mtime":1609448882867,"results":"15","hashOfConfig":"12"},{"size":402,"mtime":1609452953574,"results":"16","hashOfConfig":"12"},{"size":424,"mtime":1609448271170,"results":"17","hashOfConfig":"12"},{"size":142,"mtime":1609448138377,"results":"18","hashOfConfig":"12"},{"size":132,"mtime":1609448124025,"results":"19","hashOfConfig":"12"},{"size":6652,"mtime":1609462712897,"results":"20","hashOfConfig":"12"},{"size":1072,"mtime":1609462531624,"results":"21","hashOfConfig":"12"},{"filePath":"22","messages":"23","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"24"},"lcbj9u",{"filePath":"25","messages":"26","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"24"},{"filePath":"27","messages":"28","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"24"},{"filePath":"29","messages":"30","errorCount":0,"warningCount":2,"fixableErrorCount":0,"fixableWarningCount":0,"source":"31","usedDeprecatedRules":"24"},{"filePath":"32","messages":"33","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"24"},{"filePath":"34","messages":"35","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"24"},{"filePath":"36","messages":"37","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"24"},{"filePath":"38","messages":"39","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"24"},{"filePath":"40","messages":"41","errorCount":0,"warningCount":2,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"42","messages":"43","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\index.tsx",[],["44","45"],"C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\reportWebVitals.ts",[],"C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\App.tsx",[],"C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\Header.tsx",["46","47"],"import React from \"react\";\nimport \"./Header.scss\";\nimport {Button, Space, Typography} from \"antd\";\nimport {Link} from \"react-router-dom\";\n\nconst {Title} = Typography;\n\nexport const Header = () => {\n return (\n
\n \n

Jake Cover

\n \n\n \n \n

Home

\n \n\n \n

Contact

\n \n \n

Resume

\n \n \n

GitHub

\n
\n
\n
\n );\n};\n","C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\Home.tsx",[],"C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\Main.tsx",[],"C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\Contact.tsx",[],"C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\Resume.tsx",[],"C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\components\\ProjectGrid.tsx",["48","49"],"C:\\Users\\jdc10\\Documents\\GitHub\\PersonalWebsite_Static\\src\\cusotmHooks.ts",[],{"ruleId":"50","replacedBy":"51"},{"ruleId":"52","replacedBy":"53"},{"ruleId":"54","severity":1,"message":"55","line":3,"column":9,"nodeType":"56","messageId":"57","endLine":3,"endColumn":15},{"ruleId":"54","severity":1,"message":"58","line":6,"column":8,"nodeType":"56","messageId":"57","endLine":6,"endColumn":13},{"ruleId":"54","severity":1,"message":"59","line":19,"column":7,"nodeType":"56","messageId":"57","endLine":19,"endColumn":14},{"ruleId":"54","severity":1,"message":"60","line":76,"column":13,"nodeType":"56","messageId":"57","endLine":76,"endColumn":18},"no-native-reassign",["61"],"no-negated-in-lhs",["62"],"@typescript-eslint/no-unused-vars","'Button' is defined but never used.","Identifier","unusedVar","'Title' is assigned a value but never used.","'OneWide' is assigned a value but never used.","'msnry' is assigned a value but never used.","no-global-assign","no-unsafe-negation"] \ No newline at end of file diff --git a/src/components/ProjectGrid.scss b/src/components/ProjectGrid.scss index 181d672..4ab77f4 100644 --- a/src/components/ProjectGrid.scss +++ b/src/components/ProjectGrid.scss @@ -1,26 +1,81 @@ @import "~include-media/dist/_include-media.scss"; -$breakpoints: (phone: 320px, tablet: 768px, desktop: 1024px); +$breakpoints: (x-small: 320px, small: 660px, medium: 900px, large: 1300px, x-large: 1560px); -#project-grid { - display: grid; +// Override Sass min() +@function min($numbers...) { + @return m#{i}n(#{$numbers}); +} + +// Override Sass max() +@function max($numbers...) { + @return m#{a}x(#{$numbers}); +} + +#project-grid { margin: 10px; background: #FFD43B; border-radius: 5px; + //padding: 10px; + @include media("<=x-small") { + .GridSizer, .OneByOne, .FourByOne { + width: 100%; + } + } + @include media(">x-small", "=small", "=medium", "=large", "=x-large") { + .GridSizer, .OneByOne { + width: 300px; + } + .FourByOne { + width: 1200px; + } + } - //@include media(">phone") { - grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); - grid-gap: 5px; - justify-items: stretch; - align-items: stretch; - //} } -.OneByOneGridElement { +.OneByOne { display: flex; flex-direction: column; width: available; @@ -36,7 +91,7 @@ $breakpoints: (phone: 320px, tablet: 768px, desktop: 1024px); } } -.FourByOneGridElement { +.FourByOne { grid-column: span 2; display: flex; flex-direction: row; diff --git a/src/components/ProjectGrid.tsx b/src/components/ProjectGrid.tsx index 5ff896f..784f101 100644 --- a/src/components/ProjectGrid.tsx +++ b/src/components/ProjectGrid.tsx @@ -1,87 +1,172 @@ import "./ProjectGrid.scss"; import Masonry from "masonry-layout"; +import {useEffect} from "react"; +type GridElementImageProps = { + image_url: string; + image_alt: string; + title: string; + text: string; +}; type GridElementProps = { - image_url: string; - image_alt: string; - text: string; + image_url: string; + image_alt: string; + title: string; + text: string; +}; + +const OneWide = ({title, text}: GridElementProps) => { + return ( +
+
+

{title}

+
+
+

{text}

+
+
+ ); }; -const OneByOneGridElement = ({ - image_url, - image_alt, - text, -}: GridElementProps) => { - return ( -
-
- {image_alt} -
-
-

{text}

-
-
- ); +const OneWidePic = ({ + image_url, + image_alt, + title, + text, + }: GridElementImageProps) => { + return ( +
+
+ {image_alt}/ +
+
+

{title}

+

{text}

+
+
+ ); }; const FourByOneGridElement = ({ - image_url, - image_alt, - text, -}: GridElementProps) => { - return ( -
-
- {image_alt} -
-
-

{text}

-
-
- ); + image_url, + image_alt, + title, + text, + }: GridElementImageProps) => { + return ( +
+
+ {image_alt}/ +
+
+

{title}

+ +

{text}

+
+
+ ); }; export const ProjectGrid = () => { + useEffect(() => { + var elem = document.querySelector("#project-grid"); + + // @ts-ignore + var msnry = new Masonry(elem, { + itemSelector: ".GridElement", + gutter: 5, + columnWidth: ".GridSizer", + percentPosition: true, + }); + }); + return ( +
+
+
+ + + + + + - return ( -
- - - - - -
- ); + + + + +
+
+ ); }; diff --git a/src/cusotmHooks.ts b/src/cusotmHooks.ts new file mode 100644 index 0000000..6c9865e --- /dev/null +++ b/src/cusotmHooks.ts @@ -0,0 +1,33 @@ +import {useEffect, useState} from "react"; + + +export function useWindowSize() { + // Initialize state with undefined width/height so server and client renders match + // Learn more here: https://joshwcomeau.com/react/the-perils-of-rehydration/ + const [windowSize, setWindowSize] = useState({ + width: 0, + height: 0, + }); + + useEffect(() => { + // Handler to call on window resize + function handleResize() { + // Set window width/height to state + setWindowSize({ + width: window.innerWidth, + height: window.innerHeight, + }); + } + + // Add event listener + window.addEventListener("resize", handleResize); + + // Call handler right away so state gets updated with initial window size + handleResize(); + + // Remove event listener on cleanup + return () => window.removeEventListener("resize", handleResize); + }, []); // Empty array ensures that effect is only run on mount + + return windowSize; +}