1- import React , { Component } from 'react' ;
1+ import React , { FC } from 'react' ;
22import classNames from 'classnames' ;
33
44import { MediaObject } from './MediaObject' ;
55import { Text , TextProps } from './Text' ;
66import { Grid , Row , Col , GridProps } from './Grid' ;
77import { BreadCrumbs , Crumb } from './BreadCrumbs' ;
88
9+ /**
10+ *
11+ */
912export type PageHeaderDetailBodyProps = TextProps ;
1013
1114export const PageHeaderDetailBody : React . FC < PageHeaderDetailBodyProps > = ( {
@@ -20,6 +23,9 @@ export const PageHeaderDetailBody: React.FC<PageHeaderDetailBodyProps> = ({
2023 < > { children } </ >
2124 ) ;
2225
26+ /**
27+ *
28+ */
2329export type PageHeaderDetailLabelProps = TextProps ;
2430
2531export const PageHeaderDetailLabel : React . FC < PageHeaderDetailLabelProps > = ( {
@@ -39,6 +45,9 @@ export const PageHeaderDetailLabel: React.FC<PageHeaderDetailLabelProps> = ({
3945 < > { children } </ >
4046 ) ;
4147
48+ /**
49+ *
50+ */
4251export type PageHeaderDetailItemProps = {
4352 label ?: string ;
4453} & React . LiHTMLAttributes < HTMLLIElement > ;
@@ -60,6 +69,9 @@ export const PageHeaderDetailItem: React.FC<PageHeaderDetailItemProps> = (
6069 ) ;
6170} ;
6271
72+ /**
73+ *
74+ */
6375export type PageHeaderDetailProps = GridProps ;
6476
6577export const PageHeaderDetail : React . FC < GridProps > = ( {
@@ -76,6 +88,9 @@ export const PageHeaderDetail: React.FC<GridProps> = ({
7688 </ Grid >
7789) ;
7890
91+ /**
92+ *
93+ */
7994export type PageHeaderHeadingTitleProps = {
8095 className ?: string ;
8196} & React . HTMLAttributes < HTMLHeadingElement > ;
@@ -95,6 +110,9 @@ export const PageHeaderHeadingTitle: React.FC<PageHeaderHeadingTitleProps> = (
95110 ) ;
96111} ;
97112
113+ /**
114+ *
115+ */
98116export type PageHeaderHeadingProps = {
99117 info ?: string ;
100118 legend ?: string ;
@@ -105,100 +123,93 @@ export type PageHeaderHeadingProps = {
105123 rightActions ?: JSX . Element | Array < JSX . Element > ;
106124} ;
107125
108- export class PageHeaderHeading extends Component < PageHeaderHeadingProps > {
109- renderInfo ( info : string ) {
110- return info ? (
111- < Text category = 'body' type = 'small' >
112- { info }
113- </ Text >
114- ) : null ;
115- }
126+ /**
127+ *
128+ */
129+ export const PageHeaderHeading : FC < PageHeaderHeadingProps > = ( props ) => {
130+ const {
131+ leftActions,
132+ rightActions,
133+ title,
134+ info,
135+ breadCrumbs,
136+ figure,
137+ legend,
138+ } = props ;
139+
140+ const infoPart = info ? (
141+ < Text category = 'body' type = 'small' >
142+ { info }
143+ </ Text >
144+ ) : null ;
116145
117- renderWithMedia ( figure : JSX . Element | undefined ) {
118- const content = this . renderContent ( ) ;
119- return figure ? (
120- < MediaObject figureLeft = { figure } > { content } </ MediaObject >
146+ const titlePart =
147+ typeof title === 'string' ? (
148+ < PageHeaderHeadingTitle className = 'slds-m-right_small' >
149+ { title }
150+ </ PageHeaderHeadingTitle >
121151 ) : (
122- content
152+ title
123153 ) ;
124- }
125154
126- renderContent ( ) {
127- const { rightActions, info, legend, title, breadCrumbs, leftActions } =
128- this . props ;
129- const infoPart =
130- info && ! breadCrumbs && ! legend && ! rightActions
131- ? this . renderInfo ( info )
132- : null ;
133- const titlePart =
134- typeof title === 'string' ? (
135- < PageHeaderHeadingTitle className = 'slds-m-right_small' >
136- { title }
137- </ PageHeaderHeadingTitle >
155+ let breadCrumbsPart = null ;
156+ if ( breadCrumbs ) {
157+ breadCrumbsPart =
158+ breadCrumbs . length && breadCrumbs [ 0 ] . type === Crumb ? (
159+ < BreadCrumbs > { breadCrumbs } </ BreadCrumbs >
138160 ) : (
139- title
161+ breadCrumbs
140162 ) ;
141-
142- let breadCrumbsPart = null ;
143- if ( breadCrumbs ) {
144- breadCrumbsPart =
145- breadCrumbs . length && breadCrumbs [ 0 ] . type === Crumb ? (
146- < BreadCrumbs > { breadCrumbs } </ BreadCrumbs >
147- ) : (
148- breadCrumbs
149- ) ;
150- }
151-
152- return (
153- < div >
154- { breadCrumbsPart }
155- { legend ? (
156- < Text category = 'title' type = 'caps' className = 'slds-line-height_reset' >
157- { legend }
158- </ Text >
159- ) : null }
160- { leftActions ? (
161- < Grid vertical = { false } >
162- { titlePart }
163- < Col className = 'slds-shrink-none' > { leftActions } </ Col >
164- </ Grid >
165- ) : (
166- titlePart
167- ) }
168- { infoPart }
169- </ div >
170- ) ;
171163 }
172164
173- render ( ) {
174- const { rightActions, info, breadCrumbs, figure, legend } = this . props ;
175- const content = this . renderWithMedia ( figure ) ;
176- const infoPart =
177- info && ( breadCrumbs || legend || rightActions )
178- ? this . renderInfo ( info )
179- : null ;
180-
181- return rightActions ? (
182- < div >
165+ const content_ = (
166+ < div >
167+ { breadCrumbsPart }
168+ { legend ? (
169+ < Text category = 'title' type = 'caps' className = 'slds-line-height_reset' >
170+ { legend }
171+ </ Text >
172+ ) : null }
173+ { leftActions ? (
183174 < Grid vertical = { false } >
184- < Col className = 'slds-has-flexi-truncate' > { content } </ Col >
185- < Col align = 'top' noFlex >
186- < Grid >
187- < Row cols = { 1 } > { rightActions } </ Row >
188- </ Grid >
189- </ Col >
175+ { titlePart }
176+ < Col className = 'slds-shrink-none' > { leftActions } </ Col >
190177 </ Grid >
191- { infoPart }
192- </ div >
193- ) : (
194- < div >
195- { content }
196- { infoPart }
197- </ div >
198- ) ;
199- }
200- }
178+ ) : (
179+ titlePart
180+ ) }
181+ { breadCrumbs && ! legend && ! rightActions ? infoPart : null }
182+ </ div >
183+ ) ;
184+ const content = figure ? (
185+ < MediaObject figureLeft = { figure } > { content_ } </ MediaObject >
186+ ) : (
187+ content_
188+ ) ;
189+
190+ return rightActions ? (
191+ < div >
192+ < Grid vertical = { false } >
193+ < Col className = 'slds-has-flexi-truncate' > { content } </ Col >
194+ < Col align = 'top' noFlex >
195+ < Grid >
196+ < Row cols = { 1 } > { rightActions } </ Row >
197+ </ Grid >
198+ </ Col >
199+ </ Grid >
200+ { breadCrumbs || legend || rightActions ? infoPart : null }
201+ </ div >
202+ ) : (
203+ < div >
204+ { content }
205+ { breadCrumbs || legend || rightActions ? infoPart : null }
206+ </ div >
207+ ) ;
208+ } ;
201209
210+ /**
211+ *
212+ */
202213export type PageHeaderProps = React . HTMLAttributes < HTMLDivElement > ;
203214
204215export const PageHeader : React . FC < PageHeaderProps > = ( props ) => (
0 commit comments