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.

use dropdown menu for unit selection

Sultanf86ce6aca2da
diff --git a/apps/designer/app/designer/features/breakpoints/breakpoints.tsx b/apps/designer/app/designer/features/breakpoints/breakpoints.tsx
index 99437785bc..2f75919cc8 100644
--- a/apps/designer/app/designer/features/breakpoints/breakpoints.tsx
+++ b/apps/designer/app/designer/features/breakpoints/breakpoints.tsx
@@ -128,7 +128,11 @@ export const Breakpoints = ({ publish }: BreakpointsProps) => {
<TriggerButton />
</DropdownMenuTrigger>
<DropdownMenuPortal>
- <DropdownMenuContent css={{ zIndex: "$1" }}>
+ <DropdownMenuContent
+ css={{ zIndex: "$1" }}
+ sideOffset={4}
+ collisionPadding={4}
+ >
{view === "confirmation" && (
<ConfirmationDialog
breakpoint={selectedBreakpoint}
@@ -202,7 +206,6 @@ export const Breakpoints = ({ publish }: BreakpointsProps) => {
</DropdownMenuItem>
</>
)}
- <DropdownMenuArrow offset={10} />
</DropdownMenuContent>
</DropdownMenuPortal>
</DropdownMenu>
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 005ab9f19a..15344e825f 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,8 +1,21 @@
-import { FocusEvent, KeyboardEvent, PointerEvent, useCallback } from "react";
+import {
+ FocusEvent,
+ KeyboardEvent,
+ PointerEvent,
+ useRef,
+ useCallback,
+} from "react";
import {
Box,
Text,
IconButton,
+ DropdownMenu,
+ DropdownMenuTrigger,
+ DropdownMenuPortal,
+ DropdownMenuContent,
+ DropdownMenuRadioItem,
+ DropdownMenuRadioGroup,
+ Select,
TextField,
Combobox,
numericScrubControl,
@@ -33,16 +46,7 @@ export const TextControl = ({
property: styleConfig.property,
});
- const getInputNode = (node: HTMLElement): HTMLInputElement => {
- return node
- .closest("[data-control]")
- ?.querySelector("input") as HTMLInputElement;
- };
- const isExpanded = (node: HTMLElement) => {
- return node
- .closest("[data-control]")
- ?.querySelector("[aria-expanded=true]");
- };
+ const inputRef = useRef<HTMLInputElement | null>(null);
const numericScrubRefCallback = useCallback(
(node: HTMLButtonElement) => {
@@ -54,7 +58,7 @@ export const TextControl = ({
Object(node)[id] = numericScrubControl(node, {
initialValue: value.value,
onValueChange: (event) => {
- getInputNode(node).value = String(event.value);
+ if (inputRef.current) inputRef.current.value = String(event.value);
handleChange("unit", event.value, true);
},
});
@@ -67,10 +71,8 @@ export const TextControl = ({
const setValue = setProperty(styleConfig.property);
- const items =
- value.type === "unit"
- ? sortedUnits.map((unit) => ({ name: unit, label: unit }))
- : styleConfig.items;
+ const items = styleConfig.items.map(({ label }) => label);
+ const units = sortedUnits.map((unit) => unit);
const handleChange = (
type: string,
item: string | number | undefined,
@@ -84,21 +86,21 @@ export const TextControl = ({
});
};
const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
- handleKeyDownEnter(event, event.target);
- if (isExpanded(event.target)) {
- inputProps?.onKeyDown?.(event);
- return false;
- }
+ handleKeyDownEnter(event);
+ if (event.currentTarget.matches("[aria-activedescendant]")) return true;
if (value.type !== "unit") return true;
if (!["ArrowUp", "ArrowDown"].includes(event.code)) return false;
event.preventDefault();
handleKeyDownArrowUpDown(event);
};
const handleKeyDownEnter = (event: KeyboardEvent<HTMLInputElement>) => {
- if (event.code === "Enter" && String(value.value) !== event.target.value) {
- setValue(event.target.value);
- const number = parseFloat(event.target.value);
- if (!isNaN(number)) event.target.value = String(number);
+ if (
+ event.code === "Enter" &&
+ String(value.value) !== event.currentTarget.value
+ ) {
+ setValue(event.currentTarget.value);
+ const number = parseFloat(event.currentTarget.value);
+ if (!isNaN(number)) event.currentTarget.value = String(number);
}
};
const handleKeyDownArrowUpDown = (event: KeyboardEvent<HTMLInputElement>) => {
@@ -121,9 +123,8 @@ export const TextControl = ({
return (
<Combobox
name={styleConfig.property}
- items={items.map((item) => item.label)}
+ items={items}
value={String(value.value)}
- selected={String(value.type === "unit" ? value.unit : value.value)}
onItemSelect={(item) => {
handleChange(value.type, item, false);
}}
@@ -135,12 +136,16 @@ export const TextControl = ({
<Box css={{ position: "relative" }}>
<TextField
{...inputProps}
+ inputRef={inputRef}
onFocus={(event: FocusEvent<HTMLInputElement>) => {
- event.target.select();
+ event.currentTarget.select();
}}
onBlur={(event) => {
- if (event.target.value !== event.target.getAttribute("value"))
- setValue(event.target.value);
+ if (
+ event.currentTarget.value !==
+ event.currentTarget.getAttribute("value")
+ )
+ setValue(event.currentTarget.value);
}}
onKeyDown={(event: KeyboardEvent<HTMLInputElement>) => {
if (handleKeyDown(event)) inputProps?.onKeyDown?.(event);
@@ -151,7 +156,7 @@ export const TextControl = ({
label={styleConfig.label}
{...(value.type === "unit" && {
onPointerUp: (event: PointerEvent<HTMLInputElement>) => {
- setValue(String(getInputNode(event.target).value));
+ setValue(String(inputRef.current?.value));
},
ref: numericScrubRefCallback,
})}
@@ -159,7 +164,7 @@ export const TextControl = ({
}
suffix={
<IconButton
- {...toggleProps}
+ {...(value.type !== "unit" && toggleProps)}
css={{
visibility: items.length ? "visible" : "hidden",
position: "absolute",
@@ -175,19 +180,49 @@ export const TextControl = ({
},
}}
>
- {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>
- ) : (
+ {value.type !== "unit" ? (
<ChevronDownIcon />
+ ) : (
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Text
+ css={{
+ cursor: "default",
+ minWidth: "calc($sizes$3 - $nudge$1)",
+ textAlign: "center",
+ fontSize: "calc($fontSizes$1 - $nudge$1)",
+ }}
+ >
+ {value.unit === "number" ? "—" : value.unit}
+ </Text>
+ </DropdownMenuTrigger>
+ <DropdownMenuPortal>
+ <DropdownMenuContent
+ sideOffset={14}
+ collisionPadding={16}
+ side="bottom"
+ css={{
+ minWidth: 124,
+ maxHeight: 190,
+ }}
+ >
+ <DropdownMenuRadioGroup
+ value={String(value.unit)}
+ onValueChange={(unit) =>
+ handleChange("unit", unit, false)
+ }
+ >
+ {units.map((unit) => {
+ return (
+ <DropdownMenuRadioItem key={unit} value={unit}>
+ {unit}
+ </DropdownMenuRadioItem>
+ );
+ })}
+ </DropdownMenuRadioGroup>
+ </DropdownMenuContent>
+ </DropdownMenuPortal>
+ </DropdownMenu>
)}
</IconButton>
}
diff --git a/apps/designer/app/designer/features/topbar/menu/menu.tsx b/apps/designer/app/designer/features/topbar/menu/menu.tsx
index 32d6c71884..97c6788b04 100644
--- a/apps/designer/app/designer/features/topbar/menu/menu.tsx
+++ b/apps/designer/app/designer/features/topbar/menu/menu.tsx
@@ -131,7 +131,11 @@ export const Menu = ({ config, publish }: MenuProps) => {
</Box>
</DropdownMenuTrigger>
<DropdownMenuPortal>
- <DropdownMenuContent css={{ zIndex: "$1" }}>
+ <DropdownMenuContent
+ css={{ zIndex: "$1" }}
+ sideOffset={4}
+ collisionPadding={4}
+ >
<DropdownMenuItem
css={menuItemCss}
onSelect={() => {
@@ -266,7 +270,6 @@ export const Menu = ({ config, publish }: MenuProps) => {
>
Publish
</DropdownMenuItem>
- <DropdownMenuArrow offset={10} />
</DropdownMenuContent>
</DropdownMenuPortal>
</DropdownMenu>
diff --git a/apps/designer/app/designer/features/topbar/publish.tsx b/apps/designer/app/designer/features/topbar/publish.tsx
index 0bfa1637ec..1a6d3d3252 100644
--- a/apps/designer/app/designer/features/topbar/publish.tsx
+++ b/apps/designer/app/designer/features/topbar/publish.tsx
@@ -44,6 +44,7 @@ const Content = ({ project }: PublishButtonProps) => {
return (
<PopoverContent
css={{ padding: "$3" }}
+ hideArrow={true}
onFocusOutside={(event) => {
// Used to prevent closing when opened from the main dropdown menu
event.preventDefault();
diff --git a/apps/designer/app/designer/features/topbar/share.tsx b/apps/designer/app/designer/features/topbar/share.tsx
index 102fa070a0..97c7551682 100644
--- a/apps/designer/app/designer/features/topbar/share.tsx
+++ b/apps/designer/app/designer/features/topbar/share.tsx
@@ -28,6 +28,7 @@ const Content = ({ path, projectId, pageId }: ShareButtonProps) => {
return (
<PopoverContent
css={{ padding: "$3" }}
+ hideArrow={true}
onFocusOutside={(event) => {
// Used to prevent closing when opened from the main dropdown menu
event.preventDefault();
diff --git a/packages/design-system/src/components/combobox.tsx b/packages/design-system/src/components/combobox.tsx
index 4579cd904a..d4aee1c557 100644
--- a/packages/design-system/src/components/combobox.tsx
+++ b/packages/design-system/src/components/combobox.tsx
@@ -135,7 +135,6 @@ type ComboboxProps<Item> = {
items: ReadonlyArray<Item>;
value?: Item;
onItemSelect?: (value?: Item) => void;
- selected?: Item;
onItemHighlight?: (value?: Item) => void;
itemToString?: (item?: Item | null) => string;
renderTextField?: (
@@ -150,7 +149,6 @@ type ComboboxProps<Item> = {
export const Combobox = <Item extends BaseItem>({
items,
value,
- selected = value,
name,
placeholder,
itemToString = (item) =>
@@ -272,7 +270,7 @@ export const Combobox = <Item extends BaseItem>({
items: isOpen ? foundItems : [],
getItemProps,
highlightedIndex,
- selectedItem: selected as Item,
+ selectedItem,
itemToString,
}),
})}
diff --git a/packages/design-system/src/components/dropdown-menu.tsx b/packages/design-system/src/components/dropdown-menu.tsx
index 61e05f683a..3198603371 100644
--- a/packages/design-system/src/components/dropdown-menu.tsx
+++ b/packages/design-system/src/components/dropdown-menu.tsx
@@ -9,7 +9,8 @@ import { panelStyles } from "./panel";
export const DropdownMenu = DropdownMenuPrimitive.Root;
export const DropdownMenuArrow = styled(DropdownMenuPrimitive.Arrow, {
- fill: "$panel",
+ fill: "$colors$slate4",
+ stroke: "$colors$slate1",
});
export const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;
@@ -56,23 +57,7 @@ export const DropdownMenuRadioItem = React.forwardRef<
<StyledDropdownMenuRadioItem {...props} ref={forwardedRef}>
<Box as="span" css={{ position: "absolute", left: "$1" }}>
<DropdownMenuPrimitive.ItemIndicator>
- <Flex
- css={{
- width: "$3",
- height: "$3",
- alignItems: "center",
- justifyContent: "center",
- }}
- >
- <Box
- css={{
- width: "$1",
- height: "$1",
- backgroundColor: "currentColor",
- borderRadius: "$round",
- }}
- />
- </Flex>
+ <CheckIcon />
</DropdownMenuPrimitive.ItemIndicator>
</Box>
{children}
diff --git a/packages/design-system/src/components/menu.tsx b/packages/design-system/src/components/menu.tsx
index 903c3c77b4..fc39a5616f 100644
--- a/packages/design-system/src/components/menu.tsx
+++ b/packages/design-system/src/components/menu.tsx
@@ -26,7 +26,7 @@ export const itemCss = css(baseItemCss, {
color: "$hiContrast",
"&:focus, &[data-found]": {
outline: "none",
- backgroundColor: "$blue9",
+ backgroundColor: "$blue10",
color: "white",
},
"&[data-disabled]": {
@@ -71,23 +71,7 @@ export const MenuRadioItem = React.forwardRef<
<StyledMenuRadioItem {...props} ref={forwardedRef}>
<Box as="span" css={{ position: "absolute", left: "$1" }}>
<MenuPrimitive.ItemIndicator>
- <Flex
- css={{
- width: "$3",
- height: "$3",
- alignItems: "center",
- justifyContent: "center",
- }}
- >
- <Box
- css={{
- width: "$1",
- height: "$1",
- backgroundColor: "currentColor",
- borderRadius: "$round",
- }}
- ></Box>
- </Flex>
+ <CheckIcon />
</MenuPrimitive.ItemIndicator>
</Box>
{children}
diff --git a/packages/design-system/src/components/panel.tsx b/packages/design-system/src/components/panel.tsx
index 7b3bf45b14..b4a361629b 100644
--- a/packages/design-system/src/components/panel.tsx
+++ b/packages/design-system/src/components/panel.tsx
@@ -1,10 +1,11 @@
import { css, styled } from "../stitches.config";
export const panelStyles = css({
- backgroundColor: "$panel",
- borderRadius: "$3",
+ overflow: "auto",
+ backgroundColor: "$colors$slate4",
+ borderRadius: "$1",
boxShadow:
- "$colors$shadowLight 0px 10px 38px -10px, $colors$shadowDark 0px 10px 20px -15px",
+ "0px 2px 7px rgba(0, 0, 0, 0.1), 0px 5px 17px rgba(0, 0, 0, 0.15), inset 0 0 1px 1px $colors$slate1, 0 0 0 1px $colors$slate8",
});
export const Panel = styled("div", panelStyles);
diff --git a/packages/design-system/src/components/popover.tsx b/packages/design-system/src/components/popover.tsx
index ec8c1fc640..1e7bf750f0 100644
--- a/packages/design-system/src/components/popover.tsx
+++ b/packages/design-system/src/components/popover.tsx
@@ -39,7 +39,12 @@ export const PopoverContent = React.forwardRef<
React.ElementRef<typeof StyledContent>,
PopoverContentProps
>(({ children, hideArrow, ...props }, fowardedRef) => (
- <StyledContent sideOffset={0} {...props} ref={fowardedRef}>
+ <StyledContent
+ sideOffset={4}
+ collisionPadding={4}
+ {...props}
+ ref={fowardedRef}
+ >
{children}
{!hideArrow && (
<Box css={{ color: "$panel" }}>
diff --git a/packages/design-system/src/components/text-field.tsx b/packages/design-system/src/components/text-field.tsx
index c8b4934704..ab2611ca82 100644
--- a/packages/design-system/src/components/text-field.tsx
+++ b/packages/design-system/src/components/text-field.tsx
@@ -62,6 +62,7 @@ const TextFieldBase = styled("div", {
// Custom
display: "flex",
backgroundColor: "$loContrast",
+ py: 1, // value of insert boxShadow
boxShadow: "inset 0 0 0 1px $colors$slate7",
color: "$hiContrast",
fontVariantNumeric: "tabular-nums",