| 1 | import { getLastNPathParts } from "core/util/uri"; |
| 2 | import { MouseEventHandler } from "react"; |
| 3 | import FileIcon from "../../FileIcon"; |
| 4 | import { ToolTip } from "../../gui/Tooltip"; |
| 5 | |
| 6 | export interface FileInfoProps { |
| 7 | filepath: string; |
| 8 | onClick?: MouseEventHandler<HTMLDivElement>; |
| 9 | range?: string; |
| 10 | } |
| 11 | |
| 12 | const TOOLTIP_ID = "file-info-tooltip"; |
| 13 | |
| 14 | export const FileInfo = ({ filepath, range, onClick }: FileInfoProps) => { |
| 15 | return ( |
| 16 | <> |
| 17 | <div |
| 18 | className={`flex select-none flex-row items-center gap-0.5 ${onClick && "cursor-pointer hover:underline"}`} |
| 19 | onClick={onClick} |
| 20 | data-tooltip-id={TOOLTIP_ID} |
| 21 | data-tooltip-content={filepath} |
| 22 | data-tooltip-place="top-end" |
| 23 | > |
| 24 | <div> |
| 25 | <FileIcon height="20px" width="20px" filename={filepath} /> |
| 26 | </div> |
| 27 | <span className="line-clamp-1 break-all"> |
| 28 | {getLastNPathParts(filepath, 1)} |
| 29 | {range && ` ${range}`} |
| 30 | </span> |
| 31 | </div> |
| 32 | <ToolTip |
| 33 | id={TOOLTIP_ID} |
| 34 | style={{ |
| 35 | maxWidth: "200px", |
| 36 | textAlign: "left", |
| 37 | whiteSpace: "normal", |
| 38 | wordBreak: "break-word", |
| 39 | }} |
| 40 | /> |
| 41 | </> |
| 42 | ); |
| 43 | }; |