Migrate Popover and Guide components from reakit/Dialog to Radix UI

- Replace reakit/Dialog imports with @radix-ui/react-dialog and @radix-ui/react-popover
- Update Popover component to use Radix Popover for desktop and Dialog for mobile
- Migrate Guide component to use Radix Dialog with proper overlay and content structure
- Create compatibility layer with usePopoverState hook and PopoverDisclosure component
- Update Collaborators component to use new compatibility imports
- Add placement conversion from reakit format to Radix side/align format
- Update styled components to use Radix data-state attributes instead of data-enter
- Maintain backward compatibility for existing component usage patterns
This commit is contained in:
codegen-sh[bot] committed 2025-06-01 02:21:30 +00:00
1 parent 665b19d933
commit 3dc3e8372a
7 files changed
+274 -81

No files matched your search

+2 -1
View File
@@ -5,14 +5,15 @@ import uniq from "lodash/uniq";
import { observer } from "mobx-react";
import { useState, useMemo, useEffect, useCallback } from "react";
import { useTranslation } from "react-i18next";
import { usePopoverState, PopoverDisclosure } from "reakit/Popover";
import Document from "~/models/Document";
import { AvatarSize, AvatarWithPresence } from "~/components/Avatar";
import DocumentViews from "~/components/DocumentViews";
import Facepile from "~/components/Facepile";
import NudeButton from "~/components/NudeButton";
import Popover from "~/components/Popover";
import PopoverDisclosure from "~/components/PopoverDisclosure";
import useCurrentUser from "~/hooks/useCurrentUser";
import usePopoverState from "~/hooks/usePopoverState";
import useStores from "~/hooks/useStores";
type Props = {
+31 -47
View File
@@ -1,9 +1,8 @@
import * as Dialog from "@radix-ui/react-dialog";
import * as React from "react";
import { Dialog, DialogBackdrop, useDialogState } from "reakit/Dialog";
import styled from "styled-components";
import { depths, s } from "@shared/styles";
import Scrollable from "~/components/Scrollable";
import usePrevious from "~/hooks/usePrevious";
type Props = {
children?: React.ReactNode;
@@ -18,47 +17,25 @@ const Guide: React.FC<Props> = ({
title = "Untitled",
onRequestClose,
...rest
}: Props) => {
const dialog = useDialogState({
animated: 250,
});
const wasOpen = usePrevious(isOpen);
React.useEffect(() => {
if (!wasOpen && isOpen) {
dialog.show();
}
if (wasOpen && !isOpen) {
dialog.hide();
}
}, [dialog, wasOpen, isOpen]);
return (
<DialogBackdrop {...dialog}>
{(backdropProps) => (
<Backdrop {...backdropProps}>
<Dialog
{...dialog}
aria-label={title}
preventBodyScroll
hideOnEsc
hide={onRequestClose}
>
{(dialogProps) => (
<Scene {...dialogProps} {...rest}>
<Content>
{title && <Header>{title}</Header>}
{children}
</Content>
</Scene>
)}
</Dialog>
</Backdrop>
)}
</DialogBackdrop>
);
};
}: Props) => (
<Dialog.Root open={isOpen} onOpenChange={(open) => !open && onRequestClose()}>
<Dialog.Portal>
<StyledOverlay>
<StyledContent
onEscapeKeyDown={onRequestClose}
aria-describedby={undefined}
>
<Scene {...rest}>
<Content>
{title && <Header>{title}</Header>}
{children}
</Content>
</Scene>
</StyledContent>
</StyledOverlay>
</Dialog.Portal>
</Dialog.Root>
);
const Header = styled.h1`
font-size: 18px;
@@ -66,7 +43,7 @@ const Header = styled.h1`
margin-bottom: 1em;
`;
const Backdrop = styled.div`
const StyledOverlay = styled(Dialog.Overlay)`
position: fixed;
top: 0;
left: 0;
@@ -77,12 +54,12 @@ const Backdrop = styled.div`
transition: opacity 200ms ease-in-out;
opacity: 0;
&[data-enter] {
&[data-state="open"] {
opacity: 1;
}
`;
const Scene = styled.div`
const StyledContent = styled(Dialog.Content)`
position: absolute;
top: 0;
right: 0;
@@ -100,12 +77,19 @@ const Scene = styled.div`
transform: translateX(16px);
transition: transform 250ms ease, opacity 250ms ease;
&[data-enter] {
&[data-state="open"] {
opacity: 1;
transform: translateX(0px);
}
`;
const Scene = styled.div`
width: 100%;
display: flex;
justify-content: center;
align-items: flex-start;
`;
const Content = styled(Scrollable)`
width: 100%;
padding: 16px;
+104 -33
View File
@@ -1,6 +1,6 @@
import * as Dialog from "@radix-ui/react-dialog";
import * as Popover from "@radix-ui/react-popover";
import * as React from "react";
import { Dialog } from "reakit/Dialog";
import { Popover as ReakitPopover, PopoverProps } from "reakit/Popover";
import styled from "styled-components";
import breakpoint from "styled-components-breakpoint";
import { depths, s } from "@shared/styles";
@@ -8,8 +8,10 @@ import useKeyDown from "~/hooks/useKeyDown";
import useMobile from "~/hooks/useMobile";
import { fadeAndScaleIn } from "~/styles/animations";
type Props = PopoverProps & {
type Props = {
children: React.ReactNode;
/** Whether the popover is visible */
visible?: boolean;
/** The width of the popover, defaults to 380px. */
width?: number;
/** The minimum width of the popover, use instead of width if contents adjusts size. */
@@ -25,20 +27,36 @@ type Props = PopoverProps & {
/** The position of the popover on mobile, defaults to "top". */
mobilePosition?: "top" | "bottom";
/** Function to show the popover */
show: () => void;
show?: () => void;
/** Function to hide the popover */
hide: () => void;
hide?: () => void;
/** Whether to hide on escape key, defaults to true */
hideOnEsc?: boolean;
/** Whether to hide on click outside, defaults to true */
hideOnClickOutside?: boolean;
/** Aria label for accessibility */
"aria-label"?: string;
/** Placement for the popover */
placement?: string;
/** Gutter spacing */
gutter?: number;
};
const Popover = (
const PopoverComponent = (
{
children,
visible = false,
shrink,
width = 380,
minWidth,
scrollable = true,
flex,
mobilePosition,
hideOnEsc = true,
hideOnClickOutside = true,
hide,
placement,
gutter,
...rest
}: Props,
ref: React.Ref<HTMLDivElement>
@@ -50,9 +68,9 @@ const Popover = (
useKeyDown(
"Escape",
(event) => {
if (rest.visible && rest.hideOnEsc !== false) {
if (visible && hideOnEsc !== false) {
event.preventDefault();
rest.hide();
hide?.();
}
},
{
@@ -62,33 +80,86 @@ const Popover = (
if (isMobile) {
return (
<Dialog {...rest} modal>
<Contents
ref={ref}
$shrink={shrink}
$scrollable={scrollable}
$flex={flex}
$mobilePosition={mobilePosition}
>
{children}
</Contents>
</Dialog>
<Dialog.Root open={visible} onOpenChange={(open) => !open && hide?.()}>
<Dialog.Portal>
<Dialog.Overlay />
<Dialog.Content
onEscapeKeyDown={hideOnEsc ? hide : undefined}
aria-describedby={undefined}
>
<Contents
ref={ref}
$shrink={shrink}
$scrollable={scrollable}
$flex={flex}
$mobilePosition={mobilePosition}
>
{children}
</Contents>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
);
}
// Convert reakit placement to Radix side
const getSide = (placementProp?: string) => {
if (!placementProp) {
return "bottom";
}
if (placementProp.includes("top")) {
return "top";
}
if (placementProp.includes("bottom")) {
return "bottom";
}
if (placementProp.includes("left")) {
return "left";
}
if (placementProp.includes("right")) {
return "right";
}
return "bottom";
};
const getAlign = (placementProp?: string) => {
if (!placementProp) {
return "center";
}
if (placementProp.includes("start")) {
return "start";
}
if (placementProp.includes("end")) {
return "end";
}
return "center";
};
return (
<StyledPopover {...rest} hideOnEsc={false} hideOnClickOutside>
<Contents
ref={ref}
$shrink={shrink}
$width={width}
$minWidth={minWidth}
$scrollable={scrollable}
$flex={flex}
>
{children}
</Contents>
</StyledPopover>
<Popover.Root open={visible} onOpenChange={(open) => !open && hide?.()}>
<Popover.Portal>
<StyledPopoverContent
onEscapeKeyDown={hideOnEsc ? hide : undefined}
onPointerDownOutside={hideOnClickOutside ? hide : undefined}
side={getSide(placement)}
align={getAlign(placement)}
sideOffset={gutter ?? 5}
aria-describedby={undefined}
{...rest}
>
<Contents
ref={ref}
$shrink={shrink}
$width={width}
$minWidth={minWidth}
$scrollable={scrollable}
$flex={flex}
>
{children}
</Contents>
</StyledPopoverContent>
</Popover.Portal>
</Popover.Root>
);
};
@@ -101,7 +172,7 @@ type ContentsProps = {
$mobilePosition?: "top" | "bottom";
};
const StyledPopover = styled(ReakitPopover)`
const StyledPopoverContent = styled(Popover.Content)`
z-index: ${depths.modal};
`;
@@ -142,4 +213,4 @@ const Contents = styled.div<ContentsProps>`
`};
`;
export default React.forwardRef(Popover);
export default React.forwardRef(PopoverComponent);
+51
View File
@@ -0,0 +1,51 @@
import * as Popover from "@radix-ui/react-popover";
import * as React from "react";
type PopoverProps = {
onClick?: (event: React.MouseEvent) => void;
[key: string]: unknown;
};
type Props = {
children: React.ReactNode | ((props: PopoverProps) => React.ReactNode);
show?: () => void;
hide?: () => void;
toggle?: () => void;
visible?: boolean;
} & React.ComponentProps<typeof Popover.Trigger>;
/**
* A compatibility component that provides a similar API to reakit's PopoverDisclosure
* but works with Radix UI Popover.
*/
const PopoverDisclosure = React.forwardRef<HTMLButtonElement, Props>(
({ children, show, hide, toggle, visible, onClick, ...props }, ref) => {
const handleClick = React.useCallback(
(event: React.MouseEvent) => {
if (onClick) {
onClick(event);
}
if (toggle) {
toggle();
}
},
[onClick, toggle]
);
// If children is a function, call it with popover props for backward compatibility
const content =
typeof children === "function"
? children({ onClick: handleClick, ...props })
: children;
return (
<Popover.Trigger ref={ref} {...props} onClick={handleClick} asChild>
{content}
</Popover.Trigger>
);
}
);
PopoverDisclosure.displayName = "PopoverDisclosure";
export default PopoverDisclosure;
+29
View File
@@ -0,0 +1,29 @@
import { useState, useCallback } from "react";
/**
* A compatibility hook that provides a similar API to reakit's usePopoverState
* but works with our Radix-based Popover component.
*/
export function usePopoverState(options?: {
gutter?: number;
placement?: string;
visible?: boolean;
}) {
const [visible, setVisible] = useState(options?.visible ?? false);
const show = useCallback(() => setVisible(true), []);
const hide = useCallback(() => setVisible(false), []);
const toggle = useCallback(() => setVisible((prev) => !prev), []);
return {
visible,
show,
hide,
toggle,
// For backward compatibility with existing code
placement: options?.placement,
gutter: options?.gutter,
};
}
export default usePopoverState;
+2
View File
@@ -86,6 +86,8 @@
"@octokit/auth-app": "^6.1.3",
"@outlinewiki/koa-passport": "^4.2.1",
"@outlinewiki/passport-azure-ad-oauth2": "^0.1.0",
"@radix-ui/react-dialog": "^1.1.14",
"@radix-ui/react-popover": "^1.1.14",
"@radix-ui/react-select": "^2.1.4",
"@radix-ui/react-tooltip": "^1.2.7",
"@radix-ui/react-visually-hidden": "^1.2.2",
+55
View File
@@ -3365,6 +3365,26 @@
aria-hidden "^1.2.4"
react-remove-scroll "^2.6.3"
"@radix-ui/react-dialog@^1.1.14":
version "1.1.14"
resolved "https://registry.yarnpkg.com/@radix-ui/react-dialog/-/react-dialog-1.1.14.tgz#4c69c80c258bc6561398cfce055202ea11075107"
integrity sha512-+CpweKjqpzTmwRwcYECQcNYbI8V9VSQt0SNFKeEBLgfucbsLssU6Ppq7wUdNXEGb573bMjFhVjKVll8rmV6zMw==
dependencies:
"@radix-ui/primitive" "1.1.2"
"@radix-ui/react-compose-refs" "1.1.2"
"@radix-ui/react-context" "1.1.2"
"@radix-ui/react-dismissable-layer" "1.1.10"
"@radix-ui/react-focus-guards" "1.1.2"
"@radix-ui/react-focus-scope" "1.1.7"
"@radix-ui/react-id" "1.1.1"
"@radix-ui/react-portal" "1.1.9"
"@radix-ui/react-presence" "1.1.4"
"@radix-ui/react-primitive" "2.1.3"
"@radix-ui/react-slot" "1.2.3"
"@radix-ui/react-use-controllable-state" "1.2.2"
aria-hidden "^1.2.4"
react-remove-scroll "^2.6.3"
"@radix-ui/react-direction@1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@radix-ui/react-direction/-/react-direction-1.1.0.tgz#a7d39855f4d077adc2a1922f9c353c5977a09cdc"
@@ -3408,6 +3428,11 @@
resolved "https://registry.yarnpkg.com/@radix-ui/react-focus-guards/-/react-focus-guards-1.1.1.tgz#8635edd346304f8b42cae86b05912b61aef27afe"
integrity sha512-pSIwfrT1a6sIoDASCSpFwOasEwKTZWDw/iBdtnqKO7v6FeOzYJ7U53cPzYFVR3geGGXgVHaH+CdngrrAzqUGxg==
"@radix-ui/react-focus-guards@1.1.2":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@radix-ui/react-focus-guards/-/react-focus-guards-1.1.2.tgz#4ec9a7e50925f7fb661394460045b46212a33bed"
integrity sha512-fyjAACV62oPV925xFCrH8DR5xWhg9KYtJT4s3u54jxp+L/hbpTY2kIeEFFbFe+a/HCE94zGQMZLIpVTPVZDhaA==
"@radix-ui/react-focus-scope@1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@radix-ui/react-focus-scope/-/react-focus-scope-1.1.1.tgz#5c602115d1db1c4fcfa0fae4c3b09bb8919853cb"
@@ -3426,6 +3451,15 @@
"@radix-ui/react-primitive" "2.0.2"
"@radix-ui/react-use-callback-ref" "1.1.0"
"@radix-ui/react-focus-scope@1.1.7":
version "1.1.7"
resolved "https://registry.yarnpkg.com/@radix-ui/react-focus-scope/-/react-focus-scope-1.1.7.tgz#dfe76fc103537d80bf42723a183773fd07bfb58d"
integrity sha512-t2ODlkXBQyn7jkl6TNaw/MtVEVvIGelJDCG41Okq/KwUsJBwQ4XVZsHAVUkK4mBv3ewiAS3PGuUWuY2BoK4ZUw==
dependencies:
"@radix-ui/react-compose-refs" "1.1.2"
"@radix-ui/react-primitive" "2.1.3"
"@radix-ui/react-use-callback-ref" "1.1.1"
"@radix-ui/react-id@1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@radix-ui/react-id/-/react-id-1.1.0.tgz#de47339656594ad722eb87f94a6b25f9cffae0ed"
@@ -3440,6 +3474,27 @@
dependencies:
"@radix-ui/react-use-layout-effect" "1.1.1"
"@radix-ui/react-popover@^1.1.14":
version "1.1.14"
resolved "https://registry.yarnpkg.com/@radix-ui/react-popover/-/react-popover-1.1.14.tgz#5496d1986f0287cdfc77e73f70a887e4cb77ad08"
integrity sha512-ODz16+1iIbGUfFEfKx2HTPKizg2MN39uIOV8MXeHnmdd3i/N9Wt7vU46wbHsqA0xoaQyXVcs0KIlBdOA2Y95bw==
dependencies:
"@radix-ui/primitive" "1.1.2"
"@radix-ui/react-compose-refs" "1.1.2"
"@radix-ui/react-context" "1.1.2"
"@radix-ui/react-dismissable-layer" "1.1.10"
"@radix-ui/react-focus-guards" "1.1.2"
"@radix-ui/react-focus-scope" "1.1.7"
"@radix-ui/react-id" "1.1.1"
"@radix-ui/react-popper" "1.2.7"
"@radix-ui/react-portal" "1.1.9"
"@radix-ui/react-presence" "1.1.4"
"@radix-ui/react-primitive" "2.1.3"
"@radix-ui/react-slot" "1.2.3"
"@radix-ui/react-use-controllable-state" "1.2.2"
aria-hidden "^1.2.4"
react-remove-scroll "^2.6.3"
"@radix-ui/react-popper@1.2.1":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@radix-ui/react-popper/-/react-popper-1.2.1.tgz#2fc66cfc34f95f00d858924e3bee54beae2dff0a"