@trackunit/react-components 0.1.360 → 0.1.361
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.cjs.js +27 -0
- package/index.esm.js +27 -1
- package/package.json +1 -1
- package/src/hooks/index.d.ts +1 -0
- package/src/hooks/useWindowActivity.d.ts +11 -0
package/index.cjs.js
CHANGED
|
@@ -1360,6 +1360,32 @@ const useVisibilityChange = ({ onChange, targetState = "hidden" }) => {
|
|
|
1360
1360
|
}, [onChange, targetState]);
|
|
1361
1361
|
};
|
|
1362
1362
|
|
|
1363
|
+
const hasFocus = () => typeof document !== "undefined" && document.hasFocus();
|
|
1364
|
+
/**
|
|
1365
|
+
* Use this hook to disable functionality while the tab is hidden within the browser or to react to focus or blur events
|
|
1366
|
+
*/
|
|
1367
|
+
const useWindowActivity = ({ onFocus, onBlur } = {}) => {
|
|
1368
|
+
const [focused, setFocused] = React.useState(hasFocus); // Focus for first render
|
|
1369
|
+
React.useEffect(() => {
|
|
1370
|
+
setFocused(hasFocus()); // Focus for additional renders
|
|
1371
|
+
const onFocusInternal = () => {
|
|
1372
|
+
setFocused(true);
|
|
1373
|
+
onFocus === null || onFocus === void 0 ? void 0 : onFocus();
|
|
1374
|
+
};
|
|
1375
|
+
const onBlurInternal = () => {
|
|
1376
|
+
setFocused(false);
|
|
1377
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur();
|
|
1378
|
+
};
|
|
1379
|
+
window.addEventListener("focus", () => onFocusInternal);
|
|
1380
|
+
window.addEventListener("blur", () => onBlurInternal);
|
|
1381
|
+
return () => {
|
|
1382
|
+
window.removeEventListener("focus", onFocusInternal);
|
|
1383
|
+
window.removeEventListener("blur", onBlurInternal);
|
|
1384
|
+
};
|
|
1385
|
+
}, [onBlur, onFocus]);
|
|
1386
|
+
return { focused };
|
|
1387
|
+
};
|
|
1388
|
+
|
|
1363
1389
|
const cvaBreadcrumb = cssClassVarianceUtilities.cvaMerge(["my-4", "flex", "place-items-center"]);
|
|
1364
1390
|
const cvaBreadcrumbItem = cssClassVarianceUtilities.cvaMerge(["flex", "items-center"]);
|
|
1365
1391
|
const cvaBreadcrumbForLargeScreen = cssClassVarianceUtilities.cvaMerge(["flex", "flex-nowrap"]);
|
|
@@ -4668,3 +4694,4 @@ exports.useResize = useResize;
|
|
|
4668
4694
|
exports.useSelfUpdatingRef = useSelfUpdatingRef;
|
|
4669
4695
|
exports.useTimeout = useTimeout;
|
|
4670
4696
|
exports.useVisibilityChange = useVisibilityChange;
|
|
4697
|
+
exports.useWindowActivity = useWindowActivity;
|
package/index.esm.js
CHANGED
|
@@ -1329,6 +1329,32 @@ const useVisibilityChange = ({ onChange, targetState = "hidden" }) => {
|
|
|
1329
1329
|
}, [onChange, targetState]);
|
|
1330
1330
|
};
|
|
1331
1331
|
|
|
1332
|
+
const hasFocus = () => typeof document !== "undefined" && document.hasFocus();
|
|
1333
|
+
/**
|
|
1334
|
+
* Use this hook to disable functionality while the tab is hidden within the browser or to react to focus or blur events
|
|
1335
|
+
*/
|
|
1336
|
+
const useWindowActivity = ({ onFocus, onBlur } = {}) => {
|
|
1337
|
+
const [focused, setFocused] = useState(hasFocus); // Focus for first render
|
|
1338
|
+
useEffect(() => {
|
|
1339
|
+
setFocused(hasFocus()); // Focus for additional renders
|
|
1340
|
+
const onFocusInternal = () => {
|
|
1341
|
+
setFocused(true);
|
|
1342
|
+
onFocus === null || onFocus === void 0 ? void 0 : onFocus();
|
|
1343
|
+
};
|
|
1344
|
+
const onBlurInternal = () => {
|
|
1345
|
+
setFocused(false);
|
|
1346
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur();
|
|
1347
|
+
};
|
|
1348
|
+
window.addEventListener("focus", () => onFocusInternal);
|
|
1349
|
+
window.addEventListener("blur", () => onBlurInternal);
|
|
1350
|
+
return () => {
|
|
1351
|
+
window.removeEventListener("focus", onFocusInternal);
|
|
1352
|
+
window.removeEventListener("blur", onBlurInternal);
|
|
1353
|
+
};
|
|
1354
|
+
}, [onBlur, onFocus]);
|
|
1355
|
+
return { focused };
|
|
1356
|
+
};
|
|
1357
|
+
|
|
1332
1358
|
const cvaBreadcrumb = cvaMerge(["my-4", "flex", "place-items-center"]);
|
|
1333
1359
|
const cvaBreadcrumbItem = cvaMerge(["flex", "items-center"]);
|
|
1334
1360
|
const cvaBreadcrumbForLargeScreen = cvaMerge(["flex", "flex-nowrap"]);
|
|
@@ -4541,4 +4567,4 @@ const cvaClickable = cvaMerge([
|
|
|
4541
4567
|
},
|
|
4542
4568
|
});
|
|
4543
4569
|
|
|
4544
|
-
export { Alert, Badge, Breadcrumb, BreadcrumbContainer, BreadcrumbItem, Button, Card, CardBody, CardFooter, CardHeader, Collapse, CompletionStatusIndicator, CopyableText, Drawer, EmptyState, EmptyValue, ExternalLink, Heading, Icon, IconButton, Indicator, KPICard, MenuItem, MenuList, MoreMenu, Notice, PackageNameStoryComponent, Page, PageContent, PageHeader, Pagination, Popover, PopoverContent, PopoverTitle, PopoverTrigger, Prompt, ROLE_CARD, SectionHeader, Sidebar, SkeletonLines, Spacer, Spinner, StarButton, Tab, TabContent, TabList, Tabs, Tag, Text, Timeline, TimelineElement, Tooltip, ValueBar, VirtualizedList, WidgetBody, cvaButton, cvaButtonPrefixSuffix, cvaButtonSpinner, cvaButtonSpinnerContainer, cvaClickable, cvaIconButton, cvaIndicator, cvaIndicatorIcon, cvaIndicatorIconBackground, cvaIndicatorLabel, cvaIndicatorPing, cvaMenuItem, cvaMenuItemLabel, cvaMenuItemPrefix, cvaMenuItemSuffix, docs, getDevicePixelRatio, getValueBarColorByValue, iconColorNames, iconPalette, setLocalStorage, useClickOutside, useContainerProps, useContinuousTimeout, useDebounce, useDevicePixelRatio, useGeometry, useHover, useIsFirstRender, useIsFullscreen, useIsTextCutOff, useLocalStorage, useLocalStorageReducer, useOptionallyElevatedState, useOverflowItems, usePopoverContext, usePrompt, useResize, useSelfUpdatingRef, useTimeout, useVisibilityChange };
|
|
4570
|
+
export { Alert, Badge, Breadcrumb, BreadcrumbContainer, BreadcrumbItem, Button, Card, CardBody, CardFooter, CardHeader, Collapse, CompletionStatusIndicator, CopyableText, Drawer, EmptyState, EmptyValue, ExternalLink, Heading, Icon, IconButton, Indicator, KPICard, MenuItem, MenuList, MoreMenu, Notice, PackageNameStoryComponent, Page, PageContent, PageHeader, Pagination, Popover, PopoverContent, PopoverTitle, PopoverTrigger, Prompt, ROLE_CARD, SectionHeader, Sidebar, SkeletonLines, Spacer, Spinner, StarButton, Tab, TabContent, TabList, Tabs, Tag, Text, Timeline, TimelineElement, Tooltip, ValueBar, VirtualizedList, WidgetBody, cvaButton, cvaButtonPrefixSuffix, cvaButtonSpinner, cvaButtonSpinnerContainer, cvaClickable, cvaIconButton, cvaIndicator, cvaIndicatorIcon, cvaIndicatorIconBackground, cvaIndicatorLabel, cvaIndicatorPing, cvaMenuItem, cvaMenuItemLabel, cvaMenuItemPrefix, cvaMenuItemSuffix, docs, getDevicePixelRatio, getValueBarColorByValue, iconColorNames, iconPalette, setLocalStorage, useClickOutside, useContainerProps, useContinuousTimeout, useDebounce, useDevicePixelRatio, useGeometry, useHover, useIsFirstRender, useIsFullscreen, useIsTextCutOff, useLocalStorage, useLocalStorageReducer, useOptionallyElevatedState, useOverflowItems, usePopoverContext, usePrompt, useResize, useSelfUpdatingRef, useTimeout, useVisibilityChange, useWindowActivity };
|
package/package.json
CHANGED
package/src/hooks/index.d.ts
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type UseWindowActivityProps = {
|
|
2
|
+
onFocus?: () => void;
|
|
3
|
+
onBlur?: () => void;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Use this hook to disable functionality while the tab is hidden within the browser or to react to focus or blur events
|
|
7
|
+
*/
|
|
8
|
+
export declare const useWindowActivity: ({ onFocus, onBlur }?: UseWindowActivityProps) => {
|
|
9
|
+
focused: boolean;
|
|
10
|
+
};
|
|
11
|
+
export {};
|