Skip to content

Commit c21905e

Browse files
feat(addon/components/paper-button): migrates off proxiable mixin.
1 parent 9db6402 commit c21905e

File tree

2 files changed

+104
-2
lines changed

2 files changed

+104
-2
lines changed

addon/components/paper-button.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
target={{@target}}
2020
title={{@title}}
2121
type={{this.type}}
22-
{{did-insert this.registerListeners}}
23-
{{will-destroy this.unregisterListeners}}
22+
{{did-insert this.didInsertNode}}
23+
{{will-destroy this.willDestroyNode}}
2424
{{on 'click' this.handleClick}}
2525
...attributes
2626
>

addon/components/paper-button.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,80 @@
22
* @module ember-paper
33
*/
44
import Focusable from './-focusable';
5+
import { tracked } from '@glimmer/tracking';
56
import { action } from '@ember/object';
7+
import { assert } from '@ember/debug';
68

79
/**
810
* @class PaperButton
911
* @extends Focusable
1012
*/
1113
export default class PaperButton extends Focusable {
14+
/**
15+
* Reference to the component's DOM element
16+
* @type {HTMLElement}
17+
*/
18+
@tracked element;
19+
/**
20+
* The parent this component is bound to.
21+
* @type {Boolean}
22+
*/
23+
parent;
24+
/**
25+
* Marks whether the component should register itself to the supplied parent
26+
* @type {Boolean}
27+
*/
28+
shouldRegister;
29+
30+
constructor(owner, args) {
31+
super(owner, args);
32+
33+
this.shouldRegister = this.args.shouldRegister || false;
34+
if (this.shouldRegister) {
35+
assert(
36+
'A parent component should be supplied to <PaperButton> when shouldRegister=true',
37+
this.args.parent
38+
);
39+
this.parent = this.args.parent;
40+
}
41+
}
42+
43+
/**
44+
* Performs any required DOM setup.
45+
* @param element
46+
*/
47+
@action didInsertNode(element) {
48+
this.element = element;
49+
this.registerListeners(element);
50+
51+
if (this.shouldRegister) {
52+
this.parent.registerChild(this);
53+
}
54+
}
55+
56+
/**
57+
* Performs DOM updates based on tracked args.
58+
*/
59+
@action didUpdateNode() {
60+
// noop
61+
}
62+
63+
/**
64+
* Performs any required DOM teardown.
65+
* @param element
66+
*/
67+
@action willDestroyNode(element) {
68+
this.deregisterListeners(element);
69+
}
70+
71+
willDestroy() {
72+
super.willDestroy(...arguments);
73+
74+
if (this.shouldRegister) {
75+
this.parent.deregisterChild(this);
76+
}
77+
}
78+
1279
get tag() {
1380
if (this.args.href) {
1481
return 'a';
@@ -41,4 +108,39 @@ export default class PaperButton extends Focusable {
41108

42109
return this.args.bubbles;
43110
}
111+
112+
// Proxiable Handlers
113+
114+
@action handleMouseDown(e) {
115+
super.handleMouseDown(e);
116+
117+
let parentComponent = this.parentComponent;
118+
if (parentComponent) {
119+
parentComponent.mouseActive = true;
120+
setTimeout(() => {
121+
if (parentComponent.isDestroyed) {
122+
return;
123+
}
124+
parentComponent.mouseActive = false;
125+
}, 100);
126+
}
127+
}
128+
129+
@action handleFocusIn(e) {
130+
super.handleFocusIn(e);
131+
132+
let parentComponent = this.parent;
133+
if (parentComponent && !parentComponent.mouseActive) {
134+
parentComponent.focused = true;
135+
}
136+
}
137+
138+
@action focusOut(e) {
139+
super.focusOut(e);
140+
141+
let parentComponent = this.parent;
142+
if (parentComponent) {
143+
parentComponent.focused = false;
144+
}
145+
}
44146
}

0 commit comments

Comments
 (0)