From ab064e6c7fd3f8cf86a5f0378850ba5f8cbace65 Mon Sep 17 00:00:00 2001 From: Phuoc Nguyen Date: Tue, 30 Mar 2021 10:56:39 +0700 Subject: [PATCH] Split cards by a few chunks --- client/helpers/chunk.ts | 10 +++++ client/pages/HomePage.tsx | 95 +++++++++++++-------------------------- client/pages/home.css | 45 ++++++++++--------- webpack.config.js | 2 +- 4 files changed, 67 insertions(+), 85 deletions(-) create mode 100644 client/helpers/chunk.ts diff --git a/client/helpers/chunk.ts b/client/helpers/chunk.ts new file mode 100644 index 0000000..a9fcf68 --- /dev/null +++ b/client/helpers/chunk.ts @@ -0,0 +1,10 @@ +/** + * A collection of popular layouts and patterns made with CSS (https://csslayout.io) + * (c) 2019 - 2020 Nguyen Huu Phuoc + */ + +function chunk(arr: T[], size: number): T[][] { + return arr.reduce((acc, e, i) => (i % size ? acc[acc.length - 1].push(e) : acc.push([e]), acc), []); +}; + +export default chunk; diff --git a/client/pages/HomePage.tsx b/client/pages/HomePage.tsx index 0ab9c1f..c6f8028 100644 --- a/client/pages/HomePage.tsx +++ b/client/pages/HomePage.tsx @@ -12,13 +12,19 @@ import './home.css'; import Ad from '../components/Ad'; import CoverCard from '../components/CoverCard'; import Pattern from '../constants/Pattern'; +import chunk from '../helpers/chunk'; import useDocumentTitle from '../hooks/useDocumentTitle'; import Layout from '../layouts/Layout'; +const NUM_SLIDES = 3; + const HomePage = () => { useDocumentTitle('CSS Layout'); const numPatterns = Object.keys(Pattern).length; + const numPatternsPerSlide = Math.floor(numPatterns / NUM_SLIDES); + const groups = chunk(Object.entries(Pattern).map(([_, v]) => v).slice(0, NUM_SLIDES * numPatternsPerSlide), numPatternsPerSlide); + return ( @@ -34,80 +40,41 @@ const HomePage = () => {
-
-
Zero Dependencies
+
+
Zero Dependencies
-
-
No Frameworks
+
+
No Frameworks
-
-
No CSS Hacks
+
+
No CSS Hacks
-
-
Real Use Cases
+
+
Real Use Cases
-
-
Good Practices
+
+
Good Practices
-
-
Accessibility
+
+
Accessibility
-
-
{numPatterns} patterns
- Explore the collection +
+
{numPatterns} patterns
+ Explore the collection
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
+ { + groups.map((patterns, index) => ( +
+ { + patterns.map(pattern => ) + } +
+ )) + }
diff --git a/client/pages/home.css b/client/pages/home.css index fa23924..8e65c1a 100644 --- a/client/pages/home.css +++ b/client/pages/home.css @@ -31,28 +31,28 @@ margin: 2.5rem auto; max-width: 48rem; } -.home__features-feature { +.home__feature { padding: 2rem; text-align: center; width: 33.333%; } -.home__features-feature:not(:nth-child(3n)) { +.home__feature:not(:nth-child(3n)) { border-right: 1px solid var(--text-color); } -.home__features-feature:nth-child(-n+3) { +.home__feature:nth-child(-n+3) { border-bottom: 1px solid var(--text-color); } -.home__features-title { +.home__title { font-size: 2rem; font-weight: 500; } .home__patterns { - height: 80rem; + height: 60rem; overflow: hidden; position: relative; } -.home__patterns-overlay { +.home__overlay { align-items: center; display: flex; flex-direction: column; @@ -64,12 +64,12 @@ width: 100%; z-index: 10; } -.home__patterns-heading { +.home__heading { font-size: 4rem; font-weight: 600; margin-bottom: 1rem; } -.home__patterns-explore { +.home__explore { background-color: var(--background-color); border-radius: 0.4rem; color: var(--text-color); @@ -77,23 +77,28 @@ padding: 1rem 2rem; } -.home__patterns-content { - animation: slide 40s linear infinite; +.home__sliders { + align-items: center; + display: flex; + flex-wrap: nowrap; + opacity: 0.4; + width: 192rem; +} +.home__slide { + animation: slide 20s linear infinite; display: flex; flex-wrap: wrap; + height: 60rem; justify-content: center; - opacity: 0.4; - padding: 2rem 1rem; + width: 64rem; + will-change: transform; } -@keyframes slide{ - 0% { - transform: translateY(0); +@keyframes slide { + from { + transform: translateX(0); } - 50% { - transform: translateY(-40rem); - } - 100% { - transform: translateY(0); + to { + transform: translateX(-100%); } } diff --git a/webpack.config.js b/webpack.config.js index 0eb4825..f2835a0 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -75,4 +75,4 @@ module.exports = { port: 1234, }, plugins, -}; +}; \ No newline at end of file