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.

Tab.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // @flow
  2. import React, { Component } from 'react';
  3. /**
  4. * The type of the React {@code Component} props of {@link Tab}
  5. */
  6. type Props = {
  7. /**
  8. * The index of the tab.
  9. */
  10. index: number,
  11. /**
  12. * Indicates if the tab is selected or not.
  13. */
  14. isSelected: boolean,
  15. /**
  16. * The label of the tab.
  17. */
  18. label: string,
  19. /**
  20. * Handler for selecting the tab.
  21. */
  22. onSelect: Function
  23. }
  24. /**
  25. * A React component that implements tabs.
  26. *
  27. */
  28. export default class Tab extends Component<Props> {
  29. /**
  30. * Initializes a new {@code Tab} instance.
  31. *
  32. * @inheritdoc
  33. */
  34. constructor(props: Props) {
  35. super(props);
  36. this._onSelect = this._onSelect.bind(this);
  37. }
  38. _onSelect: () => {};
  39. /**
  40. * Selects a tab.
  41. *
  42. * @returns {void}
  43. */
  44. _onSelect() {
  45. const { index, onSelect } = this.props;
  46. onSelect(index);
  47. }
  48. /**
  49. * Implements the React Components's render method.
  50. *
  51. * @inheritdoc
  52. */
  53. render() {
  54. const { index, isSelected, label } = this.props;
  55. const className = `tab${isSelected ? ' selected' : ''}`;
  56. return (
  57. <div
  58. className = { className }
  59. key = { index }
  60. onClick = { this._onSelect }>
  61. { label }
  62. </div>);
  63. }
  64. }