Skip to content

Commit 23759ff

Browse files
authored
feat: Slot controller (#1767)
Added a slot controller implementation that handles `slotchange` events inside the host render root. It features typed slots, and the ability to query assigned nodes/elements similar to the Lit's `@queryAssigned<foo>` decorators. Cleaned up a bunch of code around components which use the new controller, as well some dubious ARIA properties in the DOM of some of the components.
1 parent f3d9344 commit 23759ff

File tree

30 files changed

+1689
-1375
lines changed

30 files changed

+1689
-1375
lines changed

src/components/carousel/carousel-indicator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default class IgcCarouselIndicatorComponent extends LitElement {
3535
});
3636

3737
@consume({ context: carouselContext, subscribe: true })
38-
private _carousel?: IgcCarouselComponent;
38+
private readonly _carousel?: IgcCarouselComponent;
3939

4040
protected get _labelFormat(): string {
4141
return this._carousel ? this._carousel.indicatorsLabelFormat : '';

src/components/carousel/carousel-slide.ts

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import { addAnimationController } from '../../animations/player.js';
66
import { carouselContext } from '../common/context.js';
77
import { addInternalsController } from '../common/controllers/internals.js';
88
import { registerComponent } from '../common/definitions/register.js';
9-
import { createCounter, formatString } from '../common/util.js';
9+
import { formatString } from '../common/util.js';
1010
import { animations } from './animations.js';
1111
import type IgcCarouselComponent from './carousel.js';
1212
import { styles } from './themes/carousel-slide.base.css.js';
1313

14+
let nextId = 1;
15+
1416
/**
1517
* A single content container within a set of containers used in the context of an `igc-carousel`.
1618
*
@@ -27,25 +29,23 @@ export default class IgcCarouselSlideComponent extends LitElement {
2729
registerComponent(IgcCarouselSlideComponent);
2830
}
2931

30-
private static readonly increment = createCounter();
31-
3232
private readonly _internals = addInternalsController(this, {
3333
initialARIA: {
3434
role: 'tabpanel',
3535
ariaRoleDescription: 'slide',
3636
},
3737
});
3838

39-
private readonly _animationPlayer = addAnimationController(this);
39+
private readonly _player = addAnimationController(this);
4040

4141
@consume({ context: carouselContext, subscribe: true })
42-
private _carousel?: IgcCarouselComponent;
42+
private readonly _carousel?: IgcCarouselComponent;
4343

44-
protected get _index() {
44+
protected get _index(): number {
4545
return this._carousel ? this._carousel.slides.indexOf(this) : 0;
4646
}
4747

48-
protected get _total() {
48+
protected get _total(): number {
4949
return this._carousel ? this._carousel.slides.length : 0;
5050
}
5151

@@ -59,7 +59,7 @@ export default class IgcCarouselSlideComponent extends LitElement {
5959
return animation;
6060
}
6161

62-
protected get _labelFormat() {
62+
protected get _labelFormat(): string {
6363
return this._carousel ? this._carousel.slidesLabelFormat : '';
6464
}
6565

@@ -81,21 +81,16 @@ export default class IgcCarouselSlideComponent extends LitElement {
8181
public async toggleAnimation(
8282
type: 'in' | 'out',
8383
direction: 'normal' | 'reverse' = 'normal'
84-
) {
84+
): Promise<boolean> {
8585
const animation = animations.get(this._animation)!.get(type)!;
8686

87-
const options: KeyframeAnimationOptions = {
88-
duration: 320,
89-
easing: EaseInOut.Quad,
90-
direction,
91-
};
92-
93-
const [_, event] = await Promise.all([
94-
this._animationPlayer.stopAll(),
95-
this._animationPlayer.play(animation(options)),
96-
]);
97-
98-
return event.type === 'finish';
87+
return await this._player.playExclusive(
88+
animation({
89+
duration: 320,
90+
easing: EaseInOut.Quad,
91+
direction,
92+
})
93+
);
9994
}
10095

10196
protected override willUpdate(): void {
@@ -104,15 +99,14 @@ export default class IgcCarouselSlideComponent extends LitElement {
10499
});
105100
}
106101

102+
/** @internal */
107103
public override connectedCallback(): void {
108104
super.connectedCallback();
109-
110-
this.id =
111-
this.id || `igc-carousel-slide-${IgcCarouselSlideComponent.increment()}`;
105+
this.id = this.id || `igc-carousel-slide-${nextId++}`;
112106
}
113107

114108
protected override render() {
115-
return html` <slot></slot> `;
109+
return html`<slot></slot>`;
116110
}
117111
}
118112

0 commit comments

Comments
 (0)