File size: 11,130 Bytes
9cd6ddb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
import classNames from "classnames";
import { useState } from "react";
import {
  faChevronDown,
  faChevronRight,
  faTrash,
  faCaretDown,
  faCaretUp,
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";

import { ColorPicker } from "components/color-picker";
import { Range } from "components/range";
import { UploadImage } from "@/components/upload";
import { Switch } from "@/components/switch";
import { login, useUser } from "@/utils/auth";
import { Premium } from "@/components/premium";
import { PremiumOverlay } from "@/components/premium/overlay";
import { FormattedMessage, useIntl } from "react-intl";
import { Label } from "@/components/label";

export const ShapeSelected = ({
  shape,
  handleChange,
  onDelete,
}: {
  shape: any;
  handleChange: (s: any) => void;
  onDelete: () => void;
}) => {
  const { user } = useUser();
  const intl = useIntl();
  const [open, setOpen] = useState(true);

  return (
    <div
      className={classNames(
        "mt-5 bg-dark-600 w-full rounded-lg pl-4 py-4 pr-6 cursor-pointer transition-all border-2 border-dark-600 duration-200 hover:border-blue",
        {
          "border-blue": open,
        }
      )}
    >
      <div
        className="tracking-wider flex items-center justify-between gap-4"
        onClick={() => setOpen(!open)}
      >
        <p className="text-white font-semibold">
          <FormattedMessage id="iconsEditor.editor.shape.update.title" />
        </p>
        <div className="flex items-center justify-end gap-4">
          <div
            className="bg-danger bg-opacity-60 rounded-lg text-white hover:bg-opacity-100 cursor-pointer w-8 h-8 flex items-center justify-center"
            onClick={(e: any) => {
              e.preventDefault();
              e.stopPropagation();
              onDelete();
            }}
          >
            <FontAwesomeIcon icon={faTrash} className="w-4" />
          </div>
          <div className="w-4 flex items-center justify-end">
            <FontAwesomeIcon
              icon={open ? faChevronDown : faChevronRight}
              className="text-dark-100 transition-all duration-200"
            />
          </div>
        </div>
      </div>
      {open && (
        <div className="border-t border-dark-400 pt-3 mt-4 grid grid-cols-2 gap-4">
          <div className="w-full col-span-2">
            <Label className="!mb-2">
              <FormattedMessage id="iconsEditor.editor.customisation.rotation" />
            </Label>
            <div className="flex items-center gap-3 w-full">
              <p className="font-semibold uppercase text-dark-200 text-xs">Z</p>
              <Range
                value={shape?.position?.angle ?? 0}
                max={360}
                onChange={(value) => {
                  const newShape = {
                    ...shape,
                    position: { ...shape.position, angle: Number(value) },
                  };
                  handleChange(newShape);
                }}
              />
              <input
                type="number"
                className="w-full bg-dark-500 rounded px-2 py-2 text-sm text-white placeholder-dark-200 outline-none border-none"
                placeholder={intl.formatMessage({
                  id: "iconsEditor.editor.customisation.angle",
                })}
                value={shape?.position?.angle}
                onChange={({ target }) => {
                  const newShape = {
                    ...shape,
                    position: {
                      ...shape.position,
                      angle: target.value
                        ? Number(target.value) > 360
                          ? 360
                          : Number(target.value)
                        : undefined,
                    },
                  };
                  handleChange(newShape);
                }}
              />
            </div>
          </div>
          {shape?.component === "Square" && (
            <div className="w-full col-span-2">
              <Label className="!mb-2">
                <FormattedMessage id="iconsEditor.editor.customisation.radius" />
              </Label>
              <div className="flex items-center gap-3 w-full">
                <p className="font-semibold uppercase text-dark-200 text-xs">
                  Z
                </p>
                <Range
                  value={shape?.radius ?? 0}
                  max={120}
                  onChange={(value) => {
                    const newShape = {
                      ...shape,
                      radius: Number(value),
                    };
                    handleChange(newShape);
                  }}
                />
                <input
                  type="number"
                  className="w-full bg-dark-500 rounded px-2 py-2 text-sm text-white placeholder-dark-200 outline-none border-none"
                  placeholder={intl.formatMessage({
                    id: "iconsEditor.editor.customisation.angle",
                  })}
                  value={shape?.radius}
                  onChange={({ target }) => {
                    const newShape = {
                      ...shape,
                      radius: Number(target.value),
                    };
                    handleChange(newShape);
                  }}
                />
              </div>
            </div>
          )}
          <div className="col-span-2">
            <div className="flex items-center justify-start gap-3 mb-2.5 ">
              <Label className="">
                <FormattedMessage
                  id="iconsEditor.editor.customisation.gradientColor"
                  values={{
                    span: (t) => (
                      <span className="text-xs opacity-40">{t}</span>
                    ),
                  }}
                />
              </Label>
              <Switch
                value={!shape?.transparency}
                onChange={(transparency: boolean) => {
                  const newShape = {
                    ...shape,
                    transparency: !transparency,
                  };
                  handleChange(newShape);
                }}
              />
            </div>
            <ColorPicker
              value={shape?.stringColor ?? shape?.colour}
              data={shape}
              onChange={(c: any, datas) => {
                let newShape = { ...shape, stringColor: c };
                if (c.includes("gradient")) {
                  const { colors, degrees } = datas;
                  const gradientType = c?.startsWith("linear")
                    ? "linearGradient"
                    : "radialGradient";

                  const angle = c?.startsWith("linear")
                    ? c?.replace("linear-gradient(", "")?.split("deg")?.[0]
                    : 90;

                  newShape["gradient"] = {
                    ...newShape.gradient,
                    enabled: true,
                    colours: colors,
                    angle,
                    type: gradientType,
                  };
                } else {
                  newShape = {
                    ...newShape,
                    colour: c,
                    gradient: {
                      ...shape?.gradient,
                      enabled: false,
                    },
                  };
                }

                handleChange(newShape);
              }}
            />
          </div>
          <div className="col-span-2 grid grid-cols-2 gap-4 relative">
            <div className="col-span-2">
              <div className="flex items-center justify-start gap-3 mb-2.5 ">
                <Label className="">
                  <FormattedMessage id="iconsEditor.editor.customisation.backgroundImage" />
                </Label>
                <Switch
                  value={shape?.image?.enabled}
                  onChange={(enabled: boolean) => {
                    const newShape = {
                      ...shape,
                      image: {
                        ...shape.image,
                        enabled,
                      },
                    };
                    handleChange(newShape);
                  }}
                />
              </div>
              {shape?.image?.enabled && (
                <UploadImage
                  values={shape?.image?.urls}
                  onChange={(urls: string) => {
                    const newShape = {
                      ...shape,
                      image: {
                        ...shape.image,
                        urls,
                      },
                    };
                    handleChange(newShape);
                  }}
                />
              )}
            </div>
            <div>
              <Label className="!mb-2.5">
                <FormattedMessage id="iconsEditor.editor.customisation.border" />
              </Label>
              <div className="flex items-start justify-start gap-5">
                <div className="w-full">
                  <p className="font-semibold uppercase text-dark-200 text-xs mb-2">
                    <FormattedMessage id="iconsEditor.editor.customisation.width" />
                  </p>
                  <input
                    type="number"
                    className="bg-dark-500 w-full rounded px-4 py-2 text-sm text-white placeholder-dark-200 outline-none border-none"
                    placeholder={
                      intl.formatMessage({
                        id: "iconsEditor.editor.customisation.width",
                      }) + "...px"
                    }
                    min={0}
                    value={shape?.border?.width}
                    onChange={({ target }) => {
                      const newShape = {
                        ...shape,
                        border: {
                          ...shape.border,
                          width: target?.value
                            ? Number(target.value)
                            : undefined,
                        },
                      };
                      handleChange(newShape);
                    }}
                  />
                </div>
                <div>
                  <p className="font-semibold uppercase text-dark-200 text-xs mb-2">
                    <FormattedMessage id="iconsEditor.editor.customisation.color" />
                  </p>
                  <ColorPicker
                    value={shape?.border?.colour}
                    gradients={false}
                    onChange={(c: any) => {
                      const newShape = {
                        ...shape,
                        border: {
                          ...shape.border,
                          colour: c,
                        },
                      };
                      handleChange(newShape);
                    }}
                  />
                </div>
              </div>
            </div>
            <PremiumOverlay />
          </div>
        </div>
      )}
    </div>
  );
};