Skip to content

Commit

Permalink
feat(pageheader): add minimal component implementation
Browse files Browse the repository at this point in the history
This adds a minimal implementation for a page header.

CLOSES DCOS-54461
  • Loading branch information
Poltergeist committed Jun 6, 2019
1 parent ceca3b5 commit 58c3c8a
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/pageheader/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# PageHeader
31 changes: 31 additions & 0 deletions packages/pageheader/components/PageHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from "react";

import { default as Breadcrumb } from "../../breadcrumb/components/Breadcrumb";

import { flush } from "../../shared/styles/styleUtils";

import { style } from "../style";

export interface PageHeaderProps {
breadcrumbElements: React.ReactNodeArray;
actions?: Array<React.ReactElement<any>>;
}

class PageHeader extends React.PureComponent<PageHeaderProps, {}> {
public render() {
const { breadcrumbElements, actions = [] } = this.props;

return (
<div className={style}>
<Breadcrumb>{breadcrumbElements}</Breadcrumb>
<ul className={flush("all")}>
{actions.map(action => {
return <li key={`${action.key}`}>{action}</li>;
})}
</ul>
</div>
);
}
}

export default PageHeader;
1 change: 1 addition & 0 deletions packages/pageheader/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as PageHeader } from "./components/PageHeader";
25 changes: 25 additions & 0 deletions packages/pageheader/stories/PageHeader.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as React from "react";
import { storiesOf } from "@storybook/react";
import { withReadme } from "storybook-readme";

import { PageHeader } from "../index";
import { Clickable } from "../../clickable";

const readme = require("../README.md");
const action = () => alert("Action 1 triggered");

storiesOf("PageHeader", module)
.addDecorator(withReadme([readme]))
.add("default", () => (
<PageHeader
breadcrumbElements={[
<span key="ElementOne">One</span>,
<span key="ElementTwo">Two</span>
]}
actions={[
<Clickable key="Action1" action={action}>
<div>Action 1</div>
</Clickable>
]}
/>
));
6 changes: 6 additions & 0 deletions packages/pageheader/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { css } from "emotion";

export const style = css`
display: grid;
grid-template-columns: repeat(2, 50%);
`;
29 changes: 29 additions & 0 deletions packages/pageheader/tests/PageHeader.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from "react";
import { render } from "enzyme";
import toJSON from "enzyme-to-json";

import { PageHeader } from "../";
import { Clickable } from "../../clickable";

describe("PageHeader", () => {
it("default", () => {
const action = () => 1;
expect(
toJSON(
render(
<PageHeader
breadcrumbElements={[
<span key="One">One</span>,
<span key="Two">Two</span>
]}
actions={[
<Clickable key="Action1" action={action}>
<div>Action 1</div>
</Clickable>
]}
/>
)
)
).toMatchSnapshot();
});
});
31 changes: 31 additions & 0 deletions packages/pageheader/tests/__snapshots__/PageHeader.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`PageHeader default 1`] = `
<div
class="css-jiaax5"
>
<div
class="css-ewxxaj"
>
<span>
One
</span>
<span>
Two
</span>
</div>
<ul
class="css-10pfh7o"
>
<li>
<div
class="css-1h5x3dy"
role="button"
tabindex="-1"
>
Action 1
</div>
</li>
</ul>
</div>
`;

0 comments on commit 58c3c8a

Please sign in to comment.