session-sortable-tab.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 { Tooltip } from "@opencode-ai/ui/tooltip"
  7. import { Tabs } from "@opencode-ai/ui/tabs"
  8. import { getFilename } from "@opencode-ai/util/path"
  9. import { useFile } from "@/context/file"
  10. import { useLanguage } from "@/context/language"
  11. export function FileVisual(props: { path: string; active?: boolean }): JSX.Element {
  12. return (
  13. <div class="flex items-center gap-x-1.5 min-w-0">
  14. <FileIcon
  15. node={{ path: props.path, type: "file" }}
  16. classList={{
  17. "grayscale-100 group-data-[selected]/tab:grayscale-0": !props.active,
  18. "grayscale-0": props.active,
  19. }}
  20. />
  21. <span class="text-14-medium truncate">{getFilename(props.path)}</span>
  22. </div>
  23. )
  24. }
  25. export function SortableTab(props: { tab: string; onTabClose: (tab: string) => void }): JSX.Element {
  26. const file = useFile()
  27. const language = useLanguage()
  28. const sortable = createSortable(props.tab)
  29. const path = createMemo(() => file.pathFromTab(props.tab))
  30. return (
  31. // @ts-ignore
  32. <div use:sortable classList={{ "h-full": true, "opacity-0": sortable.isActiveDraggable }}>
  33. <div class="relative h-full">
  34. <Tabs.Trigger
  35. value={props.tab}
  36. closeButton={
  37. <Tooltip value={language.t("common.closeTab")} placement="bottom">
  38. <IconButton
  39. icon="close-small"
  40. variant="ghost"
  41. class="h-5 w-5"
  42. onClick={() => props.onTabClose(props.tab)}
  43. aria-label={language.t("common.closeTab")}
  44. />
  45. </Tooltip>
  46. }
  47. hideCloseButton
  48. onMiddleClick={() => props.onTabClose(props.tab)}
  49. >
  50. <Show when={path()}>{(p) => <FileVisual path={p()} />}</Show>
  51. </Tabs.Trigger>
  52. </div>
  53. </div>
  54. )
  55. }