Tab.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2017-2020 @polkadot/react-components authors & contributors
  2. // This software may be modified and distributed under the terms
  3. // of the Apache-2.0 license. See the LICENSE file for details.
  4. import { TabItem } from './types';
  5. import React from 'react';
  6. import { NavLink } from 'react-router-dom';
  7. import styled from 'styled-components';
  8. import Icon from '../Icon';
  9. interface Props extends TabItem {
  10. basePath: string;
  11. className?: string;
  12. index: number;
  13. isSequence?: boolean;
  14. num: number;
  15. forceMatchParams?: boolean;
  16. }
  17. function Tab ({ basePath, className = '', hasParams, index, isExact, isRoot, isSequence, name, num, text, forceMatchParams }: Props): React.ReactElement<Props> {
  18. const to = isRoot
  19. ? basePath
  20. : `${basePath}/${name}`;
  21. // only do exact matching when not the fallback (first position tab),
  22. // params are problematic for dynamic hidden such as app-accounts
  23. const tabIsExact = forceMatchParams
  24. ? false
  25. : (isExact || !hasParams || (!isSequence && index === 0));
  26. return (
  27. <NavLink
  28. activeClassName='tabLinkActive'
  29. className={`ui--Tabs-Tab ${className}`}
  30. exact={tabIsExact}
  31. strict={tabIsExact}
  32. to={to}
  33. >
  34. {text}{(isSequence && index < (num - 1)) && (
  35. <Icon
  36. className='tabIcon'
  37. icon='arrow-right'
  38. />
  39. )}
  40. </NavLink>
  41. );
  42. }
  43. export default React.memo(styled(Tab)`
  44. border-bottom: 2px solid transparent;
  45. color: rgba(0, 0, 0, 0.87) !important;
  46. padding: 0.75rem 1.5rem;
  47. &.tabLinkActive {
  48. border-bottom-color: #e6e6e6;
  49. color: rgba(0, 0, 0, 0.95);
  50. font-weight: 700;
  51. }
  52. &:hover {
  53. color: inherit !important;
  54. &:not(.tabLinkActive) {
  55. border-bottom-color: #e6e6e6;
  56. }
  57. }
  58. .tabIcon {
  59. margin-left: 0.75rem;
  60. }
  61. `);