-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(info): make sub-tabs more distinct looking
The info page /info/policies/* have two layers of tabs, which should be more distinct looking to easily distinguish the two layers. This commit fixes that by making the sub-tab selector a button group.
- Loading branch information
1 parent
b6030be
commit 0b9ed1f
Showing
4 changed files
with
88 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { ReactElement } from "react"; | ||
import ToggleButton from "@mui/material/ToggleButton"; | ||
import ToggleButtonGroup from "@mui/material/ToggleButtonGroup"; | ||
import { useRouter } from "next/dist/client/router"; | ||
import stringSimilarity from "string-similarity"; | ||
import NextLink from "next/link"; | ||
import { Box } from "@mui/system"; | ||
|
||
export interface DynamicSubNavProps { | ||
tabs: { | ||
label: string; | ||
href: string; | ||
}[]; | ||
} | ||
|
||
const DynamicSubNavInner = ({ | ||
selectedHref, | ||
tabs, | ||
small, | ||
}: { | ||
selectedHref: string | null; | ||
tabs: { label: string; href: string }[]; | ||
small?: boolean; | ||
}): ReactElement => ( | ||
<Box | ||
sx={{ | ||
display: small ? { xs: "flex", sm: "none" } : { xs: "none", sm: "flex" }, | ||
justifyContent: "center", | ||
my: 4, | ||
}} | ||
> | ||
<ToggleButtonGroup | ||
value={selectedHref} | ||
exclusive | ||
orientation={small ? "vertical" : "horizontal"} | ||
> | ||
{tabs.map(({ label, href }) => ( | ||
<ToggleButton | ||
value={href} | ||
tabIndex={-1} | ||
selected={selectedHref === href} | ||
key={href} | ||
sx={{ | ||
p: 0, | ||
borderRadius: "1rem", | ||
}} | ||
> | ||
<NextLink | ||
href={href} | ||
role="tab" | ||
style={{ | ||
color: "inherit", | ||
padding: "0.5rem 0.6rem", | ||
textDecoration: "none", | ||
}} | ||
> | ||
{label} | ||
</NextLink> | ||
</ToggleButton> | ||
))} | ||
</ToggleButtonGroup> | ||
</Box> | ||
); | ||
|
||
export default function DynamicSubNav({ tabs }: DynamicSubNavProps) { | ||
const router = useRouter(); | ||
|
||
const selectedHref = | ||
tabs[ | ||
stringSimilarity.findBestMatch( | ||
router.route, | ||
tabs.map((tab) => tab.href) | ||
).bestMatchIndex | ||
]?.href ?? null; | ||
|
||
return ( | ||
<> | ||
<DynamicSubNavInner selectedHref={selectedHref} tabs={tabs} /> | ||
<DynamicSubNavInner selectedHref={selectedHref} tabs={tabs} small /> | ||
</> | ||
); | ||
} |
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
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