Skip to content

Commit 93d16c5

Browse files
Kateryna ProkopenkoDevtools-frontend LUCI CQ
authored andcommitted
Migrate more icons off of the data setter
Bypass-Check-License: Only updating files, no new files are added. Bug: 414330824 Change-Id: I8fc79f3f4a4efa578852f668dc64e2f9ae997a87 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6874768 Auto-Submit: Kateryna Prokopenko <[email protected]> Commit-Queue: Kateryna Prokopenko <[email protected]> Reviewed-by: Ergün Erdoğmuş <[email protected]> Commit-Queue: Ergün Erdoğmuş <[email protected]>
1 parent adac104 commit 93d16c5

File tree

12 files changed

+71
-58
lines changed

12 files changed

+71
-58
lines changed

front_end/panels/application/StorageView.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,8 @@ export class StorageView extends UI.ThrottledWidget.ThrottledWidget {
519519

520520
if (!response.overrideActive && response.quota < 125829120) { // 120 MB
521521
const icon = new IconButton.Icon.Icon();
522-
icon.data = {iconName: 'info', color: 'var(--icon-info)'};
522+
icon.name = 'info';
523+
icon.style.color = 'var(--icon-info)';
523524
icon.classList.add('small');
524525
UI.Tooltip.Tooltip.install(this.quotaRow, i18nString(UIStrings.storageQuotaIsLimitedIn));
525526
this.quotaRow.appendChild(icon);

front_end/panels/console/ConsolePrompt.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ export class ConsolePrompt extends Common.ObjectWrapper.eventMixin<EventTypes, t
125125
this.element.appendChild(this.eagerPreviewElement);
126126

127127
this.promptIcon = new IconButton.Icon.Icon();
128-
this.promptIcon.data = {iconName: 'chevron-right', color: 'var(--icon-action)'};
128+
this.promptIcon.name = 'chevron-right';
129+
this.promptIcon.style.color = 'var(--icon-action)';
129130
this.promptIcon.classList.add('console-prompt-icon', 'medium');
130131
this.element.appendChild(this.promptIcon);
131132
this.iconThrottler = new Common.Throttler.Throttler(0);

front_end/panels/console/ConsoleViewMessage.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,10 +1462,8 @@ export class ConsoleViewMessage implements ConsoleViewportElement {
14621462

14631463
#createHoverButton(): HTMLButtonElement {
14641464
const icon = new IconButton.Icon.Icon();
1465-
icon.data = {
1466-
iconName: 'lightbulb-spark',
1467-
color: 'var(--devtools-icon-color)',
1468-
};
1465+
icon.name = 'lightbulb-spark';
1466+
icon.style.color = 'var(--devtools-icon-color)';
14691467
icon.classList.add('medium');
14701468
const button = document.createElement('button');
14711469
button.append(icon);
@@ -1527,10 +1525,8 @@ export class ConsoleViewMessage implements ConsoleViewportElement {
15271525
}
15281526

15291527
this.messageIcon = new IconButton.Icon.Icon();
1530-
this.messageIcon.data = {
1531-
iconName,
1532-
color,
1533-
};
1528+
this.messageIcon.name = iconName;
1529+
this.messageIcon.style.color = color;
15341530
this.messageIcon.classList.add('message-level-icon', 'small');
15351531
if (this.contentElementInternal) {
15361532
this.contentElementInternal.insertBefore(this.messageIcon, this.contentElementInternal.firstChild);

front_end/panels/elements/ElementsTreeElement.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@ export class ElementsTreeElement extends UI.TreeOutline.TreeElement {
418418

419419
if (this.nodeInternal.retained && !this.isClosingTag()) {
420420
const icon = new IconButton.Icon.Icon();
421-
// FIXME: this needs to be updated, data field is deprecated
422-
icon.data = {iconName: 'small-status-dot', color: 'var(--icon-error)'};
421+
icon.name = 'small-status-dot';
422+
icon.style.color = 'var(--icon-error)';
423423
icon.classList.add('extra-small');
424424
icon.style.setProperty('vertical-align', 'middle');
425425
this.setLeadingIcons([icon]);

front_end/panels/screencast/ScreencastView.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,8 @@ export class ScreencastView extends UI.Widget.VBox implements SDK.OverlayModel.H
694694
this.mouseInputToggle.disabled = true;
695695
{
696696
this.mouseInputToggleIcon = this.mouseInputToggle.appendChild(new IconButton.Icon.Icon());
697-
this.mouseInputToggleIcon.data = {color: 'var(--icon-toggled)', iconName: 'mouse'};
697+
this.mouseInputToggleIcon.name = 'mouse';
698+
this.mouseInputToggleIcon.classList.toggle('toggled', true);
698699
}
699700
UI.ARIAUtils.setLabel(this.mouseInputToggle, i18nString(UIStrings.mouseInput));
700701

front_end/panels/sources/DebuggerPausedMessage.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,8 @@ export class DebuggerPausedMessage {
159159

160160
const mainElement = messageWrapper.createChild('div', 'status-main');
161161
const mainIcon = new IconButton.Icon.Icon();
162-
mainIcon.data = {
163-
iconName: 'info',
164-
color: 'var(--sys-color-on-yellow-container)',
165-
};
162+
mainIcon.name = 'info';
163+
mainIcon.style.color = 'var(--sys-color-on-yellow-container)';
166164
mainIcon.classList.add('medium');
167165
mainElement.appendChild(mainIcon);
168166
const breakpointType = BreakpointTypeNouns.get(data.type);
@@ -293,10 +291,8 @@ export class DebuggerPausedMessage {
293291
const messageWrapper = document.createElement('span');
294292
const mainElement = messageWrapper.createChild('div', 'status-main');
295293
const mainIcon = new IconButton.Icon.Icon();
296-
mainIcon.data = {
297-
iconName: errorLike ? 'cross-circle-filled' : 'info',
298-
color: errorLike ? 'var(--icon-error)' : 'var(--sys-color-on-yellow-container)',
299-
};
294+
mainIcon.name = errorLike ? 'cross-circle-filled' : 'info';
295+
mainIcon.style.color = errorLike ? 'var(--icon-error)' : 'var(--sys-color-on-yellow-container)';
300296
mainIcon.classList.add('medium');
301297
mainElement.appendChild(mainIcon);
302298
mainElement.appendChild(document.createTextNode(mainText));

front_end/panels/sources/OpenFileQuickOpen.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ export class OpenFileQuickOpen extends FilteredUISourceCodeListProvider {
4444
super.renderItem(itemIndex, query, titleElement, subtitleElement);
4545

4646
const iconElement = new IconButton.Icon.Icon();
47-
const iconData = PanelUtils.iconDataForResourceType(this.itemContentTypeAt(itemIndex));
48-
iconElement.data = iconData;
47+
const {iconName, color} = PanelUtils.iconDataForResourceType(this.itemContentTypeAt(itemIndex));
48+
iconElement.name = iconName;
49+
if (color) {
50+
iconElement.style.color = color;
51+
}
4952
iconElement.classList.add('large');
5053
titleElement.parentElement?.parentElement?.insertBefore(iconElement, titleElement.parentElement);
5154
}

front_end/panels/sources/UISourceCodeFrame.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ export class UISourceCodeFrame extends Common.ObjectWrapper
538538
}
539539
}
540540

541-
function getIconDataForLevel(level: Workspace.UISourceCode.Message.Level): IconButton.Icon.IconData {
541+
function getIconDataForLevel(level: Workspace.UISourceCode.Message.Level): IconButton.Icon.IconWithName {
542542
if (level === Workspace.UISourceCode.Message.Level.ERROR) {
543543
return {color: 'var(--icon-error)', width: '16px', height: '14px', iconName: 'cross-circle-filled'};
544544
}
@@ -571,7 +571,7 @@ function messageLevelComparator(a: RowMessage, b: RowMessage): number {
571571
return messageLevelPriority[a.level()] - messageLevelPriority[b.level()];
572572
}
573573

574-
function getIconDataForMessage(message: RowMessage): IconButton.Icon.IconData {
574+
function getIconDataForMessage(message: RowMessage): IconButton.Icon.IconWithName {
575575
if (message.origin instanceof IssuesManager.SourceFrameIssuesManager.IssueMessage) {
576576
return {iconName: IssueCounter.IssueCounter.getIssueKindIconName(message.origin.getIssueKind())};
577577
}
@@ -704,14 +704,16 @@ class MessageWidget extends CodeMirror.WidgetType {
704704
const nonIssues = this.messages.filter(msg => msg.level() !== Workspace.UISourceCode.Message.Level.ISSUE);
705705
if (nonIssues.length) {
706706
const maxIssue = nonIssues.sort(messageLevelComparator)[nonIssues.length - 1];
707-
const errorIcon = wrap.appendChild(new IconButton.Icon.Icon());
708-
errorIcon.data = getIconDataForLevel(maxIssue.level());
707+
const iconData = getIconDataForLevel(maxIssue.level());
708+
const errorIcon = createIconFromIconData(iconData);
709+
wrap.appendChild(errorIcon);
709710
errorIcon.classList.add('cm-messageIcon-error');
710711
}
711712
const issue = this.messages.find(m => m.level() === Workspace.UISourceCode.Message.Level.ISSUE);
712713
if (issue) {
713-
const issueIcon = wrap.appendChild(new IconButton.Icon.Icon());
714-
issueIcon.data = getIconDataForMessage(issue);
714+
const iconData = getIconDataForMessage(issue);
715+
const issueIcon = createIconFromIconData(iconData);
716+
wrap.appendChild(issueIcon);
715717
issueIcon.classList.add('cm-messageIcon-issue', 'extra-small');
716718
issueIcon.addEventListener('click', () => (issue.clickHandler() || Math.min)());
717719
}
@@ -750,6 +752,18 @@ class RowMessageDecorations {
750752
}
751753
}
752754

755+
function createIconFromIconData(data: IconButton.Icon.IconWithName): IconButton.Icon.Icon {
756+
const icon = new IconButton.Icon.Icon();
757+
icon.name = data.iconName;
758+
if (data.width) {
759+
icon.style.width = data.width;
760+
}
761+
if (data.height) {
762+
icon.style.height = data.height;
763+
}
764+
return icon;
765+
}
766+
753767
const showRowMessages = CodeMirror.StateField.define<RowMessageDecorations>({
754768
create(state): RowMessageDecorations {
755769
return RowMessageDecorations.create(new RowMessages([]), state.doc);
@@ -782,8 +796,9 @@ function renderMessage(message: RowMessage, count: number): HTMLElement {
782796
element.style.gap = '4px';
783797

784798
if (count === 1) {
785-
const icon = element.appendChild(new IconButton.Icon.Icon());
786-
icon.data = getIconDataForMessage(message);
799+
const data = getIconDataForMessage(message);
800+
const icon = createIconFromIconData(data);
801+
element.appendChild(icon);
787802
icon.classList.add('text-editor-row-message-icon', 'extra-small');
788803
icon.addEventListener('click', () => (message.clickHandler() || Math.min)());
789804
} else {

front_end/ui/components/icon_button/Icon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface IconWithName {
2222
*/
2323
export type IconData = IconWithName|{
2424
iconPath: string,
25-
color: string,
25+
color?: string,
2626
width?: string,
2727
height?: string,
2828
};

front_end/ui/legacy/components/color_picker/ContrastDetails.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,10 @@ export class ContrastDetails extends Common.ObjectWrapper.ObjectWrapper<EventTyp
274274
this.contrastPassFailAPCA.createChild('span').textContent = `: ${apcaThreshold.toFixed(2)}%`;
275275
}
276276
if (passesAPCA) {
277-
const iconCheckmark = new IconButton.Icon.Icon();
278-
iconCheckmark
279-
.data = {iconName: 'checkmark', color: 'var(--icon-checkmark-green)', width: '20px', height: '14px'};
277+
const iconCheckmark = createIconCheckmark();
280278
this.contrastPassFailAPCA.appendChild(iconCheckmark);
281279
} else {
282-
const iconNo = new IconButton.Icon.Icon();
283-
iconNo.data = {iconName: 'clear', color: 'var(--icon-error)'};
284-
iconNo.classList.add('small');
280+
const iconNo = createIconNo();
285281
this.contrastPassFailAPCA.appendChild(iconNo);
286282
const suggestedColor = this.computeSuggestedColor('APCA');
287283
if (suggestedColor) {
@@ -325,13 +321,10 @@ export class ContrastDetails extends Common.ObjectWrapper.ObjectWrapper<EventTyp
325321
this.contrastPassFailAA.createChild('span').textContent =
326322
i18nString(UIStrings.placeholderWithColon, {PH1: aa.toFixed(1)});
327323
if (this.passesAA) {
328-
const iconCheckmark = new IconButton.Icon.Icon();
329-
iconCheckmark.data = {iconName: 'checkmark', color: 'var(--icon-checkmark-green)', width: '20px', height: '14px'};
324+
const iconCheckmark = createIconCheckmark();
330325
this.contrastPassFailAA.appendChild(iconCheckmark);
331326
} else {
332-
const iconNo = new IconButton.Icon.Icon();
333-
iconNo.data = {iconName: 'clear', color: 'var(--icon-error)'};
334-
iconNo.classList.add('small');
327+
const iconNo = createIconNo();
335328
this.contrastPassFailAA.appendChild(iconNo);
336329
const suggestedColor = this.computeSuggestedColor('aa');
337330
if (suggestedColor) {
@@ -349,13 +342,10 @@ export class ContrastDetails extends Common.ObjectWrapper.ObjectWrapper<EventTyp
349342
this.contrastPassFailAAA.createChild('span').textContent =
350343
i18nString(UIStrings.placeholderWithColon, {PH1: aaa.toFixed(1)});
351344
if (passesAAA) {
352-
const iconCheckmark = new IconButton.Icon.Icon();
353-
iconCheckmark.data = {iconName: 'checkmark', color: 'var(--icon-checkmark-green)', width: '20px', height: '14px'};
345+
const iconCheckmark = createIconCheckmark();
354346
this.contrastPassFailAAA.appendChild(iconCheckmark);
355347
} else {
356-
const iconNo = new IconButton.Icon.Icon();
357-
iconNo.data = {iconName: 'clear', color: 'var(--icon-error)'};
358-
iconNo.classList.add('small');
348+
const iconNo = createIconNo();
359349
this.contrastPassFailAAA.appendChild(iconNo);
360350
const suggestedColor = this.computeSuggestedColor('aaa');
361351
if (suggestedColor) {
@@ -500,3 +490,20 @@ export class Swatch {
500490
this.swatchElement.classList.toggle('swatch-inner-white', bgColor.as(Common.Color.Format.HSL).l > 0.9);
501491
}
502492
}
493+
494+
function createIconCheckmark(): IconButton.Icon.Icon {
495+
const icon = new IconButton.Icon.Icon();
496+
icon.name = 'checkmark';
497+
icon.style.color = 'var(--icon-checkmark-green)';
498+
icon.style.width = 'var(--sys-size-9)';
499+
icon.style.height = 'var(--sys-size-7)';
500+
return icon;
501+
}
502+
503+
function createIconNo(): IconButton.Icon.Icon {
504+
const icon = new IconButton.Icon.Icon();
505+
icon.name = 'clear';
506+
icon.style.color = 'var(--icon-error)';
507+
icon.classList.add('small');
508+
return icon;
509+
}

0 commit comments

Comments
 (0)