diff --git a/src/app/drive/components/ShareDialog/ShareDialog.tsx b/src/app/drive/components/ShareDialog/ShareDialog.tsx index 92d99cb4df..a942d328da 100644 --- a/src/app/drive/components/ShareDialog/ShareDialog.tsx +++ b/src/app/drive/components/ShareDialog/ShareDialog.tsx @@ -1,4 +1,4 @@ -import { Popover } from '@headlessui/react'; +import Popover from 'components/Popover'; import { SharingMeta } from '@internxt/sdk/dist/drive/share/types'; import { UserSettings } from '@internxt/sdk/dist/shared/types/userSettings'; import { @@ -651,9 +651,9 @@ const ShareDialog = (props: ShareDialogProps): JSX.Element => {

{translate('modals.shareModal.general.generalAccess')}

- {({ open }) => ( + {({ open, close, Button: PopoverButton, Panel: PopoverPanel }) => ( <> - + - - - - {({ close }) => ( - <> - {/* Public */} - + {/* Restricted */} + {!isWorkspace && ( + - {/* Restricted */} - {!isWorkspace && ( - - )} - {/* Stop sharing */} - {(currentUserFolderRole === 'owner' || isUserOwner || props?.isDriveItem) && ( - - )} - + {translate('modals.shareModal.general.accessOptions.restricted.subtitle')} +

+ +
+ {accessMode === 'restricted' ? ( + isLoading ? ( + + ) : ( + + ) + ) : null} +
+ + )} + {/* Stop sharing */} + {(currentUserFolderRole === 'owner' || isUserOwner || props?.isDriveItem) && ( + )} -
+ )}
@@ -842,52 +833,45 @@ const ShareDialog = (props: ShareDialogProps): JSX.Element => {
- {({ open }) => ( + {({ close, Button: PopoverButton, Panel: PopoverPanel }) => ( <> - + - + - - {({ close }) => ( - <> - {/* Reader */} - - - {/* Editor */} - - - )} - + {/* Reader */} + + + {/* Editor */} + + )} diff --git a/src/app/drive/components/ShareDialog/components/UserOptions.tsx b/src/app/drive/components/ShareDialog/components/UserOptions.tsx index 2f92a6d26b..30b6dba4c3 100644 --- a/src/app/drive/components/ShareDialog/components/UserOptions.tsx +++ b/src/app/drive/components/ShareDialog/components/UserOptions.tsx @@ -1,4 +1,4 @@ -import { Popover } from '@headlessui/react'; +import Popover from 'components/Popover'; import { Check } from '@phosphor-icons/react'; export const UserOptions = ({ @@ -14,8 +14,10 @@ export const UserOptions = ({ }): JSX.Element => { const isUserSelected = selectedUserListIndex === listPosition; - return isUserSelected ? ( - ; + + return ( +
- } + alwaysShow={true} + useTransition={false} + classPanel="absolute right-0 z-10 origin-top-right whitespace-nowrap rounded-lg border border-gray-10 bg-surface p-1 shadow-subtle dark:bg-gray-5" + panelStyle={{ top: '44px', minWidth: '160px', }} - static - > - {disableRoleChange ? ( - <> - ) : ( + panel={(close) => ( <> - {/* Editor */} - + {!disableRoleChange && ( + <> + {/* Editor */} + - {/* Reader */} + {/* Reader */} + + +
+ + )} + {/* Remove */} - -
)} - {/* Remove */} - - - - ) : ( - <> + /> +
); }; diff --git a/src/components/Popover.tsx b/src/components/Popover.tsx index 77589b6ff3..692032c4a4 100644 --- a/src/components/Popover.tsx +++ b/src/components/Popover.tsx @@ -1,35 +1,78 @@ import { Popover as HPopover, Transition } from '@headlessui/react'; import { ReactNode } from 'react'; +export interface PopoverRenderProps { + open: boolean; + close: () => void; + Button: typeof HPopover.Button; + Panel: typeof HPopover.Panel; +} + interface PopoverProps { - childrenButton: ReactNode; - panel: ReactNode; + childrenButton?: ReactNode; + panel?: ReactNode | ((close: () => void) => ReactNode); className?: string; classButton?: string; + classPanel?: string; + panelStyle?: React.CSSProperties; + buttonAs?: React.ElementType; + useTransition?: boolean; + alwaysShow?: boolean; + children?: (props: PopoverRenderProps) => ReactNode; } + +const DEFAULT_PANEL_CLASS = + 'absolute right-0 z-50 mt-1 rounded-md border border-gray-10 bg-surface py-1.5 shadow-subtle dark:bg-gray-5'; + export default function Popover({ childrenButton, panel, - className, - classButton, + className = '', + classButton = '', + classPanel, + panelStyle, + buttonAs, + useTransition = true, + alwaysShow = false, + children, }: Readonly): JSX.Element { + if (children) { + return ( + + {({ open, close }) => <>{children({ open, close, Button: HPopover.Button, Panel: HPopover.Panel })}} + + ); + } + + const PanelContent = ({ close }: { close: () => void }) => <>{typeof panel === 'function' ? panel(close) : panel}; + + const Panel = ( + + {({ close }) => } + + ); + return ( - {childrenButton} - - - - {panel} - - + + {childrenButton} + + + {useTransition ? ( + + {Panel} + + ) : ( + Panel + )} ); } diff --git a/src/views/Home/components/AccountPopover.tsx b/src/views/Home/components/AccountPopover.tsx index 034d0eaf45..8f3de0674f 100644 --- a/src/views/Home/components/AccountPopover.tsx +++ b/src/views/Home/components/AccountPopover.tsx @@ -2,7 +2,7 @@ import { UserSettings } from '@internxt/sdk/dist/shared/types/userSettings'; import { useTranslationContext } from 'app/i18n/provider/TranslationProvider'; import { Desktop, SignOut, Gear } from '@phosphor-icons/react'; import { ReactNode } from 'react'; -import { Popover } from '@internxt/ui'; +import Popover from 'components/Popover'; import { useAppDispatch, useAppSelector } from 'app/store/hooks'; import { uiActions } from 'app/store/slices/ui'; import { userThunks } from 'app/store/slices/user'; @@ -115,9 +115,7 @@ export default function AccountPopover({ className = '', user, plan }: Readonly<
); - return ( - panel} data-test="app-header-dropdown" /> - ); + return ; } interface ItemProps {