Skip to content

Commit

Permalink
feat(project): add card grid component
Browse files Browse the repository at this point in the history
  • Loading branch information
demmyhonore committed Apr 30, 2021
1 parent 6cad244 commit ca52c6b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/components/CardGrid/CardGrid.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.cardGrid {
display: grid;
grid-gap: 8px;
}
12 changes: 12 additions & 0 deletions src/components/CardGrid/CardGrid.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as React from 'react';
import { render } from '@testing-library/react';

import CardGrid from './CardGrid';

describe('<CardGrid>', () => {
it('renders card grid and children', () => {
const { getByText } = render((<CardGrid>aa</CardGrid>));
const cardGrid = getByText(/aa/i);
expect(document.body.contains(cardGrid));
});
});
29 changes: 29 additions & 0 deletions src/components/CardGrid/CardGrid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';

import useBreakpoint from '../../hooks/useBreakpoint';

import styles from './CardGrid.module.scss';

// TEMP DATA
const cols = { "xs": 2, "sm": 3, "md": 4, "lg": 5, "xl": 6 }

type CardGridProps = {
children: React.ReactNode;
};

function CardGrid({
children,
}: CardGridProps) {
const breakpoint = useBreakpoint();

return (
<div
className={styles.cardGrid}
style={{ gridTemplateColumns: `repeat(${cols[breakpoint]}, minmax(0,1fr))` }}
>
{children}
</div>
);
}

export default CardGrid;

0 comments on commit ca52c6b

Please sign in to comment.