Skip to content
This repository was archived by the owner on Mar 6, 2025. It is now read-only.

Commit 4563914

Browse files
author
Alan
committed
add align to PageTitle
1 parent c1955ab commit 4563914

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

src/components/__tests__/__snapshots__/page.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ exports[`The Page component should render 1`] = `
1414
}
1515
>
1616
<PageTitle
17+
align="center"
1718
title="Page title"
1819
/>
1920
</div>

src/components/__tests__/__snapshots__/page_title.test.tsx.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
exports[`The PageTitle component should render 1`] = `
44
<div
55
className="page-title"
6+
style={
7+
Object {
8+
"textAlign": "center",
9+
}
10+
}
611
>
712
<div
813
className="page-title__title-container"

src/components/page.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22

33
// components
4-
import PageTitle from './page_title';
4+
import { PageTitle, PageTitleAlign } from './page_title';
55

66
import classNames = require('classnames');
77

@@ -16,16 +16,18 @@ export interface PageProps {
1616
id?: string;
1717
/** Additional classes for styling */
1818
className?: string;
19+
/** How to align the page title */
20+
titleAlign?: PageTitleAlign;
1921
/** The page content */
20-
children: any;
22+
children?: any;
2123
}
2224

2325
export const Page: React.StatelessComponent<PageProps> = ({
24-
title, isBeta, maxWidth, id, className, children,
26+
title, isBeta, maxWidth, id, className, titleAlign, children,
2527
}): JSX.Element => (
2628
<div id={id} className={classNames('page', className)}>
2729
<div className="page__content" style={{ maxWidth }}>
28-
{title && <PageTitle title={title} isBeta={isBeta} />}
30+
{title && <PageTitle title={title} isBeta={isBeta} align={titleAlign} />}
2931
{children}
3032
</div>
3133
</div>

src/components/page_title.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import * as React from 'react';
22
import BetaPill from './beta_pill';
33

4+
export type PageTitleAlign = 'left' | 'center' | 'right';
5+
46
export interface PageTitleProps {
57
title: string;
68
isBeta?: boolean;
9+
align?: PageTitleAlign
710
}
811

912
export const PageTitle: React.StatelessComponent<PageTitleProps> = (
10-
{ title, isBeta },
13+
{ title, isBeta, align },
1114
): JSX.Element => (
12-
<div className="page-title">
15+
<div className="page-title" style={{ textAlign: align }}>
1316
<div className="page-title__title-container">
1417
<h2>
1518
{title}
@@ -19,6 +22,10 @@ export const PageTitle: React.StatelessComponent<PageTitleProps> = (
1922
</div>
2023
);
2124

25+
PageTitle.defaultProps = {
26+
align: 'center',
27+
};
28+
2229
PageTitle.displayName = 'PageTitle';
2330

2431
export default PageTitle;

src/stories/layout.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import SettingPanel from '../components/setting_panel';
2323
import Carousel from '../components/carousel';
2424
import AspectRatioContainer from '../components/aspect_ratio_container';
2525
import Header from '../components/header';
26-
import Navigation, { NavRoute } from '../components/navigation';
26+
import Navigation from '../components/navigation';
2727
import UserAccountMenu from '../components/user_account_menu';
2828
import AppSwitcherMenu from '../components/app_switcher_menu';
2929

0 commit comments

Comments
 (0)