Skip to content

Commit e2ebcbb

Browse files
committed
fix(reconciler): augment row/column with container props
1 parent ce44113 commit e2ebcbb

4 files changed

Lines changed: 19 additions & 14 deletions

File tree

packages/generator/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ type JsxElementsInfo = {
4343
// special elements for Grid layout (these elements are not in BabylonJS)
4444
function createJsxGridElements(jsxElements: JsxElementsInfo) {
4545
const importStatement = `import type { RowProps, ColumnProps } from '../types/props';`;
46-
const rowDeclarationStatement = `row: React.DetailedHTMLProps<RowProps, any>;`;
47-
const columnDeclarationStatement = `column: React.DetailedHTMLProps<ColumnProps, any>;`;
46+
const rowDeclarationStatement = `row: React.DetailedHTMLProps<BabylonProps<ExcludeReadonlyAndPrivate<Container>,RowProps,Grid>, any>;`;
47+
const columnDeclarationStatement = `column: React.DetailedHTMLProps<BabylonProps<ExcludeReadonlyAndPrivate<Container>,ColumnProps,Grid>, any>;`;
4848

4949
jsxElements.imports.push(importStatement);
5050
jsxElements.declarations.push(rowDeclarationStatement, columnDeclarationStatement);

packages/library/src/_generated/babylon.gui.declarations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,6 @@ name: ConstructorParameters<typeof VolumeBasedPanel>[0];
419419
parentClass: ConstructorParameters<typeof XmlLoader>[0];
420420

421421
} & GuiProps,XmlLoader>, any>;
422-
row: React.DetailedHTMLProps<RowProps, any>;
423-
column: React.DetailedHTMLProps<ColumnProps, any>;
422+
row: React.DetailedHTMLProps<BabylonProps<ExcludeReadonlyAndPrivate<Container>,RowProps,Grid>, any>;
423+
column: React.DetailedHTMLProps<BabylonProps<ExcludeReadonlyAndPrivate<Container>,ColumnProps,Grid>, any>;
424424
}

packages/library/src/components/hosts/GridHost.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ type AugmentedGrid = BabylonEntity<
2929
}
3030
>;
3131

32+
const excludedProps = ['children', 'ref', 'height', 'width', 'isPixel', ...Object.keys(GuiTriggers)];
33+
3234
export class GridHost {
3335
static createInstance(type: 'row' | 'column', Class: any, props: RowProps | ColumnProps, rootContainer: RootContainer) {
3436
const scene = rootContainer.scene;
@@ -46,6 +48,15 @@ export class GridHost {
4648
};
4749
nestedGrid.parent = null;
4850

51+
// mainly styling purpose
52+
Object.keys(props)
53+
.filter(propName => !excludedProps.includes(propName))
54+
.forEach(_key => {
55+
const key = _key as keyof (RowProps | ColumnProps);
56+
const value = props[key];
57+
nestedGrid[key] = value;
58+
});
59+
4960
handleEvents(props, nestedGrid);
5061

5162
return nestedGrid;

packages/library/src/types/props.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,16 @@ export type GuiProps =
158158
// add here other gui props
159159
};
160160

161-
type WithChildren<T> = T & {
162-
children?: React.ReactNode;
163-
};
164-
165161
// Grid Layout Props
166-
export type RowProps = WithChildren<{
162+
export type RowProps = {
167163
height: Parameters<Grid['addRowDefinition']>[0];
168164
isPixel?: Parameters<Grid['addRowDefinition']>[1];
169-
}> &
170-
GuiProps;
165+
} & GuiProps;
171166

172-
export type ColumnProps = WithChildren<{
167+
export type ColumnProps = {
173168
width: Parameters<Grid['addColumnDefinition']>[0];
174169
isPixel?: Parameters<Grid['addColumnDefinition']>[1];
175-
}> &
176-
GuiProps;
170+
} & GuiProps;
177171

178172
// MinimalHostProps don't contain JSXElements[keyof JSXElements] to avoid long TypeScript checking times, but image it like it (useful representation for Host.ts and GuiHost.ts)
179173
type MinimalHostProps = CommonProps & Pick<Node, 'name'>;

0 commit comments

Comments
 (0)