1+ import "@home-assistant/webawesome/dist/components/divider/divider" ;
12import {
23 mdiContentCopy ,
34 mdiContentCut ,
@@ -12,9 +13,10 @@ import { LitElement, css, html, nothing } from "lit";
1213import { customElement , property , state } from "lit/decorators" ;
1314import { classMap } from "lit/directives/class-map" ;
1415import { fireEvent } from "../../../common/dom/fire_event" ;
15- import "../../../components/ha-button-menu" ;
16+ import "../../../components/ha-dropdown" ;
17+ import "../../../components/ha-dropdown-item" ;
18+ import type { HaDropdownItem } from "../../../components/ha-dropdown-item" ;
1619import "../../../components/ha-icon-button" ;
17- import "../../../components/ha-list-item" ;
1820import "../../../components/ha-svg-icon" ;
1921import { haStyle } from "../../../resources/styles" ;
2022import type { HomeAssistant } from "../../../types" ;
@@ -41,9 +43,6 @@ export class HuiCardEditMode extends LitElement {
4143 @property ( { type : Boolean , attribute : "no-move" } )
4244 public noMove = false ;
4345
44- @state ( )
45- public _menuOpened = false ;
46-
4746 @state ( )
4847 public _hover = false ;
4948
@@ -91,8 +90,7 @@ export class HuiCardEditMode extends LitElement {
9190 } ;
9291
9392 protected render ( ) : TemplateResult {
94- const showOverlay =
95- ( this . _hover || this . _menuOpened || this . _focused ) && ! this . hiddenOverlay ;
93+ const showOverlay = ( this . _hover || this . _focused ) && ! this . hiddenOverlay ;
9694
9795 return html `
9896 <div class= "card-wrapper" inert > <slot> </ slot> </ div>
@@ -115,107 +113,71 @@ export class HuiCardEditMode extends LitElement {
115113 <ha- svg- icon .path = ${ mdiPencil } > </ ha- svg- icon>
116114 </ div>
117115 ` }
118- <ha- but to n - menu
116+ <ha- dropdown
119117 class= "more"
120- corner = "BOTTOM_END"
121- menu- cor ner= "END"
122- .path = ${ [ this . path ! ] }
123- @action = ${ this . _handleAction }
124- @opened = ${ this . _handleOpened }
125- @closed = ${ this . _handleClosed }
118+ placement = "botto m- end"
119+ @wa-select = ${ this . _handleDropdownSelect }
126120 >
127121 <ha- icon- butto n slot= "trigger" .path = ${ mdiDotsVertical } >
128122 </ ha- icon- butto n>
129123 ${ this . noEdit
130124 ? nothing
131125 : html `
132- <ha- lis t- item
133- graphic= "icon"
134- @click = ${ this . _handleAction }
135- .action = ${ "edit" }
136- >
137- <ha- svg- icon slot= "graphic" .path = ${ mdiPencil } > </ ha- svg- icon>
126+ <ha- dropdown- item value= "edit" >
127+ <ha- svg- icon slot= "icon" .path = ${ mdiPencil } > </ ha- svg- icon>
138128 ${ this . hass . localize (
139129 "ui.panel.lovelace.editor.edit_card.edit"
140130 ) }
141- </ ha- l is t - item>
131+ </ ha- dropdown - item>
142132 ` }
143133 ${ this . noDuplicate
144134 ? nothing
145135 : html `
146- <ha- lis t- item
147- graphic= "icon"
148- @click = ${ this . _handleAction }
149- .action = ${ "duplicate" }
150- >
136+ <ha- dropdown- item value= "duplicate" >
151137 <ha- svg- icon
152- slot= "graphic "
138+ slot= "icon "
153139 .path = ${ mdiPlusCircleMultipleOutline }
154140 > </ ha- svg- icon>
155141 ${ this . hass . localize (
156142 "ui.panel.lovelace.editor.edit_card.duplicate"
157143 ) }
158- </ ha- l is t - item>
144+ </ ha- dropdown - item>
159145 ` }
160146 ${ this . noMove
161147 ? nothing
162148 : html `
163- <ha- lis t- item
164- graphic= "icon"
165- @click = ${ this . _handleAction }
166- .action = ${ "copy" }
167- >
149+ <ha- dropdown- item value= "copy" >
168150 <ha- svg- icon
169- slot= "graphic "
151+ slot= "icon "
170152 .path = ${ mdiContentCopy }
171153 > </ ha- svg- icon>
172154 ${ this . hass . localize (
173155 "ui.panel.lovelace.editor.edit_card.copy"
174156 ) }
175- </ ha- lis t- item>
176- <ha- lis t- item
177- graphic= "icon"
178- @click = ${ this . _handleAction }
179- .action = ${ "cut" }
180- >
181- <ha- svg- icon
182- slot= "graphic"
183- .path = ${ mdiContentCut }
184- > </ ha- svg- icon>
157+ </ ha- dropdown- item>
158+ <ha- dropdown- item value= "cut" >
159+ <ha- svg- icon slot= "icon" .path = ${ mdiContentCut } > </ ha- svg- icon>
185160 ${ this . hass . localize (
186161 "ui.panel.lovelace.editor.edit_card.cut"
187162 ) }
188- </ ha- l is t - item>
163+ </ ha- dropdown - item>
189164 ` }
190165 ${ this . noDuplicate && this . noEdit && this . noMove
191166 ? nothing
192- : html `<li divider role= "separator" > </ li> ` }
193- <ha- lis t- item
194- graphic= "icon"
195- class = "warning"
196- @click = ${ this . _handleAction }
197- .action = ${ "delete" }
198- >
167+ : html `<wa- divider> </ wa- divider> ` }
168+ <ha- dropdown- item value= "delete" variant = "danger">
199169 ${ this . hass . localize ( "ui.panel.lovelace.editor.edit_card.delete" ) }
200170 <ha- svg- icon
201171 class= "warning"
202- slot = "graphic "
172+ slot = "icon "
203173 .path = ${ mdiDelete }
204174 > </ ha- svg- icon>
205- </ ha- l is t - item>
206- </ ha- but to n - menu >
175+ </ ha- dropdown - item>
176+ </ ha- dropdown >
207177 </ div>
208178 ` ;
209179 }
210180
211- private _handleOpened ( ) {
212- this . _menuOpened = true ;
213- }
214-
215- private _handleClosed ( ) {
216- this . _menuOpened = false ;
217- }
218-
219181 private _handleOverlayClick ( ev ) : void {
220182 if ( ev . defaultPrevented ) {
221183 return ;
@@ -228,8 +190,14 @@ export class HuiCardEditMode extends LitElement {
228190 this . _editCard ( ) ;
229191 }
230192
231- private _handleAction ( ev ) {
232- switch ( ev . currentTarget . action ) {
193+ private _handleDropdownSelect ( ev : CustomEvent < { item : HaDropdownItem } > ) {
194+ const action = ev . detail ?. item ?. value ;
195+
196+ if ( ! action ) {
197+ return ;
198+ }
199+
200+ switch ( action ) {
233201 case "edit" :
234202 this . _editCard ( ) ;
235203 break ;
@@ -330,14 +298,12 @@ export class HuiCardEditMode extends LitElement {
330298 background : var (--secondary-background-color );
331299 --mdc-icon-size : 20px ;
332300 }
333- .more {
301+ .more ha-icon-button {
334302 position : absolute;
335303 right : -6px ;
336304 top : -6px ;
337305 inset-inline-end : -6px ;
338306 inset-inline-start : initial;
339- }
340- .more ha-icon-button {
341307 cursor : pointer;
342308 border-radius : var (--ha-border-radius-circle );
343309 background : var (--secondary-background-color );
0 commit comments