-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathutils.tsx
More file actions
64 lines (58 loc) · 2.22 KB
/
utils.tsx
File metadata and controls
64 lines (58 loc) · 2.22 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { _ICoordinates, _useContainerHeight, _useContainerWidth } from '@internal/react-components';
import { useMemo, useRef } from 'react';
import { MODAL_PIP_DEFAULT_PX } from './styles/ModalLocalAndRemotePIP.styles';
/**
* Interface for ModalLocalAndRemotePIP drag positions
*/
interface MinMaxDragPosition {
minDragPosition: _ICoordinates | undefined;
maxDragPosition: _ICoordinates | undefined;
}
/**
* @private
*/
// Use document.getElementById until Fluent's Stack supports componentRef property: https://github.com/microsoft/fluentui/issues/20410
export const useMinMaxDragPosition = (modalLayerHostId: string, rtl?: boolean): MinMaxDragPosition => {
const modalHostRef = useRef<HTMLElement>(document.getElementById(modalLayerHostId));
const modalHostWidth = _useContainerWidth(modalHostRef);
const modalHostHeight = _useContainerHeight(modalHostRef);
const minDragPosition: _ICoordinates | undefined = useMemo(
() =>
modalHostWidth === undefined
? undefined
: {
x: rtl
? -1 * MODAL_PIP_DEFAULT_PX.rightPositionPx
: MODAL_PIP_DEFAULT_PX.rightPositionPx - modalHostWidth + MODAL_PIP_DEFAULT_PX.widthPx,
y: -1 * MODAL_PIP_DEFAULT_PX.topPositionPx
},
[modalHostWidth, rtl]
);
const maxDragPosition: _ICoordinates | undefined = useMemo(
() =>
modalHostWidth === undefined || modalHostHeight === undefined
? undefined
: {
x: rtl
? modalHostWidth - MODAL_PIP_DEFAULT_PX.rightPositionPx - MODAL_PIP_DEFAULT_PX.widthPx
: MODAL_PIP_DEFAULT_PX.rightPositionPx,
y: modalHostHeight - MODAL_PIP_DEFAULT_PX.topPositionPx - MODAL_PIP_DEFAULT_PX.heightPx
},
[modalHostHeight, modalHostWidth, rtl]
);
return { minDragPosition: minDragPosition, maxDragPosition: maxDragPosition };
};
/**
* @private
*/
export const defaultSpokenLanguage = 'en-us';
/**
* @private
* * Generate a unique id
* TODO: Replace with useId() once React 18 becomes a required dependency.
*/
export const generateUniqueId = (): string => {
return 'acr-' + Math.floor(Math.random() * Date.now()).toString(16);
};