-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathMobileCommandBar.tsx
More file actions
247 lines (227 loc) · 9.8 KB
/
MobileCommandBar.tsx
File metadata and controls
247 lines (227 loc) · 9.8 KB
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
"use client"
import type React from "react"
import { useState } from "react"
import { Menu, Plus, Minus } from "lucide-react"
import { Sheet, SheetContent, SheetHeader, SheetTitle } from "@/components/ui/sheet"
import { cn } from "@/lib/utils"
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./ui/tooltip";
import { Button } from "./ui/button"
import { PaletteFilled } from "./SvgIcons"
import { BgFill, FillStyle, FontFamily, FontSize, RoughStyle, StrokeEdge, StrokeFill, StrokeStyle, StrokeWidth, TextAlign, ToolType } from "@/types/canvas"
import { AppSidebar } from "./AppSidebar"
import { StyleConfigurator } from "./StyleConfigurator"
interface MobileCommandBarProps {
canvasColor: string
setCanvasColor: (color: string) => void
sidebarOpen: boolean
setSidebarOpen: (open: boolean) => void
scale: number;
setScale: React.Dispatch<React.SetStateAction<number>>
activeTool: ToolType;
strokeFill: StrokeFill;
setStrokeFill: React.Dispatch<React.SetStateAction<StrokeFill>>;
strokeWidth: StrokeWidth;
setStrokeWidth: React.Dispatch<React.SetStateAction<StrokeWidth>>;
bgFill: BgFill;
setBgFill: React.Dispatch<React.SetStateAction<BgFill>>;
strokeEdge: StrokeEdge;
setStrokeEdge: React.Dispatch<React.SetStateAction<StrokeEdge>>;
strokeStyle: StrokeStyle;
setStrokeStyle: React.Dispatch<React.SetStateAction<StrokeStyle>>;
roughStyle: RoughStyle;
setRoughStyle: React.Dispatch<React.SetStateAction<RoughStyle>>;
fillStyle: FillStyle;
setFillStyle: React.Dispatch<React.SetStateAction<FillStyle>>;
fontFamily: FontFamily;
setFontFamily: React.Dispatch<React.SetStateAction<FontFamily>>;
fontSize: FontSize;
setFontSize: React.Dispatch<React.SetStateAction<FontSize>>;
textAlign: TextAlign;
setTextAlign: React.Dispatch<React.SetStateAction<TextAlign>>;
roomName?: string
isStandalone?: boolean;
onClearCanvas?: () => void;
onExportCanvas?: () => void;
onImportCanvas?: () => void;
onSearchCanvas?: () => void;
}
export function MobileCommandBar({ canvasColor,
setCanvasColor,
sidebarOpen,
setSidebarOpen,
scale,
setScale,
activeTool,
strokeFill,
setStrokeFill,
strokeWidth,
setStrokeWidth,
bgFill,
setBgFill,
strokeEdge,
setStrokeEdge,
strokeStyle,
setStrokeStyle,
roughStyle,
setRoughStyle,
fillStyle,
setFillStyle,
fontFamily,
setFontFamily,
fontSize,
setFontSize,
textAlign,
setTextAlign,
roomName,
isStandalone,
onClearCanvas,
onExportCanvas,
onImportCanvas,
onSearchCanvas,
}: MobileCommandBarProps) {
const [colorPickerOpen, setColorPickerOpen] = useState(false);
const handleMenuButton = () => {
setSidebarOpen(!sidebarOpen);
};
return (
<>
<footer className="Appbar_Bottom Mobile_Appbar fixed bottom-0 left-0 right-0 z-50 md:hidden w-full max-w-full min-w-full ">
<div className="mx-auto w-full max-w-full min-w-full px-4 pb-4">
<div data-active-tool={activeTool} className="flex items-center justify-between rounded-[8px] border p-2 backdrop-blur-md Island">
<NavbarButton icon={Menu} label="Menu" onClick={handleMenuButton} active={sidebarOpen} />
{activeTool !== 'grab' && activeTool !== 'eraser' && (
<NavbarButton icon={PaletteFilled} label="Colors" onClick={() => setColorPickerOpen(true)} active={colorPickerOpen} />
)}
<ScaleWidget scale={scale} setScale={setScale} />
</div>
</div>
</footer>
{sidebarOpen && (
<Sheet open={sidebarOpen} onOpenChange={setSidebarOpen}>
<SheetContent side="bottom" className="h-auto max-h-[80vh] w-full rounded-t-[20px] px-4 py-4 overflow-auto overflow-x-hiddenustom-scrollbar Island">
<SheetHeader className="mb-5">
<SheetTitle>App Menu</SheetTitle>
</SheetHeader>
<AppSidebar
isOpen={sidebarOpen}
onClose={() => setSidebarOpen(false)}
canvasColor={canvasColor}
setCanvasColor={setCanvasColor}
isMobile={true}
roomName={roomName}
isStandalone={isStandalone}
onClearCanvas={onClearCanvas}
onExportCanvas={onExportCanvas}
onImportCanvas={onImportCanvas}
onSearchCanvas={onSearchCanvas}
/>
</SheetContent>
</Sheet>
)}
<Sheet open={colorPickerOpen} onOpenChange={setColorPickerOpen}>
<SheetContent side="bottom" className="h-auto max-h-[80vh] w-full rounded-t-[20px] px-4 py-4 overflow-auto overflow-x-hidden custom-scrollbar Island">
<SheetHeader className="mb-5">
<SheetTitle>Canvas Styles</SheetTitle>
</SheetHeader>
<StyleConfigurator
isMobile={true}
activeTool={activeTool}
strokeFill={strokeFill}
setStrokeFill={setStrokeFill}
strokeWidth={strokeWidth}
setStrokeWidth={setStrokeWidth}
bgFill={bgFill}
setBgFill={setBgFill}
strokeEdge={strokeEdge}
setStrokeEdge={setStrokeEdge}
strokeStyle={strokeStyle}
setStrokeStyle={setStrokeStyle}
roughStyle={roughStyle}
setRoughStyle={setRoughStyle}
fillStyle={fillStyle}
setFillStyle={setFillStyle}
fontFamily={fontFamily}
setFontFamily={setFontFamily}
fontSize={fontSize}
setFontSize={setFontSize}
textAlign={textAlign}
setTextAlign={setTextAlign}
/>
</SheetContent>
</Sheet>
</>
)
}
interface NavbarButtonProps {
icon: React.ElementType
label: string
onClick: () => void
active?: boolean
}
function NavbarButton({ icon: Icon, label, onClick, active = false }: NavbarButtonProps) {
return (
<button
className={cn(
"flex flex-col items-center justify-center w-8 h-8 rounded-lg transition-all hover:bg-light-btn-hover-bg text-icon-fill-color dark:bg-transparent dark:hover:bg-d-btn-hover-bg dark:text-white",
label === 'Menu' ? 'menu-btn-box-shadow bg-light-btn-bg' : '',
active
? "bg-light-btn-hover-bg dark:bg-d-btn-hover-bg"
: '',
)}
onClick={onClick}
>
<Icon className="w-5 h-5" />
<span className="text-xs font-medium hidden">{label}</span>
</button>
)
}
function ScaleWidget({ scale, setScale }: {
scale: number;
setScale: React.Dispatch<React.SetStateAction<number>>
}) {
const zoomIn = () => {
setScale((prevScale: number) => Math.min(prevScale * 1.1, 5));
};
const zoomOut = () => {
setScale(prevScale => Math.max(prevScale * 0.9, 0.2));
};
const resetScale = () => {
setScale(1);
};
return (
<>
<div className="rounded-lg flex items-center bg-white dark:bg-w-bg surface-box-shadow">
<TooltipProvider delayDuration={0}>
<Tooltip>
<TooltipTrigger asChild>
<Button variant="ghost" size="icon" onClick={zoomOut} className="w-9 h-9 rounded-l-lg rounded-r-none bg-light-btn-bg text-text-primary-color dark:bg-w-bg dark:hover:bg-d-btn-hover-bg dark:text-w-text select-none">
<Minus className="h-4 w-4" />
</Button>
</TooltipTrigger>
<TooltipContent className="dark:bg-w-bg dark:text-white">Zoom Out</TooltipContent>
</Tooltip>
</TooltipProvider>
<TooltipProvider delayDuration={0}>
<Tooltip>
<TooltipTrigger asChild>
<Button variant="ghost" size="icon" onClick={resetScale} className="w-14 px-3 h-9 rounded-none bg-light-btn-bg text-text-primary-color dark:bg-w-bg dark:hover:bg-d-btn-hover-bg dark:text-w-text select-none">
{Math.round(scale * 100)}%
</Button>
</TooltipTrigger>
<TooltipContent className="dark:bg-w-bg dark:text-white">Reset Scale</TooltipContent>
</Tooltip>
</TooltipProvider>
<TooltipProvider delayDuration={0}>
<Tooltip>
<TooltipTrigger asChild>
<Button variant="ghost" size="icon" onClick={zoomIn} className="w-9 h-9 rounded-r-lg rounded-l-none bg-light-btn-bg text-text-primary-color dark:bg-w-bg dark:hover:bg-d-btn-hover-bg dark:text-w-text select-none">
<Plus className="h-4 w-4" />
</Button>
</TooltipTrigger>
<TooltipContent className="dark:bg-w-bg dark:text-white">Zoom In</TooltipContent>
</Tooltip>
</TooltipProvider>
</div>
</>
)
}