diff --git a/packages/index.ts b/packages/index.ts index 3b1cb041c..9a9fb00ae 100644 --- a/packages/index.ts +++ b/packages/index.ts @@ -65,7 +65,7 @@ export { LargeDialogModalWithFooter, FullscreenModal } from "./modal"; -export { PageHeader } from "./pageheader"; +export { PageHeader, PageHeaderTabs } from "./pageheader"; export { ProgressBar } from "./progressbar"; export { SegmentedControl, SegmentedControlButton } from "./segmentedControl"; export { SelectInput } from "./selectInput"; diff --git a/packages/pageheader/components/PageHeader.tsx b/packages/pageheader/components/PageHeader.tsx index 68352a0c1..83f74af9b 100644 --- a/packages/pageheader/components/PageHeader.tsx +++ b/packages/pageheader/components/PageHeader.tsx @@ -1,7 +1,6 @@ import * as React from "react"; - +import { cx } from "emotion"; import { default as Breadcrumb } from "../../breadcrumb/components/Breadcrumb"; - import { listReset, flex, @@ -10,46 +9,53 @@ import { display, border } from "../../shared/styles/styleUtils"; -import { cx } from "emotion"; +import { SpaceSizes } from "../../shared/styles/styleUtils/modifiers/modifierUtils"; +import PageHeaderTabs from "../components/PageHeaderTabs"; export interface PageHeaderProps { breadcrumbElements: React.ReactNodeArray; actions?: Array>; + children?: React.ReactNode; } +export const pageHeaderPaddingSize: SpaceSizes = "l"; + class PageHeader extends React.PureComponent { public render() { - const { breadcrumbElements, actions = [] } = this.props; + const { breadcrumbElements, actions = [], children } = this.props; + const hasTabsChild = React.Children.toArray(children).some( + child => React.isValidElement(child) && child.type === PageHeaderTabs + ); return (
-
- {breadcrumbElements} -
-
-
    - {actions.map(action => { - return ( -
  • - {action} -
  • - ); - })} -
+
+
+ {breadcrumbElements} +
+
+
    + {actions.map(action => { + return ( +
  • + {action} +
  • + ); + })} +
+
+ {children}
); } diff --git a/packages/pageheader/components/PageHeaderTabs.tsx b/packages/pageheader/components/PageHeaderTabs.tsx new file mode 100644 index 000000000..8bb5575bf --- /dev/null +++ b/packages/pageheader/components/PageHeaderTabs.tsx @@ -0,0 +1,19 @@ +import * as React from "react"; +import { css } from "react-emotion"; +import { spaceSizes } from "../../shared/styles/styleUtils/modifiers/modifierUtils"; +import { pageHeaderPaddingSize } from "./PageHeader"; + +const PageHeaderTabs = ({ children }) => { + return ( +
+ {children} +
+ ); +}; + +export default PageHeaderTabs; diff --git a/packages/pageheader/index.ts b/packages/pageheader/index.ts index 4fbd4bf63..291def1ae 100644 --- a/packages/pageheader/index.ts +++ b/packages/pageheader/index.ts @@ -1 +1,2 @@ export { default as PageHeader } from "./components/PageHeader"; +export { default as PageHeaderTabs } from "./components/PageHeaderTabs"; diff --git a/packages/pageheader/stories/PageHeader.stories.tsx b/packages/pageheader/stories/PageHeader.stories.tsx index b3505d9ae..f5685e874 100644 --- a/packages/pageheader/stories/PageHeader.stories.tsx +++ b/packages/pageheader/stories/PageHeader.stories.tsx @@ -2,9 +2,11 @@ import * as React from "react"; import { storiesOf } from "@storybook/react"; import { withReadme } from "storybook-readme"; -import { PageHeader } from "../index"; +import { PageHeader, PageHeaderTabs } from "../index"; import { PrimaryButton, SecondaryButton } from "../../button"; +import { SpacingBox } from "../../styleUtils/modifiers"; import PageHeaderOverflowMenu from "./helpers/PageHeaderOverflowMenu"; +import { Tabs, TabItem, TabTitle } from "../../tabs"; const readme = require("../README.md"); const action = () => alert("Action triggered"); @@ -54,4 +56,45 @@ storiesOf("PageHeader", module)
Earth
]} /> - )); + )) + .add("with children", () => ( + Universe
, +
Milky Way
, +
Earth
+ ]} + > + + This content is PageHeader children + + + )) + .add("with PageHeaderTabs", () => { + const tabOnSelect = selectedTab => { + alert(`${selectedTab} clicked`); + }; + + return ( + Universe, +
Milky Way
, +
Earth
+ ]} + > + + + + Tab 1 Name +
First tab Content
+
+ + Tab 2 Name + Second Tab Content + +
+
+
+ ); + }); diff --git a/packages/pageheader/tests/__snapshots__/PageHeader.test.tsx.snap b/packages/pageheader/tests/__snapshots__/PageHeader.test.tsx.snap index 2751a7909..aa45e2898 100644 --- a/packages/pageheader/tests/__snapshots__/PageHeader.test.tsx.snap +++ b/packages/pageheader/tests/__snapshots__/PageHeader.test.tsx.snap @@ -2,71 +2,75 @@ exports[`PageHeader default 1`] = `
- -
-
-
    -
  • + + One + +
+
+ + + +
- Action 1 + + Two +
- - + +
+
+
    +
  • +
    + Action 1 +
    +
  • +
+
`;