Skip to content

Commit eeaf81f

Browse files
committed
refactor: Removed support for static strings
Simplified some of the logic in the `update` method of the directive. Fixed some instances where static parts were still present.
1 parent 0e8e603 commit eeaf81f

File tree

3 files changed

+14
-29
lines changed

3 files changed

+14
-29
lines changed

src/components/common/part-map.ts

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@ import {
99
} from 'lit/directive.js';
1010

1111
export interface PartMapInfo {
12-
readonly [name: string]: string | boolean | number;
12+
readonly [name: string]: boolean | null | undefined;
1313
}
1414

1515
class PartMapDirective extends Directive {
1616
private _previousParts?: Set<string>;
17-
private _staticParts?: Set<string>;
1817

1918
constructor(partInfo: PartInfo) {
2019
super(partInfo);
2120

2221
if (
2322
partInfo.type !== PartType.ATTRIBUTE ||
2423
partInfo.name !== 'part' ||
25-
(partInfo.strings?.length as number) > 2
24+
(partInfo.strings?.length as number) > 0
2625
) {
2726
throw new Error(
2827
'`partMap() can only be used in the `part` attribute and must be the only part in the attribute.'
@@ -40,47 +39,33 @@ class PartMapDirective extends Directive {
4039
part: AttributePart,
4140
[partMapInfo]: DirectiveParameters<this>
4241
) {
42+
const partList = part.element.part;
43+
4344
if (this._previousParts === undefined) {
4445
this._previousParts = new Set();
45-
if (part.strings !== undefined) {
46-
this._staticParts = new Set(
47-
part.strings
48-
.join(' ')
49-
.split(/\s/)
50-
.filter((s) => s !== '')
51-
);
52-
}
46+
5347
for (const name in partMapInfo) {
54-
if (partMapInfo[name] && !this._staticParts?.has(name)) {
48+
if (partMapInfo[name]) {
49+
partList.add(name);
5550
this._previousParts.add(name);
5651
}
5752
}
5853

5954
return this.render(partMapInfo);
6055
}
6156

62-
const partList = part.element.part;
63-
6457
for (const name of this._previousParts) {
65-
if (!(name in partMapInfo)) {
58+
if (!(name in partMapInfo) || !partMapInfo[name]) {
6659
partList.remove(name);
67-
this._previousParts!.delete(name);
60+
this._previousParts.delete(name);
6861
}
6962
}
7063

7164
for (const name in partMapInfo) {
7265
const value = !!partMapInfo[name];
73-
if (
74-
value !== this._previousParts.has(name) &&
75-
!this._staticParts?.has(name)
76-
) {
77-
if (value) {
78-
partList.add(name);
79-
this._previousParts.add(name);
80-
} else {
81-
partList.remove(name);
82-
this._previousParts.delete(name);
83-
}
66+
if (value && !this._previousParts.has(name)) {
67+
partList.add(name);
68+
this._previousParts.add(name);
8469
}
8570
}
8671

src/components/progress/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export abstract class IgcProgressBaseComponent extends LitElement {
170170

171171
return this.labelFormat
172172
? html`<span part=${partMap(parts)}>${this.renderLabelFormat()}</span>`
173-
: html`<span part="${partMap(parts)} counter"></span>`;
173+
: html`<span part=${partMap({ ...parts, counter: true })}></span>`;
174174
}
175175

176176
protected renderLabelFormat() {

src/components/progress/linear-progress.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default class IgcLinearProgressComponent extends IgcProgressBaseComponent
6666
<div part="base" style=${styleMap(this._styleInfo)}>
6767
<div part="track">
6868
<div part=${partMap(parts)}></div>
69-
<div part="${partMap(parts)} secondary"></div>
69+
<div part=${partMap({ ...parts, secondary: true })}></div>
7070
</div>
7171
${this.renderDefaultSlot()}
7272
</div>

0 commit comments

Comments
 (0)