Skip to content

Commit

Permalink
feat: make appchrome props optional (#907)
Browse files Browse the repository at this point in the history
Allows for someone to use just the header or sidebar without needing to
declare both. Also add children prop and deprecates mainContent because
its a lot easier to use with children, as it allows JSX to simply be
nested rather than part of a prop. Found these while trying to use this
component during innovation days.
  • Loading branch information
Russell Anderson authored Dec 12, 2022
1 parent 196e25d commit 37984f8
Showing 1 changed file with 40 additions and 9 deletions.
49 changes: 40 additions & 9 deletions packages/appChrome/components/AppChrome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,35 @@ import {
} from "./HeaderBar";

export interface AppChromeProps {
sidebar: React.ReactNode;
headerBar: React.ReactNode;
mainContent: React.ReactNode;
/**
* Optional className to apply to outermost div
*/
className?: string;
/**
* JSX to render along the left side
*/
sidebar?: React.ReactNode;
/**
* JSX to render as the navigation bar at the top
*/
headerBar?: React.ReactNode;
/**
* @deprecated This prop should not be used, use children instead
*/
mainContent?: React.ReactNode;
/**
* JSX for the main html element
*/
children?: React.ReactNode;
}

const AppChrome = ({ sidebar, headerBar, mainContent }: AppChromeProps) => {
const AppChrome = ({
className,
sidebar,
headerBar,
mainContent,
children
}: AppChromeProps) => {
return (
<ThemeProvider
theme={{
Expand All @@ -36,19 +59,27 @@ const AppChrome = ({ sidebar, headerBar, mainContent }: AppChromeProps) => {
}}
>
<div
className={cx(appChrome, textSize("m"), flex({ direction: "column" }))}
className={cx(
appChrome,
textSize("m"),
flex({ direction: "column" }),
className
)}
data-cy="appChrome"
>
<div data-cy="headerBar">{headerBar}</div>
{headerBar && <div data-cy="headerBar">{headerBar}</div>}
<div className={cx(flex(), appWrapper)}>
<div className={flexItem("shrink")} data-cy="sidebar">
{sidebar}
</div>
{sidebar && (
<div className={flexItem("shrink")} data-cy="sidebar">
{sidebar}
</div>
)}
<main
className={cx(flexItem("grow"), flush("left"), appWrapper)}
data-cy="main"
>
{mainContent}
{children}
</main>
</div>
</div>
Expand Down

0 comments on commit 37984f8

Please sign in to comment.