Skip to content

Commit 1903670

Browse files
authored
fix(SplitterLayout - TypeScript): extend children type (#7457)
The type now allows conditional rendering. The change also moves types to a dedicated file.
1 parent 498b5ec commit 1903670

File tree

3 files changed

+42
-36
lines changed

3 files changed

+42
-36
lines changed

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

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,13 @@
22

33
import { debounce, useStylesheet, useSyncRef } from '@ui5/webcomponents-react-base';
44
import { clsx } from 'clsx';
5-
import type { CSSProperties, DependencyList, ReactElement } from 'react';
5+
import type { CSSProperties } from 'react';
66
import { forwardRef, useEffect, useRef, useState } from 'react';
77
import { SplitterLayoutContext } from '../../internal/SplitterLayoutContext.js';
8-
import type { CommonProps } from '../../types/index.js';
9-
import type { SplitterElementPropTypes } from '../SplitterElement/index.js';
108
import { classNames, styleData } from './SplitterLayout.module.css.js';
9+
import type { SplitterLayoutPropTypes } from './types.js';
1110
import { useConcatSplitterElements } from './useConcatSplitterElements.js';
1211

13-
interface SplitterLayoutOptions {
14-
/**
15-
* Defines whether the `SplitterLayout` should be reset when its size changes depending on the orientation.
16-
*/
17-
resetOnSizeChange?: boolean;
18-
/**
19-
* Defines whether the `SplitterLayout` should be reset when its `children` change.
20-
*/
21-
resetOnChildrenChange?: boolean;
22-
/**
23-
* Defines a list of dependencies that trigger a reset of the `SplitterLayout` when they are changed.
24-
*
25-
* __Note:__ The order and size of arrays of dependencies must remain constant in React, it's therefore not possible to change size or order between renders.
26-
*/
27-
resetOnCustomDepsChange?: DependencyList;
28-
}
29-
30-
export interface SplitterLayoutPropTypes extends CommonProps {
31-
/**
32-
* Controls if a vertical or horizontal `SplitterLayout` is rendered.
33-
*/
34-
vertical?: boolean;
35-
/**
36-
* The content areas (optional) to be split. The control will show n-1 splitter bars between n controls in this aggregation.
37-
*/
38-
children?: ReactElement<SplitterElementPropTypes> | ReactElement<SplitterElementPropTypes>[];
39-
/**
40-
* Defines options to customize the behavior of the SplitterLayout.
41-
*/
42-
options?: SplitterLayoutOptions;
43-
}
44-
4512
/**
4613
* A layout that contains several content areas. The content that is added to the `SplitterLayout` should be wrapped
4714
* into 0-n `SplitterElement`s which define the size and size constraints of the content area.
@@ -137,4 +104,5 @@ const SplitterLayout = forwardRef<HTMLDivElement, SplitterLayoutPropTypes>((prop
137104

138105
SplitterLayout.displayName = 'SplitterLayout';
139106

107+
export type { SplitterLayoutPropTypes };
140108
export { SplitterLayout };
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import type { CommonProps } from '@ui5/webcomponents-react-base';
2+
import type { DependencyList, ReactElement } from 'react';
3+
import type { SplitterElementPropTypes } from '../SplitterElement/index.js';
4+
5+
interface SplitterLayoutOptions {
6+
/**
7+
* Defines whether the `SplitterLayout` should be reset when its size changes depending on the orientation.
8+
*/
9+
resetOnSizeChange?: boolean;
10+
/**
11+
* Defines whether the `SplitterLayout` should be reset when its `children` change.
12+
*/
13+
resetOnChildrenChange?: boolean;
14+
/**
15+
* Defines a list of dependencies that trigger a reset of the `SplitterLayout` when they are changed.
16+
*
17+
* __Note:__ The order and size of arrays of dependencies must remain constant in React, it's therefore not possible to change size or order between renders.
18+
*/
19+
resetOnCustomDepsChange?: DependencyList;
20+
}
21+
22+
type SplitterLayoutChild = ReactElement<SplitterElementPropTypes> | undefined | false | null;
23+
24+
export interface SplitterLayoutPropTypes extends CommonProps {
25+
/**
26+
* Controls if a vertical or horizontal `SplitterLayout` is rendered.
27+
*/
28+
vertical?: boolean;
29+
/**
30+
* The content areas (optional) to be split. The control will show n-1 splitter bars between n controls in this aggregation.
31+
*/
32+
children?: SplitterLayoutChild | SplitterLayoutChild[];
33+
/**
34+
* Defines options to customize the behavior of the SplitterLayout.
35+
*/
36+
options?: SplitterLayoutOptions;
37+
}

packages/main/src/components/SplitterLayout/useConcatSplitterElements.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import type { CSSProperties, ReactElement } from 'react';
22
import { Children, cloneElement, isValidElement, useMemo } from 'react';
33
import { Splitter } from '../Splitter/index.js';
44
import type { SplitterElementPropTypes } from '../SplitterElement/index.js';
5+
import type { SplitterLayoutPropTypes } from './types.js';
56

67
interface ConcatSplitterElements {
7-
children: ReactElement<SplitterElementPropTypes> | ReactElement<SplitterElementPropTypes>[];
8+
children: SplitterLayoutPropTypes['children'];
89
width: CSSProperties['width'];
910
height: CSSProperties['height'];
1011
vertical: boolean;

0 commit comments

Comments
 (0)