MCPcopy Create free account
hub / github.com/adobe/react-spectrum / TabLine

Function TabLine

packages/dev/s2-docs/src/Tabs.tsx:136–175  ·  view source on GitHub ↗
(props: TabLineProps)

Source from the content-addressed store, hash-verified

134});
135
136function TabLine(props: TabLineProps) {
137 let {selectedTab} = props;
138 let {direction} = useLocale();
139 let state = useContext(TabListStateContext);
140
141 let [style, setStyle] = useState<{
142 transform: string | undefined;
143 width: string | undefined;
144 height: string | undefined;
145 }>({
146 transform: undefined,
147 width: undefined,
148 height: undefined
149 });
150
151 let onResize = useCallback(() => {
152 if (selectedTab) {
153 let styleObj: {
154 transform: string | undefined;
155 width: string | undefined;
156 height: string | undefined;
157 } = {
158 transform: undefined,
159 width: undefined,
160 height: undefined
161 };
162
163 styleObj.transform = `translateY(${selectedTab.offsetTop}px)`;
164
165 styleObj.height = `${selectedTab.offsetHeight}px`;
166 setStyle(styleObj);
167 }
168 }, [setStyle, selectedTab]);
169
170 useLayoutEffect(() => {
171 onResize();
172 }, [onResize, state?.selectedItem?.key, direction]);
173
174 return <div style={{...style}} className={selectedIndicator} />;
175}
176
177const tab = style<
178 TabRenderProps & {

Callers

nothing calls this directly

Calls 3

useLocaleFunction · 0.90
setStyleFunction · 0.85
onResizeFunction · 0.50

Tested by

no test coverage detected