Skip to content
Snippets Groups Projects
Commit e14d3b3a authored by tovo's avatar tovo Committed by Tojo
Browse files

fix cardlist

parent 981783e5
No related branches found
No related tags found
No related merge requests found
......@@ -127,6 +127,7 @@ interface CardListProps {
cards?: CardProps[];
layout?: 'row' | 'col' | 'grid';
className?: string;
anime?: boolean;
}
export function CardList(props: CardListProps): JSX.Element;
......
......
......@@ -2,9 +2,6 @@ import React from "react";
import { IGatsbyImageData } from "gatsby-plugin-image";
import Card from "./Card";
import CardListColumn from "./cardlist/CardListColumn";
import CardListGrid from "./cardlist/CardListGrid";
import CardListRow from "./cardlist/CardListRow";
interface CardProps {
......@@ -21,29 +18,21 @@ interface Props {
cards?: CardProps[];
layout?: 'row' | 'col' | 'grid';
className?: string;
anime?: boolean;
}
const oComponents = {
'row': CardListRow,
'col': CardListColumn,
'grid': CardListGrid
}
const oCardProps = {
'row': {
layout: 'left',
anime: false,
className: ''
},
'col': {
layout: 'top',
anime: true,
className: ''
},
'grid': {
layout: 'top',
anime: true,
className: 'max-w-full'
}
}
......@@ -53,16 +42,23 @@ const CardList = (props: Props) => {
const {
cards = [],
layout = 'row',
className = ''
className = '',
anime = true
} = props;
const CardListComponent = oComponents[layout];
const oListClassName = {
'row': `space-y-10 w-full ${className}`,
'col': `flex space-x-12 flex-nowrap justify-center ${className}`,
'grid': `grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-12 ${className}`
}
const tmpProps = oCardProps[layout];
const listCards = cards.map((card, index) => {
let cardProps = {
...card,
...tmpProps
...tmpProps,
anime
};
return (
......@@ -74,11 +70,11 @@ const CardList = (props: Props) => {
})
return (
<CardListComponent
className={className}
<div
className={oListClassName[layout]}
>
{listCards}
</CardListComponent>
</div>
)
};
......
......
import React, { PropsWithChildren } from "react";
interface Props {
className?: string;
}
const CardListColumn = (props: PropsWithChildren<Props>) => {
const {
children,
className = ''
} = props;
return (
<div className={`${className} flex space-x-12 flex-nowrap justify-center`}>
{children}
</div>
)
};
export default CardListColumn;
\ No newline at end of file
import React, { PropsWithChildren } from "react";
interface Props {
className?: string;
}
const CardListGrid = (props: PropsWithChildren<Props>) => {
const {
children,
className = ''
} = props;
return (
<div className={`${className} grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-12`}>
{children}
</div>
)
};
export default CardListGrid;
\ No newline at end of file
import React, { PropsWithChildren } from "react";
interface Props {
className?: string;
}
const CardListRow = (props: PropsWithChildren<Props>) => {
const {
children,
className = ''
} = props;
return (
<div className={`${className} space-y-10 w-full`}>
{children}
</div>
)
};
export default CardListRow;
\ No newline at end of file
......@@ -24,6 +24,7 @@ interface CardProps {
anime?: boolean;
layout?: "top" | "left";
className?: string;
anime?: boolean;
}
interface CardListProps {
cards?: CardProps[];
......@@ -49,6 +50,7 @@ interface CardListProps {
content: 'Action description for the Button'
}]}
layout='row'
anime={false}
/>
<CardList
cards={[{
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment