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
Floating panel refactor & new Popover & MenuItemButton (#902)
Roman Pominov4ad1a3f4b24f
diff --git a/.lostpixel/baseline/library-menu-menu-item--menu-menu-item.png b/.lostpixel/baseline/library-menu-menu-item--menu-menu-item.pngindex 35695b4e96..9400851c19 100644Binary files a/.lostpixel/baseline/library-menu-menu-item--menu-menu-item.png and b/.lostpixel/baseline/library-menu-menu-item--menu-menu-item.png differdiff --git a/.lostpixel/baseline/library-popover--popover.png b/.lostpixel/baseline/library-popover--popover.pngnew file mode 100644index 0000000000..fe536eb135Binary files /dev/null and b/.lostpixel/baseline/library-popover--popover.png differdiff --git a/apps/designer/app/designer/features/style-panel/sections/space/input-popover.tsx b/apps/designer/app/designer/features/style-panel/sections/space/input-popover.tsxindex f9aa30094d..4d05ad4e52 100644--- a/apps/designer/app/designer/features/style-panel/sections/space/input-popover.tsx+++ b/apps/designer/app/designer/features/style-panel/sections/space/input-popover.tsx@@ -1,10 +1,10 @@import { type ComponentProps, useState } from "react";import {keyframes,- Popover,- PopoverTrigger,- PopoverContent,- PopoverPortal,+ DeprecatedPopover,+ DeprecatedPopoverTrigger,+ DeprecatedPopoverContent,+ DeprecatedPopoverPortal,styled,} from "@webstudio-is/design-system";import { StyleUpdate } from "@webstudio-is/project";@@ -89,7 +89,7 @@ const Input = ({// trigger is used only for positioningconst Trigger = styled("div", { position: "absolute", width: 0, height: 0 });-const PopoverContentStyled = styled(PopoverContent, {+const PopoverContentStyled = styled(DeprecatedPopoverContent, {minWidth: 0,minHeight: 0,width: theme.spacing[20],@@ -119,7 +119,7 @@ export const InputPopover = ({onClose: () => void;}) => {return (- <Popover+ <DeprecatedPopoveropen={isOpen}onOpenChange={(nextOpen) => {if (nextOpen === false) {@@ -127,10 +127,10 @@ export const InputPopover = ({}}}>- <PopoverTrigger asChild>+ <DeprecatedPopoverTrigger asChild><Trigger />- </PopoverTrigger>- <PopoverPortal>+ </DeprecatedPopoverTrigger>+ <DeprecatedPopoverPortal><PopoverContentStyled hideArrow sideOffset={-24}><InputstyleSource={styleSource}@@ -140,7 +140,7 @@ export const InputPopover = ({onClosePopover={onClose}/></PopoverContentStyled>- </PopoverPortal>- </Popover>+ </DeprecatedPopoverPortal>+ </DeprecatedPopover>);};diff --git a/apps/designer/app/designer/features/style-panel/shared/color-picker.tsx b/apps/designer/app/designer/features/style-panel/shared/color-picker.tsxindex e71f6d05ce..f8179174ff 100644--- a/apps/designer/app/designer/features/style-panel/shared/color-picker.tsx+++ b/apps/designer/app/designer/features/style-panel/shared/color-picker.tsx@@ -5,10 +5,10 @@ import type { RgbValue } from "@webstudio-is/css-data";import {Box,- Popover,- PopoverTrigger,- PopoverContent,- PopoverPortal,+ DeprecatedPopover,+ DeprecatedPopoverTrigger,+ DeprecatedPopoverContent,+ DeprecatedPopoverPortal,TextField,css,} from "@webstudio-is/design-system";@@ -121,12 +121,12 @@ export const ColorPicker = ({const rgbValue = intermediateValue?.rgbValue ?? rgbValueToRgbColor(value);const prefix = (- <Popover+ <DeprecatedPopovermodalopen={displayColorPicker}onOpenChange={setDisplayColorPicker}>- <PopoverTrigger+ <DeprecatedPopoverTriggerasChildaria-label="Open color picker"onClick={() => setDisplayColorPicker((shown) => !shown)}@@ -140,9 +140,9 @@ export const ColorPicker = ({background: toValue(value),}}/>- </PopoverTrigger>- <PopoverPortal>- <PopoverContent>+ </DeprecatedPopoverTrigger>+ <DeprecatedPopoverPortal>+ <DeprecatedPopoverContent><SketchPickercolor={rgbValue}onChange={(color: ColorResult) => {@@ -162,9 +162,9 @@ export const ColorPicker = ({className={pickerStyle()}styles={defaultPickerStyles}/>- </PopoverContent>- </PopoverPortal>- </Popover>+ </DeprecatedPopoverContent>+ </DeprecatedPopoverPortal>+ </DeprecatedPopover>);return (diff --git a/apps/designer/app/designer/features/style-panel/shared/property-name.tsx b/apps/designer/app/designer/features/style-panel/shared/property-name.tsxindex d7c7031225..1c57288a08 100644--- a/apps/designer/app/designer/features/style-panel/shared/property-name.tsx+++ b/apps/designer/app/designer/features/style-panel/shared/property-name.tsx@@ -10,10 +10,10 @@ import {Text,Label,Tooltip,- Popover,- PopoverContent,- PopoverPortal,- PopoverTrigger,+ DeprecatedPopover,+ DeprecatedPopoverContent,+ DeprecatedPopoverPortal,+ DeprecatedPopoverTrigger,Separator,} from "@webstudio-is/design-system";import { UndoIcon } from "@webstudio-is/icons";@@ -150,21 +150,27 @@ export const PropertyName = ({if (isPopoverEnabled) {return (<Flex align="center">- <Popover modal open={isOpen} onOpenChange={setIsOpen}>- <PopoverTrigger asChild aria-label="Show proprety description">+ <DeprecatedPopover modal open={isOpen} onOpenChange={setIsOpen}>+ <DeprecatedPopoverTrigger+ asChild+ aria-label="Show proprety description"+ >{labelElement}- </PopoverTrigger>- <PopoverPortal>- <PopoverContent align="start" onClick={() => setIsOpen(false)}>+ </DeprecatedPopoverTrigger>+ <DeprecatedPopoverPortal>+ <DeprecatedPopoverContent+ align="start"+ onClick={() => setIsOpen(false)}+ ><PropertyPopoverContentproperties={properties}style={style}styleSource={styleSource}onReset={onReset}/>- </PopoverContent>- </PopoverPortal>- </Popover>+ </DeprecatedPopoverContent>+ </DeprecatedPopoverPortal>+ </DeprecatedPopover></Flex>);}diff --git a/apps/designer/app/designer/features/topbar/publish.tsx b/apps/designer/app/designer/features/topbar/publish.tsxindex aec7673908..7616fafdf3 100644--- a/apps/designer/app/designer/features/topbar/publish.tsx+++ b/apps/designer/app/designer/features/topbar/publish.tsx@@ -8,10 +8,10 @@ import {Flex,DeprecatedLabel,Link,- Popover,- PopoverContent,- PopoverPortal,- PopoverTrigger,+ DeprecatedPopover,+ DeprecatedPopoverTrigger,+ DeprecatedPopoverContent,+ DeprecatedPopoverPortal,TextField,useId,} from "@webstudio-is/design-system";@@ -32,7 +32,7 @@ const Content = ({ project }: PublishButtonProps) => {}, [domain]);return (- <PopoverContent+ <DeprecatedPopoverContentcss={{ padding: theme.spacing[9] }}hideArrow={true}onFocusOutside={(event) => {@@ -71,15 +71,15 @@ const Content = ({ project }: PublishButtonProps) => {</Button></Flex></fetcher.Form>- </PopoverContent>+ </DeprecatedPopoverContent>);};export const PublishButton = ({ project }: PublishButtonProps) => {const [isOpen, setIsOpen] = useIsPublishDialogOpen();return (- <Popover open={isOpen} onOpenChange={setIsOpen}>- <PopoverTrigger asChild aria-label="Publish">+ <DeprecatedPopover open={isOpen} onOpenChange={setIsOpen}>+ <DeprecatedPopoverTrigger asChild aria-label="Publish"><DeprecatedButtonghostcss={{ display: "flex", gap: theme.spacing[3] }}@@ -87,10 +87,10 @@ export const PublishButton = ({ project }: PublishButtonProps) => {<RocketIcon /><Text>Publish</Text></DeprecatedButton>- </PopoverTrigger>- <PopoverPortal>+ </DeprecatedPopoverTrigger>+ <DeprecatedPopoverPortal><Content project={project} />- </PopoverPortal>- </Popover>+ </DeprecatedPopoverPortal>+ </DeprecatedPopover>);};diff --git a/apps/designer/app/designer/features/topbar/share.tsx b/apps/designer/app/designer/features/topbar/share.tsxindex b1c967c5b1..136d0ec293 100644--- a/apps/designer/app/designer/features/topbar/share.tsx+++ b/apps/designer/app/designer/features/topbar/share.tsx@@ -1,10 +1,10 @@import {Button,DeprecatedIconButton,- Popover,- PopoverContent,- PopoverPortal,- PopoverTrigger,+ DeprecatedPopover,+ DeprecatedPopoverTrigger,+ DeprecatedPopoverContent,+ DeprecatedPopoverPortal,} from "@webstudio-is/design-system";import { Share1Icon } from "@webstudio-is/icons";import { useIsShareDialogOpen } from "../../shared/nano-states";@@ -24,7 +24,7 @@ const Content = ({ url }: ShareButtonDeprecatedProps) => {return null;}return (- <PopoverContent+ <DeprecatedPopoverContentcss={{ padding: theme.spacing[9] }}hideArrow={true}onFocusOutside={(event) => {@@ -33,23 +33,23 @@ const Content = ({ url }: ShareButtonDeprecatedProps) => {}}><ShareProjectDeprecated url={url} />- </PopoverContent>+ </DeprecatedPopoverContent>);};export const ShareButtonDeprecated = (props: ShareButtonDeprecatedProps) => {const [isOpen, setIsOpen] = useIsShareDialogOpen();return (- <Popover open={isOpen} onOpenChange={setIsOpen}>- <PopoverTrigger asChild aria-label="Share project">+ <DeprecatedPopover open={isOpen} onOpenChange={setIsOpen}>+ <DeprecatedPopoverTrigger asChild aria-label="Share project"><DeprecatedIconButton><Share1Icon /></DeprecatedIconButton>- </PopoverTrigger>- <PopoverPortal>+ </DeprecatedPopoverTrigger>+ <DeprecatedPopoverPortal><Content {...props} />- </PopoverPortal>- </Popover>+ </DeprecatedPopoverPortal>+ </DeprecatedPopover>);};diff --git a/apps/designer/app/designer/shared/floating-panel/floating-panel.tsx b/apps/designer/app/designer/shared/floating-panel/floating-panel.tsxindex 86a024895f..c15e68a24d 100644--- a/apps/designer/app/designer/shared/floating-panel/floating-panel.tsx+++ b/apps/designer/app/designer/shared/floating-panel/floating-panel.tsx@@ -1,7 +1,10 @@import {- FloatingPanelPopover as Popover,+ FloatingPanelPopover,theme,css,+ FloatingPanelPopoverTrigger,+ FloatingPanelPopoverContent,+ FloatingPanelPopoverTitle,} from "@webstudio-is/design-system";import {MutableRefObject,@@ -67,8 +70,8 @@ export const FloatingPanel = ({const { isOpen, handleOpenChange, triggerRef, sideOffset } =useLogic(onOpenChange);return (- <Popover.Root open={isOpen} onOpenChange={handleOpenChange} modal>- <Popover.Trigger+ <FloatingPanelPopover open={isOpen} onOpenChange={handleOpenChange} modal>+ <FloatingPanelPopoverTriggerasChildref={triggerRef}onClick={() => {@@ -76,16 +79,16 @@ export const FloatingPanel = ({}}>{children}- </Popover.Trigger>- <Popover.Content+ </FloatingPanelPopoverTrigger>+ <FloatingPanelPopoverContentsideOffset={sideOffset}side="left"align="start"className={contetnStyles()}>{content}- <Popover.Title>{title}</Popover.Title>- </Popover.Content>- </Popover.Root>+ <FloatingPanelPopoverTitle>{title}</FloatingPanelPopoverTitle>+ </FloatingPanelPopoverContent>+ </FloatingPanelPopover>);};diff --git a/apps/designer/app/designer/shared/image-manager/image-info-tigger.tsx b/apps/designer/app/designer/shared/image-manager/image-info-tigger.tsxindex 025f88a2d8..d53dc788d7 100644--- a/apps/designer/app/designer/shared/image-manager/image-info-tigger.tsx+++ b/apps/designer/app/designer/shared/image-manager/image-info-tigger.tsx@@ -1,11 +1,11 @@import { useState } from "react";import {DeprecatedButton,- Popover,- PopoverContent,- PopoverPortal,- PopoverTrigger,- PopoverHeader,+ DeprecatedPopover,+ DeprecatedPopoverTrigger,+ DeprecatedPopoverContent,+ DeprecatedPopoverPortal,+ DeprecatedPopoverHeader,} from "@webstudio-is/design-system";import { GearIcon, gearIconCssVars } from "@webstudio-is/icons";import { ImageInfo } from "./image-info";@@ -28,8 +28,8 @@ export const ImageInfoTrigger = ({}) => {const [isInfoOpen, setInfoOpen] = useState(false);return (- <Popover open={isInfoOpen} onOpenChange={setInfoOpen}>- <PopoverTrigger asChild>+ <DeprecatedPopover open={isInfoOpen} onOpenChange={setInfoOpen}>+ <DeprecatedPopoverTrigger asChild><DeprecatedButtonvariant="raw"title="Options"@@ -50,10 +50,10 @@ export const ImageInfoTrigger = ({><GearIcon /></DeprecatedButton>- </PopoverTrigger>- <PopoverPortal>- <PopoverContent css={{ zIndex: theme.zIndices[1] }}>- <PopoverHeader title="Asset Details" />+ </DeprecatedPopoverTrigger>+ <DeprecatedPopoverPortal>+ <DeprecatedPopoverContent css={{ zIndex: theme.zIndices[1] }}>+ <DeprecatedPopoverHeader title="Asset Details" /><ImageInfoonDelete={(ids) => {setInfoOpen(false);@@ -61,8 +61,8 @@ export const ImageInfoTrigger = ({}}asset={asset}/>- </PopoverContent>- </PopoverPortal>- </Popover>+ </DeprecatedPopoverContent>+ </DeprecatedPopoverPortal>+ </DeprecatedPopover>);};diff --git a/apps/designer/app/shared/share-project/share-project2.tsx b/apps/designer/app/shared/share-project/share-project2.tsxindex 7b4eb1dd49..dd46c9abab 100644--- a/apps/designer/app/shared/share-project/share-project2.tsx+++ b/apps/designer/app/shared/share-project/share-project2.tsx@@ -4,11 +4,11 @@ import {css,Flex,Label,- Popover,- PopoverContent,- PopoverHeader,- PopoverPortal,- PopoverTrigger,+ DeprecatedPopover,+ DeprecatedPopoverTrigger,+ DeprecatedPopoverContent,+ DeprecatedPopoverPortal,+ DeprecatedPopoverHeader,rawTheme,Separator,Switch,@@ -77,15 +77,15 @@ const Menu = ({};return (- <Popover>- <PopoverTrigger asChild>+ <DeprecatedPopover>+ <DeprecatedPopoverTrigger asChild><Buttonprefix={<MenuIcon />}color="ghost"aria-label="Menu Button for options"></Button>- </PopoverTrigger>- <PopoverContent>+ </DeprecatedPopoverTrigger>+ <DeprecatedPopoverContent><Item><Label>Name</Label><TextField@@ -131,8 +131,8 @@ const Menu = ({Delete Link</Button></Item>- </PopoverContent>- </Popover>+ </DeprecatedPopoverContent>+ </DeprecatedPopover>);};@@ -242,10 +242,10 @@ export const ShareProject = ({// @todo this should use FloatingPanel instead of Popover, which we need to refactor firstreturn (- <Popover modal open={isOpen} onOpenChange={onOpenChange}>- <PopoverTrigger asChild>{children}</PopoverTrigger>- <PopoverPortal>- <PopoverContent hideArrow>+ <DeprecatedPopover modal open={isOpen} onOpenChange={onOpenChange}>+ <DeprecatedPopoverTrigger asChild>{children}</DeprecatedPopoverTrigger>+ <DeprecatedPopoverPortal>+ <DeprecatedPopoverContent hideArrow><Flexdirection="column"css={{@@ -255,9 +255,9 @@ export const ShareProject = ({{items}{create}</Flex>- <PopoverHeader title="Share" />- </PopoverContent>- </PopoverPortal>- </Popover>+ <DeprecatedPopoverHeader title="Share" />+ </DeprecatedPopoverContent>+ </DeprecatedPopoverPortal>+ </DeprecatedPopover>);};diff --git a/packages/design-system/src/components/__DEPRECATED__/popover.tsx b/packages/design-system/src/components/__DEPRECATED__/popover.tsxnew file mode 100644index 0000000000..db723f38b4--- /dev/null+++ b/packages/design-system/src/components/__DEPRECATED__/popover.tsx@@ -0,0 +1,99 @@+import React from "react";+import { CrossLargeIcon } from "@webstudio-is/icons";+import * as PopoverPrimitive from "@radix-ui/react-popover";+import { Box } from "../box";+import { panelStyles } from "../panel";+import { Flex } from "../flex";+import { DeprecatedIconButton } from "./icon-button";+import { Text } from "../text";+import { Separator } from "../separator";+import { styled, CSS } from "../../stitches.config";+import { theme } from "../../stitches.config";++type PopoverProps = React.ComponentProps<typeof PopoverPrimitive.Root> & {+ children: React.ReactNode;+};++export const DeprecatedPopover = ({ children, ...props }: PopoverProps) => {+ return <PopoverPrimitive.Root {...props}>{children}</PopoverPrimitive.Root>;+};++const StyledContent = styled(PopoverPrimitive.Content, panelStyles, {+ backgroundColor: "white",+ minWidth: 200,+ minHeight: theme.spacing[13],+ maxWidth: "max-content",+ "&:focus": {+ outline: "none",+ },+ display: "flex",+ flexDirection: "column",+});++type PopoverContentPrimitiveProps = React.ComponentProps<+ typeof PopoverPrimitive.Content+>;++type PopoverContentProps = PopoverContentPrimitiveProps & {+ css?: CSS;+ hideArrow?: boolean;+};++export const DeprecatedPopoverContent = React.forwardRef<+ React.ElementRef<typeof StyledContent>,+ PopoverContentProps+>(({ children, hideArrow, ...props }, fowardedRef) => (+ <StyledContent+ sideOffset={4}+ collisionPadding={4}+ {...props}+ ref={fowardedRef}+ >+ {children}+ {!hideArrow && (+ <Box css={{ color: theme.colors.panel }}>+ <PopoverPrimitive.Arrow+ width={11}+ height={5}+ offset={5}+ style={{ fill: "currentColor" }}+ />+ </Box>+ )}+ </StyledContent>+));+DeprecatedPopoverContent.displayName = "PopoverContent";++type PopoverHeaderProps = {+ title: string;+};++export const DeprecatedPopoverHeader = ({ title }: PopoverHeaderProps) => {+ return (+ <Box css={{ order: -1 }}>+ <Flex+ css={{ height: 40, paddingLeft: theme.spacing[9] }}+ align="center"+ justify="between"+ >+ <Text variant="title">{title}</Text>+ <DeprecatedPopoverClose asChild>+ <DeprecatedIconButton+ size="2"+ css={{+ marginRight: theme.spacing[5],+ }}+ aria-label="Close"+ >+ <CrossLargeIcon />+ </DeprecatedIconButton>+ </DeprecatedPopoverClose>+ </Flex>+ <Separator />+ </Box>+ );+};++export const DeprecatedPopoverTrigger = PopoverPrimitive.Trigger;+export const DeprecatedPopoverClose = PopoverPrimitive.Close;+export const DeprecatedPopoverPortal = PopoverPrimitive.Portal;diff --git a/packages/design-system/src/components/button.tsx b/packages/design-system/src/components/button.tsxindex 4c5834572d..3b29f3f7ad 100644--- a/packages/design-system/src/components/button.tsx+++ b/packages/design-system/src/components/button.tsx@@ -24,7 +24,7 @@ type ButtonColor = typeof colors[number];type ButtonState = "auto" | "hover" | "focus" | "pressed" | "pending";-const bg: Record<ButtonColor, string> = {+const backgrounds: Record<ButtonColor, string> = {primary: theme.colors.backgroundPrimary,neutral: theme.colors.backgroundNeutralMain,destructive: theme.colors.backgroundDestructiveMain,@@ -32,7 +32,7 @@ const bg: Record<ButtonColor, string> = {ghost: theme.colors.backgroundHover,};-const fg: Record<ButtonColor, string> = {+const foregrounds: Record<ButtonColor, string> = {primary: theme.colors.foregroundContrastMain,destructive: theme.colors.foregroundContrastMain,positive: theme.colors.foregroundContrastMain,@@ -45,12 +45,12 @@ const backgroundColors = (base: string, overlay: string) =>`linear-gradient(${overlay}, ${overlay}), linear-gradient(${base}, ${base})`;const perColorStyle = (variant: ButtonColor) => ({- background: variant === "ghost" ? "transparent" : bg[variant],- color: fg[variant],+ background: variant === "ghost" ? "transparent" : backgrounds[variant],+ color: foregrounds[variant],"&[data-button-state=auto]:hover, &[data-button-state=hover]": {background: backgroundColors(- bg[variant],+ backgrounds[variant],theme.colors.backgroundButtonHover),},@@ -62,7 +62,7 @@ const perColorStyle = (variant: ButtonColor) => ({"&[data-button-state=auto]:active, &[data-button-state=pressed]": {background: backgroundColors(- bg[variant],+ backgrounds[variant],theme.colors.backgroundButtonPressed),},diff --git a/packages/design-system/src/components/floating-panel/dialog.stories.tsx b/packages/design-system/src/components/dialog.stories.tsxsimilarity index 57%rename from packages/design-system/src/components/floating-panel/dialog.stories.tsxrename to packages/design-system/src/components/dialog.stories.tsxindex 2b974aefff..94c1c2e5fb 100644--- a/packages/design-system/src/components/floating-panel/dialog.stories.tsx+++ b/packages/design-system/src/components/dialog.stories.tsx@@ -1,7 +1,14 @@-import { Button } from "../button";-import { css, theme } from "../../stitches.config";-import { typography } from "../typography";-import * as Dialog from "./dialog";+import { Button } from "./button";+import { css, theme } from "../stitches.config";+import { typography } from "./typography";+import {+ Dialog,+ DialogClose,+ DialogContent,+ DialogDescription,+ DialogTitle,+ DialogTrigger,+} from "./dialog";export default {title: "Library/Floating Panel/Dialog",@@ -23,30 +30,30 @@ const buttonsStyle = css({});const DialogDemo = () => (- <Dialog.Root defaultOpen>- <Dialog.Trigger asChild>+ <Dialog defaultOpen>+ <DialogTrigger asChild><Button>Open</Button>- </Dialog.Trigger>- <Dialog.Content>+ </DialogTrigger>+ <DialogContent><div className={bodyStyles()}>- <Dialog.Description asChild>+ <DialogDescription asChild><p className={descriptionStyles()}>This is a description</p>- </Dialog.Description>+ </DialogDescription><div className={buttonsStyle()}>- <Dialog.Close asChild>+ <DialogClose asChild><Button color="ghost">Cancel</Button>- </Dialog.Close>- <Dialog.Close asChild>+ </DialogClose>+ <DialogClose asChild><Button color="positive">Save</Button>- </Dialog.Close>+ </DialogClose></div></div>{/* Title is at the end intentionally,* to make the close button last in the tab order*/}- <Dialog.Title>Title</Dialog.Title>- </Dialog.Content>- </Dialog.Root>+ <DialogTitle>Title</DialogTitle>+ </DialogContent>+ </Dialog>);export { DialogDemo as Dialog };diff --git a/packages/design-system/src/components/floating-panel/dialog.tsx b/packages/design-system/src/components/dialog.tsxsimilarity index 81%rename from packages/design-system/src/components/floating-panel/dialog.tsxrename to packages/design-system/src/components/dialog.tsxindex 90e23c83b6..167985bac5 100644--- a/packages/design-system/src/components/floating-panel/dialog.tsx+++ b/packages/design-system/src/components/dialog.tsx@@ -1,21 +1,21 @@import React, { type ReactNode, type ComponentProps, type Ref } from "react";import * as Primitive from "@radix-ui/react-dialog";-import { css, theme, keyframes } from "../../stitches.config";-import { Title } from "../title";-import { floatingPanelStyles, CloseButton, TitleSlot } from "./shared";+import { css, theme, keyframes } from "../stitches.config";+import { Title } from "./title";+import { floatingPanelStyles, CloseButton, TitleSlot } from "./floating-panel";-export const Root = Primitive.Root;-export const Trigger = Primitive.Trigger;+export const Dialog = Primitive.Root;+export const DialogTrigger = Primitive.Trigger;// Wrap a close button with this// https://www.radix-ui.com/docs/primitives/components/dialog#close-export const Close = Primitive.Close;+export const DialogClose = Primitive.Close;// An optional accessible description to be announced when the dialog is opened// https://www.radix-ui.com/docs/primitives/components/dialog#description-export const Description = Primitive.Description;+export const DialogDescription = Primitive.Description;-export const Content = React.forwardRef(+export const DialogContent = React.forwardRef(({ children, className, ...props }: ComponentProps<typeof Primitive.Content>,forwardedRef: Ref<HTMLDivElement>@@ -34,9 +34,9 @@ export const Content = React.forwardRef();});-Content.displayName = "Content";+DialogContent.displayName = "DialogContent";-const ContentTitle = ({+export const DialogTitle = ({children,closeLabel = "Close dialog",}: {@@ -55,7 +55,6 @@ const ContentTitle = ({</Title></TitleSlot>);-export { ContentTitle as Title };// Styles specific to dialog// (as opposed to be common for all floating panels)diff --git a/packages/design-system/src/components/floating-panel/popover.stories.tsx b/packages/design-system/src/components/floating-panel-popover.stories.tsxsimilarity index 51%rename from packages/design-system/src/components/floating-panel/popover.stories.tsxrename to packages/design-system/src/components/floating-panel-popover.stories.tsxindex 10b88e0778..3397d8ba19 100644--- a/packages/design-system/src/components/floating-panel/popover.stories.tsx+++ b/packages/design-system/src/components/floating-panel-popover.stories.tsx@@ -1,7 +1,13 @@-import { Button } from "../button";-import { css, theme } from "../../stitches.config";-import { typography } from "../typography";-import * as Popover from "./popover";+import { Button } from "./button";+import { css, theme } from "../stitches.config";+import { typography } from "./typography";+import {+ FloatingPanelPopover,+ FloatingPanelPopoverClose,+ FloatingPanelPopoverContent,+ FloatingPanelPopoverTitle,+ FloatingPanelPopoverTrigger,+} from "./floating-panel-popover";export default {title: "Library/Floating Panel/Popover",@@ -23,28 +29,28 @@ const buttonsStyle = css({});const PopoverDemo = () => (- <Popover.Root defaultOpen>- <Popover.Trigger asChild>+ <FloatingPanelPopover defaultOpen>+ <FloatingPanelPopoverTrigger asChild><Button>Open</Button>- </Popover.Trigger>- <Popover.Content>+ </FloatingPanelPopoverTrigger>+ <FloatingPanelPopoverContent><div className={bodyStyles()}><p className={descriptionStyles()}>This is a description</p><div className={buttonsStyle()}>- <Popover.Close asChild>+ <FloatingPanelPopoverClose asChild><Button color="ghost">Cancel</Button>- </Popover.Close>- <Popover.Close asChild>+ </FloatingPanelPopoverClose>+ <FloatingPanelPopoverClose asChild><Button color="positive">Save</Button>- </Popover.Close>+ </FloatingPanelPopoverClose></div></div>{/* Title is at the end intentionally,* to make the close button last in the tab order*/}- <Popover.Title>Title</Popover.Title>- </Popover.Content>- </Popover.Root>+ <FloatingPanelPopoverTitle>Title</FloatingPanelPopoverTitle>+ </FloatingPanelPopoverContent>+ </FloatingPanelPopover>);export { PopoverDemo as Popover };diff --git a/packages/design-system/src/components/floating-panel/popover.tsx b/packages/design-system/src/components/floating-panel-popover.tsxsimilarity index 65%rename from packages/design-system/src/components/floating-panel/popover.tsxrename to packages/design-system/src/components/floating-panel-popover.tsxindex d1a10cab5b..dc882d9830 100644--- a/packages/design-system/src/components/floating-panel/popover.tsx+++ b/packages/design-system/src/components/floating-panel-popover.tsx@@ -1,17 +1,17 @@import React, { type ComponentProps, type Ref, type ReactNode } from "react";import * as Primitive from "@radix-ui/react-popover";-import { css, theme } from "../../stitches.config";-import { Title } from "../title";-import { floatingPanelStyles, CloseButton, TitleSlot } from "./shared";+import { css, theme } from "../stitches.config";+import { Title } from "./title";+import { floatingPanelStyles, CloseButton, TitleSlot } from "./floating-panel";-export const Root = Primitive.Root;+export const FloatingPanelPopover = Primitive.Root;const contentStyles = css(floatingPanelStyles, {minWidth: theme.spacing[28],maxWidth: "max-content",});-export const Content = React.forwardRef(+export const FloatingPanelPopoverContent = React.forwardRef(({ children, className, ...props }: ComponentProps<typeof Primitive.Content>,ref: Ref<HTMLDivElement>@@ -29,9 +29,9 @@ export const Content = React.forwardRef(</Primitive.Portal>));-Content.displayName = "Content";+FloatingPanelPopoverContent.displayName = "FloatingPanelPopoverContent";-const PopoverTitle = ({+export const FloatingPanelPopoverTitle = ({children,closeLabel = "Close dialog",}: {@@ -50,7 +50,6 @@ const PopoverTitle = ({</Title></TitleSlot>);-export { PopoverTitle as Title };-export const Trigger = Primitive.Trigger;-export const Close = Primitive.Close;+export const FloatingPanelPopoverTrigger = Primitive.Trigger;+export const FloatingPanelPopoverClose = Primitive.Close;diff --git a/packages/design-system/src/components/floating-panel/shared.tsx b/packages/design-system/src/components/floating-panel.tsxsimilarity index 76%rename from packages/design-system/src/components/floating-panel/shared.tsxrename to packages/design-system/src/components/floating-panel.tsxindex 6b8b6c19aa..df6daf3ba5 100644--- a/packages/design-system/src/components/floating-panel/shared.tsx+++ b/packages/design-system/src/components/floating-panel.tsx@@ -1,8 +1,13 @@+/**+ * Implementations of the "Floating Panel" component from:+ * https://www.figma.com/file/sfCE7iLS0k25qCxiifQNLE/%F0%9F%93%9A-Webstudio-Library?node-id=4%3A2679&t=6Q0l4j0CBvXkuKYp-0+ */+import { forwardRef, Ref, type ReactNode, type ComponentProps } from "react";import { CrossIcon } from "@webstudio-is/icons";-import { css, theme } from "../../stitches.config";-import { Button } from "../button";-import { Separator } from "../separator";+import { css, theme } from "../stitches.config";+import { Button } from "./button";+import { Separator } from "./separator";export const floatingPanelStyles = css({border: `1px solid ${theme.colors.borderMain}`,diff --git a/packages/design-system/src/components/floating-panel/index.ts b/packages/design-system/src/components/floating-panel/index.tsdeleted file mode 100644index c55484f14d..0000000000--- a/packages/design-system/src/components/floating-panel/index.ts+++ /dev/null@@ -1,7 +0,0 @@-/**- * Implementations of the "Floating Panel" component from:- * https://www.figma.com/file/sfCE7iLS0k25qCxiifQNLE/%F0%9F%93%9A-Webstudio-Library?node-id=4%3A2679&t=6Q0l4j0CBvXkuKYp-0- */--export * as FloatingPanelDialog from "./dialog";-export * as FloatingPanelPopover from "./popover";diff --git a/packages/design-system/src/components/menu.tsx b/packages/design-system/src/components/menu.tsxindex 42e7d39269..9628d490c0 100644--- a/packages/design-system/src/components/menu.tsx+++ b/packages/design-system/src/components/menu.tsx@@ -41,6 +41,7 @@ export const itemIndicatorCss = css({height: indicatorSize,});+const itemMargin = theme.spacing[3];export const itemCss = css(typography.labelTitleCase, {outline: "none",cursor: "default",@@ -48,13 +49,13 @@ export const itemCss = css(typography.labelTitleCase, {display: "flex",alignItems: "center",color: theme.colors.foregroundMain,- mx: theme.spacing[3],+ mx: itemMargin,padding: theme.spacing[3],borderRadius: theme.borderRadius[3],"&:focus, &[data-found], &[aria-selected=true], &[data-state=open]": {backgroundColor: theme.colors.backgroundItemMenuItemHover,},- "&[data-disabled], &[aria-disabled]": {+ "&[data-disabled], &[aria-disabled], &[disabled]": {color: theme.colors.foregroundDisabled,},variants: {@@ -71,6 +72,17 @@ export const itemCss = css(typography.labelTitleCase, {},});+// To use outside of any menu context, e.g. in a Popover+export const MenuItemButton = styled("button", itemCss, {+ border: "none",+ boxSizing: "border-box",+ width: `calc(100% - ${itemMargin} * 2)`,+ "&:focus:not(:focus-visible)": { backgroundColor: "unset" },+ "&:hover:not([diabled])": {+ backgroundColor: theme.colors.backgroundItemMenuItemHover,+ },+});+export const separatorCss = css({height: 1,my: theme.spacing[3],@@ -82,18 +94,11 @@ const menuBorderWidth = "1px";export const menuCss = css({boxSizing: "border-box",-borderRadius: theme.borderRadius[6],backgroundColor: theme.colors.backgroundMenu,-- // in Figma there are 2 borders on two rectangles,- // but we have only one element to work with,- // so we implement borders using shadows- boxShadow: `${theme.shadows.menuDropShadow}, inset 0 0 0 1px ${theme.colors.borderMain}, inset 0 0 0 2px ${theme.colors.borderMenuInner}`,-- // extra 1px padding to account for one of the shadow-borders above- padding: `calc(${menuBorderWidth} + ${menuPadding}) ${menuBorderWidth}`,-+ border: `1px solid ${theme.colors.borderMain}`,+ boxShadow: `${theme.shadows.menuDropShadow}, inset 0 0 0 1px ${theme.colors.borderMenuInner}`,+ padding: `${menuPadding} 0`,variants: {width: {regular: { width: theme.spacing[26] },diff --git a/packages/design-system/src/components/popover.stories.tsx b/packages/design-system/src/components/popover.stories.tsxnew file mode 100644index 0000000000..d8874b1962--- /dev/null+++ b/packages/design-system/src/components/popover.stories.tsx@@ -0,0 +1,36 @@+import { Button } from "./button";+import { typography } from "./typography";+import {+ Popover,+ PopoverClose,+ PopoverContent,+ PopoverTrigger,+ PopoverContentContainer,+ PopoverMenuItemContainer,+ PopoverSeparator,+} from "./popover";+import { MenuItemButton } from "./menu";++export default {+ title: "Library/Popover",+};++const PopoverDemo = () => (+ <Popover defaultOpen>+ <PopoverTrigger asChild>+ <Button>Open</Button>+ </PopoverTrigger>+ <PopoverContent>+ <PopoverContentContainer>+ <div className={typography.regular()}>Some content</div>+ </PopoverContentContainer>+ <PopoverSeparator />+ <PopoverMenuItemContainer>+ <PopoverClose asChild>+ <MenuItemButton>Close</MenuItemButton>+ </PopoverClose>+ </PopoverMenuItemContainer>+ </PopoverContent>+ </Popover>+);+export { PopoverDemo as Popover };diff --git a/packages/design-system/src/components/popover.tsx b/packages/design-system/src/components/popover.tsxindex 99bff4c44d..2e596f1534 100644--- a/packages/design-system/src/components/popover.tsx+++ b/packages/design-system/src/components/popover.tsx@@ -1,99 +1,76 @@-import React from "react";-import { CrossLargeIcon } from "@webstudio-is/icons";-import * as PopoverPrimitive from "@radix-ui/react-popover";-import { Box } from "./box";-import { panelStyles } from "./panel";-import { Flex } from "./flex";-import { DeprecatedIconButton } from "./__DEPRECATED__/icon-button";-import { Text } from "./text";+import React, { type ComponentProps, type Ref } from "react";+import * as Primitive from "@radix-ui/react-popover";+import { css, theme, styled } from "../stitches.config";import { Separator } from "./separator";-import { styled, CSS } from "../stitches.config";-import { theme } from "../stitches.config";-type PopoverProps = React.ComponentProps<typeof PopoverPrimitive.Root> & {- children: React.ReactNode;-};+export const Popover = Primitive.Root;-export const Popover = ({ children, ...props }: PopoverProps) => {- return <PopoverPrimitive.Root {...props}>{children}</PopoverPrimitive.Root>;-};--const StyledContent = styled(PopoverPrimitive.Content, panelStyles, {- backgroundColor: "white",- minWidth: 200,- minHeight: theme.spacing[13],+const contentStyles = css({+ border: `1px solid ${theme.colors.borderMain}`,+ boxShadow: `${theme.shadows.menuDropShadow}, inset 0 0 0 1px ${theme.colors.borderMenuInner}`,+ background: theme.colors.backgroundMenu,+ borderRadius: theme.borderRadius[6],+ padding: `${theme.spacing[5]} 0`,+ display: "flex",+ flexDirection: "column",maxWidth: "max-content","&:focus": {+ // override browser defaultoutline: "none",},- display: "flex",- flexDirection: "column",});-type PopoverContentPrimitiveProps = React.ComponentProps<- typeof PopoverPrimitive.Content->;--type PopoverContentProps = PopoverContentPrimitiveProps & {- css?: CSS;- hideArrow?: boolean;-};+const ArrowBackground = styled("path", { fill: theme.colors.backgroundMenu });+const ArrowInnerBorder = styled("path", { fill: theme.colors.borderMenuInner });+const ArrowOuterBorder = styled("path", { fill: theme.colors.borderMain });+const ArrowSgv = styled("svg", { transform: "translateY(-3px)" });+const Arrow = () => (+ <Primitive.Arrow width={16} height={11} asChild>+ <ArrowSgv xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 11">+ <ArrowOuterBorder d="M8.73 9.76a1 1 0 0 1-1.46 0L.5 2.54h15L8.73 9.76Z" />+ <ArrowInnerBorder d="M8.146 8.909a.2.2 0 0 1-.292 0L.5 1.065h15L8.146 8.909Z" />+ <ArrowBackground d="M8.073 7.52a.1.1 0 0 1-.146 0L.877 0h14.246l-7.05 7.52Z" />+ </ArrowSgv>+ </Primitive.Arrow>+);-export const PopoverContent = React.forwardRef<- React.ElementRef<typeof StyledContent>,- PopoverContentProps->(({ children, hideArrow, ...props }, fowardedRef) => (- <StyledContent- sideOffset={4}- collisionPadding={4}- {...props}- ref={fowardedRef}- >- {children}- {!hideArrow && (- <Box css={{ color: theme.colors.panel }}>- <PopoverPrimitive.Arrow- width={11}- height={5}- offset={5}- style={{ fill: "currentColor" }}- />- </Box>- )}- </StyledContent>-));+export const PopoverContent = React.forwardRef(+ (+ {+ children,+ className,+ hideArrow,+ ...props+ }: ComponentProps<typeof Primitive.Content> & { hideArrow?: boolean },+ ref: Ref<HTMLDivElement>+ ) => (+ <Primitive.Portal>+ <Primitive.Content+ sideOffset={4}+ collisionPadding={4}+ className={contentStyles({ className })}+ {...props}+ ref={ref}+ >+ {children}+ {hideArrow !== true && <Arrow />}+ </Primitive.Content>+ </Primitive.Portal>+ )+);PopoverContent.displayName = "PopoverContent";-type PopoverHeaderProps = {- title: string;-};+export const PopoverTrigger = Primitive.Trigger;+export const PopoverClose = Primitive.Close;-export const PopoverHeader = ({ title }: PopoverHeaderProps) => {- return (- <Box css={{ order: -1 }}>- <Flex- css={{ height: 40, paddingLeft: theme.spacing[9] }}- align="center"- justify="between"- >- <Text variant="title">{title}</Text>- <PopoverClose asChild>- <DeprecatedIconButton- size="2"- css={{- marginRight: theme.spacing[5],- }}- aria-label="Close"- >- <CrossLargeIcon />- </DeprecatedIconButton>- </PopoverClose>- </Flex>- <Separator />- </Box>- );-};+export const PopoverContentContainer = styled("div", {+ margin: `0 ${theme.spacing[7]}`,+});-export const PopoverTrigger = PopoverPrimitive.Trigger;-export const PopoverClose = PopoverPrimitive.Close;-export const PopoverPortal = PopoverPrimitive.Portal;+export const PopoverMenuItemContainer = styled("div", {+ margin: `0 ${theme.spacing[3]}`,+});++export const PopoverSeparator = styled(Separator, {+ margin: `${theme.spacing[5]} 0`,+});diff --git a/packages/design-system/src/index.ts b/packages/design-system/src/index.tsindex e69d2c5996..377caefc0d 100644--- a/packages/design-system/src/index.ts+++ b/packages/design-system/src/index.ts@@ -11,8 +11,10 @@ export * from "./components/label";export * from "./components/select"; // menu is aligned, but trigger is notexport * from "./components/combobox";export * from "./components/dropdown-menu";-export * from "./components/floating-panel";export * from "./components/icon-button"; // mostly aligned, but needs a demo and to use tokens+export * from "./components/dialog";+export * from "./components/floating-panel-popover";+export { MenuItemButton } from "./components/menu";// Not aligned@@ -51,7 +53,6 @@ export * from "./components/icon-button-with-menu";export * from "./components/tree";export * from "./components/text";export * from "./components/list";-export * from "./components/popover";// No need to align@@ -70,3 +71,4 @@ export { DeprecatedButton } from "./components/__DEPRECATED__/button";export { DeprecatedIconButton } from "./components/__DEPRECATED__/icon-button";export { DeprecatedHeading } from "./components/__DEPRECATED__/heading";export { DeprecatedLabel } from "./components/__DEPRECATED__/label";+export * from "./components/__DEPRECATED__/popover";