|
1 | | -import { consume } from '@lit/context'; |
2 | 1 | import { html, LitElement } from 'lit'; |
3 | 2 | import { property } from 'lit/decorators.js'; |
4 | 3 | import { EaseInOut } from '../../animations/easings.js'; |
5 | 4 | import { addAnimationController } from '../../animations/player.js'; |
6 | 5 | import { carouselContext } from '../common/context.js'; |
| 6 | +import { createAsyncContext } from '../common/controllers/async-consumer.js'; |
7 | 7 | import { addInternalsController } from '../common/controllers/internals.js'; |
8 | 8 | import { registerComponent } from '../common/definitions/register.js'; |
9 | 9 | import { formatString } from '../common/util.js'; |
@@ -38,29 +38,44 @@ export default class IgcCarouselSlideComponent extends LitElement { |
38 | 38 |
|
39 | 39 | private readonly _player = addAnimationController(this); |
40 | 40 |
|
41 | | - @consume({ context: carouselContext, subscribe: true }) |
42 | | - private readonly _carousel?: IgcCarouselComponent; |
| 41 | + private _carousel?: IgcCarouselComponent; |
| 42 | + |
| 43 | + private readonly _context = createAsyncContext( |
| 44 | + this, |
| 45 | + carouselContext, |
| 46 | + (carousel) => { |
| 47 | + this._carousel = carousel; |
| 48 | + } |
| 49 | + ); |
| 50 | + |
| 51 | + private get _carouselInstance(): IgcCarouselComponent | undefined { |
| 52 | + return this._carousel ?? this._context.value; |
| 53 | + } |
43 | 54 |
|
44 | 55 | protected get _index(): number { |
45 | | - return this._carousel ? this._carousel.slides.indexOf(this) : 0; |
| 56 | + return this._carouselInstance |
| 57 | + ? this._carouselInstance.slides.indexOf(this) |
| 58 | + : 0; |
46 | 59 | } |
47 | 60 |
|
48 | 61 | protected get _total(): number { |
49 | | - return this._carousel ? this._carousel.slides.length : 0; |
| 62 | + return this._carouselInstance ? this._carouselInstance.slides.length : 0; |
50 | 63 | } |
51 | 64 |
|
52 | 65 | protected get _animation() { |
53 | | - const animation = this._carousel?.animationType ?? 'slide'; |
| 66 | + const animation = this._carouselInstance?.animationType ?? 'slide'; |
54 | 67 |
|
55 | 68 | if (animation === 'slide') { |
56 | | - return this._carousel?.vertical ? 'slideVer' : 'slideHor'; |
| 69 | + return this._carouselInstance?.vertical ? 'slideVer' : 'slideHor'; |
57 | 70 | } |
58 | 71 |
|
59 | 72 | return animation; |
60 | 73 | } |
61 | 74 |
|
62 | 75 | protected get _labelFormat(): string { |
63 | | - return this._carousel ? this._carousel.slidesLabelFormat : ''; |
| 76 | + return this._carouselInstance |
| 77 | + ? this._carouselInstance.slidesLabelFormat |
| 78 | + : ''; |
64 | 79 | } |
65 | 80 |
|
66 | 81 | /** |
|
0 commit comments