summaryrefslogtreecommitdiff
path: root/extension/react-app/src/components/PillButton.tsx
blob: 5a16516e6ec7d76b8342dcc006909c18011ebae8 (plain)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import { useContext, useState } from "react";
import styled from "styled-components";
import { StyledTooltip, defaultBorderRadius, secondaryDark } from ".";
import {
  Trash,
  PaintBrush,
  ExclamationTriangle,
} from "@styled-icons/heroicons-outline";
import { GUIClientContext } from "../App";

const Button = styled.button`
  border: none;
  color: white;
  background-color: ${secondaryDark};
  border-radius: ${defaultBorderRadius};
  padding: 8px;
  overflow: hidden;

  cursor: pointer;
`;

const GridDiv = styled.div`
  position: absolute;
  left: 0px;
  top: 0px;
  width: 100%;
  height: 100%;
  display: grid;
  grid-gap: 0;
  align-items: center;
  border-radius: ${defaultBorderRadius};

  background-color: ${secondaryDark};
`;

const ButtonDiv = styled.div<{ backgroundColor: string }>`
  background-color: ${secondaryDark};
  padding: 3px;
  height: 100%;
  display: flex;
  align-items: center;

  &:hover {
    background-color: ${(props) => props.backgroundColor};
  }
`;

const CircleDiv = styled.div`
  position: absolute;
  top: -10px;
  right: -10px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: red;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
`;

interface PillButtonProps {
  onHover?: (arg0: boolean) => void;
  onDelete?: () => void;
  title: string;
  index: number;
  editing: boolean;
  pinned: boolean;
  warning?: string;
  onlyShowDelete?: boolean;
}

const PillButton = (props: PillButtonProps) => {
  const [isHovered, setIsHovered] = useState(false);
  const client = useContext(GUIClientContext);

  return (
    <>
      <div style={{ position: "relative" }}>
        <Button
          style={{
            position: "relative",
            borderColor: props.warning
              ? "red"
              : props.editing
              ? "#8800aa"
              : props.pinned
              ? "#ffff0099"
              : "transparent",
            borderWidth: "1px",
            borderStyle: "solid",
          }}
          onMouseEnter={() => {
            setIsHovered(true);
            if (props.onHover) {
              props.onHover(true);
            }
          }}
          onMouseLeave={() => {
            setIsHovered(false);
            if (props.onHover) {
              props.onHover(false);
            }
          }}
        >
          {isHovered && (
            <GridDiv
              style={{
                gridTemplateColumns: props.onlyShowDelete ? "1fr" : "1fr 1fr",
              }}
            >
              {props.onlyShowDelete || (
                <ButtonDiv
                  data-tooltip-id={`edit-${props.index}`}
                  backgroundColor={"#8800aa55"}
                  onClick={() => {
                    client?.setEditingAtIndices([props.index]);
                  }}
                >
                  <PaintBrush
                    style={{ margin: "auto" }}
                    width="1.6em"
                  ></PaintBrush>
                </ButtonDiv>
              )}

              {/* <ButtonDiv
            data-tooltip-id={`pin-${props.index}`}
            backgroundColor={"#ffff0055"}
            onClick={() => {
              client?.setPinnedAtIndices([props.index]);
            }}
            >
            <MapPin style={{ margin: "auto" }} width="1.6em"></MapPin>
          </ButtonDiv> */}
              <StyledTooltip id={`pin-${props.index}`}>
                Edit this range
              </StyledTooltip>
              <ButtonDiv
                data-tooltip-id={`delete-${props.index}`}
                backgroundColor={"#cc000055"}
                onClick={() => {
                  if (props.onDelete) {
                    props.onDelete();
                  }
                }}
              >
                <Trash style={{ margin: "auto" }} width="1.6em"></Trash>
              </ButtonDiv>
            </GridDiv>
          )}
          {props.title}
        </Button>
        <StyledTooltip id={`edit-${props.index}`}>
          {props.editing
            ? "Editing this range (with rest of file as context)"
            : "Edit this range"}
        </StyledTooltip>
        <StyledTooltip id={`delete-${props.index}`}>Delete</StyledTooltip>
        {props.warning && (
          <>
            <CircleDiv data-tooltip-id={`circle-div-${props.title}`}>
              <ExclamationTriangle
                style={{ margin: "auto" }}
                width="1.0em"
                strokeWidth={2}
              />
            </CircleDiv>
            <StyledTooltip id={`circle-div-${props.title}`}>
              {props.warning}
            </StyledTooltip>
          </>
        )}
      </div>
    </>
  );
};

export default PillButton;