Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions src/layouts/page-layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,39 @@
*/

import { Content, Theme } from '@carbon/react';
import { Suspense } from 'react';
import { Children, Suspense } from 'react';
import { Nav } from '../components/nav/Nav';
import classNames from 'classnames';
import { useThemeContext } from '../context/ThemeContext';

export const PageLayout = ({
children,
className,
fallback,
renderPageHeader,
}) => {
export const PageLayout = ({ children, className, fallback }) => {
const { theme } = useThemeContext();
const childArray = Children.toArray(children);
console.log(childArray);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

const otherChildren = childArray.filter(
(child) => child.type !== PageLayoutHeader,
);
const Header = childArray.find((child) => child.type === PageLayoutHeader);

console.log(Header);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove console log


return (
<Suspense fallback={fallback}>
<div className={classNames('cs--page-layout', className)}>
<Nav />
<Theme theme={theme} as={Content}>
<div className="cs--page-layout__content">
{renderPageHeader && (
<div className="cs--page-layout__content-header">
{renderPageHeader()}
</div>
)}
<div className="cs--page-layout__content-body">{children}</div>
{Header}
<div className="cs--page-layout__content-body">{otherChildren}</div>
</div>
</Theme>
</div>
</Suspense>
);
};

const PageLayoutHeader = ({ children }) => (
<div className="cs--page-layout__content-header">{children}</div>
);
PageLayoutHeader.displayName = 'PageLayoutHeader';
PageLayout.Header = PageLayoutHeader;
4 changes: 4 additions & 0 deletions src/pages/dashboard/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Column, Grid, Tile } from '@carbon/react';

import { Footer } from '../../components/footer/Footer';
import { PageLayout } from '../../layouts/page-layout';
import { PageHeader } from '@carbon/ibm-products';

// The styles are imported into index.scss by default.
// Do the same unless you have a good reason not to.
Expand All @@ -32,6 +33,9 @@ const Dashboard = () => {
className="cs--dashboard"
fallback={<p>Loading dashboard page...</p>}
>
<PageLayout.Header>
<PageHeader title="Dashboard" />
</PageLayout.Header>
<Grid>
<NumberTile />
<NumberTile />
Expand Down
Loading