aboutsummaryrefslogtreecommitdiffstats
path: root/src/pages/index.tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-10-18 19:25:02 +0200
committerArmand Philippot <git@armandphilippot.com>2023-11-11 18:14:41 +0100
commit94448fa278ab352a741ff13f22d6104869571144 (patch)
tree2185e77f2866d11a0144d4ac5a01c71a76807341 /src/pages/index.tsx
parentc153f93dc8691a71dc76aad3dd618298da9d238a (diff)
feat(components): add a generic Grid component
* merge Columns, Gallery and CardsList into Grid component * add more options to control the grid
Diffstat (limited to 'src/pages/index.tsx')
-rw-r--r--src/pages/index.tsx45
1 files changed, 33 insertions, 12 deletions
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,