@@ -20,7 +20,7 @@ import {
20
20
EuiTitle ,
21
21
EuiSpacer ,
22
22
} from '@elastic/eui' ;
23
- import { isEmpty } from 'lodash' ;
23
+ import { isEmpty , get } from 'lodash' ;
24
24
25
25
type ContentPanelProps = {
26
26
// keep title string part for backwards compatibility
@@ -39,96 +39,109 @@ type ContentPanelProps = {
39
39
children : React . ReactNode | React . ReactNode [ ] ;
40
40
contentPanelClassName ?: string ;
41
41
hideBody ?: boolean ;
42
+ titleDataTestSubj ?: string ;
42
43
} ;
43
44
44
- const ContentPanel = ( props : ContentPanelProps ) => (
45
- < EuiPanel
46
- style = { { padding : '20px' , ...props . panelStyles } }
47
- className = { props . contentPanelClassName }
48
- betaBadgeLabel = { props . badgeLabel }
49
- >
50
- < EuiFlexGroup
51
- style = { { padding : '0px' , ...props . titleContainerStyles } }
52
- justifyContent = "spaceBetween"
53
- alignItems = "center"
45
+ const ContentPanel = ( props : ContentPanelProps ) => {
46
+ const titleDataTestSubj = get (
47
+ props ,
48
+ 'titleDataTestSubj' ,
49
+ 'contentPanelTitle'
50
+ ) ;
51
+ return (
52
+ < EuiPanel
53
+ style = { { padding : '20px' , ...props . panelStyles } }
54
+ className = { props . contentPanelClassName }
55
+ betaBadgeLabel = { props . badgeLabel }
54
56
>
55
- < EuiFlexItem >
56
- { typeof props . title === 'string' ? (
57
- < EuiTitle
58
- size = { props . titleSize || 's' }
59
- className = { props . titleClassName }
60
- >
61
- < h3 > { props . title } </ h3 >
62
- </ EuiTitle >
63
- ) : (
64
- < EuiFlexGroup justifyContent = "flexStart" alignItems = "center" >
65
- { Array . isArray ( props . title ) ? (
66
- props . title . map (
67
- ( titleComponent : React . ReactNode , idx : number ) => (
68
- < EuiFlexItem grow = { false } key = { idx } >
69
- { titleComponent }
57
+ < EuiFlexGroup
58
+ style = { { padding : '0px' , ...props . titleContainerStyles } }
59
+ justifyContent = "spaceBetween"
60
+ alignItems = "center"
61
+ >
62
+ < EuiFlexItem >
63
+ { typeof props . title === 'string' ? (
64
+ < EuiTitle
65
+ data-test-subj = { titleDataTestSubj }
66
+ size = { props . titleSize || 's' }
67
+ className = { props . titleClassName }
68
+ >
69
+ < h3 > { props . title } </ h3 >
70
+ </ EuiTitle >
71
+ ) : (
72
+ < EuiFlexGroup
73
+ data-test-subj = { titleDataTestSubj }
74
+ justifyContent = "flexStart"
75
+ alignItems = "center"
76
+ >
77
+ { Array . isArray ( props . title ) ? (
78
+ props . title . map (
79
+ ( titleComponent : React . ReactNode , idx : number ) => (
80
+ < EuiFlexItem grow = { false } key = { idx } >
81
+ { titleComponent }
82
+ </ EuiFlexItem >
83
+ )
84
+ )
85
+ ) : (
86
+ < EuiFlexItem > { props . title } </ EuiFlexItem >
87
+ ) }
88
+ </ EuiFlexGroup >
89
+ ) }
90
+ < EuiFlexGroup >
91
+ { Array . isArray ( props . subTitle ) ? (
92
+ props . subTitle . map (
93
+ ( subTitleComponent : React . ReactNode , idx : number ) => (
94
+ < EuiFlexItem
95
+ grow = { false }
96
+ key = { idx }
97
+ className = "content-panel-subTitle"
98
+ style = { { lineHeight : 'normal' , maxWidth : '75%' } }
99
+ >
100
+ { subTitleComponent }
70
101
</ EuiFlexItem >
71
102
)
72
103
)
73
104
) : (
74
- < EuiFlexItem > { props . title } </ EuiFlexItem >
105
+ < EuiFlexItem
106
+ className = "content-panel-subTitle"
107
+ style = { { lineHeight : 'normal' , maxWidth : '75%' } }
108
+ >
109
+ { props . subTitle }
110
+ </ EuiFlexItem >
75
111
) }
76
112
</ EuiFlexGroup >
77
- ) }
78
- < EuiFlexGroup >
79
- { Array . isArray ( props . subTitle ) ? (
80
- props . subTitle . map (
81
- ( subTitleComponent : React . ReactNode , idx : number ) => (
82
- < EuiFlexItem
83
- grow = { false }
84
- key = { idx }
85
- className = "content-panel-subTitle"
86
- style = { { lineHeight : 'normal' , maxWidth : '75%' } }
87
- >
88
- { subTitleComponent }
89
- </ EuiFlexItem >
90
- )
91
- )
92
- ) : (
93
- < EuiFlexItem
94
- className = "content-panel-subTitle"
95
- style = { { lineHeight : 'normal' , maxWidth : '75%' } }
96
- >
97
- { props . subTitle }
98
- </ EuiFlexItem >
99
- ) }
100
- </ EuiFlexGroup >
101
- </ EuiFlexItem >
113
+ </ EuiFlexItem >
102
114
103
- < EuiFlexItem grow = { false } >
104
- < EuiFlexGroup
105
- justifyContent = "spaceBetween"
106
- alignItems = "center"
107
- gutterSize = "m"
108
- >
109
- { Array . isArray ( props . actions ) ? (
110
- props . actions . map ( ( action : React . ReactNode , idx : number ) => (
111
- < EuiFlexItem key = { idx } > { action } </ EuiFlexItem >
112
- ) )
113
- ) : (
114
- < EuiFlexItem > { props . actions } </ EuiFlexItem >
115
- ) }
116
- </ EuiFlexGroup >
117
- </ EuiFlexItem >
118
- </ EuiFlexGroup >
119
- { ! isEmpty ( props . actions ) ? < EuiSpacer size = "s" /> : null }
120
- { props . title != '' && props . hideBody !== true ? (
121
- < div >
122
- < EuiHorizontalRule
123
- margin = "s"
124
- className = { props . horizontalRuleClassName }
125
- />
126
- < div style = { { padding : '10px 0px' , ...props . bodyStyles } } >
127
- { props . children }
115
+ < EuiFlexItem grow = { false } >
116
+ < EuiFlexGroup
117
+ justifyContent = "spaceBetween"
118
+ alignItems = "center"
119
+ gutterSize = "m"
120
+ >
121
+ { Array . isArray ( props . actions ) ? (
122
+ props . actions . map ( ( action : React . ReactNode , idx : number ) => (
123
+ < EuiFlexItem key = { idx } > { action } </ EuiFlexItem >
124
+ ) )
125
+ ) : (
126
+ < EuiFlexItem > { props . actions } </ EuiFlexItem >
127
+ ) }
128
+ </ EuiFlexGroup >
129
+ </ EuiFlexItem >
130
+ </ EuiFlexGroup >
131
+ { ! isEmpty ( props . actions ) ? < EuiSpacer size = "s" /> : null }
132
+ { props . title != '' && props . hideBody !== true ? (
133
+ < div >
134
+ < EuiHorizontalRule
135
+ margin = "s"
136
+ className = { props . horizontalRuleClassName }
137
+ />
138
+ < div style = { { padding : '10px 0px' , ...props . bodyStyles } } >
139
+ { props . children }
140
+ </ div >
128
141
</ div >
129
- </ div >
130
- ) : null }
131
- </ EuiPanel >
132
- ) ;
142
+ ) : null }
143
+ </ EuiPanel >
144
+ ) ;
145
+ } ;
133
146
134
147
export default ContentPanel ;
0 commit comments