diff options
| author | Sandy Tao <[email protected]> | 2025-06-27 16:39:54 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-27 23:39:54 +0000 |
| commit | 150df382f8e0b84aa6028622480c28186c99b8a7 (patch) | |
| tree | bf2e663e90914390408202aed409a95dfd56fe57 /packages/cli/src/ui/components/shared/MaxSizedBox.tsx | |
| parent | 19d2a0fb35ff75ebbed2dda5c8574ffcc66cd4d5 (diff) | |
Upgrade to Ink 6 and React 19 (#2096)
Co-authored-by: jacob314 <[email protected]>
Diffstat (limited to 'packages/cli/src/ui/components/shared/MaxSizedBox.tsx')
| -rw-r--r-- | packages/cli/src/ui/components/shared/MaxSizedBox.tsx | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/packages/cli/src/ui/components/shared/MaxSizedBox.tsx b/packages/cli/src/ui/components/shared/MaxSizedBox.tsx index cd31ff04..8880e894 100644 --- a/packages/cli/src/ui/components/shared/MaxSizedBox.tsx +++ b/packages/cli/src/ui/components/shared/MaxSizedBox.tsx @@ -116,13 +116,15 @@ export const MaxSizedBox: React.FC<MaxSizedBoxProps> = ({ throw new Error('maxWidth must be defined when maxHeight is set.'); } function visitRows(element: React.ReactNode) { - if (!React.isValidElement(element)) { + if (!React.isValidElement<{ children?: React.ReactNode }>(element)) { return; } + if (element.type === Fragment) { React.Children.forEach(element.props.children, visitRows); return; } + if (element.type === Box) { layoutInkElementAsStyledText(element, maxWidth!, laidOutStyledText); return; @@ -246,7 +248,10 @@ interface Row { * @returns An array of `Row` objects. */ function visitBoxRow(element: React.ReactNode): Row { - if (!React.isValidElement(element) || element.type !== Box) { + if ( + !React.isValidElement<{ children?: React.ReactNode }>(element) || + element.type !== Box + ) { debugReportError( `All children of MaxSizedBox must be <Box> elements`, element, @@ -258,7 +263,15 @@ function visitBoxRow(element: React.ReactNode): Row { } if (enableDebugLog) { - const boxProps = element.props; + const boxProps = element.props as { + children?: React.ReactNode | undefined; + readonly flexDirection?: + | 'row' + | 'column' + | 'row-reverse' + | 'column-reverse' + | undefined; + }; // Ensure the Box has no props other than the default ones and key. let maxExpectedProps = 4; if (boxProps.children !== undefined) { @@ -323,14 +336,13 @@ function visitBoxRow(element: React.ReactNode): Row { return; } - if (!React.isValidElement(element)) { + if (!React.isValidElement<{ children?: React.ReactNode }>(element)) { debugReportError('Invalid element.', element); return; } if (element.type === Fragment) { - const fragmentChildren = element.props.children; - React.Children.forEach(fragmentChildren, (child) => + React.Children.forEach(element.props.children, (child) => visitRowChild(child, parentProps), ); return; |
