From 739d7ec5feeeaee7dff7319190109fc11604edb2 Mon Sep 17 00:00:00 2001 From: zeye Date: Mon, 3 Feb 2020 13:01:38 +0800 Subject: [PATCH] use correct widget in ChoiceInput --- .../components/nodes/steps/ChoiceInput.tsx | 109 +++++++++--------- .../src/layouters/measureJsonBoundary.ts | 2 +- .../visual-designer/src/schema/uischema.tsx | 4 + .../src/widgets/ActionCard.tsx | 13 ++- 4 files changed, 74 insertions(+), 54 deletions(-) diff --git a/Composer/packages/extensions/visual-designer/src/components/nodes/steps/ChoiceInput.tsx b/Composer/packages/extensions/visual-designer/src/components/nodes/steps/ChoiceInput.tsx index 7781a8c635..4584ffd4d5 100644 --- a/Composer/packages/extensions/visual-designer/src/components/nodes/steps/ChoiceInput.tsx +++ b/Composer/packages/extensions/visual-designer/src/components/nodes/steps/ChoiceInput.tsx @@ -15,62 +15,67 @@ import { FormCard } from '../templates/FormCard'; import { NodeProps } from '../nodeProps'; import { getUserAnswersTitle } from '../utils'; +export const ChoiceInputChoices = ({ choices }) => { + if (!Array.isArray(choices)) { + return null; + } + + return ( +
+ {choices.map(({ value }, index) => { + if (index < 3) { + return ( +
+ {value} +
+ ); + } + })} + {Array.isArray(choices) && choices.length > 3 ? ( +
+ {`${choices.length - 3} more`} +
+ ) : null} +
+ ); +}; + export const ChoiceInput: FC = ({ id, data, onEvent }): JSX.Element => { const boundary = measureJsonBoundary(data); const { choices } = data; - let children: any = null; + const children = ; - if (Array.isArray(choices)) { - children = ( -
- {choices.map(({ value }, index) => { - if (index < 3) { - return ( -
- {value} -
- ); - } - })} - {Array.isArray(choices) && choices.length > 3 ? ( -
- {`${choices.length - 3} more`} -
- ) : null} -
- ); - } return ( data.property || '', + children: data => (data.$type === SDKTypes.ChoiceInput ? : null), + size: data => measureChoiceInputDetailBoundary(data), colors: { theme: ObiColors.LightBlue, icon: ObiColors.AzureBlue, diff --git a/Composer/packages/extensions/visual-designer/src/widgets/ActionCard.tsx b/Composer/packages/extensions/visual-designer/src/widgets/ActionCard.tsx index 21d71b47c5..db45d55919 100644 --- a/Composer/packages/extensions/visual-designer/src/widgets/ActionCard.tsx +++ b/Composer/packages/extensions/visual-designer/src/widgets/ActionCard.tsx @@ -15,6 +15,12 @@ export interface ActionCardProps extends WidgetContainerProps { icon: string; content: string | number | JSX.Element; menu?: JSX.Element | string; + children?: JSX.Element; + size?: { + width: number; + + height: number; + }; colors?: { theme: string; icon: string; @@ -35,6 +41,8 @@ export const ActionCard: WidgetComponent = ({ icon, menu, content, + children, + size, colors = DefaultCardColor, }) => { const header = disableSDKTitle ? title : generateSDKTitle(data, title); @@ -46,6 +54,9 @@ export const ActionCard: WidgetComponent = ({ icon={icon} label={content} nodeColors={nodeColors} - /> + styles={{ ...size }} + > + {children} + ); };