Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // @flow
  2. import React, { Component } from 'react';
  3. import Tab from './Tab';
  4. /**
  5. * The type of the React {@code Component} props of {@link Tabs}
  6. */
  7. type Props = {
  8. /**
  9. * Handler for selecting the tab.
  10. */
  11. onSelect: Function,
  12. /**
  13. * The index of the selected tab.
  14. */
  15. selected: number,
  16. /**
  17. * Tabs information.
  18. */
  19. tabs: Object
  20. };
  21. /**
  22. * A React component that implements tabs.
  23. *
  24. */
  25. export default class Tabs extends Component<Props> {
  26. static defaultProps = {
  27. tabs: [],
  28. selected: 0
  29. };
  30. /**
  31. * Implements the React Components's render method.
  32. *
  33. * @inheritdoc
  34. */
  35. render() {
  36. const { onSelect, selected, tabs } = this.props;
  37. const { content = null } = tabs.length
  38. ? tabs[Math.min(selected, tabs.length - 1)]
  39. : {};
  40. return (
  41. <div className = 'tab-container'>
  42. <div className = 'tab-content'>
  43. { content }
  44. </div>
  45. { tabs.length > 1 ? (
  46. <div className = 'tab-buttons'>
  47. {
  48. tabs.map((tab, index) => (
  49. <Tab
  50. index = { index }
  51. isSelected = { index === selected }
  52. key = { index }
  53. label = { tab.label }
  54. onSelect = { onSelect } />
  55. ))
  56. }
  57. </div>) : null
  58. }
  59. </div>
  60. );
  61. }
  62. }