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.

convert to prefix/suffix TextField api, some errors from merge

Sultan3539b35c838c
diff --git a/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx b/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx
index 78d4546cb0..7c7c434539 100644
--- a/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx
+++ b/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx
@@ -1,5 +1,6 @@
import { FocusEvent, PointerEvent, useCallback } from "react";
import {
+ Box,
Text,
IconButton,
TextField,
@@ -82,7 +83,6 @@ export const TextControl = ({
isEphemeral,
});
};
-
return (
<Combobox
name={styleConfig.property}
@@ -98,24 +98,8 @@ export const TextControl = ({
renderTextField={({ inputProps, toggleProps }) => {
return (
<Box css={{ position: "relative" }}>
- <PropertyIcon
- property={styleConfig.property}
- label={styleConfig.label}
- {...(value.type === "unit" && {
- onPointerUp: (event: PointerEvent<HTMLInputElement>) => {
- setValue(String(getInputNode(event.target).value));
- },
- ref: numericScrubRefCallback,
- })}
- />
<TextField
{...inputProps}
- css={{
- cursor: "default",
- height: "calc($sizes$5 + $sizes$1)",
- fontWeight: "500",
- paddingLeft: "calc($sizes$4 / 2)",
- }}
onFocus={(event: FocusEvent<HTMLInputElement>) => {
event.target.select();
}}
@@ -155,39 +139,53 @@ export const TextControl = ({
target.value = currentValueAsString;
setValue(currentValueAsString, { isEphemeral: true });
}}
- />
- <IconButton
- {...toggleProps}
- css={{
- visibility: items.length ? "visible" : "hidden",
- position: "absolute",
- right: "1px",
- top: "1px",
- width: "auto",
- height: "calc(100% - 2px)",
- px: "calc($1 / 2)",
- borderRadius: "$1",
- border: "2px solid $colors$loContrast",
- "&:focus": {
- outline: "none",
- },
- }}
- >
- {value.type === "unit" ? (
- <Text
+ prefix={
+ <PropertyIcon
+ property={styleConfig.property}
+ label={styleConfig.label}
+ {...(value.type === "unit" && {
+ onPointerUp: (event: PointerEvent<HTMLInputElement>) => {
+ setValue(String(getInputNode(event.target).value));
+ },
+ ref: numericScrubRefCallback,
+ })}
+ />
+ }
+ suffix={
+ <IconButton
+ {...toggleProps}
css={{
- cursor: "default",
- minWidth: "calc($sizes$3 - $nudge$1)",
- textAlign: "center",
- fontSize: "calc($fontSizes$1 - $nudge$1)",
+ visibility: items.length ? "visible" : "hidden",
+ position: "absolute",
+ right: "1px",
+ top: "1px",
+ width: "auto",
+ height: "calc(100% - 2px)",
+ px: "calc($1 / 2)",
+ borderRadius: "$1",
+ border: "2px solid $colors$loContrast",
+ "&:focus": {
+ outline: "none",
+ },
}}
>
- {value.unit === "number" ? "—" : value.unit}
- </Text>
- ) : (
- <ChevronDownIcon />
- )}
- </IconButton>
+ {value.type === "unit" ? (
+ <Text
+ css={{
+ cursor: "default",
+ minWidth: "calc($sizes$3 - $nudge$1)",
+ textAlign: "center",
+ fontSize: "calc($fontSizes$1 - $nudge$1)",
+ }}
+ >
+ {value.unit === "number" ? "—" : value.unit}
+ </Text>
+ ) : (
+ <ChevronDownIcon />
+ )}
+ </IconButton>
+ }
+ />
</Box>
);
}}
diff --git a/apps/designer/app/designer/features/style-panel/shared/configs.ts b/apps/designer/app/designer/features/style-panel/shared/configs.ts
index 71ac380e9d..ce0cec3a23 100644
--- a/apps/designer/app/designer/features/style-panel/shared/configs.ts
+++ b/apps/designer/app/designer/features/style-panel/shared/configs.ts
@@ -60,30 +60,8 @@ const getControl = (property: StyleProperty): Control => {
if (property.toLocaleLowerCase().includes("color")) {
return "Color";
}
- // Spacing properties is more narrow than StyleProperty,
- // so we have to widen it to be able to run .includes.
- // @todo do better
- const spacing = categories.spacing
- .properties as unknown as Array<StyleProperty>;
- if (spacing.includes(property)) {
- return "Spacing";
- }
switch (property) {
- case "display": {
- return "Select";
- }
- case "flexDirection":
- case "flexWrap":
- case "alignItems":
- case "justifyItems":
- case "justifyContent":
- case "alignContent": {
- return "Menu";
- }
- case "placeContent": {
- return "Empty";
- }
case "fontFamily": {
return isFeatureEnabled("assets") ? "FontFamily" : "Text";
}
diff --git a/packages/design-system/src/components/combobox.tsx b/packages/design-system/src/components/combobox.tsx
index a2fb903fbb..82c36565b6 100644
--- a/packages/design-system/src/components/combobox.tsx
+++ b/packages/design-system/src/components/combobox.tsx
@@ -154,7 +154,9 @@ export const Combobox = <Item extends BaseItem>({
name,
placeholder,
itemToString = (item) =>
- item != null && "label" in item ? item.label : item ?? "",
+ item != null && typeof item == "object" && "label" in item
+ ? item.label
+ : item ?? "",
onItemSelect,
onItemHighlight,
renderTextField = (props) => <ComboboxTextField {...props} />,
@@ -205,6 +207,7 @@ export const Combobox = <Item extends BaseItem>({
getComboboxProps,
highlightedIndex,
getItemProps,
+ selectedItem,
} = useCombobox({
items: foundItems as Item[],
selectedItem: value ?? null, // Avoid downshift warning about switching controlled mode