diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fd1af09a..e59c90298 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ### Added +- `Flex`: Allow class names +- `Grid`: Allow class names + ### Changed ### Deprecated @@ -10,6 +13,8 @@ ### Fixed +- `Grid`: Export `GridItem` through the `Grid` component + ### Dependency updates ## [18.3.0] - 2022-12-19 diff --git a/src/components/flex/Flex.tsx b/src/components/flex/Flex.tsx index c37ba4d4a..da17e985c 100644 --- a/src/components/flex/Flex.tsx +++ b/src/components/flex/Flex.tsx @@ -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 = forwardRef( - ({ 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 }; diff --git a/src/components/grid/Grid.tsx b/src/components/grid/Grid.tsx index f2fc73db1..d8e9cbe66 100644 --- a/src/components/grid/Grid.tsx +++ b/src/components/grid/Grid.tsx @@ -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; @@ -14,16 +15,24 @@ export type GridProps = Partial<{ gap: Gap; columnGap: Gap; rowGap: Gap; - ref: ForwardedRef; + className: string; }>; +export interface GridWithSubcomponentProps extends GenericComponent { + Item: GenericComponent; +} + const Grid: GenericComponent = forwardRef( - ({ 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(' '), @@ -41,4 +50,7 @@ const Grid: GenericComponent = forwardRef( Grid.displayName = 'Grid'; -export default Grid; +const GridWithSubComponents = Grid as GridWithSubcomponentProps; +GridWithSubComponents.Item = GridItem; + +export default GridWithSubComponents; diff --git a/src/components/grid/grid.stories.tsx b/src/components/grid/grid.stories.tsx index 31c47a413..05c05d18b 100644 --- a/src/components/grid/grid.stories.tsx +++ b/src/components/grid/grid.stories.tsx @@ -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, @@ -15,7 +14,7 @@ export const basic: ComponentStory = (args) => ( Grid Box - + = (args) => ( height: '100%', }} /> - - + + = (args) => ( height: '200px', }} /> - - + + = (args) => ( height: '100%', }} /> - - + + = (args) => ( height: '100%', }} /> - +