OptionsDropdown.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import React, { useState } from "react";
  2. import styled from "styled-components";
  3. export const OptionsDropdown: React.FC<{
  4. expandIcon?: string;
  5. shrinkIcon?: string;
  6. }> = ({ children, expandIcon = "expand_more", shrinkIcon = "expand_less" }) => {
  7. const [isOpen, setIsOpen] = useState(false);
  8. const handleClick = (e: any) => {
  9. e.stopPropagation();
  10. e.preventDefault();
  11. setIsOpen(!isOpen);
  12. };
  13. const handleOnBlur = () => {
  14. setIsOpen(false);
  15. };
  16. return (
  17. <OptionsButton onClick={handleClick} onBlur={handleOnBlur}>
  18. <i className="material-icons">{isOpen ? shrinkIcon : expandIcon}</i>
  19. {isOpen && <DropdownMenu>{children}</DropdownMenu>}
  20. </OptionsButton>
  21. );
  22. };
  23. const OptionsButton = styled.button`
  24. position: relative;
  25. border: none;
  26. background: none;
  27. color: white;
  28. padding: 5px;
  29. display: flex;
  30. justify-content: center;
  31. align-items: center;
  32. border-radius: 50%;
  33. color: #ffffff44;
  34. :hover {
  35. background: #32343a;
  36. cursor: pointer;
  37. }
  38. > i {
  39. font-size: 20px;
  40. }
  41. `;
  42. const DropdownMenu = styled.div`
  43. position: absolute;
  44. right: 12px;
  45. top: 30px;
  46. overflow: hidden;
  47. width: 120px;
  48. height: auto;
  49. background: #26282f;
  50. box-shadow: 0 8px 20px 0px #00000088;
  51. color: white;
  52. overflow: hidden;
  53. border-radius: 5px;
  54. `;
  55. const DropdownOption = styled.div`
  56. width: 100%;
  57. height: 37px;
  58. font-size: 13px;
  59. cursor: pointer;
  60. padding-left: 10px;
  61. padding-right: 10px;
  62. font-weight: 500;
  63. white-space: nowrap;
  64. overflow: hidden;
  65. text-overflow: ellipsis;
  66. display: flex;
  67. justify-content: center;
  68. align-items: center;
  69. :hover {
  70. background: #ffffff22;
  71. }
  72. :not(:first-child) {
  73. border-top: 1px solid #00000000;
  74. }
  75. :not(:last-child) {
  76. border-bottom: 1px solid #ffffff15;
  77. }
  78. > i {
  79. margin-right: 7px;
  80. font-size: 16px;
  81. }
  82. `;
  83. export default {
  84. Dropdown: OptionsDropdown,
  85. Option: DropdownOption,
  86. };