Skip to content

feat(FlexBox): introduce gap prop #6849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/main/src/components/FlexBox/FlexBox.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ describe('FlexBox', () => {
.should('have.css', 'height', '200px');
});

it('gap', () => {
cy.mount(
<FlexBox gap="1337px" data-testid="fb">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
<div>Item 4</div>
</FlexBox>
);
cy.findByTestId('fb').should('have.css', 'gap', '1337px');
});

mountWithCustomTagName<FlexBoxPropTypes>(FlexBox, { children: <span>Test 1</span> });
cypressPassThroughTestsFactory(FlexBox);
});
32 changes: 22 additions & 10 deletions packages/main/src/components/FlexBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@

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

export interface FlexBoxPropTypes extends CommonProps {
/**
* Controls the alignment of items on the Cross Axis.<br />
* <b>Note:</b> Corresponds to `align-items`.
* Controls the alignment of items on the Cross Axis.
*
* __Note:__ Corresponds to `align-items`.
*/
alignItems?: FlexBoxAlignItems | keyof typeof FlexBoxAlignItems;
/**
* Controls how the items are placed in the `FlexBox`.<br />
* <b>Note:</b> Corresponds to `flex-direction`.
* Controls how the items are placed in the `FlexBox`.
*
* __Note:__ Corresponds to `flex-direction`.
*/
direction?: FlexBoxDirection | keyof typeof FlexBoxDirection;
/**
Expand All @@ -30,15 +32,23 @@ export interface FlexBoxPropTypes extends CommonProps {
*/
fitContainer?: boolean;
/**
* Defines how the browser distributes space between and around items along the main-axis.<br />
* <b>Note:</b> Corresponds to `justify-content`.
* Defines how the browser distributes space between and around items along the main-axis.
*
* __Note:__ Corresponds to `justify-content`.
*/
justifyContent?: FlexBoxJustifyContent | keyof typeof FlexBoxJustifyContent;
/**
* Determines whether the `FlexBox` should wrap, when there is not enough space to display all items in one line.<br />
* <b>Note:</b> Corresponds to `flex-wrap`.
* Determines whether the `FlexBox` should wrap, when there is not enough space to display all items in one line.
*
* __Note:__ Corresponds to `flex-wrap`.
*/
wrap?: FlexBoxWrap | keyof typeof FlexBoxWrap;
/**
* Define the gap (gutters) between flex items and flex lines.
*
* __Note:__ Corresponds to the `gap` CSS Property.
*/
gap?: CSSProperties['gap'];
/**
* Content of the `FlexBox`.
*/
Expand All @@ -64,7 +74,9 @@ const FlexBox = forwardRef<HTMLDivElement, FlexBoxPropTypes>((props, ref) => {
wrap = FlexBoxWrap.NoWrap,
className,
fitContainer,
gap,
as = 'div',
style,
...rest
} = props;

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

const CustomTag = as as ElementType;
return (
<CustomTag ref={ref} className={flexBoxClasses} {...rest}>
<CustomTag ref={ref} className={flexBoxClasses} style={{ gap, ...style }} {...rest}>
{children}
</CustomTag>
);
Expand Down
Loading