MCPcopy Create free account
hub / github.com/dailydotdev/apps / tabAt

Function tabAt

packages/shared/src/components/shell/ShellCluster.tsx:242–258  ·  view source on GitHub ↗
(clientX: number)

Source from the content-addressed store, hash-verified

240 // the pill moves in the bar's own, unscaled pixels: map through the
241 // layout width so the pill stops at the right edge as it does at the left.
242 const tabAt = (clientX: number) => {
243 const track = trackRef.current;
244 const rect = track?.getBoundingClientRect();
245 if (!track || !rect || !rect.width) {
246 return null;
247 }
248 const trackWidth = track.offsetWidth || rect.width;
249 const width = trackWidth / tabs.length;
250 const x = ((clientX - rect.left) / rect.width) * trackWidth;
251 return {
252 left: Math.min(Math.max(x - width / 2, 0), trackWidth - width),
253 index: Math.min(
254 tabs.length - 1,
255 Math.floor(clamp(x / trackWidth) * tabs.length),
256 ),
257 };
258 };
259
260 const onPointerDown = (event: React.PointerEvent<HTMLDivElement>) => {
261 if (event.pointerType === 'mouse' && event.button !== 0) {

Callers 2

onPointerMoveFunction · 0.85
onPointerUpFunction · 0.85

Calls 1

clampFunction · 0.90

Tested by

no test coverage detected