Skip to content

Commit 0e9d9ba

Browse files
committed
feat(passage): add purpose tags to tabs and text + tab change event
1 parent 7d31c13 commit 0e9d9ba

File tree

2 files changed

+61
-45
lines changed

2 files changed

+61
-45
lines changed

packages/passage/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"dependencies": {
1919
"@material-ui/core": "^3.9.2",
2020
"@pie-framework/pie-player-events": "^0.1.0",
21+
"@pie-lib/render-ui": "^4.9.4",
2122
"prop-types": "^15.6.1",
2223
"react": "^16.8.1",
2324
"react-dom": "^16.8.1"

packages/passage/src/stimulus-tabs.jsx

Lines changed: 60 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import Tabs from '@material-ui/core/Tabs';
44
import Tab from '@material-ui/core/Tab';
55
import { withStyles } from '@material-ui/core/styles';
66
import Typography from '@material-ui/core/Typography';
7+
import { Purpose } from '@pie-lib/render-ui';
78

8-
9-
10-
11-
const styles = theme => ({
9+
const styles = (theme) => ({
1210
root: {
1311
flexGrow: 1,
1412
backgroundColor: theme.palette.background.paper,
@@ -17,14 +15,14 @@ const styles = theme => ({
1715
color: 'red',
1816
},
1917
tab: {
20-
fontSize: '0.8125em'
18+
fontSize: '0.8125em',
2119
},
2220
stickyTabs: {
2321
background: '#fff',
2422
paddingBottom: '20px',
2523
position: 'sticky',
26-
top: 0
27-
}
24+
top: 0,
25+
},
2826
});
2927

3028
function TabContainer(props) {
@@ -39,73 +37,90 @@ function TabContainer(props) {
3937

4038
TabContainer.propTypes = {
4139
children: PropTypes.node.isRequired,
42-
multiple: PropTypes.bool
40+
multiple: PropTypes.bool,
4341
};
44-
42+
4543
class StimulusTabs extends React.Component {
4644
state = {
4745
activeTab: 0,
4846
};
49-
47+
5048
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+
})
5259
};
53-
60+
5461
render() {
5562
const { classes, tabs } = this.props;
5663
const { activeTab } = this.state;
5764
if (tabs && tabs.length > 1) {
5865
return (
5966
<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+
)}
87101
</div>
88102
);
89103
} else if (tabs && tabs[0]) {
90104
return (
91105
<div>
92-
<TabContainer><div dangerouslySetInnerHTML={{__html: tabs[0].text}} /></TabContainer>
106+
<TabContainer>
107+
<div dangerouslySetInnerHTML={{ __html: tabs[0].text }} />
108+
</TabContainer>
93109
</div>
94110
);
95111
}
96-
97112
}
98113
}
99-
114+
100115
StimulusTabs.propTypes = {
101116
classes: PropTypes.object.isRequired,
102117
tabs: PropTypes.arrayOf(
103118
PropTypes.shape({
104119
id: PropTypes.number.isRequired,
105120
title: PropTypes.string.isRequired,
106121
text: PropTypes.string.isRequired,
107-
}).isRequired)
108-
.isRequired,
122+
}).isRequired
123+
).isRequired,
109124
};
110-
125+
111126
export default withStyles(styles)(StimulusTabs);

0 commit comments

Comments
 (0)