searchResultWrapper.tsx 785 B

123456789101112131415161718192021222324252627282930313233
  1. import {css} from '@emotion/react';
  2. import styled from '@emotion/styled';
  3. interface Props extends React.HTMLAttributes<HTMLDivElement> {
  4. highlighted?: boolean;
  5. }
  6. function scrollIntoView(element: HTMLDivElement) {
  7. element?.scrollIntoView?.({block: 'nearest'});
  8. }
  9. const SearchResultWrapper = styled(({highlighted, ...props}: Props) => (
  10. <div {...props} ref={highlighted ? scrollIntoView : undefined} />
  11. ))`
  12. cursor: pointer;
  13. display: block;
  14. color: ${p => p.theme.textColor};
  15. padding: 10px;
  16. scroll-margin: 120px;
  17. ${p =>
  18. p.highlighted &&
  19. css`
  20. color: ${p.theme.purple300};
  21. background: ${p.theme.backgroundSecondary};
  22. `};
  23. &:not(:first-child) {
  24. border-top: 1px solid ${p => p.theme.innerBorder};
  25. }
  26. `;
  27. export default SearchResultWrapper;