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
unit and content menu for text control
Sultane4d7792096b5
diff --git a/apps/designer/app/designer/features/style-panel/controls/menu/menu-control.tsx b/apps/designer/app/designer/features/style-panel/controls/menu/menu-control.tsxindex 8055c76543..3027e725e3 100644--- a/apps/designer/app/designer/features/style-panel/controls/menu/menu-control.tsx+++ b/apps/designer/app/designer/features/style-panel/controls/menu/menu-control.tsx@@ -61,11 +61,12 @@ export const MenuControl = ({.filter((item) => item.icon);return (<IconButtonWithMenu+ icon={items.find(({ name }) => name === currentValue)?.icon}label={styleConfig.label}items={items}value={String(currentValue)}onChange={setValue}- isFromCurrentBreakpoint={isFromCurrentBreakpoint}+ isActive={isFromCurrentBreakpoint}></IconButtonWithMenu>);};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.tsxindex a14e708bab..caab6abff9 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,17 +1,18 @@-import { ChangeEvent } from "react";+import { ChangeEvent, FocusEvent, KeyboardEvent } from "react";import {+ Box,Text,Grid,IconButton,- Button,TextField,Tooltip,+ IconButtonWithMenu,} from "@webstudio-is/design-system";import { getFinalValue } from "../../shared/get-final-value";import { useIsFromCurrentBreakpoint } from "../../shared/use-is-from-current-breakpoint";import { ControlProps } from "../../style-sections";import { iconConfigs, StyleConfig } from "../../shared/configs";-import type { StyleValue, Unit } from "@webstudio-is/react-sdk";+import { type StyleValue, type Unit, units } from "@webstudio-is/react-sdk";import { ChevronDownIcon } from "@webstudio-is/icons";const CSSGridLeft = {@@ -78,7 +79,7 @@ export const TextControl = ({delayDuration={700 / 4}disableHoverableContent={true}>- {/* @todo unite values should feature the ScrubControl */}+ {/* @todo unit values should feature the ScrubControl */}<IconButtonvariant="ghost"size="1"@@ -95,58 +96,101 @@ export const TextControl = ({</IconButton></Tooltip><TextField+ css={CSSTextField}spellCheck={false}value={value.value}onChange={(event: ChangeEvent<HTMLInputElement>) =>setValue(event.target.value)}- css={CSSTextField}+ onFocus={(event: FocusEvent<HTMLInputElement>) => event.target.select()}+ onKeyUp={(event: KeyboardEvent<HTMLInputElement>) => {+ if (value.type !== "unit") return;+ if (event.code === "ArrowUp") setValue(String(value.value + 1));+ if (event.code === "ArrowDown") setValue(String(value.value - 1));+ event.preventDefault();+ }}/>{value.type === "unit" ? (- <Units value={value.unit} />+ <Units+ value={value.unit}+ items={units+ .filter((v) =>+ [+ "%",+ "px",+ "rem",+ "em",+ "ch",+ "vh",+ "vw",+ "hv",+ "vmin",+ "vmax",+ ].includes(v)+ )+ .map((unit) => ({ name: unit, label: unit }))}+ onChange={(unit) => setValue(value.value + unit)}+ />) : (<Itemsvalue={value.value}items={styleConfig.items}- onChange={() => {}}+ onChange={(item) => setValue(item)}/>)}</Grid>);};-// @todo open unit menu on click-const Units = ({ value }: { value: Unit }) => {+const Units = ({+ value,+ items,+ onChange,+}: {+ value: Unit;+ items: StyleConfig["items"];+ onChange?: (value: string) => void;+}) => {return (- <IconButton+ <Boxcss={{...CSSGridRight,- ...CSSIconButton,+ button: { ...CSSIconButton },}}>- <Text css={CSSTextUnit}>{value === "number" ? "—" : value}</Text>- </IconButton>+ <IconButtonWithMenu+ icon={<Text css={CSSTextUnit}>{value === "number" ? "—" : value}</Text>}+ items={items}+ value={String(value)}+ onChange={onChange}+ ></IconButtonWithMenu>+ </Box>);};-// @todo open items menu on clickconst Items = ({value,items,+ onChange,}: {value: StyleValue["value"];items: StyleConfig["items"];- onChange: (value: string) => void;+ onChange?: (value: string) => void;}) => {- if (!items) return null;+ if (!items?.length) return null;return (- <IconButton+ <Boxcss={{...CSSGridRight,- ...CSSIconButton,+ button: { ...CSSIconButton },}}>- <ChevronDownIcon />- </IconButton>+ <IconButtonWithMenu+ icon={<ChevronDownIcon />}+ items={items}+ value={String(value)}+ onChange={onChange}+ ></IconButtonWithMenu>+ </Box>);};diff --git a/apps/designer/app/designer/features/style-panel/style-panel.tsx b/apps/designer/app/designer/features/style-panel/style-panel.tsxindex 38cbf8372e..771539a594 100644--- a/apps/designer/app/designer/features/style-panel/style-panel.tsx+++ b/apps/designer/app/designer/features/style-panel/style-panel.tsx@@ -10,7 +10,6 @@ import {useCanvasWidth,useSelectedBreakpoint,} from "~/designer/shared/nano-states";-import { ComponentInfo } from "~/designer/shared/inspector";type StylePanelProps = {publish: Publish;diff --git a/packages/design-system/src/components/icon-button-with-menu.tsx b/packages/design-system/src/components/icon-button-with-menu.tsxindex 7190be06e0..3b6ec0d7d2 100644--- a/packages/design-system/src/components/icon-button-with-menu.tsx+++ b/packages/design-system/src/components/icon-button-with-menu.tsx@@ -1,4 +1,3 @@-import React from "react";import { CheckIcon, IconComponent } from "@webstudio-is/icons";import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";import { styled } from "../stitches.config";@@ -6,6 +5,8 @@ import { Tooltip } from "./tooltip";const StyledContent = styled(DropdownMenuPrimitive.Content, {maxWidth: "$sizes$dropdownMenu",+ maxHeight: 320,+ overflow: "auto",backgroundColor: "$colors$slate4",borderRadius: "$radii$1",padding: "$sizes$2",@@ -58,8 +59,8 @@ const IconButton = styled("button", {all: "unset",fontFamily: "inherit",borderRadius: "calc($radii$1 / 2)",- width: "100%",- height: "100%",+ width: "$6",+ height: "$6",display: "inline-flex",alignItems: "center",justifyContent: "center",@@ -68,36 +69,27 @@ const IconButton = styled("button", {"&:hover": {backgroundColor: "$colors$gray3",},- "& path": {- fill: "currentColor",- },- "&[data-state=open]": {- backgroundColor: "$colors$blue10",- "& path": {- fill: "$colors$blue1",- },- },});export const IconButtonWithMenu = ({+ icon: Icon,label,value,items,+ isActive,onChange,- isFromCurrentBreakpoint,}: {- label: string;+ icon?: JSX.Element;+ label?: string;value: string;items: Array<{label: string;name: string;- icon: ReturnType<IconComponent>;+ icon?: ReturnType<IconComponent>;}>;- onChange: (value: string) => void;- isFromCurrentBreakpoint: boolean;+ isActive?: boolean;+ onChange?: (value: string) => void;}) => {- const activeItem = items.find(({ name }) => name === value);- const TriggerIcon = activeItem?.icon;return (<DropdownMenuPrimitive.Root modal={false}><Tooltip@@ -108,18 +100,18 @@ export const IconButtonWithMenu = ({<DropdownMenuPrimitive.Trigger asChild><IconButtoncss={- isFromCurrentBreakpoint+ isActive? {color: "$colors$blue11",backgroundColor: "$colors$blue4",- "&:not([data-state=open]):hover": {+ "&:hover": {backgroundColor: "$colors$blue4",},}: {}}>- {TriggerIcon}+ {Icon}</IconButton></DropdownMenuPrimitive.Trigger></Tooltip>diff --git a/packages/design-system/src/components/tooltip.tsx b/packages/design-system/src/components/tooltip.tsxindex c2e7b5880d..a92fc72d22 100644--- a/packages/design-system/src/components/tooltip.tsx+++ b/packages/design-system/src/components/tooltip.tsx@@ -54,6 +54,7 @@ export const Tooltip = React.forwardRef(function TooltipWrapper(}: TooltipProps,ref: Ref<HTMLDivElement>) {+ if (!content) return children;return (<TooltipPrimitive.Rootopen={open}diff --git a/packages/react-sdk/src/css/get-browser-style.ts b/packages/react-sdk/src/css/get-browser-style.tsindex 08563cc7fa..bd0586e918 100644--- a/packages/react-sdk/src/css/get-browser-style.ts+++ b/packages/react-sdk/src/css/get-browser-style.ts@@ -3,7 +3,6 @@ import { properties } from "./properties";import { units } from "./units";const unitRegex = new RegExp(`${units.join("|")}`);-const unitProps = ["columnGap", "rowGap"];// @todo use a parserconst parseValue = (property: StyleProperty, value: string): StyleValue => {