Skip to content

Commit 36cb033

Browse files
bmeurerDevtools-frontend LUCI CQ
authored andcommitted
[unified-css] Migrate icon_button component.
Now that we have an agreement on how to proceed with the CSS in the front-end, migrate the `icon_button` component as the first guinea pig, and remove the offending ESLint rule. Bug: 391381439 Change-Id: Ie996db09fcf9dfc329206f62b136fad62583b730 Doc: https://goo.gle/devtools-unified-css-design Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6216261 Commit-Queue: Benedikt Meurer <[email protected]> Reviewed-by: Danil Somsikov <[email protected]> Auto-Submit: Benedikt Meurer <[email protected]>
1 parent 2e725f7 commit 36cb033

File tree

10 files changed

+27
-155
lines changed

10 files changed

+27
-155
lines changed

config/gni/devtools_grd_files.gni

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,9 +2234,9 @@ grd_files_debug_sources = [
22342234
"front_end/ui/components/icon_button/FileSourceIcon.js",
22352235
"front_end/ui/components/icon_button/Icon.js",
22362236
"front_end/ui/components/icon_button/IconButton.js",
2237-
"front_end/ui/components/icon_button/fileSourceIcon.css.js",
2238-
"front_end/ui/components/icon_button/icon.css.js",
2239-
"front_end/ui/components/icon_button/iconButton.css.js",
2237+
"front_end/ui/components/icon_button/fileSourceIcon.css.legacy.js",
2238+
"front_end/ui/components/icon_button/icon.css.legacy.js",
2239+
"front_end/ui/components/icon_button/iconButton.css.legacy.js",
22402240
"front_end/ui/components/input/checkbox.css.js",
22412241
"front_end/ui/components/input/textInput.css.js",
22422242
"front_end/ui/components/issue_counter/IssueCounter.js",

eslint.config.mjs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,11 @@ export default [
281281
parserOptions: {
282282
allowAutomaticSingleRunInference: true,
283283
project: join(
284-
import.meta.dirname,
285-
'config',
286-
'typescript',
287-
'tsconfig.eslint.json',
288-
),
284+
import.meta.dirname,
285+
'config',
286+
'typescript',
287+
'tsconfig.eslint.json',
288+
),
289289
},
290290
},
291291

@@ -474,12 +474,12 @@ export default [
474474
{
475475
// Enforce that any import of models/trace/trace.js names the import Trace.
476476
modulePath: join(
477-
import.meta.dirname,
478-
'front_end',
479-
'models',
480-
'trace',
481-
'trace.js',
482-
),
477+
import.meta.dirname,
478+
'front_end',
479+
'models',
480+
'trace',
481+
'trace.js',
482+
),
483483
importName: 'Trace',
484484
},
485485
],
@@ -530,7 +530,6 @@ export default [
530530
'rulesdir/no-bound-component-methods': 'error',
531531
'rulesdir/no-customized-builtin-elements': 'error',
532532
'rulesdir/no-self-closing-custom-element-tagnames': 'error',
533-
'rulesdir/no-style-tags-in-lit': 'error',
534533
'rulesdir/no-a-tags-in-lit': 'error',
535534
'rulesdir/check-css-import': 'error',
536535
'rulesdir/enforce-optional-properties-last': 'error',
@@ -685,7 +684,6 @@ export default [
685684
// anything, so we leave return types to the developer within the
686685
// component_docs folder.
687686
'@typescript-eslint/explicit-function-return-type': 'off',
688-
'rulesdir/no-style-tags-in-lit': 'off',
689687
// We use Lit to help render examples sometimes and we don't use
690688
// {host: this} as often the `this` is the window.
691689
'rulesdir/lit-host-this': 'off',

front_end/panels/emulation/components/DeviceSizeInputElement.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ export class SizeInputElement extends HTMLElement {
6161
// For now, use an inline style tag and later we can refactor this
6262
// to use proper constructed stylesheets, when the code runs
6363
// in the correct frame context.
64-
// eslint-disable-next-line rulesdir/no-style-tags-in-lit
6564
html`
6665
<style>
6766
input {

front_end/ui/components/icon_button/BUILD.gn

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ import("../visibility.gni")
1111
generate_css("css_files") {
1212
sources = [
1313
"fileSourceIcon.css",
14+
"icon.css",
1415
"iconButton.css",
1516
]
16-
}
1717

18-
generate_css("legacy_css_files") {
19-
sources = [ "icon.css" ]
18+
legacy = true
2019
}
2120

2221
devtools_module("icon_button") {
@@ -38,7 +37,6 @@ devtools_entrypoint("bundle") {
3837
deps = [
3938
":css_files",
4039
":icon_button",
41-
":legacy_css_files",
4240
]
4341

4442
visibility = [

front_end/ui/components/icon_button/FileSourceIcon.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import * as Lit from '../../lit/lit.js';
66

7-
import styles from './fileSourceIcon.css.js';
7+
import fileSourceIconStyles from './fileSourceIcon.css.legacy.js';
88
import {create} from './Icon.js';
99

1010
const {html} = Lit;
@@ -44,7 +44,6 @@ export class FileSourceIcon extends HTMLElement {
4444
}
4545

4646
connectedCallback(): void {
47-
this.#shadow.adoptedStyleSheets = [styles];
4847
this.#render();
4948
}
5049

@@ -59,7 +58,9 @@ export class FileSourceIcon extends HTMLElement {
5958
const icon = create(this.#iconType, iconStyles.join(' '));
6059

6160
// clang-format off
62-
Lit.render(html`${icon}`, this.#shadow, {
61+
Lit.render(
62+
html`<style>${fileSourceIconStyles.cssContent}</style>${icon}`,
63+
this.#shadow, {
6364
host: this,
6465
});
6566
// clang-format on

front_end/ui/components/icon_button/Icon.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import iconStyles from './icon.css.js';
5+
import iconStyles from './icon.css.legacy.js';
66

77
/**
88
* @deprecated
@@ -72,13 +72,11 @@ export class Icon extends HTMLElement {
7272
constructor() {
7373
super();
7474
this.role = 'presentation';
75+
const style = document.createElement('style');
76+
style.textContent = iconStyles.cssContent;
7577
this.#icon = document.createElement('span');
7678
this.#shadowRoot = this.attachShadow({mode: 'open'});
77-
this.#shadowRoot.appendChild(this.#icon);
78-
}
79-
80-
connectedCallback(): void {
81-
this.#shadowRoot.adoptedStyleSheets = [iconStyles];
79+
this.#shadowRoot.append(style, this.#icon);
8280
}
8381

8482
/**

front_end/ui/components/icon_button/IconButton.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import './Icon.js';
77
import * as Lit from '../../lit/lit.js';
88

99
import type {IconData} from './Icon.js';
10-
import iconButtonStyles from './iconButton.css.js';
10+
import iconButtonStyles from './iconButton.css.legacy.js';
1111

1212
const {html} = Lit;
1313

@@ -58,10 +58,6 @@ export class IconButton extends HTMLElement {
5858
};
5959
}
6060

61-
connectedCallback(): void {
62-
this.#shadow.adoptedStyleSheets = [iconButtonStyles];
63-
}
64-
6561
#onClickHandler(event: Event): void {
6662
if (this.#clickHandler) {
6763
event.preventDefault();
@@ -80,6 +76,7 @@ export class IconButton extends HTMLElement {
8076
// Disabled until https://crbug.com/1079231 is fixed.
8177
// clang-format off
8278
Lit.render(html`
79+
<style>${iconButtonStyles.cssContent}</style>
8380
<button class=${buttonClasses} @click=${this.#onClickHandler} aria-label=${Lit.Directives.ifDefined(this.#accessibleName)}>
8481
${(!this.#compact && this.#leadingText) ? html`<span class="icon-button-title">${this.#leadingText}</span>` : Lit.nothing}
8582
${filteredGroups.map(counter =>

front_end/ui/legacy/components/perf_ui/BrickBreaker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const colorPallettes: ColorPalette[] = [
108108
},
109109
];
110110

111-
/* rulesdir/no-underscored-properties, rulesdir/no-style-tags-in-lit, rulesdir/no-a-tags-in-lit, rulesdir/lit-host-this */
111+
/* rulesdir/no-underscored-properties, rulesdir/no-a-tags-in-lit, rulesdir/lit-host-this */
112112
export class BrickBreaker extends HTMLElement {
113113
#canvas: HTMLCanvasElement;
114114
#ctx: CanvasRenderingContext2D;

scripts/eslint_rules/lib/no-style-tags-in-lit.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

scripts/eslint_rules/tests/no-style-tags-in-lit.test.js

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)