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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
Add background section tooltips (#1821)
Ivan Starkov056170e1a8ef
diff --git a/apps/builder/app/builder/features/style-panel/controls/position/position-control.tsx b/apps/builder/app/builder/features/style-panel/controls/position/position-control.tsxindex ca491764f5..1173e7db2b 100644--- a/apps/builder/app/builder/features/style-panel/controls/position/position-control.tsx+++ b/apps/builder/app/builder/features/style-panel/controls/position/position-control.tsx@@ -3,12 +3,13 @@ import {type StyleValue,TupleValueItem,} from "@webstudio-is/css-data";-import { Flex, Label, PositionGrid, theme } from "@webstudio-is/design-system";+import { Flex, Grid, PositionGrid } from "@webstudio-is/design-system";import type { ControlProps } from "../../style-sections";import { styleConfigByName } from "../../shared/configs";import { getStyleSource } from "../../shared/style-info";import { CssValueInputContainer } from "./css-value-input-container";import type { SetValue } from "../../shared/use-style-data";+import { NonResetablePropertyName } from "../../shared/property-name";const toPosition = (value: TupleValue) => {return {@@ -67,7 +68,12 @@ export const PositionControl = ({return (<Flex direction="column" gap="1">- <Label>Position</Label>+ <NonResetablePropertyName+ style={currentStyle}+ properties={[property]}+ label="Position"+ />+<Flex gap="6"><PositionGridselectedPosition={toPosition(value)}@@ -81,36 +87,47 @@ export const PositionControl = ({});}}/>- <Flex- css={{ my: theme.spacing[3] }}- direction="column"- justify="between"+ <Grid+ css={{+ gridTemplateColumns: "max-content 1fr",+ }}+ align="center"+ gapX="2">- <Flex align="center" gap="2">- <Label>Left</Label>- <CssValueInputContainer- label={label}- property={property}- styleSource={styleSource}- keywords={keywords}- value={value.value[0]}- setValue={setValueX}- deleteProperty={deleteProperty}- />- </Flex>- <Flex align="center" gap="2">- <Label>Top</Label>- <CssValueInputContainer- label={label}- property={property}- styleSource={styleSource}- keywords={keywords}- value={value.value[1]}- setValue={setValueY}- deleteProperty={deleteProperty}- />- </Flex>- </Flex>+ <NonResetablePropertyName+ style={currentStyle}+ properties={[property]}+ description="Left position offset"+ label="Left"+ />++ <CssValueInputContainer+ label={label}+ property={property}+ styleSource={styleSource}+ keywords={keywords}+ value={value.value[0]}+ setValue={setValueX}+ deleteProperty={deleteProperty}+ />++ <NonResetablePropertyName+ style={currentStyle}+ properties={[property]}+ description="Top position offset"+ label="Top"+ />++ <CssValueInputContainer+ label={label}+ property={property}+ styleSource={styleSource}+ keywords={keywords}+ value={value.value[1]}+ setValue={setValueY}+ deleteProperty={deleteProperty}+ />+ </Grid></Flex></Flex>);diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.tsxindex 0371352108..f384d6be44 100644--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.tsx+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.tsx@@ -8,12 +8,10 @@ import {theme,Flex,Grid,- Label,ToggleGroup,ToggleGroupItem,Separator,styled,- Tooltip,} from "@webstudio-is/design-system";import { ImageControl, SelectControl, PositionControl } from "../../controls";import type { StyleInfo } from "../../shared/style-info";@@ -39,10 +37,10 @@ import {RepeatColumnIcon,RepeatRowIcon,CrossSmallIcon,- InformationIcon,} from "@webstudio-is/icons";import { toValue } from "@webstudio-is/css-engine";import { BackgroundGradient } from "./background-gradient";+import { NonResetablePropertyName } from "../../shared/property-name";type BackgroundContentProps = {currentStyle: StyleInfo;@@ -153,9 +151,11 @@ export const BackgroundContent = (props: BackgroundContentProps) => {>{imageGradientToggle === "image" && (<>- <Label color="default" truncate>- Image- </Label>+ <NonResetablePropertyName+ style={props.currentStyle}+ properties={["backgroundImage"]}+ label="Image"+ /><FloatingPanelProvider container={elementRef}><ImageControl@@ -170,28 +170,23 @@ export const BackgroundContent = (props: BackgroundContentProps) => {{imageGradientToggle === "gradient" && (<Flex css={{ gridColumn: "span 2" }} direction="column">- <Label color="default">- <Flex align={"center"} gap={1}>- Code- <Tooltip- variant="wrapped"- content={- <>- Paste a CSS gradient, for example:- <br />- <br />- linear-gradient(...)- <br />- <br />- If pasting from figma, remove the “background” property- name.- </>- }- >- <InformationIcon />- </Tooltip>- </Flex>- </Label>+ <NonResetablePropertyName+ style={props.currentStyle}+ description={+ <>+ Paste a CSS gradient, for example:+ <br />+ <br />+ linear-gradient(...)+ <br />+ <br />+ If pasting from figma, remove the “background” property+ name.+ </>+ }+ properties={["backgroundImage"]}+ label="Code"+ /><BackgroundGradientsetProperty={setProperty}@@ -202,9 +197,11 @@ export const BackgroundContent = (props: BackgroundContentProps) => {</Flex>)}- <Label color="default" truncate>- Clip- </Label>+ <NonResetablePropertyName+ style={props.currentStyle}+ properties={["backgroundClip"]}+ label="Clip"+ /><SelectControlsetProperty={setProperty}@@ -213,9 +210,11 @@ export const BackgroundContent = (props: BackgroundContentProps) => {property="backgroundClip"/>- <Label color="default" truncate>- Origin- </Label>+ <NonResetablePropertyName+ style={props.currentStyle}+ properties={["backgroundOrigin"]}+ label="Origin"+ /><SelectControlsetProperty={setProperty}@@ -252,9 +251,11 @@ export const BackgroundContent = (props: BackgroundContentProps) => {>{imageGradientToggle === "image" && (<>- <Label color="default" truncate>- Repeat- </Label>+ <NonResetablePropertyName+ style={props.currentStyle}+ properties={["backgroundRepeat"]}+ label="Repeat"+ /><Flex css={{ justifySelf: "end" }}><ToggleGroupControl@@ -293,9 +294,11 @@ export const BackgroundContent = (props: BackgroundContentProps) => {</>)}- <Label color="default" truncate>- Attachment- </Label>+ <NonResetablePropertyName+ style={props.currentStyle}+ properties={["backgroundAttachment"]}+ label="Attachment"+ /><Flex css={{ justifySelf: "end" }}><ToggleGroup@@ -317,9 +320,11 @@ export const BackgroundContent = (props: BackgroundContentProps) => {</ToggleGroup></Flex>- <Label color="default" truncate>- Blend mode- </Label>+ <NonResetablePropertyName+ style={props.currentStyle}+ properties={["backgroundBlendMode"]}+ label="Blend mode"+ /><SelectControlsetProperty={setProperty}diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-size.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-size.tsxindex 3cbcd78186..19bf225974 100644--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-size.tsx+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-size.tsx@@ -1,4 +1,4 @@-import { Grid, Label, Select, theme } from "@webstudio-is/design-system";+import { Grid, Select, theme } from "@webstudio-is/design-system";import { toValue } from "@webstudio-is/css-engine";import { styleConfigByName } from "../../shared/configs";import { toPascalCase } from "../../shared/keyword-utils";@@ -11,6 +11,7 @@ import {TupleValueItem,} from "@webstudio-is/css-data";import type { SetValue } from "../../shared/use-style-data";+import { NonResetablePropertyName } from "../../shared/property-name";const StyleKeywordAuto = { type: "keyword" as const, value: "auto" };@@ -72,9 +73,11 @@ export const BackgroundSize = (align="center"gap={2}>- <Label color="default" truncate>- Size- </Label>+ <NonResetablePropertyName+ style={props.currentStyle}+ properties={[property]}+ label="Size"+ /><Select// show empty field instead of radix placeholder@@ -104,13 +107,21 @@ export const BackgroundSize = (gapX={2}gapY={1}>- <Label color="default" disabled={customSizeDisabled} truncate>- Width- </Label>+ <NonResetablePropertyName+ style={props.currentStyle}+ properties={[property]}+ label="Width"+ description="The width of the background image."+ disabled={customSizeDisabled}+ />- <Label color="default" disabled={customSizeDisabled} truncate>- Height- </Label>+ <NonResetablePropertyName+ style={props.currentStyle}+ properties={[property]}+ label="Height"+ description="The height of the background image."+ disabled={customSizeDisabled}+ /><CssValueInputContainerdisabled={customSizeDisabled}diff --git a/apps/builder/app/builder/features/style-panel/shared/property-name.tsx b/apps/builder/app/builder/features/style-panel/shared/property-name.tsxindex 2a5c9f5f08..00e455ad3b 100644--- a/apps/builder/app/builder/features/style-panel/shared/property-name.tsx+++ b/apps/builder/app/builder/features/style-panel/shared/property-name.tsx@@ -115,10 +115,10 @@ const TooltipContent = ({onClose,}: {title: string;- description?: string;+ description?: React.ReactNode;properties: StyleProperty[];style: StyleInfo;- onReset: () => void;+ onReset?: undefined | (() => void);onClose: () => void;}) => {const breakpoints = useStore(breakpointsStore);@@ -193,44 +193,47 @@ const TooltipContent = ({</Flex></Flex>)}- {(styleSource === "local" || styleSource === "overwritten") && (- <Button- color="dark"- prefix={<ResetIcon />}- css={{ flexGrow: 1 }}- onMouseDown={(event) => {- // Prevent closing tooltip- event.preventDefault();- }}- onClickCapture={() => {- onReset();- onClose();- }}- >- Reset value- </Button>- )}+ {(styleSource === "local" || styleSource === "overwritten") &&+ onReset !== undefined && (+ <Button+ color="dark"+ prefix={<ResetIcon />}+ css={{ flexGrow: 1 }}+ onMouseDown={(event) => {+ // Prevent closing tooltip+ event.preventDefault();+ }}+ onClickCapture={() => {+ onReset();+ onClose();+ }}+ >+ Reset value+ </Button>+ )}</Flex>);};-type PropertyNameProps = {+type PropertyNameInternalProps = {style: StyleInfo;properties: StyleProperty[];label: string | ReactElement;title?: string;- description?: string;- onReset: () => void;+ description?: React.ReactNode;+ onReset?: undefined | (() => void);+ disabled?: boolean;};-export const PropertyName = ({+const PropertyNameInternal = ({style,title,description,properties,label,onReset,-}: PropertyNameProps) => {+ disabled,+}: PropertyNameInternalProps) => {const [isOpen, setIsOpen] = useState(false);// When we have multiple properties, they must be originating from the same source, so we can just use one.const property = properties[0];@@ -265,7 +268,15 @@ export const PropertyName = ({}}>{typeof label === "string" && property ? (- <Label color={getStyleSource(style[property])} truncate>+ <Label+ color={+ onReset === undefined+ ? "default"+ : getStyleSource(style[property])+ }+ truncate+ disabled={disabled}+ >{label}</Label>) : (@@ -276,3 +287,62 @@ export const PropertyName = ({</Flex>);};++type PropertyNameProps = {+ style: StyleInfo;+ properties: StyleProperty[];+ label: string | ReactElement;+ title?: string;+ description?: React.ReactNode;+ onReset: () => void;+};++export const PropertyName = ({+ style,+ title,+ description,+ properties,+ label,+ onReset,+}: PropertyNameProps) => (+ <PropertyNameInternal+ style={style}+ title={title}+ description={description}+ properties={properties}+ label={label}+ onReset={onReset}+ />+);++type NonResetablePropertyNameProps = {+ style: StyleInfo;+ properties: StyleProperty[];+ label: string | ReactElement;+ title?: string;+ description?: React.ReactNode;+ disabled?: boolean;+};+/**+ * Some properties like layered background-image, background-size are non resetable.+ * UI of background would be unreadable, imagine you have+ * background-size inherited from one source, background-image from the other,+ * Every property have different amount of layers. The final result on the screen would be a mess.+ */+export const NonResetablePropertyName = ({+ style,+ title,+ description,+ properties,+ label,+ disabled,+}: NonResetablePropertyNameProps) => (+ <PropertyNameInternal+ style={style}+ title={title}+ description={description}+ properties={properties}+ label={label}+ disabled={disabled}+ />+);