From 7ed469b14c6be673ca619323e061a33daa50360b Mon Sep 17 00:00:00 2001 From: Yauheni Mileika Date: Fri, 6 Dec 2024 15:42:25 +0300 Subject: [PATCH] feat(AsideHeader): add drag placeholder --- .../AllPagesListItem/AllPagesListItem.tsx | 22 +++++++++- .../AllPagesPanel/AllPagesPanel.scss | 7 ++++ .../AllPagesPanel/AllPagesPanel.tsx | 41 ++++++++++++++----- 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/src/components/AllPagesPanel/AllPagesListItem/AllPagesListItem.tsx b/src/components/AllPagesPanel/AllPagesListItem/AllPagesListItem.tsx index c2c0c30..71671c8 100644 --- a/src/components/AllPagesPanel/AllPagesListItem/AllPagesListItem.tsx +++ b/src/components/AllPagesPanel/AllPagesListItem/AllPagesListItem.tsx @@ -15,10 +15,12 @@ interface AllPagesListItemProps { editMode?: boolean; enableSorting?: boolean; onToggle: () => void; + onDragStart?: () => void; + onDragEnd?: () => void; } export const AllPagesListItem: React.FC = (props) => { - const {item, editMode, onToggle, enableSorting} = props; + const {item, editMode, onToggle, enableSorting, onDragStart, onDragEnd} = props; const onPinButtonClick = useCallback( (e: MouseEvent) => { e.stopPropagation(); @@ -35,12 +37,30 @@ export const AllPagesListItem: React.FC = (props) => { } }; + const onItemDrugStart = (e: MouseEvent) => { + if (editMode && onDragStart) { + e.stopPropagation(); + e.preventDefault(); + onDragStart(); + } + }; + + const onItemDrugEnd = (e: MouseEvent) => { + if (editMode && onDragEnd) { + e.stopPropagation(); + e.preventDefault(); + onDragEnd(); + } + }; + return (
{item.icon ? ( diff --git a/src/components/AllPagesPanel/AllPagesPanel.scss b/src/components/AllPagesPanel/AllPagesPanel.scss index df5d0ee..9f73ac9 100644 --- a/src/components/AllPagesPanel/AllPagesPanel.scss +++ b/src/components/AllPagesPanel/AllPagesPanel.scss @@ -24,4 +24,11 @@ &__item_editMode { padding: 0 var(--g-spacing-6); } + + &__drag-placeholder { + padding-left: 88px; + padding-right: 68px; + text-wrap: nowrap; + visibility: hidden; + } } diff --git a/src/components/AllPagesPanel/AllPagesPanel.tsx b/src/components/AllPagesPanel/AllPagesPanel.tsx index c993cb9..7e9e648 100644 --- a/src/components/AllPagesPanel/AllPagesPanel.tsx +++ b/src/components/AllPagesPanel/AllPagesPanel.tsx @@ -1,4 +1,4 @@ -import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; +import React, {ReactNode, useCallback, useEffect, useMemo, useRef, useState} from 'react'; import {Gear} from '@gravity-ui/icons'; import {Button, Flex, Icon, List, ListItemData, Text} from '@gravity-ui/uikit'; @@ -30,6 +30,9 @@ export const AllPagesPanel: React.FC = (props) => { menuItemsRef.current = menuItems; const [isEditMode, setIsEditMode] = useState(false); + + const [dragingItemTitle, setDragingItemTitle] = useState(null); + const toggleEditMode = useCallback(() => { setIsEditMode((prev) => !prev); }, []); @@ -72,16 +75,28 @@ export const AllPagesPanel: React.FC = (props) => { [onMenuItemsChanged, editMenuProps], ); + const onDragEnd = useCallback(() => { + setDragingItemTitle(null); + }, [onMenuItemsChanged]); + const itemRender = useCallback( - (item: ListItemData, _isActive: boolean, _itemIndex: number) => ( - togglePageVisibility(item)} - enableSorting={editMenuProps?.enableSorting} - /> - ), - [isEditMode, togglePageVisibility], + (item: ListItemData, _isActive: boolean, _itemIndex: number) => { + const onDragStart = () => { + setDragingItemTitle(item.title); + }; + + return ( + togglePageVisibility(item)} + enableSorting={editMenuProps?.enableSorting} + /> + ); + }, + [isEditMode, togglePageVisibility, onMenuItemsChanged], ); const onResetToDefaultClick = useCallback(() => { @@ -106,6 +121,8 @@ export const AllPagesPanel: React.FC = (props) => { newItems.splice(newIndex, 0, element); onMenuItemsChanged?.(newItems); + + setDragingItemTitle(null); editMenuProps?.onChangeItemsOrder?.(element, oldIndex, newIndex); }, [onMenuItemsChanged], @@ -141,6 +158,10 @@ export const AllPagesPanel: React.FC = (props) => { onItemClick={onItemClick} renderItem={itemRender} /> + + {dragingItemTitle && ( +
{dragingItemTitle}
+ )}
) : ( Object.keys(groupedItems).map((category) => {