Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

Merge branch 'main' into 24-support-component-story-format-csf

Oleg Isonenb30a533c757d
diff --cc app/designer/features/inspector/inspector.tsx
index 05196b33c0,795822c344..16dec44c92
--- a/app/designer/features/inspector/inspector.tsx
+++ b/app/designer/features/inspector/inspector.tsx
@@@ -9,9 -9,9 +9,9 @@@ import
Box,
} from "~/shared/design-system";
import { StylePanel } from "~/designer/features/style-panel";
-import { SettingsPanel } from "~/designer/features/settings-panel";
+import { PropsPanel } from "~/designer/features/props-panel";
import { BrushIcon, GearIcon } from "~/shared/icons";
- import { useSelectedInstanceData } from "~/designer/shared/nano-values";
+ import { useSelectedInstanceData } from "~/designer/shared/nano-states";
type InspectorProps = {
publish: Publish;
diff --cc app/designer/features/props-panel/props-panel.tsx
index ab37d658bf,0000000000..c37e8db7c6
mode 100644,000000..100644
--- a/app/designer/features/props-panel/props-panel.tsx
+++ b/app/designer/features/props-panel/props-panel.tsx
@@@ -1,275 -1,0 +1,275 @@@
+import { type ComponentProps } from "react";
+import {
+ type UserProp,
+ type Publish,
+ componentsMeta,
+ type Instance,
+} from "@webstudio-is/sdk";
+import { CollapsibleSection, ComponentInfo } from "~/designer/shared/inspector";
+import {
+ TextField,
+ Flex,
+ Label,
+ Button,
+ Box,
+ Radio,
+ RadioGroup,
+ Select,
+ Switch,
+} from "~/shared/design-system";
+import { PlusIcon, TrashIcon } from "~/shared/icons";
- import type { SelectedInstanceData } from "~/shared/component";
++import type { SelectedInstanceData } from "~/shared/canvas-components";
+import { usePropsLogic } from "./use-props-logic";
+
+type BaseControlProps = {
+ value?: UserProp["value"];
+ onValueChange: (value: UserProp["value"]) => void;
+};
+
+type TextControlProps = BaseControlProps & {
+ type?: ComponentProps<typeof TextField>["type"];
+ defaultValue?: UserProp["value"];
+};
+
+const TextControl = ({
+ value,
+ defaultValue,
+ type,
+ onValueChange,
+}: TextControlProps) => (
+ <TextField
+ type={type}
+ variant="ghost"
+ placeholder="Value"
+ name="value"
+ value={String(value || defaultValue || "")}
+ onChange={(event) => {
+ onValueChange(event.target.value);
+ }}
+ />
+);
+
+type RadioControlProps = BaseControlProps & {
+ options: Array<string>;
+ defaultValue: UserProp["value"];
+};
+
+const RadioControl = ({
+ value,
+ options,
+ defaultValue,
+ onValueChange,
+}: RadioControlProps) => (
+ <RadioGroup
+ css={{ flexDirection: "column" }}
+ name="value"
+ value={String(value || defaultValue || "")}
+ onValueChange={onValueChange}
+ >
+ {options.map((value) => (
+ <Flex align="center" gap="1" key={value}>
+ <Radio value={value} />
+ <Label>{value}</Label>
+ </Flex>
+ ))}
+ </RadioGroup>
+);
+
+type SelectControlProps = BaseControlProps & {
+ options: Array<string>;
+ defaultValue: UserProp["value"];
+};
+
+const SelectControl = ({
+ value,
+ options,
+ defaultValue,
+ onValueChange,
+}: SelectControlProps) => (
+ <Select
+ name="value"
+ value={String(value || defaultValue || "")}
+ onChange={(event) => {
+ onValueChange(event.target.value);
+ }}
+ >
+ {options.map((optionValue) => (
+ <option value={optionValue} key={optionValue}>
+ {optionValue}
+ </option>
+ ))}
+ </Select>
+);
+
+type BooleanControlProps = BaseControlProps & {
+ defaultValue: boolean;
+};
+
+const BooleanControl = ({
+ value,
+ defaultValue,
+ onValueChange,
+}: BooleanControlProps) => (
+ <Switch
+ name="value"
+ defaultChecked={defaultValue}
+ checked={value === true}
+ onCheckedChange={onValueChange}
+ />
+);
+
+const renderControl = ({
+ component,
+ prop,
+ ...props
+}: BaseControlProps & {
+ component: Instance["component"];
+ prop: UserProp["prop"];
+}) => {
+ const meta = componentsMeta[component];
+
+ const argType = meta?.argTypes?.[prop as keyof typeof meta.argTypes];
+
+ switch (argType?.control.type) {
+ case "text": {
+ return <TextControl {...props} defaultValue={argType.defaultValue} />;
+ }
+ case "number": {
+ return (
+ <TextControl
+ {...props}
+ defaultValue={argType.defaultValue}
+ type="number"
+ />
+ );
+ }
+ case "radio": {
+ return (
+ <RadioControl
+ {...props}
+ defaultValue={argType.defaultValue}
+ options={argType.options}
+ />
+ );
+ }
+ case "select": {
+ return (
+ <SelectControl
+ {...props}
+ defaultValue={argType.defaultValue}
+ options={argType.options}
+ />
+ );
+ }
+ case "boolean": {
+ return <BooleanControl {...props} defaultValue={argType.defaultValue} />;
+ }
+ }
+
+ return <TextControl {...props} />;
+};
+
+type PropertyProps = {
+ id: UserProp["id"];
+ prop: UserProp["prop"];
+ value: UserProp["value"];
+ component: Instance["component"];
+ onChange: (
+ id: UserProp["id"],
+ field: keyof UserProp,
+ value: UserProp["prop"] | UserProp["value"]
+ ) => void;
+ onDelete: (id: UserProp["id"]) => void;
+};
+
+const Property = ({
+ id,
+ prop,
+ value,
+ component,
+ onChange,
+ onDelete,
+}: PropertyProps) => {
+ return (
+ <Flex gap="1">
+ <TextField
+ variant="ghost"
+ placeholder="Property"
+ name="prop"
+ value={prop}
+ onChange={(event) => {
+ onChange(id, "prop", event.target.value);
+ }}
+ />
+ {renderControl({
+ prop,
+ component,
+ value,
+ onValueChange(value: UserProp["prop"] | UserProp["value"]) {
+ onChange(id, "value", value);
+ },
+ })}
+ <Button
+ ghost
+ onClick={() => {
+ onDelete(id);
+ }}
+ >
+ <TrashIcon />
+ </Button>
+ </Flex>
+ );
+};
+
+type PropsPanelProps = {
+ publish: Publish;
+ selectedInstanceData?: SelectedInstanceData;
+};
+
+export const PropsPanel = ({
+ selectedInstanceData,
+ publish,
+}: PropsPanelProps) => {
+ const { userProps, addEmptyProp, handleChangeProp, handleDeleteProp } =
+ usePropsLogic({ selectedInstanceData, publish });
+
+ if (selectedInstanceData === undefined) return null;
+
+ const addButton = (
+ <Button
+ ghost
+ onClick={(event) => {
+ event.preventDefault();
+ addEmptyProp();
+ }}
+ >
+ <PlusIcon />
+ </Button>
+ );
+ return (
+ <>
+ <Box css={{ p: "$2" }}>
+ <ComponentInfo selectedInstanceData={selectedInstanceData} />
+ </Box>
+ <CollapsibleSection
+ label="Properties"
+ rightSlot={addButton}
+ isOpenDefault
+ >
+ <>
+ {userProps.map(({ id, prop, value }) => (
+ <Property
+ key={id}
+ id={id}
+ prop={prop}
+ value={value}
+ component={selectedInstanceData.component}
+ onChange={handleChangeProp}
+ onDelete={handleDeleteProp}
+ />
+ ))}
+ </>
+ </CollapsibleSection>
+ </>
+ );
+};
diff --cc yarn.lock
index aa8e15275a,b64dc6c534..5781ea5c31
--- a/yarn.lock
+++ b/yarn.lock
@@@ -11468,12 -11533,7 +11533,7 @@@ punycode@^2.1.0, punycode@^2.1.1
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==
- version "6.9.6"
- resolved "https://registry.yarnpkg.com/qs/-/qs-6.9.6.tgz#26ed3c8243a431b2924aca84cc90471f35d5a0ee"
- integrity sha512-TIRk4aqYLNoJUbd+g2lEdz5kLWIuTMRagAXxl78Q0RiVjAOugHmeKNGdd3cwo/ktpf9aL9epCfFqWDEKysUlLQ==
-
- qs@^6.10.0:
[email protected], qs@^6.10.0:
version "6.10.3"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.10.3.tgz#d6cde1b2ffca87b5aa57889816c5f81535e22e8e"
integrity sha512-wr7M2E0OFRfIfJZjKGieI8lBKb7fRCH4Fv5KNPEs7gJ8jadvotdsS08PzOKR7opXhZ/Xkjtt3WF9g38drmyRqQ==