summaryrefslogtreecommitdiff
path: root/apps/web/src/components/editor/panels/properties/index.tsx
blob: 3a552b93c02d62a92b29940c90f05ad604869455 (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
"use client";

import { ScrollArea } from "@/components/ui/scroll-area";
import { AudioProperties } from "./audio-properties";
import { VideoProperties } from "./video-properties";
import { TextProperties } from "./text-properties";
import { HugeiconsIcon } from "@hugeicons/react";
import { Settings05Icon } from "@hugeicons/core-free-icons";
import { useEditor } from "@/hooks/use-editor";
import { useElementSelection } from "@/hooks/timeline/element/use-element-selection";

export function PropertiesPanel() {
	const editor = useEditor();
	const { selectedElements } = useElementSelection();

	const elementsWithTracks = editor.timeline.getElementsWithTracks({
		elements: selectedElements,
	});

	return (
		<>
			{selectedElements.length > 0 ? (
				<ScrollArea className="bg-panel h-full rounded-sm">
					{elementsWithTracks.map(({ track, element }) => {
						if (element.type === "text") {
							return (
								<div key={element.id}>
									<TextProperties element={element} trackId={track.id} />
								</div>
							);
						}
						if (element.type === "audio") {
							return <AudioProperties key={element.id} _element={element} />;
						}
						if (element.type === "video" || element.type === "image") {
							return (
								<div key={element.id}>
									<VideoProperties _element={element} />
								</div>
							);
						}
						return null;
					})}
				</ScrollArea>
			) : (
				<EmptyView />
			)}
		</>
	);
}

function EmptyView() {
	return (
		<div className="bg-panel flex h-full flex-col items-center justify-center gap-3 p-4">
			<HugeiconsIcon
				icon={Settings05Icon}
				className="text-muted-foreground/75 size-10"
				strokeWidth={1}
			/>
			<div className="flex flex-col gap-2 text-center">
				<p className="text-lg font-medium">It's empty here</p>
				<p className="text-muted-foreground text-sm text-balance">
					Click an element on the timeline to edit its properties
				</p>
			</div>
		</div>
	);
}