@@ -4,11 +4,9 @@ import Tabs from '@material-ui/core/Tabs';
4
4
import Tab from '@material-ui/core/Tab' ;
5
5
import { withStyles } from '@material-ui/core/styles' ;
6
6
import Typography from '@material-ui/core/Typography' ;
7
+ import { Purpose } from '@pie-lib/render-ui' ;
7
8
8
-
9
-
10
-
11
- const styles = theme => ( {
9
+ const styles = ( theme ) => ( {
12
10
root : {
13
11
flexGrow : 1 ,
14
12
backgroundColor : theme . palette . background . paper ,
@@ -17,14 +15,14 @@ const styles = theme => ({
17
15
color : 'red' ,
18
16
} ,
19
17
tab : {
20
- fontSize : '0.8125em'
18
+ fontSize : '0.8125em' ,
21
19
} ,
22
20
stickyTabs : {
23
21
background : '#fff' ,
24
22
paddingBottom : '20px' ,
25
23
position : 'sticky' ,
26
- top : 0
27
- }
24
+ top : 0 ,
25
+ } ,
28
26
} ) ;
29
27
30
28
function TabContainer ( props ) {
@@ -39,73 +37,90 @@ function TabContainer(props) {
39
37
40
38
TabContainer . propTypes = {
41
39
children : PropTypes . node . isRequired ,
42
- multiple : PropTypes . bool
40
+ multiple : PropTypes . bool ,
43
41
} ;
44
-
42
+
45
43
class StimulusTabs extends React . Component {
46
44
state = {
47
45
activeTab : 0 ,
48
46
} ;
49
-
47
+
50
48
handleChange = ( event , activeTab ) => {
51
- this . setState ( ( ) => ( { activeTab} ) ) ;
49
+ this . setState ( ( ) => ( { activeTab } ) ) ;
50
+ setTimeout ( ( ) => {
51
+ const tabChangeEvent = new CustomEvent ( 'pie-ui-passage-tabChanged' , {
52
+ detail : {
53
+ tab : activeTab
54
+ }
55
+ } ) ;
56
+
57
+ window . dispatchEvent ( tabChangeEvent ) ;
58
+ } )
52
59
} ;
53
-
60
+
54
61
render ( ) {
55
62
const { classes, tabs } = this . props ;
56
63
const { activeTab } = this . state ;
57
64
if ( tabs && tabs . length > 1 ) {
58
65
return (
59
66
< div className = { classes . root } >
60
-
61
- < Tabs
62
- classes = { {
63
- root : classes . stickyTabs
64
- } }
65
- value = { activeTab }
66
- onChange = { this . handleChange }
67
- >
68
- {
69
- tabs . map ( tab => (
70
- < Tab
71
- className = { classes . tab }
72
- key = { tab . id }
73
- label = { < span dangerouslySetInnerHTML = { { __html : tab . title } } > </ span > }
74
- value = { tab . id }
75
- />
76
-
77
- ) )
78
- }
79
- </ Tabs >
80
- {
81
- tabs . map ( tab => (
82
- activeTab === tab . id
83
- ? < TabContainer multiple key = { tab . id } > < div key = { tab . id } dangerouslySetInnerHTML = { { __html : tab . text } } /> </ TabContainer >
84
- : null
85
- ) )
86
- }
67
+ < Tabs
68
+ classes = { {
69
+ root : classes . stickyTabs ,
70
+ } }
71
+ value = { activeTab }
72
+ onChange = { this . handleChange }
73
+ >
74
+ { tabs . map ( ( tab ) => (
75
+ < Tab
76
+ className = { classes . tab }
77
+ key = { tab . id }
78
+ label = {
79
+ < Purpose purpose = "passage-title" >
80
+ < span
81
+ dangerouslySetInnerHTML = { { __html : tab . title } }
82
+ > </ span >
83
+ </ Purpose >
84
+ }
85
+ value = { tab . id }
86
+ />
87
+ ) ) }
88
+ </ Tabs >
89
+ { tabs . map ( ( tab ) =>
90
+ activeTab === tab . id ? (
91
+ < TabContainer multiple key = { tab . id } >
92
+ < Purpose purpose = "passage-text" >
93
+ < div
94
+ key = { tab . id }
95
+ dangerouslySetInnerHTML = { { __html : tab . text } }
96
+ />
97
+ </ Purpose >
98
+ </ TabContainer >
99
+ ) : null
100
+ ) }
87
101
</ div >
88
102
) ;
89
103
} else if ( tabs && tabs [ 0 ] ) {
90
104
return (
91
105
< div >
92
- < TabContainer > < div dangerouslySetInnerHTML = { { __html : tabs [ 0 ] . text } } /> </ TabContainer >
106
+ < TabContainer >
107
+ < div dangerouslySetInnerHTML = { { __html : tabs [ 0 ] . text } } />
108
+ </ TabContainer >
93
109
</ div >
94
110
) ;
95
111
}
96
-
97
112
}
98
113
}
99
-
114
+
100
115
StimulusTabs . propTypes = {
101
116
classes : PropTypes . object . isRequired ,
102
117
tabs : PropTypes . arrayOf (
103
118
PropTypes . shape ( {
104
119
id : PropTypes . number . isRequired ,
105
120
title : PropTypes . string . isRequired ,
106
121
text : PropTypes . string . isRequired ,
107
- } ) . isRequired )
108
- . isRequired ,
122
+ } ) . isRequired
123
+ ) . isRequired ,
109
124
} ;
110
-
125
+
111
126
export default withStyles ( styles ) ( StimulusTabs ) ;
0 commit comments