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 tooltip to comboicon, gap inputs
Sultan464dcc90e72e
diff --git a/apps/designer/app/designer/features/style-panel/style-section.tsx b/apps/designer/app/designer/features/style-panel/style-section.tsxindex 02b3a9e4b0..16219917eb 100644--- a/apps/designer/app/designer/features/style-panel/style-section.tsx+++ b/apps/designer/app/designer/features/style-panel/style-section.tsx@@ -1,4 +1,8 @@-import { useState, KeyboardEvent } from "react";+import {+ useState,+ KeyboardEvent,+ // useCallback,+} from "react";import {Box,Flex,@@ -12,6 +16,8 @@ import {Select,IconButton,TextField,+ Tooltip,+ // numericGestureControl,} from "@webstudio-is/design-system";import { TriangleRightIcon, TriangleDownIcon } from "@webstudio-is/icons";import * as icons from "@webstudio-is/icons";@@ -189,6 +195,22 @@ const ComboboxControl = ({}: ControlProps) => {const isCurrentBreakpoint = useIsFromCurrentBreakpoint(styleConfig.property);+ // @todo, better hook abstraction(use effects), update value, should be part of the updated(per next todo below) combobox abstraction+ // const refCallback = useCallback((node: HTMLElement) => {+ // let disconnectedCallback = () => {};+ // if (node) {+ // disconnectedCallback = numericGestureControl(node, {+ // minValue: 0,+ // initialValue: parseFloat(String(value?.value)) || 0,+ // onValueChange: (event) => {+ // event.target.parentNode.querySelector("input").value = event.value;+ // },+ // }).disconnectedCallback;+ // } else {+ // disconnectedCallback?.();+ // }+ // }, []);+if (styleConfig.control !== "Combobox") return null;// @todo show which instance we inherited the value from@@ -212,6 +234,7 @@ const ComboboxControl = ({gap: Record<string, (props: unknown) => JSX.Element>;}).gap[styleConfig.property];+ // @todo abstract to a variant of the combobox componentreturn (<Gridcss={{@@ -219,30 +242,37 @@ const ComboboxControl = ({gridTemplateRows: "repeat(1, 1fr)",}}>- <IconButton- variant="ghost"- size="1"- css={{- zIndex: 1,- gridArea: "1 / 1 / 2 / 2",- marginLeft: 2,- marginTop: 2,- borderRadius: 1,- height: "calc($sizes$5 - 4px)",- width: "calc($sizes$5 - 4px)",- "&:focus": {- boxShadow: "none",- },- ...(isCurrentBreakpoint && {- bc: "$colors$blue4",- "& svg *": {- fill: "$colors$blue11",- },- }),- }}+ <Tooltip+ content={styleConfig.label}+ delayDuration={700}+ disableHoverableContent={true}>- <Icon />- </IconButton>+ <IconButton+ // ref={refCallback}+ variant="ghost"+ size="1"+ css={{+ zIndex: 1,+ gridArea: "1 / 1 / 2 / 2",+ marginLeft: 2,+ marginTop: 2,+ borderRadius: 1,+ height: "calc($sizes$5 - 4px)",+ width: "calc($sizes$5 - 4px)",+ "&:focus": {+ boxShadow: "none",+ },+ ...(isCurrentBreakpoint && {+ bc: "$colors$blue4",+ "& svg *": {+ fill: "$colors$blue11",+ },+ }),+ }}+ >+ <Icon />+ </IconButton>+ </Tooltip><TextFieldtype="number"defaultValue={parseFloat(String(value.value)) || 0}@@ -361,6 +391,7 @@ const ComboiconControl = ({const currentValue = value.value as string;return (<Comboicon+ label={styleConfig.label}items={styleConfig.items}value={String(currentValue)}onChange={setValue}diff --git a/packages/design-system/src/components/comboicon.tsx b/packages/design-system/src/components/comboicon.tsxindex 2f59b8c698..ebeb8f9b2f 100644--- a/packages/design-system/src/components/comboicon.tsx+++ b/packages/design-system/src/components/comboicon.tsx@@ -3,6 +3,7 @@ import { CheckIcon } from "@webstudio-is/icons";import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";import { styled, CSS } from "../stitches.config";import { Box } from "./box";+import { Tooltip } from "./tooltip";const StyledContent = styled(DropdownMenuPrimitive.Content, {maxWidth: "224px",@@ -84,12 +85,14 @@ const IconButton = styled("button", {});export const Comboicon = ({+ label,value,items,onChange,icons,css,}: {+ label: string;value: string;items: Array<{ label: string; name: string }>;onChange: (value: string) => void;@@ -99,9 +102,15 @@ export const Comboicon = ({const TriggerIcon = icons?.[value];return (<DropdownMenuPrimitive.Root modal={false}>- <DropdownMenuPrimitive.Trigger asChild>- <IconButton css={css}>{TriggerIcon && <TriggerIcon />}</IconButton>- </DropdownMenuPrimitive.Trigger>+ <Tooltip+ content={label}+ delayDuration={700 * 2}+ disableHoverableContent={true}+ >+ <DropdownMenuPrimitive.Trigger asChild>+ <IconButton css={css}>{TriggerIcon && <TriggerIcon />}</IconButton>+ </DropdownMenuPrimitive.Trigger>+ </Tooltip><StyledContent sideOffset={4}><DropdownMenuPrimitive.RadioGroupdiff --git a/packages/design-system/src/components/primitives/numeric-gesture-control.stories.tsx b/packages/design-system/src/components/primitives/numeric-gesture-control.stories.tsxindex c1d4509877..895631e6bc 100644--- a/packages/design-system/src/components/primitives/numeric-gesture-control.stories.tsx+++ b/packages/design-system/src/components/primitives/numeric-gesture-control.stories.tsx@@ -1,8 +1,8 @@import { useRef, useEffect, RefObject } from "react";import {numericGestureControl,- type Value,- type Direction,+ type NumericGestureValue,+ type NumericGestureDirection,} from "./numeric-gesture-control";const useNumericGestureControl = ({@@ -11,8 +11,8 @@ const useNumericGestureControl = ({direction,}: {ref: RefObject<HTMLInputElement>;- value: Value;- direction: Direction;+ value: NumericGestureValue;+ direction: NumericGestureDirection;}) => {useEffect(() => {if (ref.current === null) return;@@ -34,8 +34,8 @@ const Input = ({value,direction,}: {- value: Value;- direction: Direction;+ value: NumericGestureValue;+ direction: NumericGestureDirection;}) => {const ref = useRef<HTMLInputElement | null>(null);useNumericGestureControl({ ref, value, direction });diff --git a/packages/design-system/src/components/primitives/numeric-gesture-control.ts b/packages/design-system/src/components/primitives/numeric-gesture-control.tsindex ba71e5a8a4..fa4e475193 100644--- a/packages/design-system/src/components/primitives/numeric-gesture-control.ts+++ b/packages/design-system/src/components/primitives/numeric-gesture-control.ts@@ -14,21 +14,23 @@* });*/-export type Direction = "horizontal" | "vertical";+export type NumericGestureDirection = "horizontal" | "vertical";-export type Value = number;+export type NumericGestureValue = number;-type Options = {- initialValue: Value;- direction: Direction;+export type NumericGestureOptions = {+ minValue?: NumericGestureValue;+ maxValue?: NumericGestureValue;+ initialValue?: NumericGestureValue;+ direction?: NumericGestureDirection;onValueChange: (event: {target: HTMLInputElement;- value: Value;+ value: NumericGestureValue;preventDefault: () => void;}) => void;};-type State = {+type NumericGestureState = {value: number;cursor?: SVGElement;offset: number;@@ -39,13 +41,15 @@ type State = {export const numericGestureControl = (targetNode: HTMLInputElement,{+ minValue = Number.MIN_SAFE_INTEGER,+ maxValue = Number.MAX_SAFE_INTEGER,initialValue = 0,direction = "horizontal",onValueChange = () => null,- }: Options+ }: NumericGestureOptions) => {const eventNames = ["pointerup", "pointerdown", "pointermove"] as const;- const state: State = {+ const state: NumericGestureState = {value: initialValue,cursor: undefined,offset: 0,@@ -66,9 +70,9 @@ export const numericGestureControl = (}};const handleEvent = (event: PointerEvent) => {- const { type, offsetX, offsetY, movementY, movementX } = event;- const offset = direction === "horizontal" ? offsetX : offsetY;- const movement = direction === "horizontal" ? movementX : -movementY;+ const { type, clientX, clientY, movementY, movementX } = event;+ const offset = direction === "horizontal" ? clientX : clientY;+ let movement = direction === "horizontal" ? movementX : -movementY;switch (type) {case "pointerup": {state.offset = 0;@@ -87,6 +91,8 @@ export const numericGestureControl = (if (state.offset < 0) state.offset = globalThis.innerWidth + 1;else if (state.offset > globalThis.innerWidth) state.offset = 1;state.value += movement;+ if (state.value < minValue) state.value = minValue;+ else if (state.value > maxValue) state.value = maxValue;state.offset += movement * state.velocity;onValueChange({target: targetNode,@@ -98,7 +104,6 @@ export const numericGestureControl = (}}};-handleCursor(targetNode, true);eventNames.forEach((eventName) =>targetNode.addEventListener(eventName, handleEvent)@@ -114,7 +119,7 @@ export const numericGestureControl = (};const requestPointerLock = (- state: State,+ state: NumericGestureState,event: PointerEvent,targetNode: HTMLElement) => {@@ -127,20 +132,23 @@ const requestPointerLock = (// albeit without an infinite cursor ux.if (shouldUsePointerLock) {targetNode.requestPointerLock();- const cursorNode = new Range().createContextualFragment(`- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="46" height="15" style="filter:drop-shadow(${- state.direction === "horizontal" ? "0 1px" : "1px 0"- } 1.1px rgba(0,0,0,.4))">+ const cursorNode = (targetNode.ownerDocument.querySelector("#cursor") ||+ new Range().createContextualFragment(`+ <svg id="cursor" version="1.1" xmlns="http://www.w3.org/2000/svg" width="46" height="15"><g transform="translate(2 3)"><path d="M 15 4.5L 15 2L 11.5 5.5L 15 9L 15 6.5L 31 6.5L 31 9L 34.5 5.5L 31 2L 31 4.5Z" fill="#111" fill-rule="evenodd" stroke="#FFF" stroke-width="2"></path><path d="M 15 4.5L 15 2L 11.5 5.5L 15 9L 15 6.5L 31 6.5L 31 9L 34.5 5.5L 31 2L 31 4.5Z" fill="#111" fill-rule="evenodd"></path></g>- </svg>`).firstElementChild as SVGElement;+ </svg>`).firstElementChild) as SVGElement;+ cursorNode.style.filter = `drop-shadow(${+ state.direction === "horizontal" ? "0 1px" : "1px 0"+ } 1.1px rgba(0,0,0,.4))`;cursorNode.style.position = "absolute";- cursorNode.style.left = `${event.offsetX}px`;- cursorNode.style.top = `${event.offsetY}px`;- cursorNode.style.transform =- state.direction === "horizontal" ? "rotate(0deg)" : "rotate(90deg)";+ cursorNode.style.left = `${event.clientX}px`;+ cursorNode.style.top = `${event.clientY}px`;+ cursorNode.style.transform = `translate(-50%, -50%) ${+ state.direction === "horizontal" ? "rotate(0deg)" : "rotate(90deg)"+ }`;state.cursor = cursorNode;if (state.cursor) {targetNode.ownerDocument.documentElement.append(state.cursor);@@ -158,7 +166,7 @@ const requestPointerLock = (};const exitPointerLock = (- state: State,+ state: NumericGestureState,event: PointerEvent,targetNode: HTMLElement) => {diff --git a/packages/design-system/src/components/tooltip.tsx b/packages/design-system/src/components/tooltip.tsxindex 0cb9d347ee..c2e7b5880d 100644--- a/packages/design-system/src/components/tooltip.tsx+++ b/packages/design-system/src/components/tooltip.tsx@@ -11,13 +11,13 @@ type TooltipProps = React.ComponentProps<typeof TooltipPrimitive.Root> &content: React.ReactNode;multiline?: boolean;delayDuration?: number;+ disableHoverableContent?: boolean;css?: CSS;};const Content = styled(TooltipPrimitive.Content, {- backgroundColor: "$loContrast",- boxShadow: "inset 0 0 0 1px $colors$slate7",- color: "$hiContrast",+ backgroundColor: "$hiContrast",+ color: "$loContrast",borderRadius: "$1",padding: "$1 $2",zIndex: "$max",@@ -26,7 +26,7 @@ const Content = styled(TooltipPrimitive.Content, {variants: {multiline: {true: {- // @todo makew this part of the design system+ // @todo make this part of the design systemmaxWidth: 110,pb: 7,},@@ -35,8 +35,7 @@ const Content = styled(TooltipPrimitive.Content, {});const Arrow = styled(TooltipPrimitive.Arrow, {- fill: "$loContrast",- stroke: "$slate7",+ fill: "$hiContrast",strokeWidth: "$1",marginTop: -0.5,});@@ -50,6 +49,7 @@ export const Tooltip = React.forwardRef(function TooltipWrapper(onOpenChange,multiline,delayDuration,+ disableHoverableContent,...props}: TooltipProps,ref: Ref<HTMLDivElement>@@ -60,6 +60,7 @@ export const Tooltip = React.forwardRef(function TooltipWrapper(defaultOpen={defaultOpen}onOpenChange={onOpenChange}delayDuration={delayDuration}+ disableHoverableContent={disableHoverableContent}><TooltipPrimitive.Trigger asChild>{children}</TooltipPrimitive.Trigger>diff --git a/packages/design-system/src/index.ts b/packages/design-system/src/index.tsindex 48ad0f4b6e..da3c190777 100644--- a/packages/design-system/src/index.ts+++ b/packages/design-system/src/index.ts@@ -60,3 +60,4 @@ export * from "./components/combobox";export * from "./components/checkbox";export * from "./components/avatar";export * from "./components/comboicon";+export * from "./components/primitives/numeric-gesture-control";