1import { ColorScheme } from "../common"
2import { icon_button, toggleable_icon_button } from "../component/icon_button"
3import { toggleable_text_button } from "../component/text_button"
4import { interactive, toggleable } from "../element"
5import { withOpacity } from "../theme/color"
6import { background, border, foreground, text } from "./components"
7
8const ITEM_SPACING = 8
9const TITLEBAR_HEIGHT = 32
10
11function build_spacing(
12 container_height: number,
13 element_height: number,
14 spacing: number
15) {
16 return {
17 group: spacing,
18 item: spacing / 2,
19 half_item: spacing / 4,
20 marginY: (container_height - element_height) / 2,
21 marginX: (container_height - element_height) / 2,
22 }
23}
24
25function call_controls(theme: ColorScheme) {
26 const button_height = 18
27
28 const space = build_spacing(TITLEBAR_HEIGHT, button_height, ITEM_SPACING)
29 const marginY = {
30 top: space.marginY,
31 bottom: space.marginY,
32 }
33
34 return {
35 toggle_microphone_button: toggleable_icon_button(theme, {
36 margin: {
37 ...marginY,
38 left: space.group,
39 right: space.half_item,
40 },
41 active_color: "negative",
42 }),
43
44 toggle_speakers_button: toggleable_icon_button(theme, {
45 margin: {
46 ...marginY,
47 left: space.half_item,
48 right: space.half_item,
49 },
50 }),
51
52 screen_share_button: toggleable_icon_button(theme, {
53 margin: {
54 ...marginY,
55 left: space.half_item,
56 right: space.group,
57 },
58 active_color: "accent",
59 }),
60
61 muted: foreground(theme.lowest, "negative"),
62 speaking: foreground(theme.lowest, "accent"),
63 }
64}
65
66/**
67 * Opens the User Menu when toggled
68 *
69 * When logged in shows the user's avatar and a chevron,
70 * When logged out only shows a chevron.
71 */
72function user_menu(theme: ColorScheme) {
73 const button_height = 18
74
75 const space = build_spacing(TITLEBAR_HEIGHT, button_height, ITEM_SPACING)
76
77 const build_button = ({ online }: { online: boolean }) => {
78 const button = toggleable({
79 base: interactive({
80 base: {
81 cornerRadius: 6,
82 height: button_height,
83 width: online ? 37 : 24,
84 padding: {
85 top: 2,
86 bottom: 2,
87 left: 6,
88 right: 6,
89 },
90 margin: {
91 left: space.item,
92 right: space.item,
93 },
94 ...text(theme.lowest, "sans", { size: "xs" }),
95 background: background(theme.lowest),
96 },
97 state: {
98 hovered: {
99 ...text(theme.lowest, "sans", "hovered", {
100 size: "xs",
101 }),
102 background: background(theme.lowest, "hovered"),
103 },
104 clicked: {
105 ...text(theme.lowest, "sans", "pressed", {
106 size: "xs",
107 }),
108 background: background(theme.lowest, "pressed"),
109 },
110 },
111 }),
112 state: {
113 active: {
114 default: {
115 ...text(theme.lowest, "sans", "active", { size: "xs" }),
116 background: background(theme.middle),
117 },
118 hovered: {
119 ...text(theme.lowest, "sans", "active", { size: "xs" }),
120 background: background(theme.middle, "hovered"),
121 },
122 clicked: {
123 ...text(theme.lowest, "sans", "active", { size: "xs" }),
124 background: background(theme.middle, "pressed"),
125 },
126 },
127 },
128 })
129
130 return {
131 user_menu: button,
132 avatar: {
133 icon_width: 16,
134 icon_height: 16,
135 corner_radius: 4,
136 outer_width: 16,
137 outer_corner_radius: 16,
138 },
139 icon: {
140 margin: {
141 top: 2,
142 left: online ? space.item : 0,
143 right: space.group,
144 bottom: 2,
145 },
146 width: 11,
147 height: 11,
148 color: foreground(theme.lowest),
149 },
150 }
151 }
152 return {
153 userMenuButtonOnline: build_button({ online: true }),
154 userMenuButtonOffline: build_button({ online: false }),
155 }
156}
157
158export function titlebar(theme: ColorScheme) {
159 const avatarWidth = 15
160 const avatarOuterWidth = avatarWidth + 4
161 const followerAvatarWidth = 14
162 const followerAvatarOuterWidth = followerAvatarWidth + 4
163
164 return {
165 item_spacing: ITEM_SPACING,
166 facePileSpacing: 2,
167 height: TITLEBAR_HEIGHT,
168 background: background(theme.lowest),
169 border: border(theme.lowest, { bottom: true }),
170 padding: {
171 left: 80,
172 right: 0,
173 },
174
175 // Project
176 title: text(theme.lowest, "sans", "variant"),
177 highlight_color: text(theme.lowest, "sans", "active").color,
178
179 // Collaborators
180 leaderAvatar: {
181 width: avatarWidth,
182 outerWidth: avatarOuterWidth,
183 cornerRadius: avatarWidth / 2,
184 outerCornerRadius: avatarOuterWidth / 2,
185 },
186 followerAvatar: {
187 width: followerAvatarWidth,
188 outerWidth: followerAvatarOuterWidth,
189 cornerRadius: followerAvatarWidth / 2,
190 outerCornerRadius: followerAvatarOuterWidth / 2,
191 },
192 inactiveAvatarGrayscale: true,
193 followerAvatarOverlap: 8,
194 leaderSelection: {
195 margin: {
196 top: 4,
197 bottom: 4,
198 },
199 padding: {
200 left: 2,
201 right: 2,
202 top: 2,
203 bottom: 2,
204 },
205 cornerRadius: 6,
206 },
207 avatarRibbon: {
208 height: 3,
209 width: 14,
210 // TODO: Chore: Make avatarRibbon colors driven by the theme rather than being hard coded.
211 },
212
213 sign_in_button: toggleable_text_button(theme, {}),
214 offlineIcon: {
215 color: foreground(theme.lowest, "variant"),
216 width: 16,
217 margin: {
218 left: ITEM_SPACING,
219 },
220 padding: {
221 right: 4,
222 },
223 },
224
225 // When the collaboration server is out of date, show a warning
226 outdatedWarning: {
227 ...text(theme.lowest, "sans", "warning", { size: "xs" }),
228 background: withOpacity(background(theme.lowest, "warning"), 0.3),
229 border: border(theme.lowest, "warning"),
230 margin: {
231 left: ITEM_SPACING,
232 },
233 padding: {
234 left: 8,
235 right: 8,
236 },
237 cornerRadius: 6,
238 },
239
240 leave_call_button: icon_button(theme, {
241 margin: {
242 left: ITEM_SPACING / 2,
243 right: ITEM_SPACING,
244 },
245 }),
246
247 ...call_controls(theme),
248
249 toggle_contacts_button: toggleable_icon_button(theme, {
250 margin: {
251 left: ITEM_SPACING,
252 },
253 }),
254
255 // Jewel that notifies you that there are new contact requests
256 toggleContactsBadge: {
257 cornerRadius: 3,
258 padding: 2,
259 margin: { top: 3, left: 3 },
260 border: border(theme.lowest),
261 background: foreground(theme.lowest, "accent"),
262 },
263 shareButton: toggleable_text_button(theme, {}),
264 user_menu: user_menu(theme),
265 }
266}