Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2506 from teamleadercrm/FRONT-354-fix-Grid-Item
Browse files Browse the repository at this point in the history
[FRONT-354] Fix GridItem
  • Loading branch information
farazatarodi authored Jan 2, 2023
2 parents f7f0b66 + 9eecf62 commit 10cd92f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

### Added

- `Flex`: Allow class names
- `Grid`: Allow class names

### Changed

### Deprecated
Expand All @@ -10,6 +13,8 @@

### Fixed

- `Grid`: Export `GridItem` through the `Grid` component

### Dependency updates

## [18.3.0] - 2022-12-19
Expand Down
14 changes: 10 additions & 4 deletions src/components/flex/Flex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ export type FlexProps = Partial<{
// The library can be fixed with template literal types.
alignItems: 'center' | 'flex-start' | 'flex-end' | 'baseline' | 'stretch';
justifyContent: 'center' | 'flex-start' | 'flex-end' | 'space-around' | 'space-between' | 'space-evenly';
className: string;
}>;

const Flex: GenericComponent<FlexProps> = forwardRef<HTMLDivElement, FlexProps>(
({ children, direction = 'row', gap = 0, alignItems, justifyContent }, ref) => {
const classNames = cx(theme['flex'], theme[`${direction}`], {
[theme[`gap-${gap}`]]: gap > 0,
});
({ children, direction = 'row', gap = 0, alignItems, justifyContent, className }, ref) => {
const classNames = cx(
theme['flex'],
theme[`${direction}`],
{
[theme[`gap-${gap}`]]: gap > 0,
},
className,
);

const flexStyles = { alignItems, justifyContent };

Expand Down
30 changes: 21 additions & 9 deletions src/components/grid/Grid.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import cx from 'classnames';
import React, { ForwardedRef, forwardRef, ReactNode } from 'react';
import React, { forwardRef, ReactNode } from 'react';

import { GenericComponent } from '../../@types/types';
import GridItem, { GridItemProps } from './GridItem';
import theme from './theme.css';

type Gap = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
Expand All @@ -14,16 +15,24 @@ export type GridProps = Partial<{
gap: Gap;
columnGap: Gap;
rowGap: Gap;
ref: ForwardedRef<HTMLDivElement>;
className: string;
}>;

export interface GridWithSubcomponentProps extends GenericComponent<GridProps> {
Item: GenericComponent<GridItemProps>;
}

const Grid: GenericComponent<GridProps> = forwardRef<HTMLDivElement, GridProps>(
({ children, areas, rows, columns, gap = 0, columnGap = 0, rowGap = 0 }, ref) => {
const classNames = cx(theme['grid'], {
[theme[`gap-${gap}`]]: gap > 0,
[theme[`column-gap-${columnGap}`]]: columnGap > 0,
[theme[`row-gap-${rowGap}`]]: rowGap > 0,
});
({ children, areas, rows, columns, gap = 0, columnGap = 0, rowGap = 0, className }, ref) => {
const classNames = cx(
theme['grid'],
{
[theme[`gap-${gap}`]]: gap > 0,
[theme[`column-gap-${columnGap}`]]: columnGap > 0,
[theme[`row-gap-${rowGap}`]]: rowGap > 0,
},
className,
);

const gridStyles = {
gridTemplateAreas: areas?.map((area) => `"${area}"`).join(' '),
Expand All @@ -41,4 +50,7 @@ const Grid: GenericComponent<GridProps> = forwardRef<HTMLDivElement, GridProps>(

Grid.displayName = 'Grid';

export default Grid;
const GridWithSubComponents = Grid as GridWithSubcomponentProps;
GridWithSubComponents.Item = GridItem;

export default GridWithSubComponents;
17 changes: 8 additions & 9 deletions src/components/grid/grid.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React from 'react';
import { addStoryInGroup, LOW_LEVEL_BLOCKS } from '../../../.storybook/utils';
import { Grid, Box } from '../../index';
import { Heading3 } from '../typography';
import GridItem from './GridItem';

export default {
component: Grid,
Expand All @@ -15,7 +14,7 @@ export const basic: ComponentStory<typeof Grid> = (args) => (
<Heading3>Grid Box</Heading3>
<Box borderColor="neutral" borderWidth={1} borderRadius="rounded" backgroundColor="neutral" backgroundTint="light">
<Grid {...args}>
<GridItem area="header">
<Grid.Item area="header">
<Box
backgroundColor="mint"
backgroundTint="lightest"
Expand All @@ -27,8 +26,8 @@ export const basic: ComponentStory<typeof Grid> = (args) => (
height: '100%',
}}
/>
</GridItem>
<GridItem area="sidebar">
</Grid.Item>
<Grid.Item area="sidebar">
<Box
backgroundColor="teal"
backgroundTint="lightest"
Expand All @@ -40,8 +39,8 @@ export const basic: ComponentStory<typeof Grid> = (args) => (
height: '200px',
}}
/>
</GridItem>
<GridItem area="content">
</Grid.Item>
<Grid.Item area="content">
<Box
backgroundColor="gold"
backgroundTint="lightest"
Expand All @@ -53,8 +52,8 @@ export const basic: ComponentStory<typeof Grid> = (args) => (
height: '100%',
}}
/>
</GridItem>
<GridItem area="footer">
</Grid.Item>
<Grid.Item area="footer">
<Box
backgroundColor="ruby"
backgroundTint="lightest"
Expand All @@ -66,7 +65,7 @@ export const basic: ComponentStory<typeof Grid> = (args) => (
height: '100%',
}}
/>
</GridItem>
</Grid.Item>
</Grid>
</Box>
</Box>
Expand Down

0 comments on commit 10cd92f

Please sign in to comment.