Skip to content

Commit

Permalink
feat: added wrappers to Flex children components if spacing enabled (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaevAlexandr authored Mar 22, 2023
1 parent 0f49e6b commit 0a44309
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/components/layout/Flex/Flex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ export interface FlexProps<T extends React.ElementType> extends QAProps {
alignItems?: AdaptiveProp<'alignItems'>;
/**
* `flex-wrap` property
*
* If value equals `true`, add css property `flex-wrap: wrap`;
*/
wrap?: React.CSSProperties['flexWrap'];
width?: React.CSSProperties['width'];
wrap?: true | React.CSSProperties['flexWrap'];
width?: number;
/**
* display: inline-flex;
*/
Expand Down Expand Up @@ -179,7 +181,7 @@ export const Flex = React.forwardRef(
flexDirection:
typeof direction === 'function' ? direction(isMediaActive) : direction,
flexGrow: grow === true ? 1 : grow,
flexWrap: wrap,
flexWrap: wrap === true ? 'wrap' : wrap,
flexBasis: basis,
flexShrink: shrink,
gap: g ? SPACE_TO_PIXEL[g] : undefined,
Expand All @@ -197,7 +199,12 @@ export const Flex = React.forwardRef(
data-qa={qa}
{...restProps}
>
{children}
{space
? React.Children.map(children, (child) => (
// `space` uses negative margins under the hood. This is hack to prevent wrong background position appearance.
<div className={b('wr')}>{child}</div>
))
: children}
</Tag>
);
},
Expand Down
19 changes: 19 additions & 0 deletions src/components/layout/Flex/__stories__/Flex.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Row} from '../../Row/Row';
import {Box, LayoutPresenter} from '../../demo';
import {Container} from '../..';
import {Text} from '../../../Text';
import {Button} from '../../../Button/Button';

export default {
title: 'Layout (unstable)/Flex',
Expand Down Expand Up @@ -69,3 +70,21 @@ GapAndRowGap.args = {
gap: 'l',
rowGap: 'nano',
};

const ChildrenWithBgColorTemplate: Story<FlexProps<'div'>> = (args) => (
<LayoutPresenter title="Change screen size to 's' to see result">
<Container>
<Row>
<Col>
<Flex {...args} space wrap>
<Button>Some element with background</Button>
<Button>Some element with background</Button>
</Flex>
</Col>
</Row>
</Container>
</LayoutPresenter>
);

export const ChildrenWithBgColor = ChildrenWithBgColorTemplate.bind({});
ChildrenWithBgColor.args = {};

0 comments on commit 0a44309

Please sign in to comment.