-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Use StudioContentMenu in ContentLibrary (#13927)
- Loading branch information
Showing
40 changed files
with
212 additions
and
225 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
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
3 changes: 1 addition & 2 deletions
3
...ContentLibrary/InfoBox/InfoBox.module.css → ...ry/LibraryBody/InfoBox/InfoBox.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
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
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
.../ContentLibrary/InfoBox/infoBoxConfigs.ts → ...ary/LibraryBody/InfoBox/infoBoxConfigs.ts
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
9 changes: 9 additions & 0 deletions
9
frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/LibraryBody.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,9 @@ | ||
.libraryContent { | ||
display: grid; | ||
grid-template-columns: 2fr 7fr 3fr; | ||
height: 100%; | ||
} | ||
|
||
.component { | ||
padding: var(--fds-spacing-10); | ||
} |
58 changes: 58 additions & 0 deletions
58
frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/LibraryBody.tsx
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,58 @@ | ||
import React from 'react'; | ||
import classes from './LibraryBody.module.css'; | ||
import { PagesRouter } from './PagesRouter'; | ||
import { InfoBox } from './InfoBox'; | ||
import type { PagePropsMap, PagesConfig } from '../../types/PagesProps'; | ||
import type { PageName } from '../../types/PageName'; | ||
import type { PageComponent } from '../../utils/router/RouterRouteMapper'; | ||
|
||
type LibraryBodyProps<T extends PageName> = { | ||
Component: PageComponent<PagePropsMap<T>>; | ||
pages: PagesConfig; | ||
currentPage: T; | ||
}; | ||
|
||
export function LibraryBody<T extends PageName>({ | ||
Component, | ||
pages, | ||
currentPage, | ||
}: LibraryBodyProps<T>) { | ||
const componentProps: PagePropsMap<T> = getComponentProps(pages, currentPage); | ||
|
||
return ( | ||
<div className={classes.libraryContent}> | ||
<PagesRouter pageNames={getAllPageNamesFromPagesConfig(pages)} /> | ||
<Page<T> Component={Component} componentProps={componentProps} currentPage={currentPage} /> | ||
</div> | ||
); | ||
} | ||
|
||
type PageProps<T extends PageName> = { | ||
Component: PageComponent<PagePropsMap<T>>; | ||
componentProps: PagePropsMap<T>; | ||
currentPage: T; | ||
}; | ||
|
||
function Page<T extends PageName>({ Component, componentProps, currentPage }: PageProps<T>) { | ||
return ( | ||
<> | ||
<div className={classes.component}> | ||
<Component {...componentProps} /> | ||
</div> | ||
<InfoBox pageName={currentPage} /> | ||
</> | ||
); | ||
} | ||
|
||
const getComponentProps = <T extends PageName>( | ||
pages: PagesConfig, | ||
currentPage: T, | ||
): PagePropsMap<T> => { | ||
if (currentPage === 'landingPage') return {} as PagePropsMap<T>; | ||
return pages[currentPage].props; | ||
}; | ||
|
||
const getAllPageNamesFromPagesConfig = (pages: PagesConfig): PageName[] => { | ||
const customPages = Object.keys(pages) as PageName[]; | ||
return ['landingPage', ...customPages]; | ||
}; |
28 changes: 14 additions & 14 deletions
28
...tLibrary/PagesRouter/PagesRouter.test.tsx → ...raryBody/PagesRouter/PagesRouter.test.tsx
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
32 changes: 32 additions & 0 deletions
32
...nd/libs/studio-content-library/src/ContentLibrary/LibraryBody/PagesRouter/PagesRouter.tsx
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,32 @@ | ||
import React from 'react'; | ||
import { useRouterContext } from '../../../contexts/RouterContext'; | ||
import type { PageName } from '../../../types/PageName'; | ||
import { useContentTabs } from '../../../hooks/useLibraryMenuContentTabs'; | ||
import { StudioContentMenu } from '@studio/components'; | ||
|
||
type PagesRouterProps = { | ||
pageNames: PageName[]; | ||
}; | ||
|
||
export function PagesRouter({ pageNames }: PagesRouterProps): React.ReactElement { | ||
const { navigate, currentPage } = useRouterContext(); | ||
const contentTabs = useContentTabs(); | ||
|
||
const handleNavigation = (pageToNavigateTo: PageName) => { | ||
navigate(pageToNavigateTo); | ||
}; | ||
|
||
return ( | ||
<StudioContentMenu selectedTabId={currentPage} onChangeTab={handleNavigation}> | ||
{pageNames.map((pageName) => ( | ||
<StudioContentMenu.LinkTab | ||
key={contentTabs[pageName].tabId} | ||
icon={contentTabs[pageName].icon} | ||
tabId={contentTabs[pageName].tabId} | ||
tabName={contentTabs[pageName].tabName} | ||
renderTab={contentTabs[pageName].renderTab} | ||
/> | ||
))} | ||
</StudioContentMenu> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/PagesRouter/index.ts
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 @@ | ||
export { PagesRouter } from './PagesRouter'; |
1 change: 1 addition & 0 deletions
1
frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/index.ts
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 @@ | ||
export { LibraryBody } from './LibraryBody'; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 6 additions & 5 deletions
11
...end/libs/studio-content-library/src/ContentLibrary/LibraryHeader/LibraryHeader.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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
.libraryHeading { | ||
display: flex; | ||
align-items: center; | ||
gap: var(--fds-spacing-1); | ||
padding: var(--fds-spacing-4); | ||
border-bottom: solid 1px var(--fds-semantic-border-neutral-subtle); | ||
} | ||
|
||
.libraryLandingPageNavigation { | ||
.headingIcon { | ||
display: flex; | ||
align-items: center; | ||
gap: var(--fds-spacing-1); | ||
cursor: pointer; | ||
width: fit-content; | ||
color: var(--fds-semantic-text-neutral-default); | ||
font-size: var(--fds-sizing-10); | ||
} |
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
Oops, something went wrong.