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