-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathdropdown-button.js
More file actions
83 lines (71 loc) · 2.77 KB
/
dropdown-button.js
File metadata and controls
83 lines (71 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
export default class DropdownButtonComponent extends Component {
@service abilities;
@tracked type = 'default';
@tracked buttonSize = 'md';
@tracked buttonComponentArgs = {};
@tracked _onInsertFired = false;
@tracked _onTriggerInsertFired = false;
@tracked _onButtonInsertFired = false;
@tracked disabled = false;
@tracked visible = true;
@tracked permissionRequired = false;
@tracked doesntHavePermissions = false;
/**
* Creates an instance of DropdownButtonComponent.
* @param {ApplicationInstance} owner
* @param {Object} { type = 'default', size = 'md', buttonComponentArgs = {}}
* @memberof DropdownButtonComponent
*/
constructor(owner, { type = 'default', size = 'md', buttonComponentArgs = {}, permission = null, disabled = false, visible = true }) {
super(...arguments);
this.type = type;
this.buttonSize = size;
this.buttonComponentArgs = buttonComponentArgs;
this.permissionRequired = permission;
this.disabled = disabled;
this.visible = visible;
// If no permissions disable
if (!disabled && permission) {
this.disabled = this.doesntHavePermissions = permission && this.abilities.cannot(permission);
}
}
@action onRegisterAPI() {
if (typeof this.args.registerAPI === 'function') {
this.args.registerAPI(...arguments);
}
}
@action onTriggerInsert() {
if (typeof this.args.onTriggerInsert === 'function') {
this.args.onTriggerInsert(...arguments);
}
this._onTriggerInsertFired = true;
// Fallback for insert, when `renderInPlace=false` Trigger becomes whole node
if (this.args.renderInPlace === true || this._onInsertFired === false) {
this.onInsert(...arguments);
}
}
@action onButtonInsert() {
if (typeof this.args.onButtonInsert === 'function') {
this.args.onButtonInsert(...arguments);
}
this._onButtonInsertFired = true;
}
@action onInsert() {
if (typeof this.args.onInsert === 'function') {
this.args.onInsert(...arguments);
}
this._onInsertFired = true;
}
@action onArgsChanged(el, [disabled = false, visible = true, permission = null, buttonComponentArgs = {}]) {
this.buttonComponentArgs = buttonComponentArgs;
this.visible = visible;
this.disabled = disabled;
if (!disabled && permission) {
this.disabled = this.doesntHavePermissions = permission && this.abilities.cannot(permission);
}
}
}