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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
import * as React from 'react';
import { observer } from 'mobx-react';
import { observable, action, runInAction, IReactionDisposer, reaction } from 'mobx';
import "./CheckBox.scss";
import * as anime from 'animejs';
interface CheckBoxProps {
originalStatus: boolean;
updateStatus(newStatus: boolean): void;
title: string;
parent: any;
numCount: number;
default: boolean;
}
@observer
export class CheckBox extends React.Component<CheckBoxProps>{
// true = checked, false = unchecked
@observable _status: boolean;
@observable uncheckTimeline: anime.AnimeTimelineInstance;
@observable checkTimeline: anime.AnimeTimelineInstance;
@observable checkRef: any;
@observable _resetReaction?: IReactionDisposer;
constructor(props: CheckBoxProps) {
super(props);
this._status = this.props.originalStatus;
this.checkRef = React.createRef();
this.checkTimeline = anime.timeline({
loop: false,
autoplay: false,
direction: "normal",
}); this.uncheckTimeline = anime.timeline({
loop: false,
autoplay: false,
direction: "normal",
});
}
componentDidMount = () => {
this.uncheckTimeline.add({
targets: this.checkRef.current,
easing: "easeInOutQuad",
duration: 500,
opacity: 0,
});
this.checkTimeline.add({
targets: this.checkRef.current,
easing: "easeInOutQuad",
duration: 500,
strokeDashoffset: [anime.setDashoffset, 0],
opacity: 1
});
if (this.props.originalStatus) {
this.checkTimeline.play();
this.checkTimeline.restart();
}
this._resetReaction = reaction(
() => this.props.parent.resetBoolean,
() => {
if (this.props.parent.resetBoolean) {
runInAction(() => {
this.reset();
this.props.parent.resetCounter++;
if (this.props.parent.resetCounter === this.props.numCount) {
this.props.parent.resetCounter = 0;
this.props.parent.resetBoolean = false;
}
});
}
},
);
}
@action.bound
reset() {
if (this.props.default) {
if (!this._status) {
this._status = true;
this.checkTimeline.play();
this.checkTimeline.restart();
}
}
else {
if (this._status) {
this._status = false;
this.uncheckTimeline.play();
this.uncheckTimeline.restart();
}
}
this.props.updateStatus(this.props.default);
}
@action.bound
onClick = () => {
if (this._status) {
this.uncheckTimeline.play();
this.uncheckTimeline.restart();
}
else {
this.checkTimeline.play();
this.checkTimeline.restart();
}
this._status = !this._status;
this.props.updateStatus(this._status);
}
render() {
return (
<div className="checkboxfilter" onClick={this.onClick}>
<div className="outer">
<div className="check-container">
<svg viewBox="0 12 40 40">
<path ref={this.checkRef} className="checkmark" d="M14.1 27.2l7.1 7.2 16.7-18" />
</svg>
</div>
<div className="check-box" />
</div>
<div className="checkbox-title">{this.props.title}</div>
</div>
);
}
}
|