11// Copyright 2024 The Chromium Authors
22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
4- /* eslint-disable @devtools/no-lit-render-outside-of-view */
54
65/**
76 * @file A list of pass/fail conditions for an insight.
@@ -11,11 +10,13 @@ import '../../../../ui/kit/kit.js';
1110
1211import * as i18n from '../../../../core/i18n/i18n.js' ;
1312import type * as Trace from '../../../../models/trace/trace.js' ;
14- import * as ComponentHelpers from '../../../../ui/components/helpers/helpers .js' ;
13+ import * as UI from '../../../../ui/legacy/legacy .js' ;
1514import * as Lit from '../../../../ui/lit/lit.js' ;
1615
1716import checklistStyles from './checklist.css.js' ;
1817
18+ const { html} = Lit ;
19+
1920const UIStrings = {
2021 /**
2122 * @description Text for a screen-reader label to tell the user that the icon represents a successful insight check
@@ -32,7 +33,43 @@ const UIStrings = {
3233const str_ = i18n . i18n . registerUIStrings ( 'panels/timeline/components/insights/Checklist.ts' , UIStrings ) ;
3334const i18nString = i18n . i18n . getLocalizedString . bind ( undefined , str_ ) ;
3435
35- const { html} = Lit ;
36+ interface ViewInput {
37+ checklist : GenericChecklist ;
38+ }
39+
40+ type View = ( input : ViewInput , output : undefined , target : HTMLElement ) => void ;
41+
42+ export const DEFAULT_VIEW : View = ( input , output , target ) => {
43+ const {
44+ checklist,
45+ } = input ;
46+
47+ function getIcon ( check : GenericChecklist [ '' ] ) : Lit . TemplateResult {
48+ const icon = check . value ? 'check-circle' : 'clear' ;
49+
50+ const ariaLabel = check . value ? i18nString ( UIStrings . successAriaLabel , { PH1 : check . label } ) :
51+ i18nString ( UIStrings . failedAriaLabel , { PH1 : check . label } ) ;
52+ return html `
53+ < devtools-icon
54+ aria-label =${ ariaLabel }
55+ name =${ icon }
56+ class=${ check . value ? 'check-passed' : 'check-failed' }
57+ > </ devtools-icon >
58+ ` ;
59+ }
60+
61+ // clang-format off
62+ Lit . render ( html `
63+ < style > ${ checklistStyles } </ style >
64+ < ul >
65+ ${ Object . values ( checklist ) . map ( check => html `< li >
66+ ${ getIcon ( check ) }
67+ < span data-checklist-label > ${ check . label } </ span >
68+ </ li > ` ) }
69+ </ ul >
70+ ` , target ) ;
71+ // clang-format on
72+ } ;
3673
3774// eslint-disable-next-line @typescript-eslint/no-explicit-any
3875type GenericChecklist = Trace . Insights . Types . Checklist < any > ;
@@ -46,55 +83,28 @@ export interface TableDataRow {
4683 overlays ?: Trace . Types . Overlays . Overlay [ ] ;
4784}
4885
49- export class Checklist extends HTMLElement {
50- readonly #shadow = this . attachShadow ( { mode : 'open' } ) ;
86+ export class Checklist extends UI . Widget . Widget {
87+ #view: View ;
5188 #checklist?: GenericChecklist ;
5289
53- set checklist ( checklist : GenericChecklist ) {
54- this . #checklist = checklist ;
55- void ComponentHelpers . ScheduledRender . scheduleRender ( this , this . #render) ;
56- }
57-
58- connectedCallback ( ) : void {
59- void ComponentHelpers . ScheduledRender . scheduleRender ( this , this . #render) ;
90+ constructor ( element ?: HTMLElement , view : View = DEFAULT_VIEW ) {
91+ super ( element , { useShadowDom : true } ) ;
92+ this . #view = view ;
6093 }
6194
62- #getIcon( check : GenericChecklist [ '' ] ) : Lit . TemplateResult {
63- const icon = check . value ? 'check-circle' : 'clear' ;
64-
65- const ariaLabel = check . value ? i18nString ( UIStrings . successAriaLabel , { PH1 : check . label } ) :
66- i18nString ( UIStrings . failedAriaLabel , { PH1 : check . label } ) ;
67- return html `
68- < devtools-icon
69- aria-label =${ ariaLabel }
70- name =${ icon }
71- class=${ check . value ? 'check-passed' : 'check-failed' }
72- > </ devtools-icon >
73- ` ;
95+ set checklist ( checklist : GenericChecklist ) {
96+ this . #checklist = checklist ;
97+ this . requestUpdate ( ) ;
7498 }
7599
76- async #render ( ) : Promise < void > {
100+ override performUpdate ( ) : void {
77101 if ( ! this . #checklist) {
78102 return ;
79103 }
80104
81- Lit . render (
82- html `
83- < style > ${ checklistStyles } </ style >
84- < ul >
85- ${ Object . values ( this . #checklist) . map ( check => html `< li >
86- ${ this . #getIcon( check ) }
87- < span data-checklist-label > ${ check . label } </ span >
88- </ li > ` ) }
89- </ ul > ` ,
90- this . #shadow, { host : this } ) ;
105+ const input : ViewInput = {
106+ checklist : this . #checklist,
107+ } ;
108+ this . #view( input , undefined , this . contentElement ) ;
91109 }
92110}
93-
94- declare global {
95- interface HTMLElementTagNameMap {
96- 'devtools-performance-checklist' : Checklist ;
97- }
98- }
99-
100- customElements . define ( 'devtools-performance-checklist' , Checklist ) ;
0 commit comments