Skip to content
Closed
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
92 changes: 46 additions & 46 deletions src/scripts/PageHeader.js → src/scripts/PageHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import React, { Component, ReactElement } from 'react';
import classNames from 'classnames';

import { MediaObject } from './MediaObject';
import { Text } from './Text';
import { Grid, Row, Col } from './Grid';
import { Text, TextProps } from './Text';
import { Grid, Row, Col, GridProps } from './Grid';
import { BreadCrumbs, Crumb } from './BreadCrumbs';

export const PageHeaderDetailBody = ({ children, ...props }) =>
export type PageHeaderDetailBodyProps = TextProps;

export const PageHeaderDetailBody: React.FC<PageHeaderDetailBodyProps> = ({
children,
...props
}) =>
typeof children === 'string' ? (
<Text category='body' type='regular' truncate {...props}>
{children}
</Text>
) : (
children
<>{children}</>
);

PageHeaderDetailBody.propTypes = {
children: PropTypes.node,
};
export type PageHeaderDetailLabelProps = TextProps;

export const PageHeaderDetailLabel = ({ children, ...props }) =>
export const PageHeaderDetailLabel: React.FC<PageHeaderDetailLabelProps> = ({
children,
...props
}) =>
typeof children === 'string' ? (
<Text
category='title'
Expand All @@ -31,14 +36,16 @@ export const PageHeaderDetailLabel = ({ children, ...props }) =>
{children}
</Text>
) : (
children
<>{children}</>
);

PageHeaderDetailLabel.propTypes = {
children: PropTypes.node,
};
export type PageHeaderDetailItemProps = {
label?: string;
} & React.LiHTMLAttributes<HTMLLIElement>;

export const PageHeaderDetailItem = (props) => {
export const PageHeaderDetailItem: React.FC<PageHeaderDetailItemProps> = (
props
) => {
const { children, label, ...pprops } = props;
const manuallyAssembled = !label;
return (
Expand All @@ -53,12 +60,12 @@ export const PageHeaderDetailItem = (props) => {
);
};

PageHeaderDetailItem.propTypes = {
label: PropTypes.string,
children: PropTypes.node,
};
export type PageHeaderDetailProps = GridProps;

export const PageHeaderDetail = ({ children, ...props }) => (
export const PageHeaderDetail: React.FC<GridProps> = ({
children,
...props
}) => (
<Grid
tag='ul'
vertical={false}
Expand All @@ -69,11 +76,13 @@ export const PageHeaderDetail = ({ children, ...props }) => (
</Grid>
);

PageHeaderDetail.propTypes = {
children: PropTypes.node,
};
export type PageHeaderHeadingTitleProps = {
className?: string;
} & React.HTMLAttributes<HTMLHeadingElement>;

export const PageHeaderHeadingTitle = (props) => {
export const PageHeaderHeadingTitle: React.FC<PageHeaderHeadingTitleProps> = (
props
) => {
const { className, children } = props;
const titleClassNames = classNames(
className,
Expand All @@ -86,21 +95,26 @@ export const PageHeaderHeadingTitle = (props) => {
);
};

PageHeaderHeadingTitle.propTypes = {
className: PropTypes.string,
children: PropTypes.node,
export type PageHeaderHeadingProps = {
info?: string;
legend?: string;
title?: string | JSX.Element;
breadCrumbs?: Array<JSX.Element>;
leftActions?: JSX.Element;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should leftActions also be type of JSX.Element | Array<JSX.Element>?
I found rightActions accepts both single object or an array of objects in story.

figure?: JSX.Element;
rightActions?: JSX.Element | Array<JSX.Element>;
};

export class PageHeaderHeading extends Component {
renderInfo(info) {
export class PageHeaderHeading extends Component<PageHeaderHeadingProps> {
renderInfo(info: string) {
return info ? (
<Text category='body' type='small'>
{info}
</Text>
) : null;
}

renderWithMedia(figure) {
renderWithMedia(figure: JSX.Element | undefined) {
const content = this.renderContent();
return figure ? (
<MediaObject figureLeft={figure}>{content}</MediaObject>
Expand Down Expand Up @@ -195,24 +209,10 @@ export class PageHeaderHeading extends Component {
}
}

PageHeaderHeading.propTypes = {
info: PropTypes.string,
legend: PropTypes.string,
title: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
breadCrumbs: PropTypes.oneOfType([PropTypes.arrayOf(Crumb), PropTypes.node]),
leftActions: PropTypes.node,
figure: PropTypes.node,
rightActions: PropTypes.node,
};
export type PageHeaderProps = React.HTMLAttributes<HTMLDivElement>;

const PageHeader = (props) => (
export const PageHeader: React.FC<PageHeaderProps> = (props) => (
<div className='slds-page-header' role='banner' {...props}>
{props.children}
</div>
);

PageHeader.propTypes = {
children: PropTypes.node,
};

export default PageHeader;
2 changes: 1 addition & 1 deletion src/scripts/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import classnames from 'classnames';
export type TextProps = {
tag?: keyof ReactHTML;
category?: 'body' | 'heading' | 'title';
type?: 'small' | 'regular' | 'medium' | 'large' | 'caps';
type?: 'small' | 'regular' | 'medium' | 'large' | 'caps' | 'label';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since there isn't slds-text-heading_label or slds-text-heading--label class in the SLDS document,
https://www.lightningdesignsystem.com/utilities/text/#Heading-Size-Large

It is in the current source code of SLDS,
https://github.com/salesforce-ux/design-system/blob/21b01368fc63db0cf53c077def1ebffd9bb4c64d/ui/utilities/text/_index.scss#L67
(Though it's deprecated)

And, original propTypes accept it: https://github.com/mashmatrix/react-lightning-design-system/blob/master/src/scripts/Text.js#L28
So I added it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

align?: 'left' | 'center' | 'right';
className?: string;
truncate?: boolean;
Expand Down
16 changes: 1 addition & 15 deletions src/scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
import Datepicker from './Datepicker';
import Tabs, { Tab } from './Tabs';
import DateInput from './DateInput';
import PageHeader, {
PageHeaderHeading,
PageHeaderHeadingTitle,
PageHeaderDetail,
PageHeaderDetailItem,
PageHeaderDetailBody,
PageHeaderDetailLabel,
} from './PageHeader';
import Table, {
TableHeader,
TableBody,
Expand All @@ -26,13 +18,6 @@ export {
Tab,
Tabs,
DateInput,
PageHeader,
PageHeaderHeading,
PageHeaderHeadingTitle,
PageHeaderDetail,
PageHeaderDetailItem,
PageHeaderDetailBody,
PageHeaderDetailLabel,
Table,
TableHeader,
TableBody,
Expand Down Expand Up @@ -72,6 +57,7 @@ export * from './Textarea';
export * from './Toggle';
export * from './Modal';
export * from './Notification';
export * from './PageHeader';
export * from './Tree';
export * from './TreeNode';
export * from './SalesPath';
Expand Down
File renamed without changes.