|
| 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 }; |
0 commit comments