TitleSection.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import React from "react";
  2. import styled from "styled-components";
  3. interface Props {
  4. children: React.ReactNode;
  5. icon?: any;
  6. iconWidth?: string;
  7. capitalize?: boolean;
  8. className?: string;
  9. materialIconClass?: string;
  10. handleNavBack?: () => void;
  11. onClick?: any;
  12. }
  13. const TitleSection: React.FC<Props> = ({
  14. children,
  15. icon,
  16. iconWidth,
  17. capitalize,
  18. handleNavBack,
  19. className,
  20. materialIconClass,
  21. onClick,
  22. }) => {
  23. return (
  24. <StyledTitleSection className={className}>
  25. {handleNavBack && (
  26. <BackButton>
  27. <i className="material-icons" onClick={handleNavBack}>
  28. keyboard_backspace
  29. </i>
  30. </BackButton>
  31. )}
  32. {icon &&
  33. (materialIconClass?.length ? (
  34. <MaterialIcon width={iconWidth} className={materialIconClass}>
  35. {icon}
  36. </MaterialIcon>
  37. ) : (
  38. <Icon width={iconWidth} src={icon} />
  39. ))}
  40. <StyledTitle
  41. capitalize={capitalize}
  42. onClick={onClick}
  43. >
  44. {children}
  45. </StyledTitle>
  46. </StyledTitleSection>
  47. );
  48. };
  49. export default TitleSection;
  50. const BackButton = styled.div`
  51. > i {
  52. cursor: pointer;
  53. font-size: 24px;
  54. color: #aaaabb;
  55. margin-right: 10px;
  56. padding: 3px;
  57. margin-left: 0px;
  58. border-radius: 100px;
  59. :hover {
  60. background: #ffffff11;
  61. }
  62. }
  63. `;
  64. const StyledTitleSection = styled.div`
  65. display: flex;
  66. align-items: center;
  67. `;
  68. const Icon = styled.img<{ width: string }>`
  69. height: ${(props) => props.width || "24px"};
  70. margin-right: 16px;
  71. display: flex;
  72. align-items: center;
  73. `;
  74. const MaterialIcon = styled.span<{ width: string }>`
  75. height: ${(props) => props.width || "24px"};
  76. margin-right: 16px;
  77. `;
  78. const StyledTitle = styled.div<{
  79. capitalize: boolean;
  80. onClick?: any;
  81. }>`
  82. font-size: 21px;
  83. user-select: text;
  84. color: ${props => props.theme.text.primary};
  85. text-transform: ${(props) => (props.capitalize ? "capitalize" : "")};
  86. display: flex;
  87. align-items: center;
  88. cursor: ${props => props.onClick ? "pointer" : ""};
  89. :hover {
  90. text-decoration: ${props => props.onClick ? "underline" : ""};
  91. }
  92. > i {
  93. margin-left: 10px;
  94. cursor: pointer;
  95. font-size: 18px;
  96. color: #858faaaa;
  97. padding: 5px;
  98. border-radius: 100px;
  99. :hover {
  100. background: #ffffff11;
  101. }
  102. margin-bottom: -3px;
  103. }
  104. > a {
  105. > i {
  106. display: flex;
  107. align-items: center;
  108. margin-bottom: -2px;
  109. font-size: 18px;
  110. margin-left: 15px;
  111. color: #858faaaa;
  112. :hover {
  113. color: #aaaabb;
  114. }
  115. }
  116. }
  117. `;