From ec0847f62eb45cf63ad7490c39932cdac18ef487 Mon Sep 17 00:00:00 2001 From: Zvonimir Fras Date: Fri, 13 Oct 2023 17:49:58 -0400 Subject: [PATCH] Add multi-select prop type to custom components Signed-off-by: Zvonimir Fras --- src/routes/edit/settings-context-pane.tsx | 31 +++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/routes/edit/settings-context-pane.tsx b/src/routes/edit/settings-context-pane.tsx index 0906493fd..e605767c5 100644 --- a/src/routes/edit/settings-context-pane.tsx +++ b/src/routes/edit/settings-context-pane.tsx @@ -3,12 +3,13 @@ import { Button, Checkbox, DefinitionTooltip, + Dropdown, TextInput } from '@carbon/react'; import { ChevronDown,ChevronUp } from '@carbon/react/icons'; import { css, cx } from 'emotion'; import Editor from '@monaco-editor/react'; -import { throttle } from 'lodash'; +import { capitalize, throttle } from 'lodash'; import { ComponentCssClassSelector } from '../../sdk/src/css-class-selector'; import { allComponents } from '../../sdk/src/fragment-components'; @@ -75,12 +76,38 @@ const showComponentSettingsUI = (selectedComponent: any, setComponent: any, frag return <> { Object.entries(customComponent.inputs).map(([input, type]) => { + // complex types + if (typeof type === 'object') { + const t: any = type; // helps avoid casting type to `any` every time + + switch (t.type) { + default: + return <>Unsupported type; + + case 'multi-select': + return item.id === selectedComponent[input])} + itemToString={(item: any) => (item ? item.text : '')} + onChange={(event: any) => setComponent({ + ...selectedComponent, + [input]: event.selectedItem.id + })} />; + } + } + + // simple types switch (type) { default: + return <>Unsupported type; + case 'string': return setComponent({ ...selectedComponent, [input]: event.currentTarget.value