11import { html , LitElement , nothing } from 'lit' ;
2- import {
3- property ,
4- query ,
5- queryAssignedElements ,
6- state ,
7- } from 'lit/decorators.js' ;
2+ import { property , query , state } from 'lit/decorators.js' ;
83import type { StyleInfo } from 'lit/directives/style-map.js' ;
94import { addInternalsController } from '../common/controllers/internals.js' ;
5+ import type { SlotController } from '../common/controllers/slot.js' ;
106import { watch } from '../common/decorators/watch.js' ;
117import { partMap } from '../common/part-map.js' ;
12- import { asPercent , clamp , formatString , isEmpty } from '../common/util.js' ;
8+ import { asPercent , clamp , formatString } from '../common/util.js' ;
139import type { StyleVariant } from '../types.js' ;
1410
1511export abstract class IgcProgressBaseComponent extends LitElement {
@@ -21,8 +17,7 @@ export abstract class IgcProgressBaseComponent extends LitElement {
2117 } ,
2218 } ) ;
2319
24- @queryAssignedElements ( )
25- protected _assignedElements ! : HTMLElement [ ] ;
20+ protected abstract _slots : SlotController < any > ;
2621
2722 @query ( '[part="base"]' , true )
2823 protected _base ! : HTMLElement ;
@@ -97,14 +92,14 @@ export abstract class IgcProgressBaseComponent extends LitElement {
9792 public labelFormat ! : string ;
9893
9994 @watch ( 'indeterminate' )
100- protected indeterminateChange ( ) {
95+ protected _indeterminateChange ( ) : void {
10196 if ( ! this . indeterminate ) {
10297 this . _updateProgress ( ) ;
10398 }
10499 }
105100
106101 @watch ( 'max' )
107- protected maxChange ( ) {
102+ protected _maxChange ( ) : void {
108103 this . max = Math . max ( 0 , this . max ) ;
109104 if ( this . value > this . max ) {
110105 this . value = this . max ;
@@ -116,26 +111,22 @@ export abstract class IgcProgressBaseComponent extends LitElement {
116111 }
117112
118113 @watch ( 'value' )
119- protected valueChange ( ) {
114+ protected _valueChange ( ) : void {
120115 this . value = clamp ( this . value , 0 , this . max ) ;
121116
122117 if ( ! this . indeterminate ) {
123118 this . _updateProgress ( ) ;
124119 }
125120 }
126121
127- protected override createRenderRoot ( ) {
128- const root = super . createRenderRoot ( ) ;
129- root . addEventListener ( 'slotchange' , ( ) => this . requestUpdate ( ) ) ;
130- return root ;
131- }
132-
133- protected override updated ( ) {
122+ protected override updated ( ) : void {
134123 this . _updateARIA ( ) ;
135124 }
136125
137- private _updateARIA ( ) {
138- const text = this . labelFormat ? this . renderLabelFormat ( ) : `${ this . value } %` ;
126+ private _updateARIA ( ) : void {
127+ const text = this . labelFormat
128+ ? this . _renderLabelFormat ( )
129+ : `${ this . value } %` ;
139130
140131 this . _internals . setARIA ( {
141132 ariaValueMax : this . max . toString ( ) ,
@@ -144,7 +135,7 @@ export abstract class IgcProgressBaseComponent extends LitElement {
144135 } ) ;
145136 }
146137
147- private _updateProgress ( ) {
138+ private _updateProgress ( ) : void {
148139 const percentage = asPercent ( this . value , Math . max ( 1 , this . max ) ) ;
149140 const fractionValue = Math . round ( ( percentage % 1 ) * 100 ) ;
150141 this . _hasFraction = fractionValue > 0 ;
@@ -157,29 +148,31 @@ export abstract class IgcProgressBaseComponent extends LitElement {
157148 } ;
158149 }
159150
160- protected renderLabel ( ) {
151+ protected _renderLabel ( ) {
161152 const parts = {
162153 label : true ,
163154 value : true ,
164155 fraction : this . _hasFraction ,
165156 } ;
166157
167158 return this . labelFormat
168- ? html `< span part =${ partMap ( parts ) } > ${ this . renderLabelFormat ( ) } </ span > `
159+ ? html `< span part =${ partMap ( parts ) } > ${ this . _renderLabelFormat ( ) } </ span > `
169160 : html `< span part =${ partMap ( { ...parts , counter : true } ) } > </ span > ` ;
170161 }
171162
172- protected renderLabelFormat ( ) {
163+ protected _renderLabelFormat ( ) : string {
173164 return formatString ( this . labelFormat , this . value , this . max ) ;
174165 }
175166
176- protected renderDefaultSlot ( ) {
167+ protected _renderDefaultSlot ( ) {
177168 const hideDefaultLabel =
178- this . indeterminate || this . hideLabel || ! isEmpty ( this . _assignedElements ) ;
169+ this . indeterminate ||
170+ this . hideLabel ||
171+ this . _slots . hasAssignedElements ( '[default]' ) ;
179172
180173 return html `
181174 < slot part ="label "> </ slot >
182- ${ hideDefaultLabel ? nothing : this . renderLabel ( ) }
175+ ${ hideDefaultLabel ? nothing : this . _renderLabel ( ) }
183176 ` ;
184177 }
185178}
0 commit comments