From 94448fa278ab352a741ff13f22d6104869571144 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Wed, 18 Oct 2023 19:25:02 +0200
Subject: feat(components): add a generic Grid component

* merge Columns, Gallery and CardsList into Grid component
* add more options to control the grid
---
 src/pages/index.tsx | 45 +++++++++++++++++++++++++++++++++------------
 1 file changed, 33 insertions(+), 12 deletions(-)

(limited to 'src/pages/index.tsx')

diff --git a/src/pages/index.tsx b/src/pages/index.tsx
index e482fb4..7ff1379 100644
--- a/src/pages/index.tsx
+++ b/src/pages/index.tsx
@@ -4,7 +4,7 @@ import type { GetStaticProps } from 'next';
 import Head from 'next/head';
 import NextImage, { type ImageProps as NextImageProps } from 'next/image';
 import Script from 'next/script';
-import type { FC, HTMLAttributes } from 'react';
+import type { FC, HTMLAttributes, ReactNode } from 'react';
 import { useIntl } from 'react-intl';
 import {
   ButtonLink,
@@ -14,13 +14,10 @@ import {
   CardHeader,
   CardMeta,
   CardTitle,
-  CardsList,
-  type CardsListItem,
-  Column,
-  Columns,
-  type ColumnsProps,
   Figure,
   getLayout,
+  Grid,
+  type GridItem,
   Heading,
   Icon,
   List,
@@ -38,6 +35,15 @@ import { getSchemaJson, getWebPageSchema } from '../utils/helpers';
 import { loadTranslation, type Messages } from '../utils/helpers/server';
 import { useBreadcrumb, useSettings } from '../utils/hooks';
 
+/**
+ * Column component.
+ *
+ * Render the body as a column.
+ */
+const Column = ({ children, ...props }: HTMLAttributes<HTMLDivElement>) => (
+  <div {...props}>{children}</div>
+);
+
 const H1 = ({
   children = '',
   ...props
@@ -256,8 +262,15 @@ const MoreLinks: FC = () => {
   );
 };
 
-const StyledColumns = (props: ColumnsProps) => (
-  <Columns className={styles.columns} {...props} />
+const StyledGrid = ({ children }: { children: ReactNode[] }) => (
+  <Grid
+    className={styles.columns}
+    gap="sm"
+    items={children.map((child, index) => {
+      return { id: `${index}`, item: child };
+    })}
+    sizeMin="250px"
+  />
 );
 
 /**
@@ -303,9 +316,9 @@ const HomePage: NextPageWithLayout<HomeProps> = ({ recentPosts }) => {
    * @returns {JSX.Element} - The cards list.
    */
   const getRecentPosts = (): JSX.Element => {
-    const posts: CardsListItem[] = recentPosts.map((post) => {
+    const posts: GridItem[] = recentPosts.map((post) => {
       return {
-        card: (
+        item: (
           <Card
             cover={
               post.cover ? (
@@ -345,14 +358,22 @@ const HomePage: NextPageWithLayout<HomeProps> = ({ recentPosts }) => {
     });
     const listClass = `${styles.list} ${styles['list--cards']}`;
 
-    return <CardsList className={listClass} items={posts} />;
+    return (
+      <Grid
+        className={listClass}
+        gap="sm"
+        isCentered
+        items={posts}
+        sizeMax="25ch"
+      />
+    );
   };
 
   const components: MDXComponents = {
     CodingLinks,
     ColdarkRepos,
     Column,
-    Columns: StyledColumns,
+    Grid: StyledGrid,
     h1: H1,
     h2: H2,
     h3: H3,
-- 
cgit v1.2.3

