app-sidebar-section-header.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { TextAttributes } from "@mbears/opentui-core";
  2. import React from "react";
  3. import { palette } from "./app-model.js";
  4. import { SIDEBAR_CONTENT_WIDTH } from "./app-sidebar-layout.js";
  5. const h = React.createElement as (
  6. type: React.ElementType | string,
  7. props?: Record<string, unknown> | null,
  8. ...children: React.ReactNode[]
  9. ) => React.ReactElement;
  10. const EXPANDED_MARKER = "▼";
  11. const COLLAPSED_MARKER = "▶";
  12. const SIDEBAR_SECTION_HEADER_STYLE = {
  13. attributes: TextAttributes.BOLD,
  14. fg: palette.text,
  15. flexShrink: 0,
  16. height: 1,
  17. truncate: true,
  18. width: SIDEBAR_CONTENT_WIDTH,
  19. wrapMode: "none",
  20. };
  21. type MouseEventLike = {
  22. stopPropagation?: () => void;
  23. };
  24. export function SidebarSectionHeader(props: {
  25. expanded: boolean;
  26. onToggle?: () => void;
  27. title: string;
  28. }): React.ReactElement {
  29. const marker = props.expanded ? EXPANDED_MARKER : COLLAPSED_MARKER;
  30. return h(
  31. "text",
  32. {
  33. onMouseUp: (event: MouseEventLike) => {
  34. event.stopPropagation?.();
  35. props.onToggle?.();
  36. },
  37. selectable: false,
  38. style: SIDEBAR_SECTION_HEADER_STYLE,
  39. },
  40. `${marker} ${props.title}`,
  41. );
  42. }