1
- /* eslint-disable no-unused-vars, no-param-reassign */
2
- import { define , props } from 'skatejs' ;
3
- import { h } from 'preact' ;
4
-
1
+ import { styleMap } from 'lit-html/directives/style-map' ;
2
+ import { classMap } from 'lit-html/directives/class-map' ;
3
+ import { LitElement , html , customElement } from 'lit-element' ;
5
4
import { store } from '../../store.js' ; // redux store
6
5
import {
7
6
updateDrawerState ,
8
7
updateDrawerHeight ,
9
8
updateDrawerAnimationState ,
10
9
} from '../../actions/app.js' ; // redux actions needed by this element.
11
- import { css } from '../../utils' ;
12
- import { BaseComponent } from '../base-component.js' ;
13
- import AnimateHeight from 'react-animate-height' ;
14
- import CloseIcon from '../../../icons/close.svg' ;
15
-
16
- @define
17
- class Drawer extends BaseComponent {
18
- static is = 'pl-drawer' ;
19
10
11
+ @customElement ( 'pl-drawer' )
12
+ class Drawer extends LitElement {
20
13
constructor ( self ) {
21
14
self = super ( self ) ;
22
15
self . onMouseDown = self . onMouseDown . bind ( self ) ; // fix bindings so "self" works properly
23
16
self . onMouseUp = self . onMouseUp . bind ( self ) ; // fix bindings so "self" works properly
24
17
self . onMouseMove = self . onMouseMove . bind ( self ) ; // fix bindings so "this" works properly
25
- self . useShadow = false ;
26
18
return self ;
27
19
}
28
20
29
- state = {
30
- isMouseDown : false ,
31
- isMouseUp : false ,
32
- isDragging : false ,
33
- hasDragged : false ,
34
- panelHeight : '50vh' ,
35
- } ;
21
+ static get properties ( ) {
22
+ return {
23
+ drawerOpened : {
24
+ attribute : true ,
25
+ type : Boolean ,
26
+ } ,
27
+ drawerHeight : {
28
+ attribute : true ,
29
+ type : Number ,
30
+ } ,
31
+ isViewallPage : {
32
+ attribute : true ,
33
+ type : Boolean ,
34
+ } ,
35
+ isMouseDown : {
36
+ attribute : true ,
37
+ type : Boolean ,
38
+ } ,
39
+ } ;
40
+ }
41
+
42
+ createRenderRoot ( ) {
43
+ return this ;
44
+ }
36
45
37
46
onMouseDown ( ) {
38
- this . setState ( {
39
- ...this . state ,
40
- isMouseDown : true ,
41
- } ) ;
42
-
47
+ this . isMouseDown = true ;
43
48
store . dispatch ( updateDrawerAnimationState ( true ) ) ;
44
49
45
50
document . addEventListener ( 'mousemove' , this . onMouseMove ) ;
@@ -53,96 +58,103 @@ class Drawer extends BaseComponent {
53
58
: event . clientY ;
54
59
const panelHeight = window . innerHeight - clientHeight + 7 ;
55
60
56
- store . dispatch ( updateDrawerHeight ( panelHeight ) ) ;
57
-
58
- this . setState ( {
59
- ...this . state ,
60
- isDragging : true ,
61
- panelHeight : `${ panelHeight } px` ,
62
- } ) ;
61
+ this . drawerHeight = panelHeight ;
63
62
}
64
63
65
64
onMouseUp ( ) {
66
- this . setState ( {
67
- ...this . state ,
68
- hasDragged : this . state . isDragging ,
69
- isDragging : false ,
70
- isMouseDown : false ,
71
- isMouseUp : true ,
72
- } ) ;
73
-
74
- store . dispatch ( updateDrawerAnimationState ( false ) ) ;
75
-
65
+ this . isMouseDown = false ;
76
66
document . removeEventListener ( 'mousemove' , this . onMouseMove ) ;
77
67
document . removeEventListener ( 'mouseup' , this . onMouseUp ) ;
78
- }
79
68
80
- static props = {
81
- drawerOpened : props . boolean ,
82
- } ;
83
-
84
- render ( { drawerOpened, drawerHeight, isViewallPage } ) {
85
- const classes = css (
86
- 'pl-c-drawer' ,
87
- 'pl-js-drawer' ,
88
- drawerOpened && ! isViewallPage ? 'pl-is-active' : ''
89
- ) ;
69
+ store . dispatch ( updateDrawerHeight ( this . drawerHeight ) ) ;
70
+ store . dispatch ( updateDrawerAnimationState ( false ) ) ;
71
+ }
90
72
91
- const height =
92
- drawerOpened && ! isViewallPage
93
- ? drawerHeight > 20
94
- ? drawerHeight
73
+ render ( ) {
74
+ const classes = {
75
+ 'pl-c-drawer' : true ,
76
+ 'pl-js-drawer' : true ,
77
+ 'pl-is-active' : this . drawerOpened && ! this . isViewallPage ,
78
+ } ;
79
+
80
+ const renderedHeight =
81
+ this . drawerOpened && ! this . isViewallPage
82
+ ? this . drawerHeight > 20
83
+ ? this . drawerHeight
95
84
: 300
96
85
: 0 ;
97
86
98
- return (
87
+ const coverStyles = { display : this . isMouseDown ? 'block' : 'none' } ;
88
+ const drawerStyles = {
89
+ height : `${ renderedHeight } px` ,
90
+ transitionDuration : this . isMouseDown ? '0ms' : '300ms' ,
91
+ } ;
92
+
93
+ return html `
99
94
< div >
100
- < div
101
- class = "pl-c-drawer__cover"
102
- style = { this . state . isMouseDown ? 'display: block;' : 'display: none;' }
103
- />
104
- < AnimateHeight
105
- duration = { this . state . isMouseDown ? 0 : 300 }
106
- height = { height }
107
- className = "pl-c-drawer__wrapper"
108
- >
109
- < div className = { classes } >
95
+ < div class ="pl-c-drawer__cover " style ="${ styleMap ( coverStyles ) } "> </ div >
96
+ < div style ="${ styleMap ( drawerStyles ) } " class ="pl-c-drawer__wrapper ">
97
+ < div class ="${ classMap ( classes ) } ">
110
98
< div class ="pl-c-drawer__toolbar ">
111
99
< div
112
100
class ="pl-c-drawer__resizer "
113
- onMouseDown = { this . onMouseDown }
114
- / >
101
+ @mousedown =" $ {this . onMouseDown } "
102
+ > </ div >
115
103
< div class ="pl-c-drawer__toolbar-controls ">
116
- { /* <pl-toggle-layout></pl-toggle-layout> */ }
104
+ < pl-toggle-layout
105
+ size ="small "
106
+ icon-only ="true "
107
+ > </ pl-toggle-layout >
117
108
118
- < button
119
- class = "pl-c-drawer__close-btn"
109
+ < pl-button
120
110
title ="Hide pattern info "
121
111
title ="Menu "
122
- onClick = { _ => store . dispatch ( updateDrawerState ( false ) ) }
112
+ size ="small "
113
+ icon-only ="true "
114
+ @click ="${ _ => store . dispatch ( updateDrawerState ( false ) ) } "
123
115
>
124
- < CloseIcon
125
- width = { 20 }
126
- height = { 20 }
127
- fill = "currentColor"
128
- viewBox = "0 0 24 24"
129
- className = { 'pl-c-drawer__close-btn-icon' }
130
- />
131
- </ button >
116
+ < pl-icon slot ="after " name ="close "> </ pl-icon >
117
+ </ pl-button >
132
118
</ div >
133
119
</ div >
134
- < div class = "pl-c-drawer__content pl-js-drawer-content" / >
120
+ < div class ="pl-c-drawer__content pl-js-drawer-content "> </ div >
135
121
</ div >
136
- </ AnimateHeight >
122
+ </ div >
137
123
</ div >
124
+ ` ;
125
+ }
126
+
127
+ connectedCallback ( ) {
128
+ if ( super . connectedCallback ) {
129
+ super . connectedCallback ( ) ;
130
+ }
131
+ this . __storeUnsubscribe = store . subscribe ( ( ) =>
132
+ this . _stateChanged ( store . getState ( ) )
138
133
) ;
134
+ this . _stateChanged ( store . getState ( ) ) ;
135
+ }
136
+
137
+ disconnectedCallback ( ) {
138
+ this . __storeUnsubscribe && this . __storeUnsubscribe ( ) ;
139
+
140
+ if ( super . disconnectedCallback ) {
141
+ super . disconnectedCallback ( ) ;
142
+ }
139
143
}
140
144
141
145
_stateChanged ( state ) {
142
- this . drawerOpened = state . app . drawerOpened ;
143
- this . drawerHeight = state . app . drawerHeight ;
144
- this . isDragging = state . app . isDragging ;
145
- this . isViewallPage = state . app . isViewallPage ;
146
+ if ( this . drawerOpened !== state . app . drawerOpened ) {
147
+ this . drawerOpened = state . app . drawerOpened ;
148
+ }
149
+ if ( this . drawerHeight !== state . app . drawerHeight ) {
150
+ this . drawerHeight = state . app . drawerHeight ;
151
+ }
152
+ if ( this . isDragging !== state . app . isDragging ) {
153
+ this . isDragging = state . app . isDragging ;
154
+ }
155
+ if ( this . isViewallPage !== state . app . isViewallPage ) {
156
+ this . isViewallPage = state . app . isViewallPage ;
157
+ }
146
158
}
147
159
}
148
160
0 commit comments