11import { html , LitElement } from 'lit' ;
22import { property } from 'lit/decorators.js' ;
3- import { createRef , type Ref , ref } from 'lit/directives/ref.js' ;
4-
3+ import { createRef , ref } from 'lit/directives/ref.js' ;
54import { addAnimationController } from '../../animations/player.js' ;
65import { growVerIn , growVerOut } from '../../animations/presets/grow/index.js' ;
76import { addThemingController } from '../../theming/theming-controller.js' ;
87import IgcButtonComponent from '../button/button.js' ;
98import { addInternalsController } from '../common/controllers/internals.js' ;
9+ import { addSlotController , setSlots } from '../common/controllers/slot.js' ;
1010import { registerComponent } from '../common/definitions/register.js' ;
1111import type { Constructor } from '../common/mixins/constructor.js' ;
1212import { EventEmitterMixin } from '../common/mixins/event-emitter.js' ;
@@ -50,11 +50,8 @@ export default class IgcBannerComponent extends EventEmitterMixin<
5050 registerComponent ( IgcBannerComponent , IgcButtonComponent ) ;
5151 }
5252
53- private readonly _bannerRef : Ref < HTMLElement > = createRef ( ) ;
54- private readonly _animationPlayer = addAnimationController (
55- this ,
56- this . _bannerRef
57- ) ;
53+ private readonly _bannerRef = createRef < HTMLElement > ( ) ;
54+ private readonly _player = addAnimationController ( this , this . _bannerRef ) ;
5855
5956 /**
6057 * Determines whether the banner is being shown/hidden.
@@ -67,7 +64,7 @@ export default class IgcBannerComponent extends EventEmitterMixin<
6764 super ( ) ;
6865
6966 addThemingController ( this , all ) ;
70-
67+ addSlotController ( this , { slots : setSlots ( 'prefix' , 'actions' ) } ) ;
7168 addInternalsController ( this , {
7269 initialARIA : {
7370 role : 'status' ,
@@ -76,14 +73,21 @@ export default class IgcBannerComponent extends EventEmitterMixin<
7673 } ) ;
7774 }
7875
76+ private async _handleClick ( ) : Promise < void > {
77+ if ( this . emitEvent ( 'igcClosing' , { cancelable : true } ) ) {
78+ await this . hide ( ) ;
79+ this . emitEvent ( 'igcClosed' ) ;
80+ }
81+ }
82+
7983 /** Shows the banner if not already shown. Returns `true` when the animation has completed. */
8084 public async show ( ) : Promise < boolean > {
8185 if ( this . open ) {
8286 return false ;
8387 }
8488
8589 this . open = true ;
86- return await this . toggleAnimation ( 'open' ) ;
90+ return this . _player . playExclusive ( growVerIn ( ) ) ;
8791 }
8892
8993 /** Hides the banner if not already hidden. Returns `true` when the animation has completed. */
@@ -92,26 +96,14 @@ export default class IgcBannerComponent extends EventEmitterMixin<
9296 return false ;
9397 }
9498
95- await this . toggleAnimation ( 'close' ) ;
99+ await this . _player . playExclusive ( growVerOut ( ) ) ;
96100 this . open = false ;
97101 return true ;
98102 }
99103
100104 /** Toggles between shown/hidden state. Returns `true` when the animation has completed. */
101105 public async toggle ( ) : Promise < boolean > {
102- return this . open ? await this . hide ( ) : await this . show ( ) ;
103- }
104-
105- private async toggleAnimation ( dir : 'open' | 'close' ) {
106- const animation = dir === 'open' ? growVerIn : growVerOut ;
107- return this . _animationPlayer . playExclusive ( animation ( ) ) ;
108- }
109-
110- private async handleClick ( ) {
111- if ( this . emitEvent ( 'igcClosing' , { cancelable : true } ) ) {
112- await this . hide ( ) ;
113- this . emitEvent ( 'igcClosed' ) ;
114- }
106+ return this . open ? this . hide ( ) : this . show ( ) ;
115107 }
116108
117109 protected override render ( ) {
@@ -131,7 +123,7 @@ export default class IgcBannerComponent extends EventEmitterMixin<
131123 < igc-button
132124 type ="button "
133125 variant ="flat "
134- @click =${ this . handleClick }
126+ @click =${ this . _handleClick }
135127 > OK</ igc-button
136128 >
137129 </ slot >
0 commit comments