All files / src/components SelectMenu.tsx

52.94% Statements 9/17
50% Branches 1/2
16.67% Functions 1/6
52.94% Lines 9/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118          5x                                           5x           5x         5x                 5x                               5x                     5x 10x   10x                                                                                
import { ClickAwayListener } from '@material-ui/core';
import React, { useState } from 'react';
import styled from 'styled-components';
import { ExpandIcon } from './CourseCard';
 
const Wrapper = styled.div`
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  margin-top: 15px;
  min-width:130px;
  font-family: 'Roboto', sans-serif;
  background-color: #f1f2f5;
  color: black;
  border-top-left-radius: 6px;
  border-bottom-left-radius: 6px;
 
  &:focus {
    outline: none;
  }
  padding-left: 15px;
  cursor: pointer;
  border-top-left-radius: 6px;
  border-bottom-left-radius: 6px;
  user-select: none;
`;
const Header = styled.div`
  display: flex;
  width:100%;
  align-items: center;
  justify-content: space-between;
`;
const HeaderTitle = styled.div`
  font-family: 'Roboto', sans-serif;
  font-size: 16px;
  font-weight: 400;
`;
const List = styled.ul`
  position: absolute;
  top: 50px;
  list-style-type: none;
  margin: 0;
  padding: 0;
  margin-left: -15px;
  background-color: #f2f4f7;
`;
const ListItem = styled.li`
  font-family: 'Roboto', sans-serif;
  font-size: 16px;
  user-select: none;
  padding-top: 10px;
  padding-bottom: 10px;
  padding-left: 15px;
  padding-right: 37px;
  font-weight: 400;
  :hover {
    background-color: #eceef4;
  }
  :first-child{
    margin-top:10px;
  }
`;
const ExpandIconSelect = styled(ExpandIcon)`
  width: 10px;
  height: 10px;
`;
 
interface SelectMenuProps {
  changeSelectedOption: (option: string) => void;
  changeDropdownOpen: (dropdownState: boolean) => void;
  selectedOption:string;
}
 
export const SelectMenu = ({changeSelectedOption,changeDropdownOpen, selectedOption}:SelectMenuProps) => {
  const [isOpen, setIsOpen] = useState(false);
  
  return (
    <ClickAwayListener
      onClickAway={() => {
        setIsOpen(false);
      }}
    >
      <Wrapper onClick={() => {changeDropdownOpen(false)}}>
        <Header
          onClick={() => {
            console.log('clicked');
            setIsOpen(!isOpen);
          }}
        >
          <HeaderTitle>{selectedOption}</HeaderTitle>
          <ExpandIconSelect selected={isOpen} />
        </Header>
        {isOpen && (
          <List>
            <ListItem
              onClick={() => {
                changeSelectedOption('przedmioty');
                setIsOpen(false);
              }}
            >
              przedmioty
            </ListItem>
            <ListItem
              onClick={() => {
                changeSelectedOption('studenci');
                setIsOpen(false);
              }}
            >
              studenci
            </ListItem>
          </List>
        )}
      </Wrapper>
    </ClickAwayListener>
  );
};