@@ -812,6 +812,165 @@ export const DEFAULT_VIEW = (input, _output, target) => {
812812};
813813```
814814
815+ ## Binding an action to a button
816+
817+ Use the ` bindToAction ` directive to create a button that is bound to a registered action. The button's properties (e.g., ` title ` , ` disabled ` ) will be automatically updated when the action's state changes.
818+
819+ ** Before:**
820+ ``` typescript
821+ class SomeWidget extends UI .Widget .Widget implements UI .Toolbar .ItemsProvider {
822+ constructor () {
823+ super ();
824+ this .toolbarItemsInternal = [];
825+ this .toolbarItemsInternal .push (UI .Toolbar .Toolbar .createActionButton (' elements.refresh-event-listeners' ));
826+ }
827+
828+ toolbarItems(): UI .Toolbar .ToolbarItem [] {
829+ return this .toolbarItemsInternal ;
830+ }
831+ }
832+ ```
833+
834+ ** After:**
835+ ``` typescript
836+ export const DEFAULT_VIEW = (input , _output , target ) => {
837+ const {bindToAction} = UI .UIUtils ;
838+ render (html `
839+ <div>
840+ <devtools-toolbar>
841+ <devtools-button ${bindToAction (' elements.refresh-event-listeners' )}></devtools-button>
842+ </devtools-toolbar>
843+ </div> ` ,
844+ target , {host: input });
845+ };
846+ ```
847+
848+ ## Binding a setting to a checkbox
849+
850+ Use the ` bindToSetting ` directive to bind a boolean setting to a ` <devtools-checkbox> ` component.
851+
852+ ** Before:**
853+ ``` typescript
854+ class SomeWidget extends UI .Widget .Widget {
855+ constructor () {
856+ super ();
857+ const toolbar = this .contentElement .createChild (' devtools-toolbar' );
858+ const showAllPropertiesSetting = Common .Settings .Settings .instance ().createSetting (' show-all-properties' , false );
859+ toolbar .appendToolbarItem (new UI .Toolbar .ToolbarSettingCheckbox (
860+ showAllPropertiesSetting , i18nString (UIStrings .showAllTooltip ), i18nString (UIStrings .showAll )));
861+ }
862+ }
863+ ```
864+
865+ ** After:**
866+ ``` typescript
867+ export const DEFAULT_VIEW = (input , _output , target ) => {
868+ const {bindToSetting} = UI .SettingsUI ;
869+ const showAllPropertiesSetting = Common .Settings .Settings .instance ().createSetting (' show-all-properties' , false );
870+ render (html `
871+ <div>
872+ <devtools-toolbar>
873+ <devtools-checkbox title=${i18nString (UIStrings .showAllTooltip )} ${bindToSetting (showAllPropertiesSetting )}>
874+ ${i18nString (UIStrings .showAll )}
875+ </devtools-checkbox>
876+ </devtools-toolbar>
877+ </div> ` ,
878+ target , {host: input });
879+ };
880+ ```
881+
882+ ## Migrating ` UI.Toolbar.ToolbarComboBox `
883+
884+ Replace the imperative creation of a ` ToolbarComboBox ` with a declarative ` <select> ` element.
885+
886+ ** Before:**
887+ ``` typescript
888+ class SomeWidget extends UI .Widget .Widget {
889+ constructor () {
890+ super ();
891+ const toolbar = this .contentElement .createChild (' devtools-toolbar' );
892+ toolbar .appendToolbarItem (new UI .Toolbar .ToolbarComboBox (
893+ this .someToolbarComboBoxClicked .bind (this ), ' Combox' ,
894+ ' the-toolbar-combox' , ' some-toolbar-combox' ));
895+ }
896+ }
897+ ```
898+
899+ ** After:**
900+ ``` typescript
901+ export const DEFAULT_VIEW = (input , _output , target ) => {
902+ render (html `
903+ <div>
904+ <devtools-toolbar>
905+ <select class="the-toolbar-combox" title="Combox" aria-label="Combox"
906+ jslog=${VisualLogging .dropDown (' some-toolbar-combox' ).track ({change: true })}
907+ @change=${this .someToolbarComboBoxClicked .bind (this )}></select>
908+ </devtools-toolbar>
909+ </div> ` ,
910+ target , {host: input });
911+ };
912+ ```
913+
914+ ## Migrating various Toolbar items
915+
916+ Replace various imperative ` UI.Toolbar ` methods like ` appendSeparator ` , ` appendSpacer ` , and ` setEnabled ` with their declarative equivalents.
917+
918+ ** Before:**
919+ ``` typescript
920+ class SomeWidget extends UI .Widget .Widget {
921+ constructor () {
922+ super ();
923+ const toolbar = this .contentElement .createChild (' devtools-toolbar' );
924+ toolbar .wrappable = true ;
925+ toolbar .appendSeparator ();
926+ const combo = new UI .Toolbar .ToolbarComboBox (this .onSelect .bind (this ), ' aria-label' , undefined , ' combo-box' );
927+ combo .createOption (' Option 1' , ' 1' , ' option-1' );
928+ const option2 = document .createElement (' option' );
929+ option2 .value = ' 2' ;
930+ option2 .textContent = ' Option 2' ;
931+ combo .addOption (option2 );
932+ toolbar .appendToolbarItem (combo );
933+ toolbar .appendSpacer ();
934+ const button = new UI .Toolbar .ToolbarButton (' Click me' , ' largeicon-add' );
935+ button .setEnabled (false );
936+ toolbar .appendToolbarItem (button );
937+ const otherButton = new UI .Toolbar .ToolbarButton (' Other button' , ' largeicon-delete' );
938+ otherButton .setEnabled (this .isEnabled );
939+ toolbar .appendToolbarItem (otherButton );
940+ toolbar .appendToolbarItem (new UI .Toolbar .ToolbarSeparator ());
941+ toolbar .appendToolbarItem (new UI .Toolbar .ToolbarSeparator (false ));
942+ toolbar .appendToolbarItem (new UI .Toolbar .ToolbarSeparator (true ));
943+ }
944+ }
945+ ```
946+
947+ ** After:**
948+ ``` typescript
949+ export const DEFAULT_VIEW = (input , _output , target ) => {
950+ render (html `
951+ <div>
952+ <devtools-toolbar wrappable>
953+ <div class="toolbar-divider"></div>
954+ <select title="aria-label" aria-label="aria-label"
955+ jslog=${VisualLogging .dropDown (' combo-box' ).track ({change: true })}
956+ @change=${this .onSelect .bind (this )}>
957+ <option value="1" jslog=${VisualLogging .item (' option-1' ).track ({click: true })}>Option 1</option>
958+ <option value="2">Option 2</option>
959+ </select>
960+ <div class="toolbar-spacer"></div>
961+ <devtools-button title="Click me" .variant=${Buttons .Button .Variant .TOOLBAR }
962+ .iconName=${' largeicon-add' } disabled></devtools-button>
963+ <devtools-button title="Other button" ?disabled=${! this .isEnabled }
964+ .variant=${Buttons .Button .Variant .TOOLBAR } .iconName=${' largeicon-delete' }></devtools-button>
965+ <div class="toolbar-divider"></div>
966+ <div class="toolbar-divider"></div>
967+ <div class="toolbar-spacer"></div>
968+ </devtools-toolbar>
969+ </div> ` ,
970+ target , {host: input });
971+ };
972+ ```
973+
815974## Migrating ` iframe ` creation
816975
817976Replace ` document.createElement('iframe') ` and ` setAttribute ` calls with a declarative ` <iframe> ` tag in a lit-html template.
0 commit comments