session-sortable-tab.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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">
  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">{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"
  40. variant="ghost"
  41. onClick={() => props.onTabClose(props.tab)}
  42. aria-label="Close tab"
  43. />
  44. </Tooltip>
  45. }
  46. hideCloseButton
  47. onMiddleClick={() => props.onTabClose(props.tab)}
  48. >
  49. <Show when={path()}>{(p) => <FileVisual path={p()} />}</Show>
  50. </Tabs.Trigger>
  51. </div>
  52. </div>
  53. )
  54. }