-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcarousel-indicator.ts
More file actions
92 lines (79 loc) · 2.87 KB
/
carousel-indicator.ts
File metadata and controls
92 lines (79 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { consume } from '@lit/context';
import { html, LitElement, type PropertyValues } from 'lit';
import { property } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';
import { carouselContext } from '../common/context.js';
import { addInternalsController } from '../common/controllers/internals.js';
import { registerComponent } from '../common/definitions/register.js';
import { formatString } from '../common/util.js';
import type IgcCarouselComponent from './carousel.js';
import { styles } from './themes/carousel-indicator.base.css.js';
/**
* Used when a custom indicator needs to be passed to the `igc-carousel` component.
*
* @element igc-carousel-indicator
*
* @slot - Default slot for projected inactive indicator.
* @slot active - Default slot for projected active indicator.
*
* @csspart indicator - The wrapping container of the carousel dot indicator.
* @csspart inactive - The wrapping container of the inactive dot indicator.
* @csspart active - The wrapping container of the active dot indicator.
*/
export default class IgcCarouselIndicatorComponent extends LitElement {
public static readonly tagName = 'igc-carousel-indicator';
public static override styles = styles;
/* blazorSuppress */
public static register(): void {
registerComponent(IgcCarouselIndicatorComponent);
}
private readonly _internals = addInternalsController(this, {
initialARIA: { role: 'tab' },
});
@consume({ context: carouselContext, subscribe: true })
private readonly _carousel?: IgcCarouselComponent;
protected get _labelFormat(): string {
return this._carousel ? this._carousel.indicatorsLabelFormat : '';
}
/* blazorSuppress */
@property({ attribute: false })
public active = false;
/* blazorSuppress */
@property({ attribute: false })
public index = 0;
/** @internal */
public override connectedCallback(): void {
super.connectedCallback();
this.role = 'tab';
this.slot = this.slot || 'indicator';
}
protected override willUpdate(changedProperties: PropertyValues<this>): void {
if (changedProperties.has('active')) {
this.tabIndex = this.active ? 0 : -1;
this._internals.setARIA({ ariaSelected: this.active.toString() });
}
this._internals.setARIA({
ariaLabel: formatString(this._labelFormat, this.index + 1),
});
}
protected override render() {
const forward = this.active ? 'visible' : 'hidden';
const backward = this.active ? 'hidden' : 'visible';
return html`
<div
part="indicator inactive"
style=${styleMap({ visibility: backward })}
>
<slot></slot>
</div>
<div part="indicator active" style=${styleMap({ visibility: forward })}>
<slot name="active"></slot>
</div>
`;
}
}
declare global {
interface HTMLElementTagNameMap {
'igc-carousel-indicator': IgcCarouselIndicatorComponent;
}
}