aboutsummaryrefslogtreecommitdiff
path: root/src/components/Hamburger.js
blob: 3eac865095be3533894eee893afc9d2f722c65a3 (plain) (blame)
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
/** @jsx jsx */
import { jsx } from "theme-ui";

const hamburgerStyles = {
  display: "block",
  cursor: "pointer",
  bg: "primary",
  m: 0,
  p: "1rem",
  borderRadius: "50%",

  ".Hamburger-box": {
    display: "block",
    position: "relative",
    width: 30,
    height: 30
  },

  ".Hamburger-stick": {
    bg: "background",
    borderRadius: "4px",
    display: "block",
    position: "absolute",
    top: "50%",
    width: 30,
    height: "4px",
    mt: "-2px",
    [[":before", ":after"]]: {
      bg: "background",
      display: "block",
      content: "''",
      position: "absolute",
      width: 30,
      height: "4px",
      borderRadius: "4px"
    },
    ":before": {
      top: "-10px"
    },
    ":after": {
      bottom: "-10px"
    }
  },

  "&.active": {
    ".Hamburger-stick": {
      transform: "rotate(45deg)",
      ":before": {
        top: 0,
        opacity: 0
      },
      ":after": {
        bottom: 0,
        transform: "rotate(-90deg)"
      }
    }
  }
};

function Hamburger({ open, ...props }) {
  return (
    <span {...props} className={open ? "active" : ""} sx={hamburgerStyles}>
      <span className="Hamburger-box">
        <span className="Hamburger-stick"></span>
      </span>
    </span>
  );
}

export default Hamburger;