1
1
import { css , html , LitElement } from 'lit' ;
2
2
import { classMap } from 'lit/directives/class-map.js' ;
3
3
import { PopoverMixin } from '../popover-mixin.js' ;
4
- import { styleMap } from 'lit/directives/style-map.js' ;
5
4
6
5
class Popover extends PopoverMixin ( LitElement ) {
7
6
@@ -67,8 +66,8 @@ class Popover extends PopoverMixin(LitElement) {
67
66
* @type {boolean }
68
67
*/
69
68
trapFocus : { type : Boolean , reflect : true , attribute : 'trap-focus' } ,
70
- _hasFooter : { state : true } ,
71
- _hasHeader : { state : true }
69
+ _hasFooterSlotContent : { state : true } ,
70
+ _hasHeaderSlotContent : { state : true }
72
71
} ;
73
72
}
74
73
@@ -88,9 +87,25 @@ class Popover extends PopoverMixin(LitElement) {
88
87
.test-no-header {
89
88
display: none;
90
89
}
90
+ .test-footer {
91
+ box-sizing: border-box;
92
+ max-width: 100%;
93
+ padding: 0 1rem 1rem 1rem;
94
+ width: 100%;
95
+ }
91
96
.test-no-footer {
92
97
display: none;
93
98
}
99
+ .test-close {
100
+ margin-block-start: 12px;
101
+ width: 100%;
102
+ }
103
+ .test-no-close {
104
+ display: none;
105
+ }
106
+ .test-close-no-margin {
107
+ margin-block-start: 0;
108
+ }
94
109
` ] ;
95
110
}
96
111
@@ -102,8 +117,8 @@ class Popover extends PopoverMixin(LitElement) {
102
117
this . opened = false ;
103
118
this . trapFocus = false ;
104
119
105
- this . _hasFooter = false ;
106
- this . _hasHeader = false ;
120
+ this . _hasFooterSlotContent = false ;
121
+ this . _hasHeaderSlotContent = false ;
107
122
}
108
123
109
124
connectedCallback ( ) {
@@ -116,26 +131,29 @@ class Popover extends PopoverMixin(LitElement) {
116
131
117
132
const headerClasses = {
118
133
'test-header' : true ,
119
- 'test-no-header' : ! this . _hasHeader
134
+ 'test-no-header' : ! this . _hasHeaderSlotContent
120
135
} ;
121
- const headerStyle = { } ;
122
-
123
136
const footerClasses = {
124
137
'test-footer' : true ,
125
- 'test-no-footer' : ! this . _hasFooter
138
+ 'test-no-footer' : ! ( this . _hasFooterSlotContent || ( this . _mobile && this . _mobileTrayLocation ) )
139
+ } ;
140
+ const closeButtonClasses = {
141
+ 'test-close' : true ,
142
+ 'test-no-close' : ! ( this . _mobile && this . _mobileTrayLocation ) ,
143
+ 'test-close-no-margin' : ! this . _hasFooterSlotContent
126
144
} ;
127
- const footerStyle = { } ;
128
145
129
146
const content = html `
130
147
< div class ="test-content-layout ">
131
- < div class ="${ classMap ( headerClasses ) } " style =" ${ styleMap ( headerStyle ) } " >
148
+ < div class ="${ classMap ( headerClasses ) } ">
132
149
< slot name ="header " @slotchange ="${ this . #handleHeaderSlotChange} "> </ slot >
133
150
</ div >
134
151
< div class ="test-content " @scroll ="${ this . #handleContentScroll} ">
135
152
< slot > </ slot >
136
153
</ div >
137
- < div class =${ classMap ( footerClasses ) } style = ${ styleMap ( footerStyle ) } >
154
+ < div class =" ${ classMap ( footerClasses ) } " >
138
155
< slot name ="footer " @slotchange ="${ this . #handleFooterSlotChange} "> </ slot >
156
+ < d2l-button class ="${ classMap ( closeButtonClasses ) } " @click =${ this . #handleCloseButtonClick} > Close</ d2l-button >
139
157
</ div >
140
158
</ div >
141
159
` ;
@@ -168,17 +186,21 @@ class Popover extends PopoverMixin(LitElement) {
168
186
return this . shadowRoot . querySelector ( '.test-content' ) ;
169
187
}
170
188
189
+ #handleCloseButtonClick( ) {
190
+ this . close ( ) ;
191
+ }
192
+
171
193
#handleContentScroll( ) {
172
194
// eslint-disable-next-line
173
195
console . log ( 'handle content scroll' ) ;
174
196
}
175
197
176
198
#handleFooterSlotChange( e ) {
177
- this . _hasFooter = e . target . assignedNodes ( ) . length !== 0 ;
199
+ this . _hasFooterSlotContent = e . target . assignedNodes ( ) . length !== 0 ;
178
200
}
179
201
180
202
#handleHeaderSlotChange( e ) {
181
- this . _hasHeader = e . target . assignedNodes ( ) . length !== 0 ;
203
+ this . _hasHeaderSlotContent = e . target . assignedNodes ( ) . length !== 0 ;
182
204
}
183
205
184
206
#handlePopoverClose( ) {
0 commit comments