Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(fuselage): CardGrid component #1242

Merged
merged 11 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/unlucky-parents-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/fuselage": minor
---

feat(fuselage): `CardGrid` component
31 changes: 31 additions & 0 deletions packages/fuselage/src/components/CardGrid/CardGrid.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { composeStories } from '@storybook/testing-react';
import { render } from '@testing-library/react';
import { axe } from 'jest-axe';
import React from 'react';

import * as stories from './CardGrid.stories';

const testCases = Object.values(composeStories(stories)).map((Story) => [
Story.storyName || 'Story',
Story,
]);

describe('[CardGrid Rendering]', () => {
test.each(testCases)(
`renders %s without crashing`,
async (_storyname, Story) => {
const tree = render(<Story />);
expect(tree.baseElement).toMatchSnapshot();
}
);

test.each(testCases)(
'%s should have no a11y violations',
async (_storyname, Story) => {
const { container } = render(<Story />);

const results = await axe(container);
expect(results).toHaveNoViolations();
}
);
});
60 changes: 60 additions & 0 deletions packages/fuselage/src/components/CardGrid/CardGrid.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import type { ComponentMeta, ComponentStory } from '@storybook/react';
import type { ComponentProps } from 'react';
import React from 'react';

import { CardGrid } from '.';
import { Button } from '../Button';
import {
Card,
CardBody,
CardCol,
CardControls,
CardHeader,
CardTitle,
} from '../Card';
import { Icon } from '../Icon';

export default {
title: 'Containers/CardGrid',
component: CardGrid,
parameters: {
backgrounds: { default: 'dark' },
layout: 'centered',
controls: { hideNoControlsWarning: true },
},
} as ComponentMeta<typeof CardGrid>;

const CardItem = (props: ComponentProps<typeof Card>) => (
<Card {...props}>
<CardCol>
<CardHeader>
<Icon name='address-book' size='x24' />
<CardTitle variant='h3' info='Heading info'>
Heading 3
</CardTitle>
</CardHeader>
<CardBody>
Lorem ipsum dolor sit amet. In adipisci consequatur qui laudantium rem
praesentium earum ut consectetur. Lorem ipsum dolor sit amet. In
adipisci consequatur qui laudantium rem praesentium earum ut
consectetur.
</CardBody>
</CardCol>
<CardControls>
<Button medium primary>
Button
</Button>
<Button medium>Button</Button>
</CardControls>
</Card>
);

export const _CardGrid: ComponentStory<typeof CardGrid> = (
args: ComponentProps<typeof CardGrid>
) => (
<CardGrid {...args} breakpoints={{ xs: 4, sm: 4, md: 4, lg: 3, xl: 3 }}>
{Array.from(new Array(9)).map((_, index) => (
<CardItem key={index} />
))}
</CardGrid>
);
23 changes: 23 additions & 0 deletions packages/fuselage/src/components/CardGrid/CardGrid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { ComponentProps } from 'react';
import React from 'react';

import Grid, { GridItem } from '../Grid';

type CardGridProps = {
children: React.ReactNode;
breakpoints: ComponentProps<typeof GridItem>;
};

export const CardGrid = ({
children,
breakpoints,
...props
}: CardGridProps) => (
<Grid rcx-card-grid m={-8} {...props}>
{React.Children.map(children, (child) => (
<GridItem rcx-card-grid__item p={8} {...breakpoints}>
{child}
</GridItem>
))}
</Grid>
);
Loading
Loading