| 1 | import type { MouseEvent as ReactMouseEvent } from "react"; |
| 2 | import { FolderPlus, Server } from "lucide-react"; |
| 3 | |
| 4 | import { ContextMenu, type ContextMenuItem, type ContextMenuPoint } from "./ContextMenu"; |
| 5 | import { Tooltip } from "./Tooltip"; |
| 6 | |
| 7 | export function projectTreeHeaderAddItems({ |
| 8 | blankLabel, |
| 9 | localLabel, |
| 10 | remoteLabel, |
| 11 | disabled, |
| 12 | onBlank, |
| 13 | onLocal, |
| 14 | onRemote, |
| 15 | }: { |
| 16 | blankLabel?: string; |
| 17 | localLabel: string; |
| 18 | remoteLabel: string; |
| 19 | disabled: boolean; |
| 20 | onBlank?: () => void; |
| 21 | onLocal: () => void; |
| 22 | onRemote: () => void; |
| 23 | }): ContextMenuItem[] { |
| 24 | const items: ContextMenuItem[] = []; |
| 25 | if (onBlank && blankLabel) { |
| 26 | items.push({ key: "blank-project", icon: <FolderPlus size={13} />, label: blankLabel, disabled, onSelect: onBlank }); |
| 27 | } |
| 28 | items.push( |
| 29 | { key: "open-local-folder", icon: <FolderPlus size={13} />, label: localLabel, disabled, onSelect: onLocal }, |
| 30 | { key: "remote-connection", icon: <Server size={13} />, label: remoteLabel, onSelect: onRemote }, |
| 31 | ); |
| 32 | return items; |
| 33 | } |
| 34 | |
| 35 | export function ProjectTreeHeaderAddControl({ |
| 36 | open, |
| 37 | point, |
| 38 | items, |
| 39 | label, |
| 40 | disabled, |
| 41 | onOpen, |
| 42 | onClose, |
| 43 | }: { |
| 44 | open: boolean; |
| 45 | point: ContextMenuPoint | null; |
| 46 | items: ContextMenuItem[]; |
| 47 | label: string; |
| 48 | disabled: boolean; |
| 49 | onOpen: (event: ReactMouseEvent<HTMLButtonElement>) => void; |
| 50 | onClose: () => void; |
| 51 | }) { |
| 52 | return ( |
| 53 | <span className="project-tree__header-menu-wrap"> |
| 54 | <Tooltip label={label} className="project-tree__action-slot project-tree__header-action-slot project-tree__action-slot--add"> |
| 55 | <button |
| 56 | type="button" |
| 57 | className={`project-tree__add-project${open ? " project-tree__header-icon-btn--active" : ""}`} |
| 58 | aria-label={label} |
| 59 | aria-haspopup="menu" |
| 60 | aria-expanded={open} |
| 61 | disabled={disabled} |
| 62 | onClick={onOpen} |
| 63 | > |
| 64 | <FolderPlus size={14} /> |
| 65 | </button> |
| 66 | </Tooltip> |
| 67 | <ContextMenu open={open} point={point} items={items} minWidth={206} ariaLabel={label} onClose={onClose} /> |
| 68 | </span> |
| 69 | ); |
| 70 | } |
| 71 | |
| 72 | export function ProjectTreeRemoteAction({ label, disabled, onClick }: { label: string; disabled: boolean; onClick: () => void }) { |
| 73 | return ( |
| 74 | <button type="button" className="project-tree__empty-secondary" onClick={onClick} disabled={disabled}> |
| 75 | <Server size={14} /> |
| 76 | <span>{label}</span> |
| 77 | </button> |
| 78 | ); |
| 79 | } |
| 80 |