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.

finishing touches combobox

Oleg Isonen452194364870
diff --git a/apps/designer/app/designer/features/props-panel/props-panel.tsx b/apps/designer/app/designer/features/props-panel/props-panel.tsx
index 1a6b12f489..f706555a4b 100644
--- a/apps/designer/app/designer/features/props-panel/props-panel.tsx
+++ b/apps/designer/app/designer/features/props-panel/props-panel.tsx
@@ -13,17 +13,9 @@ import {
Combobox,
ComboboxTextField,
Grid,
- IconButton,
- TextField,
Tooltip,
- Flex,
} from "~/shared/design-system";
-import {
- PlusIcon,
- TrashIcon,
- ExclamationTriangleIcon,
- ChevronDownIcon,
-} from "~/shared/icons";
+import { PlusIcon, TrashIcon, ExclamationTriangleIcon } from "~/shared/icons";
import { handleChangePropType, usePropsLogic } from "./use-props-logic";
type PropertyProps = UserProp & {
@@ -50,7 +42,7 @@ const Property = ({
const type = argType?.control.type || "text";
const defaultValue = argType?.control.defaultValue;
const options = argType?.options;
- const allProps = Object.keys(meta.argTypes);
+ const allProps = meta.argTypes ? Object.keys(meta.argTypes) : [];
return (
<Grid
@@ -61,7 +53,7 @@ const Property = ({
name="prop"
items={allProps}
value={prop}
- itemToString={(item) => item}
+ itemToString={(item) => item ?? ""}
onItemSelect={(value) => {
onChange(id, "prop", value);
}}
diff --git a/apps/designer/app/designer/features/style-panel/render-property.tsx b/apps/designer/app/designer/features/style-panel/render-property.tsx
index 2508e971e7..091d57e121 100644
--- a/apps/designer/app/designer/features/style-panel/render-property.tsx
+++ b/apps/designer/app/designer/features/style-panel/render-property.tsx
@@ -1,4 +1,11 @@
-import { Flex, Grid, Label, Text, Combobox } from "~/shared/design-system";
+import {
+ Flex,
+ Grid,
+ Label,
+ Text,
+ Combobox,
+ ComboboxTextField,
+} from "~/shared/design-system";
import type { StyleConfig } from "~/shared/style-panel-configs";
import {
categories,
@@ -162,13 +169,13 @@ const ComboboxControl = ({
if (styleConfig.control !== "Combobox") return null;
// @todo show which instance we inherited the value from
- const value = getFinalValue({
+ const currentValue = getFinalValue({
currentStyle,
inheritedStyle,
property: styleConfig.property,
});
- if (value === undefined) return null;
+ if (currentValue === undefined) return null;
const setValue = setProperty(styleConfig.property);
@@ -177,22 +184,46 @@ const ComboboxControl = ({
<PropertyName property={styleConfig.property} label={styleConfig.label} />
<Flex align="center" css={{ gridColumn: "2/4" }} gap="1">
<Combobox
- id={styleConfig.property}
+ name="prop"
items={styleConfig.items}
- variant="ghost"
- popperProps={{ align: "end", sideOffset: 5 }}
- state={value.type === "invalid" ? "invalid" : undefined}
- value={String(value.value)}
- onValueSelect={setValue}
- onValueEnter={setValue}
- onItemEnter={(value) => {
- setValue(value, { isEphemeral: true });
+ contentProps={{ sideOffset: 5 }}
+ value={{
+ name: String(currentValue.value),
+ label: String(currentValue.value),
}}
- onItemLeave={() => {
- setValue(String(value.value), { isEphemeral: true });
+ itemToString={(item) => (item ? item.name : "")}
+ onItemHighlight={(value) => {
+ if (value === undefined) {
+ setValue(String(currentValue.value), { isEphemeral: true });
+ return;
+ }
+ setValue(value.name, { isEphemeral: true });
}}
+ disclosure={({ inputProps, toggleProps }) => (
+ <ComboboxTextField
+ toggleProps={toggleProps}
+ inputProps={{
+ ...inputProps,
+ id: styleConfig.property,
+ state: currentValue.type === "invalid" ? "invalid" : undefined,
+ onKeyDown(event) {
+ inputProps.onKeyDown?.(event);
+ switch (event.key) {
+ case "Enter": {
+ setValue(event.currentTarget.value);
+ break;
+ }
+ }
+ },
+ onBlur(event) {
+ inputProps.onBlur?.(event);
+ setValue(event.target.value);
+ },
+ }}
+ />
+ )}
/>
- <Unit value={value} />
+ <Unit value={currentValue} />
</Flex>
</Grid>
);
diff --git a/apps/designer/app/shared/design-system/components/combobox.stories.tsx b/apps/designer/app/shared/design-system/components/combobox.stories.tsx
index fa56f4ecdb..bd48ed0072 100644
--- a/apps/designer/app/shared/design-system/components/combobox.stories.tsx
+++ b/apps/designer/app/shared/design-system/components/combobox.stories.tsx
@@ -1,3 +1,4 @@
+import { action } from "@storybook/addon-actions";
import { ComponentStory } from "@storybook/react";
import React from "react";
import { Combobox, ComboboxTextField } from "./combobox";
@@ -34,7 +35,7 @@ export const CustomInput: ComponentStory<typeof Combobox> = () => {
value={value}
onItemSelect={setValue}
onItemHighlight={(item) => {
- console.log(item);
+ action("Highlight")(item);
}}
disclosure={({ inputProps, toggleProps }) => (
<ComboboxTextField
@@ -45,14 +46,14 @@ export const CustomInput: ComponentStory<typeof Combobox> = () => {
inputProps.onKeyDown?.(event);
switch (event.key) {
case "Enter": {
- console.log(inputProps.value);
+ action("Enter")(inputProps.value);
break;
}
}
},
onBlur: (event) => {
inputProps.onBlur?.(event);
- console.log(inputProps.value);
+ action("Blur")(inputProps.value);
},
}}
/>
diff --git a/apps/designer/app/shared/design-system/components/combobox.tsx b/apps/designer/app/shared/design-system/components/combobox.tsx
index 756a85ab29..724b2b86fa 100644
--- a/apps/designer/app/shared/design-system/components/combobox.tsx
+++ b/apps/designer/app/shared/design-system/components/combobox.tsx
@@ -8,16 +8,16 @@ import { CheckIcon, ChevronDownIcon } from "~/shared/icons";
import { Popper, PopperContent, PopperAnchor } from "@radix-ui/react-popper";
import { useCombobox } from "downshift";
import { matchSorter } from "match-sorter";
-import { styled, type CSS } from "../stitches.config";
-import { IconButton, iconButtonReset } from "./icon-button";
+import { styled } from "../stitches.config";
+import { IconButton } from "./icon-button";
import { itemCss } from "./menu";
import { panelStyles } from "./panel";
-import { TextField, textFieldReset } from "./text-field";
+import { TextField } from "./text-field";
import { Box } from "./box";
import { Flex } from "./flex";
import { Grid } from "./grid";
-type Label = "string";
+type Label = string;
type BaseItem = { label: Label; disabled?: boolean } | Label;
@@ -44,8 +44,8 @@ export const ComboboxTextField = forwardRef<
ComboboxTextFieldProps
>(({ inputProps, toggleProps }, ref) => {
return (
- <Box ref={ref}>
- <TextField {...inputProps} />
+ <Box ref={ref} css={{ position: "relative" }}>
+ <TextField css={{ paddingRight: "$4" }} {...inputProps} />
<IconButton
{...toggleProps}
css={{
@@ -60,6 +60,8 @@ export const ComboboxTextField = forwardRef<
);
});
+ComboboxTextField.displayName = "ComboboxTextField";
+
type ComboboxProps<Item> = {
name: string;
items: Array<Item>;
@@ -133,7 +135,7 @@ export const Combobox = <Item extends BaseItem>({
<PopperAnchor asChild>
{disclosure({ inputProps, toggleProps })}
</PopperAnchor>
- <PopperContent {...contentProps}>
+ <PopperContent {...contentProps} style={{ zIndex: 1 }}>
<Listbox {...menuProps}>
{isOpen &&
filteredItems.map((item, index) => {
@@ -166,3 +168,5 @@ export const Combobox = <Item extends BaseItem>({
</Popper>
);
};
+
+Combobox.displayName = "Combobox";