@topconsultnpm/sdkui-react-beta 6.6.87 → 6.6.88
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
declare enum DeviceType {
|
|
3
|
+
MOBILE = "mobile",
|
|
4
|
+
TABLET = "tablet",
|
|
5
|
+
DESKTOP = "desktop"
|
|
6
|
+
}
|
|
7
|
+
interface DeviceContextProps {
|
|
8
|
+
deviceType?: DeviceType;
|
|
9
|
+
}
|
|
10
|
+
declare const DeviceContext: React.Context<DeviceContextProps | undefined>;
|
|
11
|
+
declare const TMDeviceProvider: React.FC<{
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
}>;
|
|
14
|
+
declare const useDeviceType: () => DeviceType | undefined;
|
|
15
|
+
export { DeviceContextProps, DeviceType, useDeviceType, TMDeviceProvider, DeviceContext };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState, createContext, useMemo, useContext } from 'react';
|
|
3
|
+
var DeviceType;
|
|
4
|
+
(function (DeviceType) {
|
|
5
|
+
DeviceType["MOBILE"] = "mobile";
|
|
6
|
+
DeviceType["TABLET"] = "tablet";
|
|
7
|
+
DeviceType["DESKTOP"] = "desktop";
|
|
8
|
+
})(DeviceType || (DeviceType = {}));
|
|
9
|
+
const DESKTOP_BREAKPOINT = 1024;
|
|
10
|
+
const TABLET_BREAKPOINT = 768;
|
|
11
|
+
const DeviceContext = createContext(undefined);
|
|
12
|
+
const TMDeviceProvider = ({ children }) => {
|
|
13
|
+
const [deviceType, setDeviceType] = useState(DeviceType.DESKTOP);
|
|
14
|
+
const updateDeviceType = () => {
|
|
15
|
+
const width = window.innerWidth;
|
|
16
|
+
if (width >= DESKTOP_BREAKPOINT) {
|
|
17
|
+
setDeviceType(DeviceType.DESKTOP);
|
|
18
|
+
}
|
|
19
|
+
else if (width >= TABLET_BREAKPOINT) {
|
|
20
|
+
setDeviceType(DeviceType.TABLET);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
setDeviceType(DeviceType.MOBILE);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
updateDeviceType();
|
|
28
|
+
window.addEventListener('resize', updateDeviceType);
|
|
29
|
+
return () => window.removeEventListener('resize', updateDeviceType);
|
|
30
|
+
}, []);
|
|
31
|
+
const contextValue = useMemo(() => ({ deviceType }), [deviceType]);
|
|
32
|
+
return (_jsxs(DeviceContext.Provider, { value: contextValue, children: [" ", children, " "] }));
|
|
33
|
+
};
|
|
34
|
+
const useDeviceType = () => {
|
|
35
|
+
const context = useContext(DeviceContext);
|
|
36
|
+
if (!context) {
|
|
37
|
+
throw new Error('DeviceProvider does not exsist');
|
|
38
|
+
}
|
|
39
|
+
return context.deviceType;
|
|
40
|
+
};
|
|
41
|
+
export { DeviceType, useDeviceType, TMDeviceProvider, DeviceContext };
|
package/lib/components/index.js
CHANGED
|
@@ -61,3 +61,5 @@ export { default as SettingsAppearance } from "./settings/SettingsAppearance";
|
|
|
61
61
|
export * from "./viewers/TMTidViewer";
|
|
62
62
|
export * from "./viewers/TMMidViewer";
|
|
63
63
|
export * from "./viewers/TMDataListItemViewer";
|
|
64
|
+
//TMDeviceProvider
|
|
65
|
+
export * from "./base/TMDeviceProvider";
|