1
1
import Adapt from 'core/js/adapt' ;
2
+ import React from 'react' ;
3
+ import ReactDOM from 'react-dom' ;
4
+ import { templates } from 'core/js/reactHelpers' ;
2
5
3
6
class PageLevelProgressIndicatorView extends Backbone . View {
4
7
@@ -16,25 +19,15 @@ class PageLevelProgressIndicatorView extends Backbone.View {
16
19
this . setUpEventListeners ( ) ;
17
20
this . setPercentageComplete ( ) ;
18
21
this . render ( ) ;
19
- this . refresh ( ) ;
20
22
}
21
23
22
24
addClasses ( ) {
23
25
this . $el . addClass ( [
24
- 'pagelevelprogress__indicator' ,
26
+ 'pagelevelprogress__indicator-outer ' ,
25
27
'is-' + this . type
26
28
] . join ( ' ' ) ) ;
27
29
}
28
30
29
- checkAria ( ) {
30
- if ( ! this . ariaLabel ) {
31
- this . $el . attr ( 'aria-hidden' , true ) ;
32
- return ;
33
- }
34
- const data = this . getRenderData ( ) ;
35
- this . $ ( '.js-indicator-aria-label' ) . html ( Handlebars . compile ( this . ariaLabel ) ( data ) ) ;
36
- }
37
-
38
31
setUpEventListeners ( ) {
39
32
if ( this . parent ) {
40
33
this . listenToOnce ( this . parent , 'postRemove' , this . remove ) ;
@@ -47,6 +40,9 @@ class PageLevelProgressIndicatorView extends Backbone.View {
47
40
setPercentageComplete ( ) {
48
41
const percentage = this . calculatePercentage ( ) ;
49
42
this . model . set ( 'percentageComplete' , percentage ) ;
43
+ this . $el . css ( {
44
+ '--adapt-pagelevelprogress-percentage' : percentage + '%'
45
+ } ) ;
50
46
return percentage ;
51
47
}
52
48
@@ -55,24 +51,15 @@ class PageLevelProgressIndicatorView extends Backbone.View {
55
51
}
56
52
57
53
render ( ) {
54
+ this . checkCompletion ( ) ;
55
+ this . checkAriaHidden ( ) ;
58
56
const data = this . getRenderData ( ) ;
59
- const template = Handlebars . templates [ this . constructor . template ] ;
60
- this . $el . html ( template ( data ) ) ;
61
- }
62
-
63
- getRenderData ( ) {
64
- const data = this . model . toJSON ( ) ;
65
- data . ariaLabel = this . ariaLabel ;
66
- data . type = this . type ;
67
- return data ;
57
+ const Component = templates . pageLevelProgressIndicator ;
58
+ ReactDOM . render ( < Component { ...data } /> , this . el ) ;
68
59
}
69
60
70
61
refresh ( ) {
71
- this . checkCompletion ( ) ;
72
- this . checkAria ( ) ;
73
- this . $ ( '.js-indicator-bar' ) . css ( {
74
- width : this . calculatePercentage ( ) + '%'
75
- } ) ;
62
+ this . render ( ) ;
76
63
}
77
64
78
65
checkCompletion ( ) {
@@ -90,8 +77,20 @@ class PageLevelProgressIndicatorView extends Backbone.View {
90
77
. toggleClass ( 'is-incorrect' , isIncorrect ) ;
91
78
}
92
79
80
+ checkAriaHidden ( ) {
81
+ if ( this . ariaLabel ) return ;
82
+ this . $el . attr ( 'aria-hidden' , true ) ;
83
+ }
84
+
85
+ getRenderData ( ) {
86
+ const data = this . model . toJSON ( ) ;
87
+ data . ariaLabel = this . ariaLabel ;
88
+ data . type = this . type ;
89
+ return data ;
90
+ }
91
+
93
92
}
94
93
95
- PageLevelProgressIndicatorView . template = 'pageLevelProgressIndicator' ;
94
+ PageLevelProgressIndicatorView . template = 'pageLevelProgressIndicator.jsx ' ;
96
95
97
96
export default PageLevelProgressIndicatorView ;
0 commit comments