From 4b7c1038d028e81c47186be4c53184a8bd00ff39 Mon Sep 17 00:00:00 2001 From: Jim Kring Date: Thu, 30 May 2024 07:12:47 -0700 Subject: [PATCH] Allow nesting subcomponents like Images inside of Tables, Details, etc. (#308) --- src/npm-fastui/src/components/display.tsx | 32 +++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/npm-fastui/src/components/display.tsx b/src/npm-fastui/src/components/display.tsx index 30bb2c14..539ea648 100644 --- a/src/npm-fastui/src/components/display.tsx +++ b/src/npm-fastui/src/components/display.tsx @@ -1,10 +1,12 @@ import { FC } from 'react' -import type { AnyEvent, DisplayMode, Display, JsonData } from '../models' +import type { AnyEvent, DisplayMode, Display, JsonData, FastProps } from '../models' import { useCustomRender } from '../hooks/config' import { unreachable, asTitle } from '../tools' +import { AnyComp } from '.' + import { JsonComp } from './Json' import { LinkRender } from './link' @@ -26,6 +28,28 @@ export const DisplayComp: FC = (props) => { } } +// todo: this list should probably be defined in the models file +const nestableSubcomponents = [ + 'Text', + 'Paragraph', + 'Div', + 'Heading', + 'Markdown', + 'Code', + 'Json', + 'Button', + 'Link', + 'LinkList', + 'ServerLoad', + 'Image', + 'Iframe', + 'Video', + 'Spinner', + 'Custom', + 'Table', + 'Details', +] + const DisplayRender: FC = (props) => { const mode = props.mode ?? 'auto' const value = props.value ?? null @@ -34,7 +58,11 @@ const DisplayRender: FC = (props) => { } else if (Array.isArray(value)) { return } else if (typeof value === 'object' && value !== null) { - return + if (value.type !== null && typeof value.type === 'string' && nestableSubcomponents.includes(value.type)) { + return + } else { + return + } } else { return }