-
Notifications
You must be signed in to change notification settings - Fork 11
feat(Tabs): add logic for component tabs & nav routing #38
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
6 commits
Select commit
Hold shift + click to select a range
f036260
feat(Tabs): add logic for component tabs & nav routing
kmcfaul 7db63cc
clean up some commented code
kmcfaul e060403
include demos and deprecated
kmcfaul a16dd50
clean up PR for review
kmcfaul 8edf33c
more cleanup, move tabs logic out a bit, update nav for layouts
kmcfaul bf21743
clean up buildTab
kmcfaul 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
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 |
|---|---|---|
| @@ -1 +1,14 @@ | ||
| export const content = [{ base: 'textContent', pattern: '*.md', name: "textContent" }, { base: 'dir', pattern: '*.md', name: "dir" }] | ||
| export const content = [ | ||
| { base: 'textContent', pattern: '*.md', name: "textContent" } | ||
| // TODO: Remove. Uncomment for local testing. | ||
| // { | ||
| // "packageName":"@patternfly/react-core", | ||
| // "pattern":"**/examples/**/*.md", // had to update this pattern to bring in demos docs | ||
| // "name":"react-component-docs" | ||
| // }, | ||
| // { | ||
| // "packageName":"@patternfly/patternfly", | ||
| // "pattern":"**/examples/**/*.md", // had to update this pattern to bring in demos docs | ||
| // "name":"core-component-docs" | ||
| // } | ||
| ] |
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,53 @@ | ||
| export const componentTabs: any = {}; | ||
|
|
||
| export const tabNames: any = { | ||
| 'react': 'React', | ||
| 'react-demos': 'React demos', | ||
| 'react-deprecated': 'React deprecated', | ||
| 'html': 'HTML', | ||
| 'html-demos': 'HTML demos' | ||
| }; | ||
|
|
||
| export const buildTab = (entry: any, tab: string) => { | ||
| const tabEntry = componentTabs[entry.data.id] | ||
|
|
||
| // if no dictionary entry exists, and tab data exists | ||
| if(tabEntry === undefined && tab) { | ||
| componentTabs[entry.data.id] = [tab] | ||
| // if dictionary entry & tab data exists, and entry does not include tab | ||
| } else if (tabEntry && tab && !tabEntry.includes(tab)) { | ||
| componentTabs[entry.data.id] = [...tabEntry, tab]; | ||
| } | ||
| } | ||
|
|
||
| export const sortTabs = () => { | ||
| const defaultOrder = 50; | ||
| const sourceOrder: any = { | ||
| react: 1, | ||
| 'react-next': 1.1, | ||
| 'react-demos': 2, | ||
| 'react-deprecated': 2.1, | ||
| html: 3, | ||
| 'html-demos': 4, | ||
| 'design-guidelines': 99, | ||
| 'accessibility': 100, | ||
| 'upgrade-guide': 101, | ||
| 'release-notes': 102, | ||
| }; | ||
|
|
||
| const sortSources = (s1: string, s2: string) => { | ||
| const s1Index = sourceOrder[s1] || defaultOrder; | ||
| const s2Index = sourceOrder[s2] || defaultOrder; | ||
| if (s1Index === defaultOrder && s2Index === defaultOrder) { | ||
| return s1.localeCompare(s2); | ||
| } | ||
|
|
||
| return s1Index > s2Index ? 1 : -1; | ||
| } | ||
|
|
||
| // Sort tabs entries based on above sort order | ||
| // Ensures all tabs are displayed in a consistent order & which tab gets displayed for a component route without a tab | ||
| Object.values(componentTabs).map((tabs: any) => { | ||
| tabs.sort(sortSources) | ||
| }) | ||
| } |
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,71 @@ | ||
| --- | ||
| import { getCollection, render } from 'astro:content' | ||
| import { Title, PageSection, Content as PFContent } from '@patternfly/react-core' | ||
| import MainLayout from '../../../layouts/Main.astro' | ||
| import { content } from "../../../content" | ||
| import { kebabCase } from 'change-case' | ||
| import { componentTabs, tabNames, buildTab, sortTabs } from '../../../globals'; | ||
|
|
||
| export async function getStaticPaths() { | ||
| const collections = await Promise.all(content.map(async (entry) => await getCollection(entry.name as 'textContent'))) | ||
|
|
||
| const flatCol = collections.flat().map((entry) => { | ||
| // Build tabs dictionary | ||
| let tab = entry.data.tab; | ||
| if(tab) { // check for demos/deprecated | ||
| if(entry.id.includes('demos')) { | ||
| tab = `${tab}-demos`; | ||
| } else if (entry.id.includes('deprecated')) { | ||
| tab = `${tab}-deprecated`; | ||
| } | ||
| } | ||
| buildTab(entry, tab); | ||
|
|
||
| return { | ||
| params: { page: kebabCase(entry.data.id), section: entry.data.section, tab }, | ||
| props: { entry, ...entry.data }, | ||
| } | ||
| }) | ||
|
|
||
| sortTabs() | ||
| return flatCol; | ||
| } | ||
|
|
||
| const { entry } = Astro.props | ||
| const { title, id, section } = entry.data | ||
| const { Content } = await render(entry) | ||
| const currentPath = Astro.url.pathname; | ||
| --- | ||
|
|
||
| <MainLayout> | ||
| { | ||
| title && ( | ||
| <Title headingLevel="h1" size="4xl"> | ||
| {title} | ||
| </Title> | ||
| ) | ||
| } | ||
| {componentTabs[id] && ( | ||
| <PageSection id="ws-sticky-nav-tabs" stickyOnBreakpoint={{ default: 'top' }} type="tabs"> | ||
| <div class="pf-v6-c-tabs pf-m-page-insets pf-m-no-border-bottom"> | ||
| <ul class="pf-v6-c-tabs__list"> | ||
| {componentTabs[id].map((tab: string) => ( | ||
| // eslint-disable-next-line react/jsx-key | ||
| <li | ||
| class={`pf-v6-c-tabs__item${currentPath === `/${section}/${kebabCase(id)}/${tab}` ? ' pf-m-current' : ''}`} | ||
| > | ||
| <a class="pf-v6-c-tabs__link" href={`/${section}/${kebabCase(id)}/${tab}`}> | ||
| {tabNames[tab]} | ||
| </a> | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| </div> | ||
| </PageSection> | ||
| )} | ||
| <PageSection id="main-content" isFilled> | ||
| <PFContent> | ||
| <Content /> | ||
| </PFContent> | ||
| </PageSection> | ||
| </MainLayout> | ||
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.