-
Notifications
You must be signed in to change notification settings - Fork 34
/
transition.js
92 lines (69 loc) · 2 KB
/
transition.js
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
84
85
86
87
88
89
90
91
92
import Component from '@glimmer/component';
import { getValue } from '@glimmer/tracking/primitives/cache';
import { assert } from '@ember/debug';
import { invokeHelper } from '@ember/helper';
import { schedule } from '@ember/runloop';
import { modifier } from 'ember-modifier';
import {
AppliedClassNamesManager,
TransitionVisibilityManager,
} from '../helpers/transition';
export default class TransitionComponent extends Component {
constructor() {
super(...arguments);
let { show } = this.args;
assert(ARG_SHOW_MISSING_ERROR_MESSAGE, typeof show === 'boolean');
schedule('afterRender', () => {
this.initialRender = false;
});
}
ownNode = modifier((element) => {
this.ownDomNode = element;
});
track = modifier((element) => {
this.allTransitionDomNodes.add(element);
return () => {
this.allTransitionDomNodes.delete(element);
};
});
get tagName() {
return this.args.tagName ?? 'div';
}
get unmount() {
return this.args.unmount ?? true;
}
/* === Component Visibility Management === */
allTransitionDomNodes = new Set();
transitionVisibilityManager = invokeHelper(
this,
TransitionVisibilityManager,
() => ({
positional: [this.allTransitionDomNodes, this.args.show],
})
);
get componentIsVisible() {
return getValue(this.transitionVisibilityManager);
}
get componentIsMounted() {
return this.unmount ? this.componentIsVisible : true;
}
get componentIsHidden() {
return this.unmount ? false : !this.componentIsVisible;
}
/* === Transition Class Name Management === */
initialRender = true;
/** @type {HTMLElement} */
ownDomNode;
appliedClassNamesManager = invokeHelper(
this,
AppliedClassNamesManager,
() => ({
positional: [this, this.args.show],
})
);
get transitionClassNames() {
return getValue(this.appliedClassNamesManager);
}
}
export const ARG_SHOW_MISSING_ERROR_MESSAGE =
'You have to provide a `show` prop to the `Transition` component';