-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
polish shared/RoutedTabsHeader & introduce RoutedTabsHeader.module.css
- Loading branch information
Showing
4 changed files
with
104 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
app/components/shared/RoutedTabsHeader/RoutedTabsHeader.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
.tabs { | ||
position: absolute; | ||
bottom: 0px; | ||
left: 100px; | ||
white-space: nowrap; | ||
} | ||
|
||
.tabs > .tab { | ||
line-height: 35px; | ||
margin-right: 55px; | ||
} | ||
|
||
.tabs > .tab:last-of-type { | ||
margin-right: 0; | ||
} | ||
|
||
.tabs > .tabCaret > { | ||
position: absolute; | ||
bottom: 0; | ||
height: 5px; | ||
} | ||
|
||
.tabs > .tabCaret > .active { | ||
background-color: var(--accent-color); | ||
position: absolute; | ||
height: 5px; | ||
} | ||
|
||
@media screen and (max-width: 1179px) { | ||
.tabs { | ||
left: 55px; | ||
} | ||
} | ||
|
||
@media screen and (max-width: 768px) { | ||
.tabs { | ||
font-size: 13px; | ||
left: 25px; | ||
right: 20px; | ||
} | ||
|
||
.tabs > .tab { | ||
margin-right: 45px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,45 @@ | ||
import { useEffect, useCallback, useState, useRef } from "react"; | ||
import { useSelector } from "react-redux"; | ||
import * as sel from "selectors"; | ||
|
||
export function useRoutedTabsHeader() { | ||
const location = useSelector(sel.location); | ||
const nodes = useRef(new Map()); | ||
const [caretLeft, setCaretLeft] = useState(null); | ||
const [caretWidth, setCaretWidth] = useState(null); | ||
const [selectedTab, setSelectedTab] = useState(null); | ||
const [localSidebarOnBottom, setLocalSidebarOnBottom] = useState(null); | ||
const { pathname } = useSelector(sel.location); | ||
const sidebarOnBottom = useSelector(sel.sidebarOnBottom); | ||
const uiAnimations = useSelector(sel.uiAnimations); | ||
|
||
return { | ||
location, | ||
const updateCaretPosition = useCallback(() => { | ||
const selectedTab = pathname; | ||
const tabForRoute = nodes.current.get(selectedTab); | ||
if (!tabForRoute) return null; | ||
const tabRect = tabForRoute.getBoundingClientRect(); | ||
const caretLeft = tabForRoute.offsetLeft; | ||
const caretWidth = tabRect.width; | ||
setCaretLeft(caretLeft); | ||
setCaretWidth(caretWidth); | ||
setSelectedTab(selectedTab); | ||
}, [pathname]); | ||
|
||
useEffect(() => { | ||
setLocalSidebarOnBottom(sidebarOnBottom); | ||
updateCaretPosition(); | ||
}, [sidebarOnBottom, updateCaretPosition]); | ||
|
||
useEffect(() => { | ||
if (selectedTab != pathname || localSidebarOnBottom != sidebarOnBottom) { | ||
updateCaretPosition(); | ||
} | ||
}, [ | ||
pathname, | ||
selectedTab, | ||
sidebarOnBottom, | ||
uiAnimations | ||
}; | ||
localSidebarOnBottom, | ||
updateCaretPosition | ||
]); | ||
|
||
return { uiAnimations, caretLeft, caretWidth, nodes }; | ||
} |