Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Popup)!: migrate to floating-ui #1952

Merged
merged 4 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 49 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,15 @@
},
"dependencies": {
"@bem-react/classname": "^1.6.0",
"@floating-ui/react": "^0.26.24",
"@gravity-ui/i18n": "^1.6.0",
"@gravity-ui/icons": "^2.8.1",
"@popperjs/core": "^2.11.8",
"blueimp-md5": "^2.19.0",
"focus-trap": "^7.5.4",
"lodash": "^4.17.21",
"rc-slider": "^10.6.2",
"react-beautiful-dnd": "^13.1.1",
"react-copy-to-clipboard": "^5.1.0",
"react-popper": "^2.3.0",
"react-transition-group": "^4.4.5",
"react-virtualized-auto-sizer": "^1.0.21",
"react-window": "^1.8.10",
Expand Down
2 changes: 1 addition & 1 deletion src/components/ActionTooltip/ActionTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function ActionTooltip(props: ActionTooltipProps) {
style={style}
open={tooltipVisible && !disabled}
placement={placement}
anchorRef={{current: anchorElement}}
anchorElement={anchorElement}
disableEscapeKeyDown
disableOutsideClick
disableLayer
Expand Down
1 change: 1 addition & 0 deletions src/components/DropdownMenu/DropdownMenuPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export const DropdownMenuPopup = <T,>({
open={open}
anchorRef={anchorRef}
onClose={onClose}
placement="bottom-start"
{...popupProps}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
Expand Down
46 changes: 22 additions & 24 deletions src/components/FilePreview/__stories__/FilePreview.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,56 +102,54 @@ const CollageTemplate: StoryFn<FilePreviewProps> = () => {

export const Collage = CollageTemplate.bind({});

const noClickableTemplateActions = [
{
icon: <Xmark width={14} height={14} />,
onClick: () => action('Are you sure you want to delete the file?'),
title: 'Close',
},
];

const NoClickableTemplate: StoryFn<Omit<FilePreviewProps, 'actions'>> = (args) => {
return (
<Flex gap={4}>
<FilePreview {...args} file={{name: 'No clickable', type: 'text/docs'} as File} />
<FilePreview
{...args}
file={{name: 'No clickable with actions', type: 'text/docs'} as File}
actions={[
{
icon: <Xmark width={14} height={14} />,
onClick: () => action('Are you sure you want to delete the file?'),
title: 'Close',
},
]}
actions={noClickableTemplateActions}
/>
<FilePreview
{...args}
file={{name: 'Clickable with actions', type: 'text/docs'} as File}
onClick={() => action('onClick')}
actions={[
{
icon: <Xmark width={14} height={14} />,
onClick: () => action('Are you sure you want to delete the file?'),
title: 'Close',
},
]}
actions={noClickableTemplateActions}
/>
</Flex>
);
};

export const NoClickable = NoClickableTemplate.bind({});

const withoutActionTooltipTemplateActions = [
{
icon: <Xmark width={14} height={14} />,
onClick: () => action('onClose'),
title: 'Close',
tooltipExtraProps: {
disabled: true,
},
},
];

const WithoutActionTooltipTemplate: StoryFn<Omit<FilePreviewProps, 'actions'>> = (args) => {
return (
<Flex gap={4}>
<FilePreview
{...args}
file={{name: 'Clicable without tooltip', type: 'text/docs'} as File}
onClick={() => action('onClick')}
actions={[
{
icon: <Xmark width={14} height={14} />,
onClick: () => action('onClose'),
title: 'Close',
tooltipExtraProps: {
disabled: true,
},
},
]}
actions={withoutActionTooltipTemplateActions}
/>
</Flex>
);
Expand Down
12 changes: 8 additions & 4 deletions src/components/Popover/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ export const Popover = React.forwardRef<PopoverInstanceProps, PopoverProps & QAP
onCloseClick,
onClick,
anchorRef,
anchorElement,
strategy,
qa,
disablePortal = false,
tooltipId,
focusTrap,
autoFocus,
restoreFocusRef,
modifiers,
middlewares,
},
ref,
) {
Expand Down Expand Up @@ -116,13 +117,16 @@ export const Popover = React.forwardRef<PopoverInstanceProps, PopoverProps & QAP

const hasTitle = Boolean(title);

const hasAnchor = Boolean(anchorRef || anchorElement);

const popoverTitleId = `popover-${tooltipId ?? ''}-title-${useUniqId()}`;

const tooltip = (
<Popup
id={tooltipId}
role={openOnHover ? 'tooltip' : 'dialog'}
strategy={strategy}
anchorElement={anchorElement}
anchorRef={anchorRef || controlRef}
className={cnPopover(
'tooltip',
Expand All @@ -139,14 +143,14 @@ export const Popover = React.forwardRef<PopoverInstanceProps, PopoverProps & QAP
placement={popupPlacement}
hasArrow={hasArrow}
offset={tooltipOffset}
onClose={anchorRef ? undefined : closeTooltip}
onClose={hasAnchor ? undefined : closeTooltip}
qa={qa ? `${qa}-tooltip` : ''}
disablePortal={disablePortal}
focusTrap={focusTrap}
autoFocus={autoFocus}
restoreFocus={true}
restoreFocusRef={restoreFocusRef || controlRef}
modifiers={modifiers}
middlewares={middlewares}
aria-labelledby={title ? popoverTitleId : undefined}
>
<React.Fragment>
Expand Down Expand Up @@ -185,7 +189,7 @@ export const Popover = React.forwardRef<PopoverInstanceProps, PopoverProps & QAP
</Popup>
);

if (anchorRef) {
if (hasAnchor) {
return tooltip;
}

Expand Down
Loading
Loading