-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add grid view for file explorer
- Loading branch information
1 parent
8623c4a
commit fe9734c
Showing
12 changed files
with
343 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
"use client"; | ||
|
||
import type { ViewItemProps } from "@/types"; | ||
|
||
import React from "react"; | ||
import { Checkbox } from "@nextui-org/checkbox"; | ||
import { Tooltip } from "@nextui-org/tooltip"; | ||
|
||
import { getFileIcon, getFolderIcon } from "./explorer-item"; | ||
|
||
import { formatSize, getFileTypeName } from "@/lib/utils"; | ||
|
||
interface GridViewItemProps extends ViewItemProps {} | ||
|
||
const ExplorerGridViewItem: React.FC<GridViewItemProps> = ({ | ||
extname, size, selected, contextMenu, setSelected, handleSelection, handleOpen, onContextMenu, ...props | ||
}) => { | ||
return ( | ||
<div | ||
className="w-[6.5rem] h-28 flex flex-col items-center overflow-hidden relative" | ||
onClick={() => handleSelection()} | ||
onKeyDown={({ key }) => { | ||
key === "Enter" && handleSelection(); | ||
}} | ||
role="button" | ||
tabIndex={0}> | ||
<div className="absolute top-1 left-1"> | ||
<Checkbox | ||
className="" | ||
size="sm" | ||
isSelected={selected} | ||
onValueChange={(value) => setSelected(value)}/> | ||
</div> | ||
|
||
<Tooltip | ||
content={ | ||
<div className="text-left"> | ||
<p>名称:{props.name}</p> | ||
<p>类型:{props.type === "folder" ? "文件夹" : getFileTypeName(extname)}</p> | ||
{props.type === "file" && <p>大小:{formatSize(size)}</p>} | ||
</div> | ||
} | ||
placement="bottom"> | ||
<div | ||
className="flex-1 flex justify-center items-center pt-5 cursor-pointer" | ||
onDoubleClick={() => handleOpen()} | ||
onContextMenu={onContextMenu}> | ||
{ | ||
props.type === "folder" | ||
? getFolderIcon(props.name, 34) | ||
: getFileIcon(extname ?? "", 34) | ||
} | ||
</div> | ||
</Tooltip> | ||
|
||
<button | ||
className="w-full text-center text-sm overflow-hidden whitespace-nowrap text-ellipsis cursor-pointer hover:underline hover:text-primary-500" | ||
onDoubleClick={() => handleOpen()} | ||
onContextMenu={onContextMenu}> | ||
{props.name} | ||
</button> | ||
|
||
{contextMenu} | ||
</div> | ||
); | ||
} | ||
|
||
export default ExplorerGridViewItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"use client"; | ||
|
||
import type { ViewProps } from "@/types"; | ||
|
||
import React from "react"; | ||
import { cn } from "@nextui-org/theme"; | ||
|
||
import ExplorerItem from "./explorer-item"; | ||
import ExplorerError from "./explorer-error"; | ||
|
||
import { scrollbarStyle } from "@/lib/style"; | ||
|
||
interface GridViewProps extends ViewProps {} | ||
|
||
const ExplorerGridView: React.FC<GridViewProps> = ({ items, error, contextMenu, onContextMenu }) => { | ||
return ( | ||
<div className="w-[730px] flex mt-2"> | ||
<div | ||
className={cn("w-full flex-1 grid grid-rows-[repeat(auto-fill,7rem)] grid-cols-[repeat(auto-fill,6.5rem)] gap-4 overflow-y-auto pr-2", scrollbarStyle)} | ||
onContextMenu={onContextMenu}> | ||
{ | ||
!error | ||
? items.map((item, index) => ( | ||
item.access | ||
? <ExplorerItem {...item} displayingMode="grid" key={index}/> | ||
: null // To hide inaccessible items | ||
)) | ||
: <ExplorerError error={error}/> | ||
} | ||
</div> | ||
|
||
{contextMenu} | ||
</div> | ||
); | ||
} | ||
|
||
export default ExplorerGridView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"use client"; | ||
|
||
import type { ViewItemProps } from "@/types"; | ||
|
||
import React from "react"; | ||
import { Checkbox } from "@nextui-org/checkbox"; | ||
import { Divider } from "@nextui-org/divider"; | ||
|
||
import { getFileIcon, getFolderIcon } from "./explorer-item"; | ||
|
||
import { formatSize, getFileTypeName } from "@/lib/utils"; | ||
|
||
interface ListViewItemProps extends ViewItemProps {} | ||
|
||
const ExplorerListViewItem: React.FC<ListViewItemProps> = ({ | ||
extname, selected, contextMenu, setSelected, handleSelection, handleOpen, onContextMenu, ...props | ||
}) => { | ||
return ( | ||
<div | ||
className="w-full min-h-8 text-md flex items-center gap-4" | ||
onClick={() => handleSelection()} | ||
onKeyDown={({ key }) => { | ||
key === "Enter" && handleSelection(); | ||
}} | ||
role="button" | ||
tabIndex={0}> | ||
<div className="w-[2%] flex items-center"> | ||
<Checkbox | ||
className="" | ||
size="sm" | ||
isSelected={selected} | ||
onValueChange={(value) => setSelected(value)}/> | ||
</div> | ||
|
||
<div className="flex-[2] min-w-0 flex items-center gap-2"> | ||
{( | ||
props.type === "folder" ? getFolderIcon(props.name, 20, "#9e9e9e") : getFileIcon(extname ?? "txt", 20, "#9e9e9e") | ||
) as React.ReactNode} | ||
<button | ||
className="text-ellipsis whitespace-nowrap cursor-pointer overflow-hidden hover:underline hover:text-primary-500" | ||
onDoubleClick={() => handleOpen()} | ||
onContextMenu={onContextMenu}> | ||
{props.name} | ||
</button> | ||
</div> | ||
|
||
<Divider orientation="vertical" className="bg-transparent"/> | ||
|
||
<span className="flex-1 text-default-400 text-sm cursor-default">{props.type === "folder" ? "文件夹" : getFileTypeName(extname)}</span> | ||
|
||
<Divider orientation="vertical" className="bg-transparent"/> | ||
|
||
<span className="flex-1 text-default-400 text-right text-sm cursor-default">{props.type === "file" ? formatSize(props.size) : ""}</span> | ||
|
||
{contextMenu} | ||
</div> | ||
); | ||
} | ||
|
||
export default ExplorerListViewItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"use client"; | ||
|
||
import type { ViewProps } from "@/types"; | ||
|
||
import React from "react"; | ||
import { cn } from "@nextui-org/theme"; | ||
import { Divider } from "@nextui-org/divider"; | ||
|
||
import ExplorerItem from "./explorer-item"; | ||
import ExplorerError from "./explorer-error"; | ||
|
||
import { scrollbarStyle } from "@/lib/style"; | ||
|
||
interface ListViewProps extends ViewProps {} | ||
|
||
const ExplorerListView: React.FC<ListViewProps> = ({ items, error, contextMenu, onContextMenu }) => { | ||
return ( | ||
<div className="w-[730px] flex flex-col gap-1"> | ||
<div className="w-full h-6 text-sm flex items-center gap-4 pr-5"> | ||
<div className="w-[2%]"/> {/* placeholder */} | ||
<span className="flex-[2] cursor-default">名称</span> | ||
<Divider orientation="vertical"/> | ||
<span className="flex-1 cursor-default">类型</span> | ||
<Divider orientation="vertical"/> | ||
<span className="flex-1 cursor-default">大小</span> | ||
</div> | ||
|
||
<div | ||
className={cn("w-full relative flex-1 flex flex-col overflow-y-auto pr-5", scrollbarStyle)} | ||
onContextMenu={onContextMenu}> | ||
{ | ||
!error | ||
? items.map((item, index) => ( | ||
item.access | ||
? <ExplorerItem {...item} displayingMode="list" key={index}/> | ||
: null // To hide inaccessible items | ||
)) | ||
: <ExplorerError error={error}/> | ||
} | ||
</div> | ||
|
||
{contextMenu} | ||
</div> | ||
); | ||
} | ||
|
||
export default ExplorerListView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.