Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
fix: added a Grid component
Browse files Browse the repository at this point in the history
  • Loading branch information
Cecilia Woodward committed Aug 20, 2021
1 parent 542e280 commit 905a2bc
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 15 deletions.
7 changes: 4 additions & 3 deletions stories/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import classNames from 'classnames';
import React, { FunctionComponent, ReactNode } from 'react';
import styles from './card.scss';
import { Layout } from './constants';
import { Grid } from './Grid';

export interface CardProps {
children?: ReactNode;
Expand All @@ -16,15 +17,15 @@ export const Card: FunctionComponent<CardProps> = ({
...props
}: CardProps) => {
return (
<div
<Grid
className={classNames(
styles.card,
styles[layout],
className
)}
layout={layout}
{...props}
>
{children}
</div>
</Grid>
);
};
13 changes: 13 additions & 0 deletions stories/Grid.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.grid {
display: grid;

&.horizontal {
grid-auto-columns: min-content;
grid-auto-flow: column;
}

&.vertical {
grid-auto-rows: auto;
grid-auto-flow: row;
}
}
50 changes: 50 additions & 0 deletions stories/Grid.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react';
import { Button } from './Button';

import { Grid, GridProps } from './Grid';
import { Layout } from './constants';
import { Icon } from './Icon';

export default {
title: 'Components/Grid',
component: Grid,
argTypes: {
children: {
table:{
disable: true,
},
},
},
};

const Template = (args: GridProps) => <Grid {...args} />;

export const Vertical = Template.bind({});
Vertical.args = {
children: (
<>
<Button>
<Icon icon='delete' />
</Button>
<Button>
<Icon icon='share' />
</Button>
</>
),
layout: Layout.Vertical,
};

export const Horizontal = Template.bind({});
Horizontal.args = {
children: (
<>
<Button>
<Icon icon='share'/>
</Button>
<Button>
<Icon icon='delete'/>
</Button>
</>
),
layout: Layout.Horizontal,
};
32 changes: 32 additions & 0 deletions stories/Grid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import classNames from 'classnames';
import React, { FunctionComponent, ReactNode } from 'react';
import { Layout } from './constants';

import styles from './Grid.scss';

export interface GridProps {
children: ReactNode;
className?: string;
layout?: Layout;
spacing?: number;
}

export const Grid: FunctionComponent<GridProps> = ({
children,
className,
layout = Layout.Vertical,
spacing = 10,
}: GridProps) => {
return (
<div
className={classNames(
styles.grid,
styles[layout],
className,
)}
style={{ gap: `${spacing}px` }}
>
{children}
</div>
);
};
12 changes: 0 additions & 12 deletions stories/card.scss
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
@use './variables' as *;

.card {
display: grid;
gap: 10px;
border-radius: $border-radius;
background-color: $secondary;
color: $primary-accent;
padding: $padding;
box-shadow: 0px 2px 2px 0px rgb(0 0 0 / 50%);

font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;

&.horizontal {
grid-auto-columns: min-content;
grid-auto-flow: column;
}

&.vertical {
grid-auto-rows: auto;
grid-auto-flow: row;
}
}
1 change: 1 addition & 0 deletions stories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export { Card } from './Card';
export { Checkbox } from './Checkbox';
export { Icon } from './Icon';
export { Input } from './Input';
export { Grid } from './Grid';

0 comments on commit 905a2bc

Please sign in to comment.