@trackunit/react-components 0.1.21 → 0.1.22
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.
- package/index.js +52 -1
- package/package.json +2 -1
- package/src/hooks/index.d.ts +1 -0
- package/src/hooks/useDevicePixelRatio.d.ts +37 -0
package/index.js
CHANGED
|
@@ -2790,6 +2790,57 @@ const useDebounce = (value, delay = 500) => {
|
|
|
2790
2790
|
return debouncedValue;
|
|
2791
2791
|
};
|
|
2792
2792
|
|
|
2793
|
+
// Copied from https://github.com/rexxars/use-device-pixel-ratio
|
|
2794
|
+
/**
|
|
2795
|
+
* Get the device pixel ratio, potentially rounded and capped.
|
|
2796
|
+
* Will emit new values if it changes.
|
|
2797
|
+
*
|
|
2798
|
+
* @param {DevicePixelRatioOptions} options the options object
|
|
2799
|
+
* @returns { number } The current device pixel ratio, or the default if none can be resolved
|
|
2800
|
+
*/
|
|
2801
|
+
function useDevicePixelRatio(options) {
|
|
2802
|
+
const dpr = getDevicePixelRatio(options);
|
|
2803
|
+
const [currentDpr, setCurrentDpr] = useState(dpr);
|
|
2804
|
+
const { defaultDpr, maxDpr, round } = options || {};
|
|
2805
|
+
useEffect(() => {
|
|
2806
|
+
const canListen = typeof window !== "undefined" && "matchMedia" in window;
|
|
2807
|
+
if (!canListen) {
|
|
2808
|
+
return;
|
|
2809
|
+
}
|
|
2810
|
+
const updateDpr = () => setCurrentDpr(getDevicePixelRatio({ defaultDpr, maxDpr, round }));
|
|
2811
|
+
const mediaMatcher = window.matchMedia(`screen and (resolution: ${currentDpr}dppx)`);
|
|
2812
|
+
// Safari 13.1 does not have `addEventListener`, but does have `addListener`
|
|
2813
|
+
if (mediaMatcher.addEventListener) {
|
|
2814
|
+
mediaMatcher.addEventListener("change", updateDpr);
|
|
2815
|
+
}
|
|
2816
|
+
else {
|
|
2817
|
+
mediaMatcher.addListener(updateDpr);
|
|
2818
|
+
}
|
|
2819
|
+
return () => {
|
|
2820
|
+
if (mediaMatcher.removeEventListener) {
|
|
2821
|
+
mediaMatcher.removeEventListener("change", updateDpr);
|
|
2822
|
+
}
|
|
2823
|
+
else {
|
|
2824
|
+
mediaMatcher.removeListener(updateDpr);
|
|
2825
|
+
}
|
|
2826
|
+
};
|
|
2827
|
+
}, [currentDpr, defaultDpr, maxDpr, round]);
|
|
2828
|
+
return currentDpr;
|
|
2829
|
+
}
|
|
2830
|
+
/**
|
|
2831
|
+
* Returns the current device pixel ratio (DPR) given the passed options
|
|
2832
|
+
*
|
|
2833
|
+
* @param { DevicePixelRatioOptions } options the options object
|
|
2834
|
+
* @returns { number } current device pixel ratio
|
|
2835
|
+
*/
|
|
2836
|
+
function getDevicePixelRatio(options) {
|
|
2837
|
+
const { defaultDpr = 1, maxDpr = 3, round = true } = options || {};
|
|
2838
|
+
const hasDprProp = typeof window !== "undefined" && typeof window.devicePixelRatio === "number";
|
|
2839
|
+
const dpr = hasDprProp ? window.devicePixelRatio : defaultDpr;
|
|
2840
|
+
const rounded = Math.min(Math.max(1, round ? Math.floor(dpr) : dpr), maxDpr);
|
|
2841
|
+
return rounded;
|
|
2842
|
+
}
|
|
2843
|
+
|
|
2793
2844
|
/**
|
|
2794
2845
|
* The useLocalStorage hook works like useState, but saves to localstorage.
|
|
2795
2846
|
*
|
|
@@ -3056,4 +3107,4 @@ const Layout = tw.div `
|
|
|
3056
3107
|
tu-layout-TwoColumnLayout
|
|
3057
3108
|
`;
|
|
3058
3109
|
|
|
3059
|
-
export { ActionButton, Alert, Badge, BaseInput, Button, Card, CardBody, CardFooter, CardHeader, Chart, Checkbox, Collapse, ContentGridArea, CopyableText, CreatableSelect, DateField, DateInput, DayPicker, DayPickerPopover, DayRangePicker, DensityContainer, Drawer, ExternalLink, FilterListMapLayout, FormGroup, FullWidthRepeatingLayout, GridArea, Heading$1 as Heading, Icon$1 as Icon, IconButton, Indicator$1 as Indicator, IntrinsicallyResponsiveGrid, Label$2 as Label, LegendItem, MenuItem, MenuList, MinTopFullContentLayout, Modal, ModalBackdrop, MoreMenu, MultiSelectMenuItem, NavGridArea, NumberField, NumberInput, PageHeader, Pagination, PieChart, Popover, PopoverList, PopoverListItem, PopoverTitle, Prompt, ROLE_CARD, RadioGroup, RadioItem, Search, SectionHeader, Select, SelectPrefix, Sidebar, SingleSelectMenuItem, SkeletonLines, Spacer, Spinner, StarButton, Tag, Text$1 as Text, TextArea, TextAreaField, TextField, TextInput, Timeline, TimelineElement, Tip, TitleGridArea, TitleNavContentLayout, Toggle, Tooltip, TwoColumnLayout, ValueBar, docs, getOrderedOptions, getValueBarColorByValue, isMultiValue, useContainerProps, useCustomComponents, useDebounce, useLocalStorage, useModal, usePrompt, useTimeout };
|
|
3110
|
+
export { ActionButton, Alert, Badge, BaseInput, Button, Card, CardBody, CardFooter, CardHeader, Chart, Checkbox, Collapse, ContentGridArea, CopyableText, CreatableSelect, DateField, DateInput, DayPicker, DayPickerPopover, DayRangePicker, DensityContainer, Drawer, ExternalLink, FilterListMapLayout, FormGroup, FullWidthRepeatingLayout, GridArea, Heading$1 as Heading, Icon$1 as Icon, IconButton, Indicator$1 as Indicator, IntrinsicallyResponsiveGrid, Label$2 as Label, LegendItem, MenuItem, MenuList, MinTopFullContentLayout, Modal, ModalBackdrop, MoreMenu, MultiSelectMenuItem, NavGridArea, NumberField, NumberInput, PageHeader, Pagination, PieChart, Popover, PopoverList, PopoverListItem, PopoverTitle, Prompt, ROLE_CARD, RadioGroup, RadioItem, Search, SectionHeader, Select, SelectPrefix, Sidebar, SingleSelectMenuItem, SkeletonLines, Spacer, Spinner, StarButton, Tag, Text$1 as Text, TextArea, TextAreaField, TextField, TextInput, Timeline, TimelineElement, Tip, TitleGridArea, TitleNavContentLayout, Toggle, Tooltip, TwoColumnLayout, ValueBar, docs, getDevicePixelRatio, getOrderedOptions, getValueBarColorByValue, isMultiValue, useContainerProps, useCustomComponents, useDebounce, useDevicePixelRatio, useLocalStorage, useModal, usePrompt, useTimeout };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-components",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.22",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"dependencies": {
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"react-router-dom": "6.4.5",
|
|
24
24
|
"react-helmet-async": "1.3.0",
|
|
25
25
|
"react-select": "5.7.0",
|
|
26
|
+
"react-dom": "18.2.0",
|
|
26
27
|
"jest-canvas-mock": "2.4.0"
|
|
27
28
|
},
|
|
28
29
|
"module": "./index.js",
|
package/src/hooks/index.d.ts
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface DevicePixelRatioOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Default DPR to use if browser does not support the `devicePixelRatio`
|
|
4
|
+
* property, or when rendering on server
|
|
5
|
+
*
|
|
6
|
+
* @default `1`
|
|
7
|
+
* @returns DPR
|
|
8
|
+
*/
|
|
9
|
+
defaultDpr?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Whether or not to round the number down to the closest integer
|
|
12
|
+
*
|
|
13
|
+
* @default `true`
|
|
14
|
+
*/
|
|
15
|
+
round?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Maximum DPR to return (set to `2` to only generate 1 and 2)
|
|
18
|
+
*
|
|
19
|
+
* @default `3`
|
|
20
|
+
*/
|
|
21
|
+
maxDpr?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get the device pixel ratio, potentially rounded and capped.
|
|
25
|
+
* Will emit new values if it changes.
|
|
26
|
+
*
|
|
27
|
+
* @param {DevicePixelRatioOptions} options the options object
|
|
28
|
+
* @returns { number } The current device pixel ratio, or the default if none can be resolved
|
|
29
|
+
*/
|
|
30
|
+
export declare function useDevicePixelRatio(options?: DevicePixelRatioOptions): number;
|
|
31
|
+
/**
|
|
32
|
+
* Returns the current device pixel ratio (DPR) given the passed options
|
|
33
|
+
*
|
|
34
|
+
* @param { DevicePixelRatioOptions } options the options object
|
|
35
|
+
* @returns { number } current device pixel ratio
|
|
36
|
+
*/
|
|
37
|
+
export declare function getDevicePixelRatio(options?: DevicePixelRatioOptions): number;
|