@@ -3,17 +3,7 @@ import {
33 LimelListCustomEvent ,
44 ListItem ,
55} from '@limetech/lime-elements' ;
6- import {
7- Component ,
8- h ,
9- State ,
10- Element ,
11- Event ,
12- EventEmitter ,
13- Watch ,
14- } from '@stencil/core' ;
15- import { createRandomString } from 'src/util/random-string' ;
16- import { portalContains } from '../../portal/contains' ;
6+ import { Component , h , State , Element , Watch } from '@stencil/core' ;
177import {
188 ARROW_DOWN ,
199 ARROW_UP ,
@@ -46,10 +36,6 @@ import { TextEditor, TriggerEventDetail } from '../text-editor.types';
4636 styleUrl : 'text-editor-custom-triggers.scss' ,
4737} )
4838export class TextEditorCustomTriggersExample {
49- constructor ( ) {
50- this . portalId = createRandomString ( ) ;
51- this . handleClick = this . handleClick . bind ( this ) ;
52- }
5339 @State ( )
5440 private value : string = '' ;
5541
@@ -62,9 +48,6 @@ export class TextEditorCustomTriggersExample {
6248 @State ( )
6349 private isPickerOpen : boolean = false ;
6450
65- @State ( )
66- private textEditorElement : HTMLElement ;
67-
6851 @State ( )
6952 private insertMode : 'text' | 'chip' = 'text' ;
7053
@@ -83,12 +66,6 @@ export class TextEditorCustomTriggersExample {
8366 @Element ( )
8467 private host : HTMLLimelPopoverElement ;
8568
86- /**
87- * Emits an event when the component is closing
88- */
89- @Event ( )
90- private close : EventEmitter < void > ;
91-
9269 private insertModeButtons : Button [ ] = [
9370 {
9471 id : '1' ,
@@ -101,8 +78,6 @@ export class TextEditorCustomTriggersExample {
10178 } ,
10279 ] ;
10380
104- private portalId : string ;
105-
10681 private triggerFunction ?: TextEditor ;
10782
10883 @Watch ( 'isPickerOpen' )
@@ -125,16 +100,10 @@ export class TextEditorCustomTriggersExample {
125100
126101 private setupEventHandlers ( ) {
127102 if ( this . isPickerOpen ) {
128- this . host . addEventListener ( 'click' , this . handleClick , {
129- capture : true ,
130- } ) ;
131103 this . host . addEventListener ( 'keydown' , this . handleKeyPress , {
132104 capture : true ,
133105 } ) ;
134106 } else {
135- this . host . removeEventListener ( 'click' , this . handleClick , {
136- capture : true ,
137- } ) ;
138107 this . host . removeEventListener ( 'keydown' , this . handleKeyPress , {
139108 capture : true ,
140109 } ) ;
@@ -163,9 +132,7 @@ export class TextEditorCustomTriggersExample {
163132 }
164133
165134 if ( event . key === ESCAPE ) {
166- this . close . emit ( ) ;
167135 this . isPickerOpen = false ;
168- // @TODO : close the trigger session
169136 }
170137 } ;
171138
@@ -212,9 +179,9 @@ export class TextEditorCustomTriggersExample {
212179
213180 public render ( ) {
214181 return [
182+ this . renderPicker ( ) ,
215183 < limel-text-editor
216184 style = { { display : 'block' } }
217- ref = { ( el ) => ( this . textEditorElement = el ) }
218185 value = { this . value }
219186 customElements = { [
220187 { tagName : 'limel-chip' , attributes : [ 'text' , 'icon' ] } ,
@@ -243,37 +210,20 @@ export class TextEditorCustomTriggersExample {
243210 />
244211 </ div >
245212 </ limel-example-controls > ,
246- this . renderPicker ( ) ,
247213 < limel-example-value value = { this . value } /> ,
248214 ] ;
249215 }
250216
251217 private renderPicker = ( ) => {
252- if ( ! this . isPickerOpen ) {
253- return ;
254- }
255-
256- const dropdownZIndex = getComputedStyle ( this . host ) . getPropertyValue (
257- '--dropdown-z-index' ,
258- ) ;
259-
260- return [
261- < limel-portal
262- containerStyle = { {
263- 'background-color' : 'rgb(var(--contrast-100))' ,
264- 'border-radius' : '0.5rem' ,
265- 'box-shadow' : 'var(--shadow-depth-16)' ,
266- 'z-index' : dropdownZIndex ,
267- } }
268- containerId = { this . portalId }
269- visible = { this . isPickerOpen }
270- openDirection = "bottom-start"
271- inheritParentWidth = { true }
272- anchor = { this . textEditorElement }
218+ return (
219+ < limel-popover
220+ open = { this . isPickerOpen }
221+ openDirection = "top-start"
222+ onClose = { this . handleTriggerStop }
273223 >
274224 { this . renderList ( this . visibleItems ) }
275- </ limel-portal > ,
276- ] ;
225+ </ limel-popover >
226+ ) ;
277227 } ;
278228
279229 private renderList = ( items : Array < ListItem < number > > ) => {
@@ -314,17 +264,6 @@ export class TextEditorCustomTriggersExample {
314264 this . value = event . detail ;
315265 } ;
316266
317- private handleClick ( event : MouseEvent ) {
318- const element : HTMLElement = event . target as HTMLElement ;
319- const clickedInside = portalContains ( this . host , element ) ;
320- if ( this . isPickerOpen && ! clickedInside ) {
321- event . stopPropagation ( ) ;
322- event . preventDefault ( ) ;
323- this . isPickerOpen = false ;
324- this . close . emit ( ) ;
325- }
326- }
327-
328267 private handleListChange = (
329268 event : LimelListCustomEvent < ListItem < number > > ,
330269 ) => {
0 commit comments