session-sortable-tab.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { createMemo, Show } from "solid-js"
  2. import type { JSX } from "solid-js"
  3. import { createSortable } from "@thisbeyond/solid-dnd"
  4. import { FileIcon } from "@opencode-ai/ui/file-icon"
  5. import { IconButton } from "@opencode-ai/ui/icon-button"
  6. import { TooltipKeybind } from "@opencode-ai/ui/tooltip"
  7. import { Tabs } from "@opencode-ai/ui/tabs"
  8. import { getFilename } from "@opencode-ai/core/util/path"
  9. import { useFile } from "@/context/file"
  10. import { useLanguage } from "@/context/language"
  11. import { useCommand } from "@/context/command"
  12. export function FileVisual(props: { path: string; active?: boolean }): JSX.Element {
  13. return (
  14. <div class="flex items-center gap-x-1.5 min-w-0">
  15. <Show
  16. when={!props.active}
  17. fallback={<FileIcon node={{ path: props.path, type: "file" }} class="size-4 shrink-0" />}
  18. >
  19. <span class="relative inline-flex size-4 shrink-0">
  20. <FileIcon node={{ path: props.path, type: "file" }} class="absolute inset-0 size-4 tab-fileicon-color" />
  21. <FileIcon node={{ path: props.path, type: "file" }} mono class="absolute inset-0 size-4 tab-fileicon-mono" />
  22. </span>
  23. </Show>
  24. <span class="text-14-medium truncate">{getFilename(props.path)}</span>
  25. </div>
  26. )
  27. }
  28. export function SortableTab(props: { tab: string; onTabClose: (tab: string) => void }): JSX.Element {
  29. const file = useFile()
  30. const language = useLanguage()
  31. const command = useCommand()
  32. const sortable = createSortable(props.tab)
  33. const path = createMemo(() => file.pathFromTab(props.tab))
  34. const content = createMemo(() => {
  35. const value = path()
  36. if (!value) return
  37. return <FileVisual path={value} />
  38. })
  39. return (
  40. <div use:sortable class="h-full flex items-center" classList={{ "opacity-0": sortable.isActiveDraggable }}>
  41. <div class="relative">
  42. <Tabs.Trigger
  43. value={props.tab}
  44. closeButton={
  45. <TooltipKeybind
  46. title={language.t("common.closeTab")}
  47. keybind={command.keybind("tab.close")}
  48. placement="bottom"
  49. gutter={10}
  50. >
  51. <IconButton
  52. icon="close-small"
  53. variant="ghost"
  54. class="h-5 w-5"
  55. onClick={() => props.onTabClose(props.tab)}
  56. aria-label={language.t("common.closeTab")}
  57. />
  58. </TooltipKeybind>
  59. }
  60. hideCloseButton
  61. onMiddleClick={() => props.onTabClose(props.tab)}
  62. >
  63. <Show when={content()}>{(value) => value()}</Show>
  64. </Tabs.Trigger>
  65. </div>
  66. </div>
  67. )
  68. }