TitleSection.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import React from "react";
  2. import styled from "styled-components";
  3. type 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 capitalize={capitalize} onClick={onClick}>
  41. {children}
  42. </StyledTitle>
  43. </StyledTitleSection>
  44. );
  45. };
  46. export default TitleSection;
  47. const BackButton = styled.div`
  48. > i {
  49. cursor: pointer;
  50. font-size: 24px;
  51. color: #aaaabb;
  52. margin-right: 10px;
  53. padding: 3px;
  54. margin-left: 0px;
  55. border-radius: 100px;
  56. :hover {
  57. background: #ffffff11;
  58. }
  59. }
  60. `;
  61. const StyledTitleSection = styled.div`
  62. display: flex;
  63. align-items: center;
  64. `;
  65. const Icon = styled.img<{ width: string }>`
  66. height: ${(props) => props.width || "24px"};
  67. margin-right: 16px;
  68. display: flex;
  69. align-items: center;
  70. `;
  71. const MaterialIcon = styled.span<{ width: string }>`
  72. height: ${(props) => props.width || "24px"};
  73. margin-right: 16px;
  74. `;
  75. const StyledTitle = styled.div<{
  76. capitalize: boolean;
  77. onClick?: any;
  78. }>`
  79. font-size: 21px;
  80. user-select: text;
  81. color: ${(props) => props.theme.text.primary};
  82. text-transform: ${(props) => (props.capitalize ? "capitalize" : "")};
  83. display: flex;
  84. align-items: center;
  85. cursor: ${(props) => (props.onClick ? "pointer" : "")};
  86. :hover {
  87. text-decoration: ${(props) => (props.onClick ? "underline" : "")};
  88. }
  89. > i {
  90. margin-left: 10px;
  91. cursor: pointer;
  92. font-size: 18px;
  93. color: #858faaaa;
  94. padding: 5px;
  95. border-radius: 100px;
  96. :hover {
  97. background: #ffffff11;
  98. }
  99. margin-bottom: -3px;
  100. }
  101. > a {
  102. > i {
  103. display: flex;
  104. align-items: center;
  105. margin-bottom: -2px;
  106. font-size: 18px;
  107. margin-left: 15px;
  108. color: #858faaaa;
  109. :hover {
  110. color: #aaaabb;
  111. }
  112. }
  113. }
  114. `;