1
+ import type { PropertyValues } from 'lit' ;
1
2
import { html } from 'lit' ;
2
- import { customElement , property , query } from 'lit/decorators.js' ;
3
+ import { customElement , property , query , state } from 'lit/decorators.js' ;
4
+ import { classMap } from 'lit/directives/class-map.js' ;
3
5
import { WaAfterHideEvent } from '../../events/after-hide.js' ;
4
6
import { WaAfterShowEvent } from '../../events/after-show.js' ;
5
7
import { WaHideEvent } from '../../events/hide.js' ;
@@ -40,6 +42,8 @@ import styles from './details.css';
40
42
* @cssproperty --spacing - The amount of space around and between the details' content. Expects a single value.
41
43
* @cssproperty [--show-duration=200ms] - The show duration to use when applying built-in animation classes.
42
44
* @cssproperty [--hide-duration=200ms] - The hide duration to use when applying built-in animation classes.
45
+ *
46
+ * @cssstate animating - Applied when the details is animating expand/collapse.
43
47
*/
44
48
@customElement ( 'wa-details' )
45
49
export default class WaDetails extends WebAwesomeElement {
@@ -53,6 +57,8 @@ export default class WaDetails extends WebAwesomeElement {
53
57
@query ( '.body' ) body : HTMLElement ;
54
58
@query ( '.expand-icon-slot' ) expandIconSlot : HTMLSlotElement ;
55
59
60
+ @state ( ) isAnimating = false ;
61
+
56
62
/**
57
63
* Indicates whether or not the details is open. You can toggle this attribute to show and hide the details, or you
58
64
* can use the `show()` and `hide()` methods and this attribute will reflect the details' open state.
@@ -74,6 +80,11 @@ export default class WaDetails extends WebAwesomeElement {
74
80
/** The position of the expand/collapse icon. */
75
81
@property ( { attribute : 'icon-position' , reflect : true } ) iconPosition : 'start' | 'end' = 'end' ;
76
82
83
+ disconnectedCallback ( ) {
84
+ super . disconnectedCallback ( ) ;
85
+ this . detailsObserver ?. disconnect ( ) ;
86
+ }
87
+
77
88
firstUpdated ( ) {
78
89
this . body . style . height = this . open ? 'auto' : '0' ;
79
90
if ( this . open ) {
@@ -94,9 +105,10 @@ export default class WaDetails extends WebAwesomeElement {
94
105
this . detailsObserver . observe ( this . details , { attributes : true } ) ;
95
106
}
96
107
97
- disconnectedCallback ( ) {
98
- super . disconnectedCallback ( ) ;
99
- this . detailsObserver ?. disconnect ( ) ;
108
+ updated ( changedProperties : PropertyValues < this> ) {
109
+ if ( changedProperties . has ( 'isAnimating' ) ) {
110
+ this . customStates . set ( 'animating' , this . isAnimating ) ;
111
+ }
100
112
}
101
113
102
114
private handleSummaryClick ( event : MouseEvent ) {
@@ -171,6 +183,7 @@ export default class WaDetails extends WebAwesomeElement {
171
183
// Close other details with the same name
172
184
this . closeOthersWithSameName ( ) ;
173
185
186
+ this . isAnimating = true ;
174
187
const duration = parseDuration ( getComputedStyle ( this . body ) . getPropertyValue ( '--show-duration' ) ) ;
175
188
// We can't animate to 'auto', so use the scroll height for now
176
189
await animate (
@@ -185,6 +198,7 @@ export default class WaDetails extends WebAwesomeElement {
185
198
} ,
186
199
) ;
187
200
this . body . style . height = 'auto' ;
201
+ this . isAnimating = false ;
188
202
189
203
this . dispatchEvent ( new WaAfterShowEvent ( ) ) ;
190
204
} else {
@@ -197,6 +211,7 @@ export default class WaDetails extends WebAwesomeElement {
197
211
return ;
198
212
}
199
213
214
+ this . isAnimating = true ;
200
215
const duration = parseDuration ( getComputedStyle ( this . body ) . getPropertyValue ( '--hide-duration' ) ) ;
201
216
// We can't animate from 'auto', so use the scroll height for now
202
217
await animate (
@@ -208,7 +223,7 @@ export default class WaDetails extends WebAwesomeElement {
208
223
{ duration, easing : 'linear' } ,
209
224
) ;
210
225
this . body . style . height = 'auto' ;
211
-
226
+ this . isAnimating = false ;
212
227
this . details . open = false ;
213
228
this . dispatchEvent ( new WaAfterHideEvent ( ) ) ;
214
229
}
@@ -271,7 +286,14 @@ export default class WaDetails extends WebAwesomeElement {
271
286
</ span >
272
287
</ summary >
273
288
274
- < div class ="body " role ="region " aria-labelledby ="header ">
289
+ < div
290
+ class =${ classMap ( {
291
+ body : true ,
292
+ animating : this . isAnimating ,
293
+ } ) }
294
+ role ="region"
295
+ aria-labelledby="header"
296
+ >
275
297
< slot part ="content " id ="content " class ="content "> </ slot >
276
298
</ div >
277
299
</ details >
0 commit comments