From 94448fa278ab352a741ff13f22d6104869571144 Mon Sep 17 00:00:00 2001 From: Armand Philippot 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) => ( +
{children}
+); + const H1 = ({ children = '', ...props @@ -256,8 +262,15 @@ const MoreLinks: FC = () => { ); }; -const StyledColumns = (props: ColumnsProps) => ( - +const StyledGrid = ({ children }: { children: ReactNode[] }) => ( + { + return { id: `${index}`, item: child }; + })} + sizeMin="250px" + /> ); /** @@ -303,9 +316,9 @@ const HomePage: NextPageWithLayout = ({ 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: ( = ({ recentPosts }) => { }); const listClass = `${styles.list} ${styles['list--cards']}`; - return ; + return ( + + ); }; const components: MDXComponents = { CodingLinks, ColdarkRepos, Column, - Columns: StyledColumns, + Grid: StyledGrid, h1: H1, h2: H2, h3: H3, -- cgit v1.2.3