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

Commit

Permalink
fix(Grid): allow more flexibility with gap customization
Browse files Browse the repository at this point in the history
  • Loading branch information
Cecilia Woodward committed Aug 21, 2021
1 parent 0dafe19 commit 6844649
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
5 changes: 4 additions & 1 deletion stories/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import classNames from 'classnames';
import React, { ReactNode } from 'react';
import styles from './Card.scss';
import { Layout } from './constants';
import { Grid } from './Grid';
import { Gap, Grid } from './Grid';
import { Spinner } from './Spinner';

export interface CardProps {
Expand All @@ -11,13 +11,15 @@ export interface CardProps {
className?: string;
layout?: Layout;
loading?: boolean;
gap?: number | Gap;
}

export function Card({
children,
className,
layout = Layout.Vertical,
loading = false,
gap,
...props
}: CardProps): JSX.Element {
return (
Expand All @@ -33,6 +35,7 @@ export function Card({
styles.content,
className,
)}
gap={gap}
layout={layout}
>
{children}
Expand Down
17 changes: 15 additions & 2 deletions stories/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ import { AlignItems, JustifyContent, Layout } from './constants';

import styles from './Grid.scss';

export interface Gap {
row: number;
column: number;
}

export interface GridProps {
[key: string]: any;
alignItems?: AlignItems;
justifyContent?: JustifyContent;
children: ReactNode;
className?: string;
layout: Layout;
gap?: number;
gap?: number | Gap;
type?: ElementType;
}

Expand All @@ -25,6 +30,13 @@ export function Grid({
type: Type = 'div',
...props
}: GridProps): JSX.Element {
const normalizedGap: Gap = typeof(gap) === 'number' ? {
column: gap,
row: gap,
} : {
column: gap.column,
row: gap.row,
};
return (
<Type
className={classNames(
Expand All @@ -34,7 +46,8 @@ export function Grid({
)}
style={{
alignItems,
gap: `${gap}px`,
columnGap: `${normalizedGap.column}px`,
rowGap: `${normalizedGap.row}px`,
justifyContent,
}}
{...props}
Expand Down

0 comments on commit 6844649

Please sign in to comment.