|
2 | 2 | * RB-TOGGLE
|
3 | 3 | ***********/
|
4 | 4 | import { RbBase, props, html } from '../../rb-base/scripts/rb-base.js';
|
| 5 | +import Converter from '../../rb-base/scripts/public/props/converters.js'; |
| 6 | +import Type from '../../rb-base/scripts/public/services/type.js'; |
| 7 | +import View from '../../rb-base/scripts/public/view/directives.js'; |
5 | 8 | import template from '../views/rb-toggle.html';
|
| 9 | +import '../../rb-button/scripts/rb-button.js'; |
| 10 | +import '../../rb-popover/scripts/rb-popover.js'; |
6 | 11 |
|
7 | 12 | export class RbToggle extends RbBase() {
|
| 13 | + /* Lifecycle |
| 14 | + ************/ |
| 15 | + viewReady() { // :void |
| 16 | + super.viewReady && super.viewReady(); |
| 17 | + Object.assign(this.rb.elms, { |
| 18 | + rbButton: this.shadowRoot.querySelector('rb-button') |
| 19 | + }); |
| 20 | + this.rb.events.add(this.rb.elms.rbButton, 'click', this._toggleAction); |
| 21 | + } |
| 22 | + |
8 | 23 | /* Properties
|
9 | 24 | *************/
|
10 | 25 | static get props() {
|
11 | 26 | return {
|
12 |
| - kind: props.string |
| 27 | + kind: props.string, |
| 28 | + caption: props.string, |
| 29 | + inline: props.boolean, |
| 30 | + action: Object.assign({}, props.string, { |
| 31 | + deserialize(val) { |
| 32 | + if (!val) return; |
| 33 | + return new Function(`return ${val}`)(); |
| 34 | + } |
| 35 | + }), |
| 36 | + disabled: Object.assign({}, props.boolean, { |
| 37 | + deserialize: Converter.valueless |
| 38 | + }), |
| 39 | + open: Object.assign({}, props.boolean, { |
| 40 | + deserialize: Converter.valueless |
| 41 | + }) |
13 | 42 | };
|
14 | 43 | }
|
15 | 44 |
|
| 45 | + /* Helpers |
| 46 | + **********/ |
| 47 | + _toggle() { // :void |
| 48 | + this.open = !this.open; |
| 49 | + } |
| 50 | + |
| 51 | + /* Event Handlers |
| 52 | + *****************/ |
| 53 | + async _toggleAction(evt) { // :void |
| 54 | + if (this.disabled) return; |
| 55 | + if (!Type.is.function(this.action)) return this._toggle(); |
| 56 | + const result = await this.action(); |
| 57 | + this._toggle(); |
| 58 | + } |
| 59 | + |
16 | 60 | /* Template
|
17 | 61 | ***********/
|
18 | 62 | render({ props, state }) { // :string
|
|
0 commit comments