In navigation drawer, cursor should not be drag on hover and some enhancements (#8975)

as per the title- on hover, the draggable items had a grab cursor.
Couldn't change it to a pointer, because then onClick would have a weird
behavior of grab which causes lag onClick.
This commit is contained in:
nitin
2024-12-13 19:07:46 +05:30
committed by GitHub
parent 9579f22bc2
commit 257834ea71
5 changed files with 47 additions and 22 deletions

View File

@ -16,6 +16,7 @@ import { NavigationDrawerItem } from '@/ui/navigation/navigation-drawer/componen
import { NavigationDrawerItemsCollapsableContainer } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerItemsCollapsableContainer'; import { NavigationDrawerItemsCollapsableContainer } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerItemsCollapsableContainer';
import { NavigationDrawerSubItem } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerSubItem'; import { NavigationDrawerSubItem } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerSubItem';
import { getNavigationSubItemLeftAdornment } from '@/ui/navigation/navigation-drawer/utils/getNavigationSubItemLeftAdornment'; import { getNavigationSubItemLeftAdornment } from '@/ui/navigation/navigation-drawer/utils/getNavigationSubItemLeftAdornment';
import { DragStart, DropResult, ResponderProvided } from '@hello-pangea/dnd';
import { useState } from 'react'; import { useState } from 'react';
import { createPortal } from 'react-dom'; import { createPortal } from 'react-dom';
import { useLocation } from 'react-router-dom'; import { useLocation } from 'react-router-dom';
@ -42,6 +43,7 @@ export const CurrentWorkspaceMemberFavorites = ({
}: CurrentWorkspaceMemberFavoritesProps) => { }: CurrentWorkspaceMemberFavoritesProps) => {
const currentPath = useLocation().pathname; const currentPath = useLocation().pathname;
const currentViewPath = useLocation().pathname + useLocation().search; const currentViewPath = useLocation().pathname + useLocation().search;
const [isDragging, setIsDragging] = useState(false);
const [isFavoriteFolderRenaming, setIsFavoriteFolderRenaming] = const [isFavoriteFolderRenaming, setIsFavoriteFolderRenaming] =
useState(false); useState(false);
@ -113,6 +115,15 @@ export const CurrentWorkspaceMemberFavorites = ({
setIsDeleteModalOpen(false); setIsDeleteModalOpen(false);
}; };
const handleDragStart = (_: DragStart) => {
setIsDragging(true);
};
const handleDragEnd = (result: DropResult, provided: ResponderProvided) => {
setIsDragging(false);
handleReorderFavorite(result, provided);
};
const rightOptions = ( const rightOptions = (
<FavoriteFolderNavigationDrawerItemDropdown <FavoriteFolderNavigationDrawerItemDropdown
folderId={folder.folderId} folderId={folder.folderId}
@ -152,7 +163,8 @@ export const CurrentWorkspaceMemberFavorites = ({
{isOpen && ( {isOpen && (
<DraggableList <DraggableList
onDragEnd={handleReorderFavorite} onDragEnd={handleDragEnd}
onDragStart={handleDragStart}
draggableItems={ draggableItems={
<> <>
{folder.favorites.map((favorite, index) => ( {folder.favorites.map((favorite, index) => (
@ -180,7 +192,7 @@ export const CurrentWorkspaceMemberFavorites = ({
accent="tertiary" accent="tertiary"
/> />
} }
isDraggable isDragging={isDragging}
/> />
} }
/> />

View File

@ -26,8 +26,12 @@ import { NavigationDrawerSection } from '@/ui/navigation/navigation-drawer/compo
import { NavigationDrawerSectionTitle } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerSectionTitle'; import { NavigationDrawerSectionTitle } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerSectionTitle';
import { useNavigationSection } from '@/ui/navigation/navigation-drawer/hooks/useNavigationSection'; import { useNavigationSection } from '@/ui/navigation/navigation-drawer/hooks/useNavigationSection';
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled'; import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
import { DragStart, DropResult, ResponderProvided } from '@hello-pangea/dnd';
import { useState } from 'react';
export const CurrentWorkspaceMemberFavoritesFolders = () => { export const CurrentWorkspaceMemberFavoritesFolders = () => {
const [isDragging, setIsDragging] = useState(false);
const currentPath = useLocation().pathname; const currentPath = useLocation().pathname;
const currentViewPath = useLocation().pathname + useLocation().search; const currentViewPath = useLocation().pathname + useLocation().search;
const theme = useTheme(); const theme = useTheme();
@ -54,6 +58,16 @@ export const CurrentWorkspaceMemberFavoritesFolders = () => {
openNavigationSection(); openNavigationSection();
setIsFavoriteFolderCreating((current) => !current); setIsFavoriteFolderCreating((current) => !current);
}; };
const handleDragStart = (_: DragStart) => {
setIsDragging(true);
};
const handleDragEnd = (result: DropResult, provided: ResponderProvided) => {
setIsDragging(false);
handleReorderFavorite(result, provided);
};
const shouldDisplayFavoritesWithFeatureFlagEnabled = true; const shouldDisplayFavoritesWithFeatureFlagEnabled = true;
//todo: remove this logic once feature flag gating is removed //todo: remove this logic once feature flag gating is removed
@ -103,7 +117,8 @@ export const CurrentWorkspaceMemberFavoritesFolders = () => {
{orphanFavorites.length > 0 && ( {orphanFavorites.length > 0 && (
<DraggableList <DraggableList
onDragEnd={handleReorderFavorite} onDragEnd={handleDragEnd}
onDragStart={handleDragStart}
draggableItems={orphanFavorites.map((favorite, index) => ( draggableItems={orphanFavorites.map((favorite, index) => (
<DraggableItem <DraggableItem
key={favorite.id} key={favorite.id}
@ -129,7 +144,7 @@ export const CurrentWorkspaceMemberFavoritesFolders = () => {
accent="tertiary" accent="tertiary"
/> />
} }
isDraggable={true} isDragging={isDragging}
/> />
} }
/> />

View File

@ -3,12 +3,14 @@ import {
DragDropContext, DragDropContext,
Droppable, Droppable,
OnDragEndResponder, OnDragEndResponder,
OnDragStartResponder,
} from '@hello-pangea/dnd'; } from '@hello-pangea/dnd';
import { useState } from 'react'; import { useState } from 'react';
import { v4 } from 'uuid'; import { v4 } from 'uuid';
type DraggableListProps = { type DraggableListProps = {
draggableItems: React.ReactNode; draggableItems: React.ReactNode;
onDragEnd: OnDragEndResponder; onDragEnd: OnDragEndResponder;
onDragStart?: OnDragStartResponder;
}; };
const StyledDragDropItemsWrapper = styled.div` const StyledDragDropItemsWrapper = styled.div`
@ -18,11 +20,12 @@ const StyledDragDropItemsWrapper = styled.div`
export const DraggableList = ({ export const DraggableList = ({
draggableItems, draggableItems,
onDragEnd, onDragEnd,
onDragStart,
}: DraggableListProps) => { }: DraggableListProps) => {
const [v4Persistable] = useState(v4()); const [v4Persistable] = useState(v4());
return ( return (
<DragDropContext onDragEnd={onDragEnd}> <DragDropContext onDragEnd={onDragEnd} onDragStart={onDragStart}>
<StyledDragDropItemsWrapper> <StyledDragDropItemsWrapper>
<Droppable droppableId={v4Persistable}> <Droppable droppableId={v4Persistable}>
{(provided) => ( {(provided) => (

View File

@ -37,17 +37,17 @@ export type NavigationDrawerItemProps = {
count?: number; count?: number;
keyboard?: string[]; keyboard?: string[];
rightOptions?: ReactNode; rightOptions?: ReactNode;
isDraggable?: boolean; isDragging?: boolean;
}; };
type StyledItemProps = Pick< type StyledItemProps = Pick<
NavigationDrawerItemProps, NavigationDrawerItemProps,
'active' | 'danger' | 'indentationLevel' | 'soon' | 'to' | 'isDraggable' 'active' | 'danger' | 'indentationLevel' | 'soon' | 'to' | 'isDragging'
> & { isNavigationDrawerExpanded: boolean }; > & { isNavigationDrawerExpanded: boolean };
const StyledItem = styled('button', { const StyledItem = styled('button', {
shouldForwardProp: (prop) => shouldForwardProp: (prop) =>
!['active', 'danger', 'soon', 'isDraggable'].includes(prop) && !['active', 'danger', 'soon', 'isDragging'].includes(prop) &&
isPropValid(prop), isPropValid(prop),
})<StyledItemProps>` })<StyledItemProps>`
box-sizing: content-box; box-sizing: content-box;
@ -89,16 +89,11 @@ const StyledItem = styled('button', {
!props.isNavigationDrawerExpanded !props.isNavigationDrawerExpanded
? `${NAV_DRAWER_WIDTHS.menu.desktop.collapsed - 24}px` ? `${NAV_DRAWER_WIDTHS.menu.desktop.collapsed - 24}px`
: '100%'}; : '100%'};
${({ isDraggable }) => ${({ isDragging }) =>
isDraggable && isDragging &&
` `
cursor: grab; cursor: grabbing;
`}
&:active {
cursor: grabbing;
}
`}
:hover { :hover {
background: ${({ theme }) => theme.background.transparent.light}; background: ${({ theme }) => theme.background.transparent.light};
color: ${(props) => color: ${(props) =>
@ -198,7 +193,7 @@ export const NavigationDrawerItem = ({
keyboard, keyboard,
subItemState, subItemState,
rightOptions, rightOptions,
isDraggable, isDragging,
}: NavigationDrawerItemProps) => { }: NavigationDrawerItemProps) => {
const theme = useTheme(); const theme = useTheme();
const isMobile = useIsMobile(); const isMobile = useIsMobile();
@ -231,7 +226,7 @@ export const NavigationDrawerItem = ({
to={to ? to : undefined} to={to ? to : undefined}
indentationLevel={indentationLevel} indentationLevel={indentationLevel}
isNavigationDrawerExpanded={isNavigationDrawerExpanded} isNavigationDrawerExpanded={isNavigationDrawerExpanded}
isDraggable={isDraggable} isDragging={isDragging}
> >
{showBreadcrumb && ( {showBreadcrumb && (
<NavigationDrawerAnimatedCollapseWrapper> <NavigationDrawerAnimatedCollapseWrapper>

View File

@ -18,7 +18,7 @@ export const NavigationDrawerSubItem = ({
keyboard, keyboard,
subItemState, subItemState,
rightOptions, rightOptions,
isDraggable, isDragging,
}: NavigationDrawerSubItemProps) => { }: NavigationDrawerSubItemProps) => {
return ( return (
<NavigationDrawerItem <NavigationDrawerItem
@ -35,7 +35,7 @@ export const NavigationDrawerSubItem = ({
count={count} count={count}
keyboard={keyboard} keyboard={keyboard}
rightOptions={rightOptions} rightOptions={rightOptions}
isDraggable={isDraggable} isDragging={isDragging}
/> />
); );
}; };