2018-10-22 18:49:18 +00:00
|
|
|
// @flow
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
|
|
|
import Tab from './Tab';
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* The type of the React {@code Component} props of {@link Tabs}.
|
2018-10-22 18:49:18 +00:00
|
|
|
*/
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for selecting the tab.
|
|
|
|
*/
|
|
|
|
onSelect: Function,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The index of the selected tab.
|
|
|
|
*/
|
|
|
|
selected: number,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tabs information.
|
|
|
|
*/
|
|
|
|
tabs: Object
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A React component that implements tabs.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export default class Tabs extends Component<Props> {
|
2019-06-18 21:27:12 +00:00
|
|
|
static defaultProps = {
|
|
|
|
tabs: [],
|
|
|
|
selected: 0
|
|
|
|
};
|
|
|
|
|
2018-10-22 18:49:18 +00:00
|
|
|
/**
|
|
|
|
* Implements the React Components's render method.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const { onSelect, selected, tabs } = this.props;
|
2019-06-18 21:27:12 +00:00
|
|
|
const { content = null } = tabs.length
|
|
|
|
? tabs[Math.min(selected, tabs.length - 1)]
|
|
|
|
: {};
|
2018-10-22 18:49:18 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className = 'tab-container'>
|
|
|
|
{ tabs.length > 1 ? (
|
|
|
|
<div className = 'tab-buttons'>
|
|
|
|
{
|
|
|
|
tabs.map((tab, index) => (
|
|
|
|
<Tab
|
|
|
|
index = { index }
|
|
|
|
isSelected = { index === selected }
|
|
|
|
key = { index }
|
|
|
|
label = { tab.label }
|
|
|
|
onSelect = { onSelect } />
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</div>) : null
|
|
|
|
}
|
2020-10-19 07:37:19 +00:00
|
|
|
<div className = 'tab-content'>
|
|
|
|
{ content }
|
|
|
|
</div>
|
2018-10-22 18:49:18 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|