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.

select control

Oleg Isonenb33a2caf53f7
diff --git a/app/designer/features/props-panel/props-panel.tsx b/app/designer/features/props-panel/props-panel.tsx
index dfb8139263..a7f3521bcf 100644
--- a/app/designer/features/props-panel/props-panel.tsx
+++ b/app/designer/features/props-panel/props-panel.tsx
@@ -1,10 +1,4 @@
-import {
- type UserProp,
- type Publish,
- components,
- componentsMeta,
- type Instance,
-} from "@webstudio-is/sdk";
+import { type UserProp, type Publish, componentsMeta, type Instance } from "@webstudio-is/sdk";
import { CollapsibleSection, ComponentInfo } from "~/designer/shared/inspector";
import {
TextField,
@@ -14,16 +8,16 @@ import {
Box,
Radio,
RadioGroup,
+ Select,
} 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"];
- onValueChange: (value: UserProp["value"]) => void;
+ onValueChange: (value: UserProp["value"]) => void;
};
const TextControl = ({ value, defaultValue, onValueChange }: ControlProps) => (
@@ -59,11 +53,26 @@ const RadioControl = ({
</RadioGroup>
);
-const controls = {
- text: TextControl,
- radio: RadioControl,
-};
-
+const SelectControl = ({
+ value,
+ options,
+ defaultValue,
+ onValueChange,
+}: ControlProps & { options: Array<string> }) => (
+ <Select
+ name="value"
+ value={value || defaultValue}
+ onChange={(event) => {
+ onValueChange(event.target.value);
+ }}
+ >
+ {options.map((optionValue) => (
+ <option value={optionValue} key={optionValue}>
+ {optionValue}
+ </option>
+ ))}
+ </Select>
+);
const renderControl = ({
component,
@@ -91,6 +100,15 @@ const renderControl = ({
/>
);
}
+ case "select": {
+ return (
+ <SelectControl
+ {...props}
+ defaultValue={argType.defaultValue}
+ options={argType.options}
+ />
+ );
+ }
}
return <TextControl {...props} />;
diff --git a/app/shared/design-system/components/select.tsx b/app/shared/design-system/components/select.tsx
index d64593ca0c..6deccf6666 100644
--- a/app/shared/design-system/components/select.tsx
+++ b/app/shared/design-system/components/select.tsx
@@ -12,7 +12,6 @@ const SelectWrapper = styled("div", {
fontVariantNumeric: "tabular-nums",
fontWeight: 400,
height: "$5",
- flexShrink: 0,
"&:hover": {
backgroundColor: "$slateA3",