From 1a5d5afadc7ce0bee0d61aa8144d2c12c388c07e Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Thu, 10 Aug 2023 16:33:33 +0100 Subject: [PATCH] fix iconY padding when folder expanded --- .../src/lib/components/file-render.tsx | 185 ++++++++++++------ 1 file changed, 124 insertions(+), 61 deletions(-) diff --git a/libs/remix-ui/workspace/src/lib/components/file-render.tsx b/libs/remix-ui/workspace/src/lib/components/file-render.tsx index b92a449f7f..4e23ab3d10 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-render.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-render.tsx @@ -1,28 +1,34 @@ // eslint-disable-next-line no-use-before-define -import React, { SyntheticEvent, useEffect, useState } from 'react' -import { FileType } from '../types' +import React, {SyntheticEvent, useEffect, useState} from 'react' +import {FileType} from '../types' // eslint-disable-next-line @typescript-eslint/no-unused-vars -import { TreeView, TreeViewItem } from '@remix-ui/tree-view' -import { getPathIcon } from '@remix-ui/helper' +import {TreeView, TreeViewItem} from '@remix-ui/tree-view' +import {getPathIcon} from '@remix-ui/helper' // eslint-disable-next-line @typescript-eslint/no-unused-vars -import { FileLabel } from './file-label' -import { fileDecoration, FileDecorationIcons } from '@remix-ui/file-decorators' -import { Draggable } from "@remix-ui/drag-n-drop" +import {FileLabel} from './file-label' +import {fileDecoration, FileDecorationIcons} from '@remix-ui/file-decorators' +import {Draggable} from '@remix-ui/drag-n-drop' export interface RenderFileProps { - file: FileType, - index: number, - focusEdit: { element: string, type: string, isNew: boolean, lastEdit: string }, - focusElement: { key: string, type: 'file' | 'folder' | 'gist' }[], - focusContext: { element: string, x: number, y: number, type: string }, - ctrlKey: boolean, - expandPath: string[], - hideIconsMenu?: React.Dispatch>, - showIconsMenu?: boolean, - editModeOff: (content: string) => void, - handleClickFolder: (path: string, type: string) => void, - handleClickFile: (path: string, type: string) => void, - handleContextMenu: (pageX: number, pageY: number, path: string, content: string, type: string) => void + file: FileType + index: number + focusEdit: {element: string; type: string; isNew: boolean; lastEdit: string} + focusElement: {key: string; type: 'file' | 'folder' | 'gist'}[] + focusContext: {element: string; x: number; y: number; type: string} + ctrlKey: boolean + expandPath: string[] + hideIconsMenu?: React.Dispatch> + showIconsMenu?: boolean + editModeOff: (content: string) => void + handleClickFolder: (path: string, type: string) => void + handleClickFile: (path: string, type: string) => void + handleContextMenu: ( + pageX: number, + pageY: number, + path: string, + content: string, + type: string + ) => void fileDecorations: fileDecoration[] } @@ -38,11 +44,17 @@ export const FileRender = (props: RenderFileProps) => { } }, [props.file]) - const labelClass = props.focusEdit.element === file.path - ? 'bg-light' : props.focusElement.findIndex(item => item.key === file.path) !== -1 - ? 'bg-secondary' : hover - ? 'bg-light border-no-shift' : (props.focusContext.element === file.path) && (props.focusEdit.element !== file.path) - ? 'bg-light border-no-shift' : '' + const labelClass = + props.focusEdit.element === file.path + ? 'bg-light' + : props.focusElement.findIndex((item) => item.key === file.path) !== -1 + ? 'bg-secondary' + : hover + ? 'bg-light border-no-shift' + : props.focusContext.element === file.path && + props.focusEdit.element !== file.path + ? 'bg-light border-no-shift' + : '' const spreadProps = { onClick: (e) => e.stopPropagation() @@ -50,20 +62,28 @@ export const FileRender = (props: RenderFileProps) => { const handleFolderClick = (event: SyntheticEvent) => { event.stopPropagation() - if (props.focusEdit.element !== file.path) props.handleClickFolder(file.path, file.type) + if (props.focusEdit.element !== file.path) + props.handleClickFolder(file.path, file.type) if (props.showIconsMenu === true) props.hideIconsMenu(!props.showIconsMenu) } const handleFileClick = (event: SyntheticEvent) => { event.stopPropagation() - if (props.focusEdit.element !== file.path) props.handleClickFile(file.path, file.type) + if (props.focusEdit.element !== file.path) + props.handleClickFile(file.path, file.type) if (props.showIconsMenu === true) props.hideIconsMenu(!props.showIconsMenu) } const handleContextMenu = (event: PointerEvent) => { event.preventDefault() event.stopPropagation() - props.handleContextMenu(event.pageX, event.pageY, file.path, (event.target as HTMLElement).textContent, file.type) + props.handleContextMenu( + event.pageX, + event.pageY, + file.path, + (event.target as HTMLElement).textContent, + file.type + ) } const handleMouseOut = (event: SyntheticEvent) => { @@ -80,17 +100,36 @@ export const FileRender = (props: RenderFileProps) => { return ( - -
- - -
-
- } + label={ + <> + +
+ + +
+
+ + } onClick={handleFolderClick} onContextMenu={handleContextMenu} labelClass={labelClass} @@ -99,26 +138,37 @@ export const FileRender = (props: RenderFileProps) => { onMouseOver={handleMouseOver} onMouseOut={handleMouseOut} > - { - file.child ? { - Object.keys(file.child).map((key, index) => ) - } - : - } + {file.child ? ( + + {Object.keys(file.child).map((key, index) => ( + + ))} + + ) : ( + + )}
) } else { @@ -128,10 +178,23 @@ export const FileRender = (props: RenderFileProps) => { key={`treeView${file.path}`} label={ <> - +
- - + +