Skip to content

Commit 85cd9c5

Browse files
committed
feat: refactor + convert pl-toggle-info to lit-element
1 parent 95a3b21 commit 85cd9c5

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { LitElement, html, customElement } from 'lit-element';
2+
import { store } from '../../store.js'; // connect to the Redux store.
3+
import { updateDrawerState } from '../../actions/app.js'; // redux actions
4+
import styles from './pl-toggle-info.scss?external';
5+
6+
@customElement('pl-toggle-info')
7+
class InfoToggle extends LitElement {
8+
constructor(self) {
9+
self = super(self);
10+
self.handleClick = self.handleClick.bind(self);
11+
return self;
12+
}
13+
14+
createRenderRoot() {
15+
return this;
16+
}
17+
18+
static get properties() {
19+
return {
20+
isDrawerOpen: {
21+
attribute: true,
22+
type: Boolean,
23+
},
24+
isViewallPage: {
25+
attribute: true,
26+
type: Boolean,
27+
},
28+
};
29+
}
30+
31+
connectedCallback() {
32+
if (super.connectedCallback) {
33+
super.connectedCallback();
34+
}
35+
36+
const state = store.getState();
37+
this.isDrawerOpen = state.app.drawerOpened;
38+
this.isViewallPage = state.app.isViewallPage;
39+
40+
this.__storeUnsubscribe = store.subscribe(() =>
41+
this._stateChanged(store.getState())
42+
);
43+
this._stateChanged(store.getState());
44+
}
45+
46+
disconnectedCallback() {
47+
this.__storeUnsubscribe && this.__storeUnsubscribe();
48+
49+
if (super.disconnectedCallback) {
50+
super.disconnectedCallback();
51+
}
52+
}
53+
54+
_stateChanged(state) {
55+
this.isDrawerOpen = state.app.drawerOpened;
56+
this.isViewallPage = state.app.isViewallPage;
57+
}
58+
59+
handleClick() {
60+
this.isDrawerOpen = !this.isDrawerOpen;
61+
store.dispatch(updateDrawerState(this.isDrawerOpen));
62+
}
63+
64+
render() {
65+
return html`
66+
<pl-button @click="${this.handleClick}">
67+
<span slot="default"
68+
>${this.isDrawerOpen ? 'Hide' : 'Show'}
69+
${this.isViewallPage ? 'all' : ''} Pattern Info</span
70+
>
71+
<pl-icon
72+
name="${this.isDrawerOpen ? 'hide' : 'show'}"
73+
slot="after"
74+
></pl-icon>
75+
</pl-button>
76+
`;
77+
}
78+
}
79+
80+
export { InfoToggle };
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@import '../../../sass/scss/core.scss';
2+
3+
pl-toggle-info {
4+
display: flex;
5+
align-self: center;
6+
justify-content: center;
7+
align-items: center;
8+
z-index: 10;
9+
width: 100%;
10+
cursor: pointer;
11+
}
12+
13+
.pl-c-toggle-info,
14+
.pl-c-toggle-info__action {
15+
width: 100%;
16+
}

0 commit comments

Comments
 (0)