summaryrefslogtreecommitdiff
path: root/apps/web/src/components/editor/properties-panel/text-properties.tsx
blob: 3dccc22643ed90db15879e7fc3577d1f189c8879 (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
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
import { Textarea } from "@/components/ui/textarea";
import { FontPicker } from "@/components/ui/font-picker";
import { FontFamily } from "@/constants/font-constants";
import { TextElement } from "@/types/timeline";
import { useTimelineStore } from "@/stores/timeline-store";
import { Slider } from "@/components/ui/slider";
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";
import {
  PropertyItem,
  PropertyItemLabel,
  PropertyItemValue,
} from "./property-item";

export function TextProperties({
  element,
  trackId,
}: {
  element: TextElement;
  trackId: string;
}) {
  const { updateTextElement } = useTimelineStore();

  return (
    <div className="space-y-6 p-5">
      <Textarea
        placeholder="Name"
        defaultValue={element.content}
        className="min-h-[4.5rem] resize-none bg-background/50"
        onChange={(e) =>
          updateTextElement(trackId, element.id, { content: e.target.value })
        }
      />
      <PropertyItem direction="row">
        <PropertyItemLabel>Font</PropertyItemLabel>
        <PropertyItemValue>
          <FontPicker
            defaultValue={element.fontFamily}
            onValueChange={(value: FontFamily) =>
              updateTextElement(trackId, element.id, { fontFamily: value })
            }
          />
        </PropertyItemValue>
      </PropertyItem>
      <PropertyItem direction="column">
      <PropertyItem direction="row">
        <PropertyItemLabel>Style</PropertyItemLabel>
        <PropertyItemValue>
          <div className="flex items-center gap-2">
            <Button
              variant={element.fontWeight === "bold" ? "default" : "outline"}
              size="sm"
              onClick={() =>
                updateTextElement(trackId, element.id, {
                  fontWeight: element.fontWeight === "bold" ? "normal" : "bold",
                })
              }
              className="h-8 px-3 font-bold"
            >
              B
            </Button>
            <Button
              variant={element.fontStyle === "italic" ? "default" : "outline"}
              size="sm"
              onClick={() =>
                updateTextElement(trackId, element.id, {
                  fontStyle: element.fontStyle === "italic" ? "normal" : "italic",
                })
              }
              className="h-8 px-3 italic"
            >
              I
            </Button>
            <Button
              variant={element.textDecoration === "underline" ? "default" : "outline"}
              size="sm"
              onClick={() =>
                updateTextElement(trackId, element.id, {
                  textDecoration: element.textDecoration === "underline" ? "none" : "underline",
                })
              }
              className="h-8 px-3 underline"
            >
              U
            </Button>
            <Button
              variant={element.textDecoration === "line-through" ? "default" : "outline"}
              size="sm"
              onClick={() =>
                updateTextElement(trackId, element.id, {
                  textDecoration: element.textDecoration === "line-through" ? "none" : "line-through",
                })
              }
              className="h-8 px-3 line-through"
            >
              <span className="line-through">S</span>
            </Button>
          </div>
        </PropertyItemValue>
      </PropertyItem>
        <PropertyItemLabel>Font size</PropertyItemLabel>
        <PropertyItemValue>
          <div className="flex items-center gap-2">
            <Slider
              defaultValue={[element.fontSize]}
              min={8}
              max={300}
              step={1}
              onValueChange={([value]) =>
                updateTextElement(trackId, element.id, { fontSize: value })
              }
              className="w-full"
            />
            <Input
              type="number"
              value={element.fontSize}
              onChange={(e) =>
                updateTextElement(trackId, element.id, {
                  fontSize: parseInt(e.target.value),
                })
              }
              className="w-12 !text-xs h-7 rounded-sm text-center
               [appearance:textfield]
               [&::-webkit-outer-spin-button]:appearance-none
               [&::-webkit-inner-spin-button]:appearance-none"
            />
          </div>
        </PropertyItemValue>
      </PropertyItem>
      <PropertyItem direction="row">
        <PropertyItemLabel>Color</PropertyItemLabel>
        <PropertyItemValue>
          <Input
            type="color"
            value={element.color || "#ffffff"}
            onChange={(e) => {
              const color = e.target.value;
              updateTextElement(trackId, element.id, { color });
            }}
            className="w-full cursor-pointer rounded-full"
          />
        </PropertyItemValue>
      </PropertyItem>
      <PropertyItem direction="row">
        <PropertyItemLabel>Background</PropertyItemLabel>
        <PropertyItemValue>
          <Input
            type="color"
            value={element.backgroundColor === "transparent" ? "#000000" : element.backgroundColor || "#000000"}
            onChange={(e) => {
              const backgroundColor = e.target.value;
              updateTextElement(trackId, element.id, { backgroundColor });
            }}
            className="w-full cursor-pointer rounded-full"
          />
        </PropertyItemValue>
      </PropertyItem>
      <PropertyItem direction="column">
        <PropertyItemLabel>Opacity</PropertyItemLabel>
        <PropertyItemValue>
          <div className="flex items-center gap-2">
            <Slider
              defaultValue={[element.opacity * 100]}
              min={0}
              max={100}
              step={1}
              onValueChange={([value]) =>
                updateTextElement(trackId, element.id, { opacity: value / 100 })
              }
              className="w-full"
            />
            <Input
              type="number"
              value={Math.round(element.opacity * 100)}
              onChange={(e) =>
                updateTextElement(trackId, element.id, {
                  opacity: parseInt(e.target.value) / 100,
                })
              }
              className="w-12 !text-xs h-7 rounded-sm text-center
               [appearance:textfield]
               [&::-webkit-outer-spin-button]:appearance-none
               [&::-webkit-inner-spin-button]:appearance-none"
            />
          </div>
        </PropertyItemValue>
      </PropertyItem>
    </div>
  );
}