Skip to content

Commit

Permalink
refactor(progressbars): Added CSS parts documentation
Browse files Browse the repository at this point in the history
* Moved slotchange to a delegated handler
* Some minor template cleanups
  • Loading branch information
rkaraivanov committed Jun 6, 2024
1 parent 562e34a commit 1e2780c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 34 deletions.
12 changes: 7 additions & 5 deletions src/components/progress/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ export abstract class IgcProgressBaseComponent extends LitElement {
}
}

protected slotChanged() {
this.requestUpdate();
}

constructor() {
super();
this.__internals = this.attachInternals();
Expand All @@ -127,6 +123,12 @@ export abstract class IgcProgressBaseComponent extends LitElement {
this.__internals.ariaValueMin = '0';
}

protected override createRenderRoot() {
const root = super.createRenderRoot();
root.addEventListener('slotchange', () => this.requestUpdate());
return root;
}

protected override updated() {
this._updateARIA();
}
Expand Down Expand Up @@ -201,7 +203,7 @@ export abstract class IgcProgressBaseComponent extends LitElement {
this.indeterminate || this.hideLabel || this.assignedElements.length;

return html`
<slot part="label" @slotchange=${this.slotChanged}></slot>
<slot part="label"></slot>
${hasNoLabel
? nothing
: html`<span part="label value">${this.renderLabelText()}</span>`}
Expand Down
28 changes: 14 additions & 14 deletions src/components/progress/circular-progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ import { all } from './themes/circular/themes.js';
* @slot - The text area container.
* @slot gradient - Customize the progress bar in order to use a color gradient instead of a solid color. Accepts `igc-circular-gradient` elements.
*
* @csspart svg
* @csspart gradient_start
* @csspart gradient_end
* @csspart track
* @csspart fill
* @csspart label
* @csspart value
* @csspart indeterminate
* @csspart primary
* @csspart danger
* @csspart warning
* @csspart info
* @csspart success
* @csspart svg - The igc-circular-progress SVG element.
* @csspart gradient_start - The igc-circular-progress linear-gradient start color.
* @csspart gradient_end - The igc-circular-progress linear-gradient end color.
* @csspart track - The igc-circular-progress ring track area.
* @csspart fill - The igc-circular-progress indicator area.
* @csspart label - The igc-circular-progress label.
* @csspart value - The igc-circular-progress label value.
* @csspart indeterminate - The igc-circular-progress indeterminate state.
* @csspart primary - The igc-circular-progress primary state.
* @csspart danger - The igc-circular-progress error state.
* @csspart warning - The igc-circular-progress warning state.
* @csspart info - The igc-circular-progress info state.
* @csspart success - The igc-circular-progress success state.
*/
@themes(all)
export default class IgcCircularProgressComponent extends IgcProgressBaseComponent {
Expand Down Expand Up @@ -92,7 +92,7 @@ export default class IgcCircularProgressComponent extends IgcProgressBaseCompone

return html`
<svg part=${partNameMap(parts)}>${this.renderSvg()}</svg>
<slot name="gradient" @slotchange=${this.slotChanged}></slot>
<slot name="gradient"></slot>
${this.renderDefaultSlot()}
`;
}
Expand Down
30 changes: 15 additions & 15 deletions src/components/progress/linear-progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ import { all } from './themes/linear/themes.js';
*
* @slot - The text area container.
*
* @csspart track
* @csspart fill
* @csspart striped
* @csspart label
* @csspart value
* @csspart indeterminate
* @csspart primary
* @csspart danger
* @csspart warning
* @csspart info
* @csspart success
* @csspart track - The igc-linear-progress track area.
* @csspart fill - The igc-linear-progress indicator area.
* @csspart striped - The igc-linear-progress striped indicator.
* @csspart label - The igc-linear-progress label.
* @csspart value - The igc-linear-progress label value.
* @csspart indeterminate - The igc-linear-progress indeterminate state.
* @csspart primary - The igc-linear-progress indicator primary state.
* @csspart danger - The igc-linear-progress indicator error state.
* @csspart warning - The igc-linear-progress indicator warning state.
* @csspart info - The igc-linear-progress indicator info state.
* @csspart success - The igc-linear-progress indicator success state.
*/
@themes(all)
export default class IgcLinearProgressComponent extends IgcProgressBaseComponent {
Expand Down Expand Up @@ -61,7 +61,7 @@ export default class IgcLinearProgressComponent extends IgcProgressBaseComponent
| 'bottom-end' = 'top-start';

protected override render() {
const parts = {
const parts = partNameMap({
fill: true,
striped: this.striped,
indeterminate: this.indeterminate,
Expand All @@ -70,7 +70,7 @@ export default class IgcLinearProgressComponent extends IgcProgressBaseComponent
danger: this.variant === 'danger',
warning: this.variant === 'warning',
info: this.variant === 'info',
};
});

const animation = {
width: `${this.progress * 100}%`,
Expand All @@ -79,8 +79,8 @@ export default class IgcLinearProgressComponent extends IgcProgressBaseComponent

return html`
<div part="track">
<div part=${partNameMap(parts)} style=${styleMap(animation)}></div>
<div part="${partNameMap(parts)} secondary"></div>
<div part=${parts} style=${styleMap(animation)}></div>
<div part="${parts} secondary"></div>
</div>
${this.renderDefaultSlot()}
`;
Expand Down

0 comments on commit 1e2780c

Please sign in to comment.