-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathcommon.ts
More file actions
38 lines (35 loc) · 1.45 KB
/
common.ts
File metadata and controls
38 lines (35 loc) · 1.45 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
* @internal
* Converts units of rem to units of pixels
* @param rem - units of rem
* @returns units of pixels
*/
export const _convertRemToPx = (rem: number): number => {
return rem * parseFloat(getComputedStyle(document.documentElement).fontSize);
};
/**
* @internal
* Disable dismiss on resize to work around a couple Fluent UI bugs
* - The Callout is dismissed whenever *any child of window (inclusive)* is resized. In practice, this
* happens when we change the VideoGallery layout, or even when the video stream element is internally resized
* by the headless SDK.
* - We also want to prevent dismiss when chat pane is scrolling especially a new message is added.
* A side effect of this workaround is that the context menu stays open when window is resized, and may
* get detached from original target visually. That bug is preferable to the bug when this value is not set -
* The Callout (frequently) gets dismissed automatically.
*/
export const _preventDismissOnEvent = (
ev: Event | React.FocusEvent | React.KeyboardEvent | React.MouseEvent
): boolean => {
return ev.type === 'resize' || ev.type === 'scroll';
};
/**
* @internal
* * Generate a unique id
* TODO: Replace with useId() once React 18 becomes a required dependency.
*/
export const _generateUniqueId = (): string => {
return 'acr-' + self.crypto.getRandomValues(new Uint32Array(1))[0].toString(16);
};