Skip to content

Commit 10bf5ac

Browse files
authored
feat(FlexBox): introduce gap prop (#6849)
Closes #6832
1 parent 567a1b3 commit 10bf5ac

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

packages/main/src/components/FlexBox/FlexBox.cy.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ describe('FlexBox', () => {
9494
.should('have.css', 'height', '200px');
9595
});
9696

97+
it('gap', () => {
98+
cy.mount(
99+
<FlexBox gap="1337px" data-testid="fb">
100+
<div>Item 1</div>
101+
<div>Item 2</div>
102+
<div>Item 3</div>
103+
<div>Item 4</div>
104+
</FlexBox>
105+
);
106+
cy.findByTestId('fb').should('have.css', 'gap', '1337px');
107+
});
108+
97109
mountWithCustomTagName<FlexBoxPropTypes>(FlexBox, { children: <span>Test 1</span> });
98110
cypressPassThroughTestsFactory(FlexBox);
99111
});

packages/main/src/components/FlexBox/index.tsx

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@
22

33
import { useStylesheet } from '@ui5/webcomponents-react-base';
44
import { clsx } from 'clsx';
5-
import type { ElementType, ReactNode } from 'react';
5+
import type { CSSProperties, ElementType, ReactNode } from 'react';
66
import { forwardRef } from 'react';
77
import { FlexBoxAlignItems, FlexBoxDirection, FlexBoxJustifyContent, FlexBoxWrap } from '../../enums/index.js';
88
import type { CommonProps } from '../../types/index.js';
99
import { classNames, styleData } from './FlexBox.module.css.js';
1010

1111
export interface FlexBoxPropTypes extends CommonProps {
1212
/**
13-
* Controls the alignment of items on the Cross Axis.<br />
14-
* <b>Note:</b> Corresponds to `align-items`.
13+
* Controls the alignment of items on the Cross Axis.
14+
*
15+
* __Note:__ Corresponds to `align-items`.
1516
*/
1617
alignItems?: FlexBoxAlignItems | keyof typeof FlexBoxAlignItems;
1718
/**
18-
* Controls how the items are placed in the `FlexBox`.<br />
19-
* <b>Note:</b> Corresponds to `flex-direction`.
19+
* Controls how the items are placed in the `FlexBox`.
20+
*
21+
* __Note:__ Corresponds to `flex-direction`.
2022
*/
2123
direction?: FlexBoxDirection | keyof typeof FlexBoxDirection;
2224
/**
@@ -30,15 +32,23 @@ export interface FlexBoxPropTypes extends CommonProps {
3032
*/
3133
fitContainer?: boolean;
3234
/**
33-
* Defines how the browser distributes space between and around items along the main-axis.<br />
34-
* <b>Note:</b> Corresponds to `justify-content`.
35+
* Defines how the browser distributes space between and around items along the main-axis.
36+
*
37+
* __Note:__ Corresponds to `justify-content`.
3538
*/
3639
justifyContent?: FlexBoxJustifyContent | keyof typeof FlexBoxJustifyContent;
3740
/**
38-
* Determines whether the `FlexBox` should wrap, when there is not enough space to display all items in one line.<br />
39-
* <b>Note:</b> Corresponds to `flex-wrap`.
41+
* Determines whether the `FlexBox` should wrap, when there is not enough space to display all items in one line.
42+
*
43+
* __Note:__ Corresponds to `flex-wrap`.
4044
*/
4145
wrap?: FlexBoxWrap | keyof typeof FlexBoxWrap;
46+
/**
47+
* Define the gap (gutters) between flex items and flex lines.
48+
*
49+
* __Note:__ Corresponds to the `gap` CSS Property.
50+
*/
51+
gap?: CSSProperties['gap'];
4252
/**
4353
* Content of the `FlexBox`.
4454
*/
@@ -64,7 +74,9 @@ const FlexBox = forwardRef<HTMLDivElement, FlexBoxPropTypes>((props, ref) => {
6474
wrap = FlexBoxWrap.NoWrap,
6575
className,
6676
fitContainer,
77+
gap,
6778
as = 'div',
79+
style,
6880
...rest
6981
} = props;
7082

@@ -82,7 +94,7 @@ const FlexBox = forwardRef<HTMLDivElement, FlexBoxPropTypes>((props, ref) => {
8294

8395
const CustomTag = as as ElementType;
8496
return (
85-
<CustomTag ref={ref} className={flexBoxClasses} {...rest}>
97+
<CustomTag ref={ref} className={flexBoxClasses} style={{ gap, ...style }} {...rest}>
8698
{children}
8799
</CustomTag>
88100
);

0 commit comments

Comments
 (0)