-
Notifications
You must be signed in to change notification settings - Fork 12
feat(layout): add page tabs and a header page title #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
79acc3e
feat(layout): add page tabs to routes
CammilleCC b45a6fe
feat(layout): show the active page title in the header
CammilleCC 125afec
docs(layout): document page tabs and the header page title
CammilleCC 0783e1c
refactor(layout): group the layout components in a FinchAppLayout folder
CammilleCC 2a0536c
style(layout): use default tailwind sizes for page tabs
CammilleCC 14edc00
feat(layout): normalize route and tab paths and reject colliding pages
CammilleCC 430ab74
fix(layout): keep the sidebar route active while one of its tabs shows
CammilleCC 150f03d
feat(layout): add a layout page title toggle, drop the root exception
CammilleCC 8b894eb
docs(layout): document page paths, root tabs, and the page title default
CammilleCC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,77 @@ | ||
| import { useRoutes } from 'react-router'; | ||
| import FinchPageTabs from './FinchPageTabs'; | ||
| import { useActiveRoute } from './hooks/useActiveRoute'; | ||
| import { buildPageRoutes } from './utils/pageRoutes'; | ||
| import { cn } from '@/lib/utils'; | ||
|
|
||
| import { RouteItem, RouteTab } from '@/types/navigationRouterTypes'; | ||
|
|
||
| export type FinchMainContentProps = { | ||
| /** Route definitions used to render the matched page component via React Router. */ | ||
| routes: RouteItem[]; | ||
| /** Additional CSS classes applied to the main outer element. */ | ||
| className?: string; | ||
| /** Additional CSS classes applied to the scrolling element that holds the page padding. */ | ||
| classNameScrollContainer?: string; | ||
| /** Additional CSS classes applied to the inner element directly rendering the route element. */ | ||
| classNameInnerContainer?: string; | ||
| /** Additional CSS classes applied to the page tab strip. */ | ||
| classNamePageTabs?: string; | ||
| /** Additional CSS classes applied to the active page tab. */ | ||
| classNamePageTabsActive?: string; | ||
| /** Additional CSS classes applied to inactive page tabs. */ | ||
| classNamePageTabsInactive?: string; | ||
| }; | ||
| export default function FinchMainContent({ | ||
| routes, | ||
| className, | ||
| classNameScrollContainer, | ||
| classNameInnerContainer, | ||
| classNamePageTabs, | ||
| classNamePageTabsActive, | ||
| classNamePageTabsInactive, | ||
| ...props | ||
| }: FinchMainContentProps) { | ||
| const activeRoute = useActiveRoute(routes); | ||
|
|
||
| const page = (route: RouteItem, tab?: RouteTab) => { | ||
| const item = tab ?? route; | ||
| const isBackgroundTransparent = | ||
| tab?.isBackgroundTransparent ?? route.isBackgroundTransparent; | ||
| return ( | ||
| <section | ||
| className={cn( | ||
| isBackgroundTransparent ? 'bg-transparent text-white' : 'bg-white', | ||
| 'w-full h-full rounded-md', | ||
| classNameInnerContainer, | ||
| route.classNameContainer, | ||
| tab?.classNameContainer, | ||
| )} | ||
| > | ||
| {item.element} | ||
| </section> | ||
| ); | ||
| }; | ||
|
|
||
| const pages = useRoutes(buildPageRoutes(routes, page)); | ||
|
|
||
| return ( | ||
| <main | ||
| className={cn('bg-sky-900 h-full w-full flex flex-col overflow-hidden', className)} | ||
| {...props} | ||
| > | ||
| {activeRoute?.tabs?.length ? ( | ||
| <FinchPageTabs | ||
| basePath={activeRoute.path} | ||
| tabs={activeRoute.tabs} | ||
| className={classNamePageTabs} | ||
| classNameActiveTab={classNamePageTabsActive} | ||
| classNameInactiveTab={classNamePageTabsInactive} | ||
| /> | ||
| ) : null} | ||
| <div className={cn('flex-1 min-h-0 overflow-y-auto p-8', classNameScrollContainer)}> | ||
| {pages} | ||
| </div> | ||
| </main> | ||
| ); | ||
| } |
This file contains hidden or 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,59 @@ | ||
| import { NavLink } from 'react-router'; | ||
| import { toTabPath } from './utils/pageRoutes'; | ||
| import { cn } from '@/lib/utils'; | ||
|
|
||
| import { RouteTab } from '@/types/navigationRouterTypes'; | ||
|
|
||
| export type FinchPageTabsProps = { | ||
| /** Path of the route these tabs belong to, used to build each tab link. */ | ||
| basePath: string; | ||
| /** Tab definitions rendered as links, in order. */ | ||
| tabs: Pick<RouteTab, 'path' | 'label'>[]; | ||
| /** Additional CSS classes applied to the root nav element. */ | ||
| className?: string; | ||
| /** Additional CSS classes applied to the active tab link. */ | ||
| classNameActiveTab?: string; | ||
| /** Additional CSS classes applied to inactive tab links. */ | ||
| classNameInactiveTab?: string; | ||
| }; | ||
|
|
||
| const tabStyles = 'self-end px-4 py-3 text-sm font-medium border-b-2 transition-colors'; | ||
|
|
||
| /** Strip of tab links rendered above a page whose route declares `tabs`. */ | ||
| export default function FinchPageTabs({ | ||
| basePath, | ||
| tabs, | ||
| className, | ||
| classNameActiveTab, | ||
| classNameInactiveTab, | ||
| ...props | ||
| }: FinchPageTabsProps) { | ||
| return ( | ||
| <nav | ||
| className={cn( | ||
| 'flex gap-1 px-7 h-12 items-stretch shrink-0 bg-black/[0.14] border-b border-white/10', | ||
| className, | ||
| )} | ||
| {...props} | ||
| > | ||
| {tabs.map((tab) => ( | ||
| <NavLink | ||
| key={tab.path} | ||
| to={toTabPath({ basePath, tab })} | ||
| end | ||
| className={({ isActive }) => | ||
| cn( | ||
| tabStyles, | ||
| isActive | ||
| ? 'text-white border-sky-300' | ||
| : 'text-white/60 border-transparent hover:text-white/80', | ||
| isActive ? classNameActiveTab : classNameInactiveTab, | ||
| ) | ||
| } | ||
| > | ||
| {tab.label} | ||
| </NavLink> | ||
| ))} | ||
| </nav> | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.