diff --git a/app/designer/features/props-panel/index.ts b/app/designer/features/props-panel/index.ts index ebb719d4d4..f1357c1481 100644 --- a/app/designer/features/props-panel/index.ts +++ b/app/designer/features/props-panel/index.ts @@ -1 +1 @@ -export * from "./settings-panel"; +export * from "./props-panel"; diff --git a/app/designer/features/props-panel/props-panel.tsx b/app/designer/features/props-panel/props-panel.tsx index 72f4c365d0..0954f8789e 100644 --- a/app/designer/features/props-panel/props-panel.tsx +++ b/app/designer/features/props-panel/props-panel.tsx @@ -1,14 +1,104 @@ -import { type UserProp, type Publish } from "@webstudio-is/sdk"; +import { + type UserProp, + type Publish, + components, + componentsMeta, + type Instance, +} from "@webstudio-is/sdk"; import { CollapsibleSection, ComponentInfo } from "~/designer/shared/inspector"; -import { TextField, Flex, Button, Box } from "~/shared/design-system"; +import { + TextField, + Flex, + Label, + Button, + Box, + Radio, + RadioGroup, +} from "~/shared/design-system"; import { PlusIcon, TrashIcon } from "~/shared/icons"; import type { SelectedInstanceData } from "~/shared/component"; import { usePropsLogic } from "./use-props-logic"; +//console.log(componentsMeta, components); + +type ControlProps = { + defaultValue?: UserProp["value"]; + value: UserProp["value"]; + onChangeValue: any; // (value: string) => void; +}; + +const TextControl = ({ value, defaultValue, onChangeValue }: ControlProps) => ( + { + onChangeValue(event.target.value); + }} + /> +); + +const RadioControl = ({ + value, + options, + defaultValue, + onChangeValue, +}: ControlProps & { options: Array }) => ( + + {options.map((value) => ( + + + + + ))} + +); + +const controls = { + text: TextControl, + radio: RadioControl, +}; + +const renderControl = ({ + component, + prop, + ...props +}: ControlProps & { + component: Instance["component"]; + prop: UserProp["prop"]; +}) => { + const meta = componentsMeta[component]; + const argType = meta?.argTypes[prop]; + console.log(prop, meta, argType); + + switch (argType?.control) { + case "text": { + return ; + } + case "radio": { + return ( + + ); + } + } + + return ; +}; type PropertyProps = { id: UserProp["id"]; prop: UserProp["prop"]; value: UserProp["value"]; + component: Instance["component"]; onChange: ( id: UserProp["id"], field: keyof UserProp, @@ -17,7 +107,14 @@ type PropertyProps = { onDelete: (id: UserProp["id"]) => void; }; -const Property = ({ id, prop, value, onChange, onDelete }: PropertyProps) => { +const Property = ({ + id, + prop, + value, + component, + onChange, + onDelete, +}: PropertyProps) => { return ( { onChange(id, "prop", event.target.value); }} /> - { - onChange(id, "value", event.target.value); - }} - /> + {renderControl({ + prop, + component, + value, + onChangeValue(value: string) { + onChange(id, "value", value); + }, + })}