Legend.js 934 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // 图例列表
  2. import styled from "styled-components";
  3. function Legend(props) {
  4. const { list, style, active, onClick } = props;
  5. return (
  6. <Box style={style}>
  7. {list.map((item) => (
  8. <Item
  9. onClick={() => onClick(item.type)}
  10. className={`${active == item.type ? "active" : ""}`}
  11. >
  12. {item.name}
  13. </Item>
  14. ))}
  15. </Box>
  16. );
  17. }
  18. const Box = styled.ul`
  19. margin: 0;
  20. padding: 0;
  21. width: 140px;
  22. position: absolute;
  23. z-index: 999;
  24. color: #fff;
  25. font-size: 16px;
  26. top: 100px;
  27. text-align: center;
  28. left: 26vw;
  29. `;
  30. const Item = styled.li`
  31. margin: 0;
  32. padding: 8px 20px;
  33. width: 100%;
  34. margin-bottom: 14px;
  35. cursor: pointer;
  36. background: url(${require("../../assets/legend.svg")}) no-repeat center;
  37. background-size: 100% 100%;
  38. &.active,
  39. &:hover {
  40. background-image: url(${require("../../assets/legend-active.svg")});
  41. }
  42. `;
  43. export default Legend;