UNPKG

744 BJavaScriptView Raw
1import { h, Component } from 'preact'
2import { connect } from 'redux-bundler-preact'
3import Page from './page'
4import InPageNav from './in-page-nav'
5
6class TabPage extends Component {
7 render ({children, links, pathname, pageClass, innerClass, width, centered = true}) {
8 let activeTab
9 const linkWithActive = links.map(link => {
10 const active = link[0] === pathname
11 const copy = link.slice()
12 if (active) {
13 copy.push(active)
14 activeTab = copy[1]
15 }
16 return copy
17 })
18 return (
19 h(Page, {centered, pageClass, width, innerClass},
20 h(InPageNav, {links: linkWithActive}),
21 children[0]()[activeTab]
22 )
23 )
24 }
25}
26
27export default connect(
28 'selectPathname',
29 TabPage
30)