11import { Component , Prop , Part } from '@pictogrammers/element' ;
22
3- import PgInputSelect from '../inputSelect/inputSelect ' ;
3+ import PgOverlaySelectMenu from '../overlaySelectMenu/overlaySelectMenu ' ;
44
55import template from './jsonBoolean.html' ;
66import style from './jsonBoolean.css' ;
@@ -15,32 +15,53 @@ export default class PgJsonBoolean extends HTMLElement {
1515 @Prop ( ) value : boolean = false ;
1616
1717 @Part ( ) $key : HTMLDivElement ;
18- @Part ( ) $value : PgInputSelect ;
18+ @Part ( ) $value : HTMLButtonElement ;
1919
2020 connectedCallback ( ) {
21- this . $value . options . push (
22- { label : 'true' , value : 'true' } ,
23- { label : 'false' , value : 'false' } ,
24- ) ;
25- this . $value . addEventListener ( 'input' , ( e : any ) => {
26- this . $value . value = e . detail . value ;
27- this . dispatchEvent (
28- new CustomEvent ( 'update' , {
29- detail : {
30- path : [ this . key ] ,
31- value : e . detail . value ,
32- }
33- } )
34- ) ;
35- } ) ;
21+ this . $value . addEventListener ( 'click' , this . #handleClick. bind ( this ) ) ;
22+ // this.$value.value = e.detail.value;
23+ // this.dispatchEvent(
24+ // new CustomEvent('update', {
25+ // detail: {
26+ // path: [this.key],
27+ // value: e.detail.value,
28+ // }
29+ // })
30+ // );
3631 }
3732
3833 render ( changes ) {
3934 if ( changes . key ) {
4035 this . $key . textContent = this . key ;
4136 }
4237 if ( changes . value ) {
43- this . $value . value = this . value ? 'true' : 'false' ;
38+ this . $value . textContent = this . value ? 'true' : 'false' ;
39+ }
40+ }
41+
42+ options = [
43+ { label : 'true' , value : 'true' } ,
44+ { label : 'false' , value : 'false' } ,
45+ ] ;
46+
47+ #menuOpen = false ;
48+ async #handleClick( ) {
49+ if ( this . #menuOpen) { return ; }
50+ this . #menuOpen = true ;
51+ const result = await PgOverlaySelectMenu . open ( {
52+ source : this . $value ,
53+ value : this . options . find ( x => x . value === `${ this . value } ` ) ?? 'false' ,
54+ items : this . options ,
55+ } ) ;
56+ if ( result !== undefined ) {
57+ this . dispatchEvent ( new CustomEvent ( 'change' , {
58+ detail : {
59+ value : result . value
60+ }
61+ } ) ) ;
62+ this . $value . textContent = result . label ;
63+ this . value = result . value === 'true' ;
4464 }
65+ this . #menuOpen = false ;
4566 }
4667}
0 commit comments