Yuchen Yuan commited on
Commit
62faa2c
·
1 Parent(s): d9a330d

TipIcon: add position prop; TopBar tooltip now opens below to stay in viewport

Browse files
frontend/src/components/TipIcon.tsx CHANGED
@@ -39,13 +39,22 @@ export function TipIcon({
39
  hint,
40
  className = "",
41
  size = 12,
 
42
  }: {
43
  hint: string;
44
  /** Extra classes on the wrapper (e.g. for inline alignment). */
45
  className?: string;
46
  /** Pixel size of the icon. Defaults to 12 to match small inline labels. */
47
  size?: number;
 
 
 
 
48
  }) {
 
 
 
 
49
  return (
50
  <span
51
  tabIndex={0}
@@ -62,7 +71,7 @@ export function TipIcon({
62
  />
63
  <span
64
  role="tooltip"
65
- className="hidden group-hover/tip:block group-focus/tip:block pointer-events-none absolute left-1/2 -translate-x-1/2 bottom-full mb-1 z-50 w-max max-w-[16rem] rounded-md border border-edge bg-surface text-ink shadow-lg px-2 py-1 text-[11px] leading-snug normal-case tracking-normal font-normal whitespace-normal text-left"
66
  >
67
  {hint}
68
  </span>
 
39
  hint,
40
  className = "",
41
  size = 12,
42
+ position = "above",
43
  }: {
44
  hint: string;
45
  /** Extra classes on the wrapper (e.g. for inline alignment). */
46
  className?: string;
47
  /** Pixel size of the icon. Defaults to 12 to match small inline labels. */
48
  size?: number;
49
+ /** Tooltip direction. Use `"below"` for elements near the top of the
50
+ * viewport (e.g. TopBar chips) so the tooltip doesn't overflow above
51
+ * the page. Defaults to `"above"`. */
52
+ position?: "above" | "below";
53
  }) {
54
+ const posClass =
55
+ position === "below"
56
+ ? "top-full mt-1"
57
+ : "bottom-full mb-1";
58
  return (
59
  <span
60
  tabIndex={0}
 
71
  />
72
  <span
73
  role="tooltip"
74
+ className={`hidden group-hover/tip:block group-focus/tip:block pointer-events-none absolute left-1/2 -translate-x-1/2 ${posClass} z-50 w-max max-w-[16rem] rounded-md border border-edge bg-surface text-ink shadow-lg px-2 py-1 text-[11px] leading-snug normal-case tracking-normal font-normal whitespace-normal text-left`}
75
  >
76
  {hint}
77
  </span>
frontend/src/components/TopBar.tsx CHANGED
@@ -123,7 +123,7 @@ export function TopBar({
123
  className={`chip transition-colors gap-1 ${chipClass}`}
124
  >
125
  <span>{mobile ? chipLabelShort : chipLabel}</span>
126
- <TipIcon hint={chipTitle} size={10} />
127
  </button>
128
  </div>
129
  </div>
 
123
  className={`chip transition-colors gap-1 ${chipClass}`}
124
  >
125
  <span>{mobile ? chipLabelShort : chipLabel}</span>
126
+ <TipIcon hint={chipTitle} size={10} position="below" />
127
  </button>
128
  </div>
129
  </div>