MCPcopy
hub / github.com/wavetermdev/waveterm / setSizeAndPosition

Function setSizeAndPosition

frontend/app/tab/tabbar.tsx:176–247  ·  view source on GitHub ↗
(animate?: boolean)

Source from the content-addressed store, hash-verified

174 }, []);
175
176 const setSizeAndPosition = (animate?: boolean) => {
177 const tabBar = tabBarRef.current;
178 if (tabBar === null) return;
179
180 const getOuterWidth = (el: HTMLElement): number => {
181 const rect = el.getBoundingClientRect();
182 const style = getComputedStyle(el);
183 return rect.width + parseFloat(style.marginLeft) + parseFloat(style.marginRight);
184 };
185
186 const tabbarWrapperWidth = tabbarWrapperRef.current.getBoundingClientRect().width;
187 const windowDragLeftWidth = draggerLeftRef.current.getBoundingClientRect().width;
188 const rightContainerWidth = rightContainerRef.current?.getBoundingClientRect().width ?? 0;
189 const addBtnWidth = getOuterWidth(addBtnRef.current);
190 const appMenuButtonWidth = appMenuButtonRef.current?.getBoundingClientRect().width ?? 0;
191 const workspaceSwitcherWidth = workspaceSwitcherRef.current?.getBoundingClientRect().width ?? 0;
192 const waveAIButtonWidth =
193 !hideAiButton && waveAIButtonRef.current != null ? getOuterWidth(waveAIButtonRef.current) : 0;
194
195 const nonTabElementsWidth =
196 windowDragLeftWidth +
197 rightContainerWidth +
198 addBtnWidth +
199 appMenuButtonWidth +
200 workspaceSwitcherWidth +
201 waveAIButtonWidth;
202 const spaceForTabs = tabbarWrapperWidth - nonTabElementsWidth;
203
204 const numberOfTabs = tabIds.length;
205
206 // Compute the ideal width per tab by dividing the available space by the number of tabs
207 let idealTabWidth = spaceForTabs / numberOfTabs;
208
209 // Apply min/max constraints
210 idealTabWidth = Math.max(TabMinWidth, Math.min(idealTabWidth, TabDefaultWidth));
211
212 // Determine if the tab bar needs to be scrollable
213 const newScrollable = idealTabWidth * numberOfTabs > spaceForTabs;
214
215 // Apply the calculated width and position to all tabs
216 tabRefs.current.forEach((ref, index) => {
217 if (ref.current) {
218 if (animate) {
219 ref.current.classList.add("animate");
220 } else {
221 ref.current.classList.remove("animate");
222 }
223 ref.current.style.width = `${idealTabWidth}px`;
224 ref.current.style.transform = `translate3d(${index * idealTabWidth}px,0,0)`;
225 ref.current.style.opacity = "1";
226 }
227 });
228
229 // Update the state with the new tab width if it has changed
230 if (idealTabWidth !== tabWidthRef.current) {
231 tabWidthRef.current = idealTabWidth;
232 }
233

Callers 1

tabbar.tsxFile · 0.85

Calls 2

getOuterWidthFunction · 0.85
destroyMethod · 0.45

Tested by

no test coverage detected