@@ -5,58 +5,109 @@ import template from './basic.html';
55import PgTreeButtonIcon from '../../../treeButtonIcon/treeButtonIcon' ;
66
77const IconEye = 'M12,9A3,3 0 0,0 9,12A3,3 0 0,0 12,15A3,3 0 0,0 15,12A3,3 0 0,0 12,9M12,17A5,5 0 0,1 7,12A5,5 0 0,1 12,7A5,5 0 0,1 17,12A5,5 0 0,1 12,17M12,4.5C7,4.5 2.73,7.61 1,12C2.73,16.39 7,19.5 12,19.5C17,19.5 21.27,16.39 23,12C21.27,7.61 17,4.5 12,4.5Z' ;
8+ const IconEyeOff = 'M2,5.27L3.28,4L20,20.72L18.73,22L15.65,18.92C14.5,19.3 13.28,19.5 12,19.5C7,19.5 2.73,16.39 1,12C1.69,10.24 2.79,8.69 4.19,7.46L2,5.27M12,9A3,3 0 0,1 15,12C15,12.35 14.94,12.69 14.83,13L11,9.17C11.31,9.06 11.65,9 12,9M12,4.5C17,4.5 21.27,7.61 23,12C22.18,14.08 20.79,15.88 19,17.19L17.58,15.76C18.94,14.82 20.06,13.54 20.82,12C19.17,8.64 15.76,6.5 12,6.5C10.91,6.5 9.84,6.68 8.84,7L7.3,5.47C8.74,4.85 10.33,4.5 12,4.5M3.18,12C4.83,15.36 8.24,17.5 12,17.5C12.69,17.5 13.37,17.43 14,17.29L11.72,15C10.29,14.85 9.15,13.71 9,12.28L5.6,8.87C4.61,9.72 3.78,10.78 3.18,12Z' ;
9+ const IconLock = 'M12,17A2,2 0 0,0 14,15C14,13.89 13.1,13 12,13A2,2 0 0,0 10,15A2,2 0 0,0 12,17M18,8A2,2 0 0,1 20,10V20A2,2 0 0,1 18,22H6A2,2 0 0,1 4,20V10C4,8.89 4.9,8 6,8H7V6A5,5 0 0,1 12,1A5,5 0 0,1 17,6V8H18M12,3A3,3 0 0,0 9,6V8H15V6A3,3 0 0,0 12,3Z' ;
10+ const IconUnlock = 'M18,8A2,2 0 0,1 20,10V20A2,2 0 0,1 18,22H6C4.89,22 4,21.1 4,20V10A2,2 0 0,1 6,8H15V6A3,3 0 0,0 12,3A3,3 0 0,0 9,6H7A5,5 0 0,1 12,1A5,5 0 0,1 17,6V8H18M12,17A2,2 0 0,0 14,15A2,2 0 0,0 12,13A2,2 0 0,0 10,15A2,2 0 0,0 12,17Z' ;
11+
12+ function createItem ( key ) {
13+ return {
14+ icon : {
15+ path : IconEye
16+ } ,
17+ label : 'Item 1' ,
18+ actions : [ {
19+ type : PgTreeButtonIcon ,
20+ icon : IconEye ,
21+ enabled : true
22+ } ,
23+ {
24+ type : PgTreeButtonIcon ,
25+ label : 'Delete' ,
26+ icon : IconUnlock ,
27+ enabled : false
28+ } ]
29+ } ;
30+ }
831
932@Component ( {
1033 selector : 'x-pg-tree-basic' ,
1134 template
1235} )
1336export default class XPgTreeBasic extends HTMLElement {
1437 @Part ( ) $tree : PgTree ;
38+ @Part ( ) $tree2 : PgTree ;
1539 @Part ( ) $addItem : HTMLButtonElement ;
40+ @Part ( ) $removeItem : HTMLButtonElement ;
41+ @Part ( ) $updateItem : HTMLButtonElement ;
1642
1743 connectedCallback ( ) {
18- this . $tree . addEventListener ( 'action' , ( e ) => {
44+ this . $tree . addEventListener ( 'action' , ( e : any ) => {
1945 // action clicked
20- console . log ( 'action' )
46+ const { index, actionIndex } = e . detail ;
47+ const action = this . $tree . items [ index ] . actions [ actionIndex ] ;
48+ const { enabled } = action ;
49+ if ( actionIndex === 0 && enabled ) {
50+ action . icon = IconEyeOff ;
51+ action . enabled = false ;
52+ } else if ( actionIndex === 0 && ! enabled ) {
53+ action . icon = IconEye ;
54+ action . enabled = true ;
55+ }
56+ if ( actionIndex === 1 && enabled ) {
57+ action . icon = IconUnlock ;
58+ action . enabled = false ;
59+ } else if ( actionIndex === 1 && ! enabled ) {
60+ action . icon = IconLock ;
61+ action . enabled = true ;
62+ }
2163 } ) ;
22- this . $tree . addEventListener ( 'rename' , ( e ) => {
23- // action clicked
64+ this . $tree . addEventListener ( 'rename' , ( e : any ) => {
65+ const { index, label } = e . detail ;
66+ this . $tree . items [ index ] . label = label ;
2467 } ) ;
25- this . $tree . addEventListener ( 'menu' , ( e ) => {
68+ this . $tree . addEventListener ( 'menu' , ( e : any ) => {
2669 // action clicked
2770 } ) ;
28- this . $tree . items . push ( {
29- key : 1 ,
71+ this . $tree . items = [ {
3072 icon : {
3173 path : IconEye
3274 } ,
3375 label : 'Item 1' ,
3476 actions : [ {
3577 type : PgTreeButtonIcon ,
36- icon : {
37- path : IconEye
38- }
78+ icon : IconEye ,
79+ enabled : true
3980 } ,
4081 {
4182 type : PgTreeButtonIcon ,
4283 label : 'Delete' ,
43- icon : {
44- path : IconEye
45- }
84+ icon : IconUnlock ,
85+ enabled : false
4686 } ]
4787 } ,
4888 {
49- key : 2 ,
5089 label : 'Item 2'
51- } ) ;
90+ } ] ;
91+ // Assign to same array instance!
92+ this . $tree2 . items = this . $tree . items ;
93+ // Push to same array instance!
94+ this . $tree . items . push ( { label : 'testing' } ) ;
5295
5396 let next : number = 2 ;
5497 this . $addItem . addEventListener ( 'click' , ( ) => {
5598 next ++ ;
5699 this . $tree . items . push ( {
57- key : `${ next } ` ,
58100 label : `Item ${ next } `
59101 } ) ;
60102 } ) ;
103+
104+ this . $removeItem . addEventListener ( 'click' , ( ) => {
105+ this . $tree . items . pop ( ) ;
106+ } ) ;
107+
108+ let updatedTimes = 0 ;
109+ this . $updateItem . addEventListener ( 'click' , ( ) => {
110+ this . $tree . items [ 1 ] . label = `Updated ${ updatedTimes ++ } ` ;
111+ } ) ;
61112 }
62113}
0 commit comments