You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Tabs.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. /**
  27. * Implements the React Components's render method.
  28. *
  29. * @inheritdoc
  30. */
  31. render() {
  32. const { onSelect, selected, tabs } = this.props;
  33. const { content } = tabs[selected];
  34. return (
  35. <div className = 'tab-container'>
  36. <div className = 'tab-content'>
  37. { content }
  38. </div>
  39. { tabs.length > 1 ? (
  40. <div className = 'tab-buttons'>
  41. {
  42. tabs.map((tab, index) => (
  43. <Tab
  44. index = { index }
  45. isSelected = { index === selected }
  46. key = { index }
  47. label = { tab.label }
  48. onSelect = { onSelect } />
  49. ))
  50. }
  51. </div>) : null
  52. }
  53. </div>
  54. );
  55. }
  56. }