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.

feat: show bindings only on control hover (#2743)

Bogdan Chadkin0070ca41e1c6
diff --git a/apps/builder/app/builder/features/settings-panel/controls/boolean.tsx b/apps/builder/app/builder/features/settings-panel/controls/boolean.tsx
index 0ade338e80..bf07725d2a 100644
--- a/apps/builder/app/builder/features/settings-panel/controls/boolean.tsx
+++ b/apps/builder/app/builder/features/settings-panel/controls/boolean.tsx
@@ -1,6 +1,9 @@
import { useStore } from "@nanostores/react";
-import { Box, Grid, Switch, theme, useId } from "@webstudio-is/design-system";
-import { BindingPopover } from "~/builder/shared/binding-popover";
+import { Grid, Switch, theme, useId } from "@webstudio-is/design-system";
+import {
+ BindingControl,
+ BindingPopover,
+} from "~/builder/shared/binding-popover";
import {
type ControlProps,
getLabel,
@@ -41,7 +44,7 @@ export const BooleanControl = ({
<Label htmlFor={id} description={meta.description} readOnly={readOnly}>
{label}
</Label>
- <Box css={{ position: "relative" }}>
+ <BindingControl>
<Switch
id={id}
disabled={readOnly}
@@ -70,7 +73,7 @@ export const BooleanControl = ({
onChange({ type: "boolean", value: Boolean(evaluatedValue) })
}
/>
- </Box>
+ </BindingControl>
{deletable && <RemovePropButton onClick={onDelete} />}
</Grid>
);
diff --git a/apps/builder/app/builder/features/settings-panel/controls/check.tsx b/apps/builder/app/builder/features/settings-panel/controls/check.tsx
index b72a466fbe..c9d52ec230 100644
--- a/apps/builder/app/builder/features/settings-panel/controls/check.tsx
+++ b/apps/builder/app/builder/features/settings-panel/controls/check.tsx
@@ -1,13 +1,10 @@
import { useStore } from "@nanostores/react";
-import {
- Box,
- Checkbox,
- CheckboxAndLabel,
- useId,
- theme,
-} from "@webstudio-is/design-system";
+import { Checkbox, CheckboxAndLabel, useId } from "@webstudio-is/design-system";
import { humanizeString } from "~/shared/string-utils";
-import { BindingPopover } from "~/builder/shared/binding-popover";
+import {
+ BindingControl,
+ BindingPopover,
+} from "~/builder/shared/binding-popover";
import {
type ControlProps,
getLabel,
@@ -68,7 +65,7 @@ export const CheckControl = ({
deletable={deletable}
onDelete={onDelete}
>
- <Box css={{ position: "relative", paddingTop: theme.spacing[2] }}>
+ <BindingControl>
{options.map((option) => (
<CheckboxAndLabel key={option}>
<Checkbox
@@ -113,7 +110,7 @@ export const CheckControl = ({
})
}
/>
- </Box>
+ </BindingControl>
</VerticalLayout>
);
};
diff --git a/apps/builder/app/builder/features/settings-panel/controls/code.tsx b/apps/builder/app/builder/features/settings-panel/controls/code.tsx
index d5ae289147..e2bbbb0625 100644
--- a/apps/builder/app/builder/features/settings-panel/controls/code.tsx
+++ b/apps/builder/app/builder/features/settings-panel/controls/code.tsx
@@ -1,5 +1,9 @@
import { useStore } from "@nanostores/react";
-import { Box, theme } from "@webstudio-is/design-system";
+import { HtmlEditor } from "~/builder/shared/html-editor";
+import {
+ BindingControl,
+ BindingPopover,
+} from "~/builder/shared/binding-popover";
import {
useLocalValue,
type ControlProps,
@@ -9,8 +13,6 @@ import {
updateExpressionValue,
$selectedInstanceScope,
} from "../shared";
-import { HtmlEditor } from "~/builder/shared/html-editor";
-import { BindingPopover } from "~/builder/shared/binding-popover";
export const CodeControl = ({
meta,
@@ -55,7 +57,7 @@ export const CodeControl = ({
deletable={deletable}
onDelete={onDelete}
>
- <Box css={{ position: "relative", py: theme.spacing[2] }}>
+ <BindingControl>
<HtmlEditor
readOnly={readOnly}
value={localValue.value}
@@ -78,7 +80,7 @@ export const CodeControl = ({
onChange({ type: "string", value: String(evaluatedValue) })
}
/>
- </Box>
+ </BindingControl>
</VerticalLayout>
);
};
diff --git a/apps/builder/app/builder/features/settings-panel/controls/file.tsx b/apps/builder/app/builder/features/settings-panel/controls/file.tsx
index a00ba71283..a9b7ea7b00 100644
--- a/apps/builder/app/builder/features/settings-panel/controls/file.tsx
+++ b/apps/builder/app/builder/features/settings-panel/controls/file.tsx
@@ -1,7 +1,10 @@
import { useStore } from "@nanostores/react";
-import { useId, type ReactNode } from "react";
+import { useId } from "react";
import { Flex, InputField, theme } from "@webstudio-is/design-system";
-import { BindingPopover } from "~/builder/shared/binding-popover";
+import {
+ BindingControl,
+ BindingPopover,
+} from "~/builder/shared/binding-popover";
import {
type ControlProps,
getLabel,
@@ -38,15 +41,6 @@ const UrlInput = ({
/>
);
-const Row = ({ children }: { children: ReactNode }) => (
- <Flex
- css={{ height: theme.spacing[13], position: "relative" }}
- align="center"
- >
- {children}
- </Flex>
-);
-
export const FileControl = ({
meta,
prop,
@@ -93,33 +87,33 @@ export const FileControl = ({
deletable={deletable}
onDelete={onDelete}
>
- <Row>
- <UrlInput id={id} readOnly={readOnly} localValue={localStringValue} />
- <BindingPopover
- scope={scope}
- aliases={aliases}
- validate={(value) => {
- if (value !== undefined && typeof value !== "string") {
- return `${label} expects a string value or file`;
+ <Flex css={{ gap: theme.spacing[3] }} direction="column" justify="center">
+ <BindingControl>
+ <UrlInput id={id} readOnly={readOnly} localValue={localStringValue} />
+ <BindingPopover
+ scope={scope}
+ aliases={aliases}
+ validate={(value) => {
+ if (value !== undefined && typeof value !== "string") {
+ return `${label} expects a string value or file`;
+ }
+ }}
+ value={expression}
+ onChange={(newExpression) =>
+ onChange({ type: "expression", value: newExpression })
}
- }}
- value={expression}
- onChange={(newExpression) =>
- onChange({ type: "expression", value: newExpression })
- }
- onRemove={(evaluatedValue) =>
- onChange({ type: "string", value: String(evaluatedValue) })
- }
- />
- </Row>
- <Row>
+ onRemove={(evaluatedValue) =>
+ onChange({ type: "string", value: String(evaluatedValue) })
+ }
+ />
+ </BindingControl>
<SelectAsset
prop={prop?.type === "asset" ? prop : undefined}
accept={meta.accept}
onChange={onChange}
onDelete={onDelete}
/>
- </Row>
+ </Flex>
</VerticalLayout>
);
};
diff --git a/apps/builder/app/builder/features/settings-panel/controls/json.tsx b/apps/builder/app/builder/features/settings-panel/controls/json.tsx
index 9cdda57d8a..fe355b16c9 100644
--- a/apps/builder/app/builder/features/settings-panel/controls/json.tsx
+++ b/apps/builder/app/builder/features/settings-panel/controls/json.tsx
@@ -1,5 +1,4 @@
import { useStore } from "@nanostores/react";
-import { theme, Box } from "@webstudio-is/design-system";
import {
type ControlProps,
getLabel,
@@ -13,7 +12,10 @@ import {
ExpressionEditor,
formatValue,
} from "~/builder/shared/expression-editor";
-import { BindingPopover } from "~/builder/shared/binding-popover";
+import {
+ BindingControl,
+ BindingPopover,
+} from "~/builder/shared/binding-popover";
export const JsonControl = ({
meta,
@@ -54,7 +56,7 @@ export const JsonControl = ({
deletable={deletable}
onDelete={onDelete}
>
- <Box css={{ position: "relative", py: theme.spacing[2] }}>
+ <BindingControl>
<ExpressionEditor
readOnly={readOnly}
value={localValue.value}
@@ -72,7 +74,7 @@ export const JsonControl = ({
onChange({ type: "json", value: evaluatedValue })
}
/>
- </Box>
+ </BindingControl>
</VerticalLayout>
);
};
diff --git a/apps/builder/app/builder/features/settings-panel/controls/number.tsx b/apps/builder/app/builder/features/settings-panel/controls/number.tsx
index 33f8b7e532..072280abd5 100644
--- a/apps/builder/app/builder/features/settings-panel/controls/number.tsx
+++ b/apps/builder/app/builder/features/settings-panel/controls/number.tsx
@@ -1,7 +1,10 @@
import { useId, useState } from "react";
import { useStore } from "@nanostores/react";
-import { Box, InputField } from "@webstudio-is/design-system";
-import { BindingPopover } from "~/builder/shared/binding-popover";
+import { InputField } from "@webstudio-is/design-system";
+import {
+ BindingControl,
+ BindingPopover,
+} from "~/builder/shared/binding-popover";
import {
type ControlProps,
getLabel,
@@ -57,7 +60,7 @@ export const NumberControl = ({
deletable={deletable}
onDelete={onDelete}
>
- <Box css={{ position: "relative" }}>
+ <BindingControl>
<InputField
id={id}
disabled={readOnly}
@@ -95,7 +98,7 @@ export const NumberControl = ({
});
}}
/>
- </Box>
+ </BindingControl>
</ResponsiveLayout>
);
};
diff --git a/apps/builder/app/builder/features/settings-panel/controls/radio.tsx b/apps/builder/app/builder/features/settings-panel/controls/radio.tsx
index e1a910f607..9673a08457 100644
--- a/apps/builder/app/builder/features/settings-panel/controls/radio.tsx
+++ b/apps/builder/app/builder/features/settings-panel/controls/radio.tsx
@@ -1,14 +1,11 @@
import { useId } from "react";
import { useStore } from "@nanostores/react";
-import {
- Box,
- RadioGroup,
- Radio,
- RadioAndLabel,
- theme,
-} from "@webstudio-is/design-system";
+import { RadioGroup, Radio, RadioAndLabel } from "@webstudio-is/design-system";
import { humanizeString } from "~/shared/string-utils";
-import { BindingPopover } from "~/builder/shared/binding-popover";
+import {
+ BindingControl,
+ BindingPopover,
+} from "~/builder/shared/binding-popover";
import {
type ControlProps,
getLabel,
@@ -51,7 +48,7 @@ export const RadioControl = ({
deletable={deletable}
onDelete={onDelete}
>
- <Box css={{ position: "relative", paddingTop: theme.spacing[2] }}>
+ <BindingControl>
<RadioGroup
disabled={readOnly}
name="value"
@@ -94,7 +91,7 @@ export const RadioControl = ({
onChange({ type: "string", value: String(evaluatedValue) })
}
/>
- </Box>
+ </BindingControl>
</VerticalLayout>
);
};
diff --git a/apps/builder/app/builder/features/settings-panel/controls/select.tsx b/apps/builder/app/builder/features/settings-panel/controls/select.tsx
index d5841650a6..d6ba35d173 100644
--- a/apps/builder/app/builder/features/settings-panel/controls/select.tsx
+++ b/apps/builder/app/builder/features/settings-panel/controls/select.tsx
@@ -1,8 +1,11 @@
import { useId } from "react";
import { useStore } from "@nanostores/react";
-import { Flex, theme, Select } from "@webstudio-is/design-system";
+import { Select } from "@webstudio-is/design-system";
import { humanizeString } from "~/shared/string-utils";
-import { BindingPopover } from "~/builder/shared/binding-popover";
+import {
+ BindingControl,
+ BindingPopover,
+} from "~/builder/shared/binding-popover";
import {
type ControlProps,
getLabel,
@@ -46,7 +49,7 @@ export const SelectControl = ({
deletable={deletable}
onDelete={onDelete}
>
- <Flex css={{ position: "relative", py: theme.spacing[2] }}>
+ <BindingControl>
<Select
fullWidth
id={id}
@@ -85,7 +88,7 @@ export const SelectControl = ({
onChange({ type: "string", value: String(evaluatedValue) })
}
/>
- </Flex>
+ </BindingControl>
</VerticalLayout>
);
};
diff --git a/apps/builder/app/builder/features/settings-panel/controls/text.tsx b/apps/builder/app/builder/features/settings-panel/controls/text.tsx
index 0e5674c510..7c6874973d 100644
--- a/apps/builder/app/builder/features/settings-panel/controls/text.tsx
+++ b/apps/builder/app/builder/features/settings-panel/controls/text.tsx
@@ -1,5 +1,9 @@
import { useStore } from "@nanostores/react";
-import { Flex, theme, useId, TextArea } from "@webstudio-is/design-system";
+import { useId, TextArea } from "@webstudio-is/design-system";
+import {
+ BindingControl,
+ BindingPopover,
+} from "~/builder/shared/binding-popover";
import {
type ControlProps,
getLabel,
@@ -10,7 +14,6 @@ import {
updateExpressionValue,
$selectedInstanceScope,
} from "../shared";
-import { BindingPopover } from "~/builder/shared/binding-popover";
export const TextControl = ({
meta,
@@ -39,7 +42,7 @@ export const TextControl = ({
prop?.type === "expression" ? prop.value : JSON.stringify(computedValue);
const input = (
- <>
+ <BindingControl>
<TextArea
id={id}
disabled={readOnly}
@@ -68,7 +71,7 @@ export const TextControl = ({
onChange({ type: "string", value: String(evaluatedValue) })
}
/>
- </>
+ </BindingControl>
);
const labelElement = (
@@ -84,7 +87,7 @@ export const TextControl = ({
deletable={deletable}
onDelete={onDelete}
>
- <Flex css={{ position: "relative" }}>{input}</Flex>
+ {input}
</ResponsiveLayout>
);
}
@@ -95,7 +98,7 @@ export const TextControl = ({
deletable={deletable}
onDelete={onDelete}
>
- <Flex css={{ py: theme.spacing[2], position: "relative" }}>{input}</Flex>
+ {input}
</VerticalLayout>
);
};
diff --git a/apps/builder/app/builder/features/settings-panel/controls/url.tsx b/apps/builder/app/builder/features/settings-panel/controls/url.tsx
index dea09e7702..134156c1a4 100644
--- a/apps/builder/app/builder/features/settings-panel/controls/url.tsx
+++ b/apps/builder/app/builder/features/settings-panel/controls/url.tsx
@@ -10,7 +10,6 @@ import {
ToggleGroupButton,
Select,
Tooltip,
- Box,
} from "@webstudio-is/design-system";
import {
AttachmentIcon,
@@ -22,7 +21,10 @@ import {
import type { Instance, Page } from "@webstudio-is/sdk";
import { findTreeInstanceIds } from "@webstudio-is/sdk";
import { instancesStore, pagesStore, propsStore } from "~/shared/nano-states";
-import { BindingPopover } from "~/builder/shared/binding-popover";
+import {
+ BindingControl,
+ BindingPopover,
+} from "~/builder/shared/binding-popover";
import {
type ControlProps,
getLabel,
@@ -483,7 +485,7 @@ export const UrlControl = ({
</ToggleGroup>
</Flex>
- <Box css={{ position: "relative" }}>
+ <BindingControl>
<BaseControl
id={id}
instanceId={instanceId}
@@ -509,7 +511,7 @@ export const UrlControl = ({
onChange({ type: "string", value: String(evaluatedValue) })
}
/>
- </Box>
+ </BindingControl>
</VerticalLayout>
);
};
diff --git a/apps/builder/app/builder/features/settings-panel/resource-panel.tsx b/apps/builder/app/builder/features/settings-panel/resource-panel.tsx
index 86887992a4..55ab97672a 100644
--- a/apps/builder/app/builder/features/settings-panel/resource-panel.tsx
+++ b/apps/builder/app/builder/features/settings-panel/resource-panel.tsx
@@ -33,6 +33,7 @@ import {
$variableValuesByInstanceSelector,
} from "~/shared/nano-states";
import {
+ BindingControl,
BindingPopover,
evaluateExpressionWithinScope,
isLiteralExpression,
@@ -120,38 +121,40 @@ const HeaderPair = ({
Value
</Label>
<Box css={{ gridArea: "value-input", position: "relative" }}>
- <BindingPopover
- scope={editorScope}
- aliases={editorAliases}
- value={value}
- onChange={(newValue) => {
- valueField.onChange(newValue);
- valueField.onBlur();
- onChange(name, newValue);
- }}
- onRemove={(evaluatedValue) => {
- valueField.onChange(JSON.stringify(evaluatedValue));
- valueField.onBlur();
- onChange(name, JSON.stringify(evaluatedValue));
- }}
- />
- <InputErrorsTooltip
- errors={valueField.error ? [valueField.error] : undefined}
- >
- <InputField
- id={valueId}
- // expressions with variables cannot be edited
- disabled={isLiteralExpression(value) === false}
- color={valueField.error ? "error" : undefined}
- value={String(evaluateExpressionWithinScope(value, editorScope))}
- // update text value as string literal
- onChange={(event) => {
- valueField.onChange(JSON.stringify(event.target.value));
- onChange(name, JSON.stringify(event.target.value));
+ <BindingControl>
+ <BindingPopover
+ scope={editorScope}
+ aliases={editorAliases}
+ value={value}
+ onChange={(newValue) => {
+ valueField.onChange(newValue);
+ valueField.onBlur();
+ onChange(name, newValue);
+ }}
+ onRemove={(evaluatedValue) => {
+ valueField.onChange(JSON.stringify(evaluatedValue));
+ valueField.onBlur();
+ onChange(name, JSON.stringify(evaluatedValue));
}}
- onBlur={valueField.onBlur}
/>
- </InputErrorsTooltip>
+ <InputErrorsTooltip
+ errors={valueField.error ? [valueField.error] : undefined}
+ >
+ <InputField
+ id={valueId}
+ // expressions with variables cannot be edited
+ disabled={isLiteralExpression(value) === false}
+ color={valueField.error ? "error" : undefined}
+ value={String(evaluateExpressionWithinScope(value, editorScope))}
+ // update text value as string literal
+ onChange={(event) => {
+ valueField.onChange(JSON.stringify(event.target.value));
+ onChange(name, JSON.stringify(event.target.value));
+ }}
+ onBlur={valueField.onBlur}
+ />
+ </InputErrorsTooltip>
+ </BindingControl>
</Box>
<Grid
@@ -377,7 +380,7 @@ export const ResourceForm = forwardRef<
<>
<Flex direction="column" css={{ gap: theme.spacing[3] }}>
<Label htmlFor={urlId}>URL</Label>
- <Box css={{ position: "relative" }}>
+ <BindingControl>
<BindingPopover
scope={scope}
aliases={aliases}
@@ -409,7 +412,7 @@ export const ResourceForm = forwardRef<
onBlur={urlField.onBlur}
/>
</InputErrorsTooltip>
- </Box>
+ </BindingControl>
</Flex>
<Flex direction="column" css={{ gap: theme.spacing[3] }}>
<Label>Method</Label>
@@ -432,7 +435,7 @@ export const ResourceForm = forwardRef<
{method !== "get" && (
<Flex direction="column" css={{ gap: theme.spacing[3] }}>
<Label>Body</Label>
- <Box css={{ position: "relative" }}>
+ <BindingControl>
<BindingPopover
scope={scope}
aliases={aliases}
@@ -465,7 +468,7 @@ export const ResourceForm = forwardRef<
onBlur={bodyField.onBlur}
/>
</InputErrorsTooltip>
- </Box>
+ </BindingControl>
</Flex>
)}
</>
diff --git a/apps/builder/app/builder/features/settings-panel/shared.tsx b/apps/builder/app/builder/features/settings-panel/shared.tsx
index 5e7d708005..766105471f 100644
--- a/apps/builder/app/builder/features/settings-panel/shared.tsx
+++ b/apps/builder/app/builder/features/settings-panel/shared.tsx
@@ -238,7 +238,7 @@ export const VerticalLayout = ({
{label}
{deletable && <RemovePropButton onClick={onDelete} />}
</Grid>
- {children}
+ <Box css={{ py: theme.spacing[2] }}>{children}</Box>
</Box>
);
diff --git a/apps/builder/app/builder/features/settings-panel/variable-popover.tsx b/apps/builder/app/builder/features/settings-panel/variable-popover.tsx
index 4a099721a4..b81f09997a 100644
--- a/apps/builder/app/builder/features/settings-panel/variable-popover.tsx
+++ b/apps/builder/app/builder/features/settings-panel/variable-popover.tsx
@@ -497,6 +497,8 @@ export const VariablePopoverTrigger = forwardRef<
}}
>
<form
+ // exclude from the flow
+ style={{ display: "contents" }}
onSubmit={(event) => {
event.preventDefault();
saveAndClose();
diff --git a/apps/builder/app/builder/shared/binding-popover.tsx b/apps/builder/app/builder/shared/binding-popover.tsx
index 70d11f7765..6a6761c076 100644
--- a/apps/builder/app/builder/shared/binding-popover.tsx
+++ b/apps/builder/app/builder/shared/binding-popover.tsx
@@ -7,6 +7,7 @@ import {
useState,
createContext,
useContext,
+ type ReactNode,
} from "react";
import { isFeatureEnabled } from "@webstudio-is/feature-flags";
import { DotIcon, PlusIcon, TrashIcon } from "@webstudio-is/icons";
@@ -191,6 +192,21 @@ const BindingPanel = ({
);
};
+const bindingOpacityProperty = "--ws-binding-opacity";
+
+export const BindingControl = ({ children }: { children: ReactNode }) => {
+ return (
+ <Box
+ css={{
+ position: "relative",
+ "&:hover": { [bindingOpacityProperty]: 1 },
+ }}
+ >
+ {children}
+ </Box>
+ );
+};
+
const BindingButton = forwardRef<
HTMLButtonElement,
ButtonHTMLAttributes<HTMLButtonElement> & { error?: string }
@@ -204,16 +220,22 @@ const BindingButton = forwardRef<
<SmallIconButton
ref={ref}
css={{
+ // hide by default
+ opacity: `var(${bindingOpacityProperty}, 0)`,
position: "absolute",
top: 0,
left: 0,
boxSizing: "border-box",
padding: 2,
transform: "translate(-50%, -50%) scale(1)",
- transition: "transform 60ms",
+ transition: "transform 60ms, opacity 0ms 60ms",
+ // https://easings.net/#easeInOutSine
+ transitionTimingFunction: "cubic-bezier(0.37, 0, 0.63, 1)",
"--dot-display": "block",
"--plus-display": "none",
- "&:hover, &[aria-expanded=true]": {
+ "&:hover, &:focus-visible, &[aria-expanded=true]": {
+ // always show when interacted with
+ opacity: 1,
transform: `translate(-50%, -50%) scale(1.5)`,
"--dot-display": "none",
"--plus-display": "block",