@trackunit/react-components 0.1.111 → 0.1.113

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 CHANGED
@@ -1228,6 +1228,9 @@ const useClickOutside = (el, options = {}, onClick) => {
1228
1228
  * @param {"in" | "out" | "both"} direction Considers truthiness of value. If set to "in", the value will only be debounced if it is truthy. If set to "out", the value will only be debounced if it is falsy. If set to "both" or if not defined, the value will be debounced regardless of truthiness.
1229
1229
  * @returns {any} The latest value received
1230
1230
  */
1231
+ /**
1232
+ *
1233
+ */
1231
1234
  const useDebounce = (value, delay = 500, direction) => {
1232
1235
  const [debouncedValue, setDebouncedValue] = React.useState(value);
1233
1236
  React.useEffect(() => {
@@ -1301,6 +1304,26 @@ function getDevicePixelRatio(options) {
1301
1304
  return rounded;
1302
1305
  }
1303
1306
 
1307
+ /**
1308
+ * The useHover hook returns a onMouseEnter, onMouseLeave and a boolean indicating whether the element is being hovered.
1309
+ * The boolean will be true if the element is being hovered, and false if it is not.
1310
+ * Can be directionally debounced.
1311
+ *
1312
+ * @param {ConditionalUseHoverProps} param0 The options
1313
+ * @returns {Object} The object containing the onMouseEnter, onMouseLeave and hovering props
1314
+ */
1315
+ const useHover = ({ debounced = false, delay = 100, direction = "out" } = { debounced: false }) => {
1316
+ const [hovering, setHovering] = React.useState(false);
1317
+ const debouncedHovering = useDebounce(hovering, delay, direction);
1318
+ const onMouseEnter = () => {
1319
+ setHovering(true);
1320
+ };
1321
+ const onMouseLeave = () => {
1322
+ setHovering(false);
1323
+ };
1324
+ return { onMouseEnter, onMouseLeave, hovering: debounced ? debouncedHovering : hovering };
1325
+ };
1326
+
1304
1327
  /**
1305
1328
  * Differentiate between the first and subsequent renders.
1306
1329
  *
@@ -1679,7 +1702,7 @@ const TipContainer = tailwindStyledComponents.tw.text `
1679
1702
  * @returns {JSX.Element} PageHeader component
1680
1703
  */
1681
1704
  const PageHeader = ({ className, dataTestId, action, showLoading, description, link, title, tag, backTo, children, }) => {
1682
- return (jsxRuntime.jsxs(StyledPageHeader, Object.assign({ className: className, "data-testid": dataTestId }, { children: [jsxRuntime.jsxs(HeadingAndAccessoriesContainer, Object.assign({ "data-testid": dataTestId && `${dataTestId}-heading-container` }, { children: [jsxRuntime.jsxs(HeadingContainer, { children: [backTo && (jsxRuntime.jsx(IconButton, { to: backTo, color: "tertiary", variant: "transparent", size: "small", icon: jsxRuntime.jsx(Icon, { name: "ArrowLeftIcon" }) })), jsxRuntime.jsx(Heading, Object.assign({ "data-testid": dataTestId && `${dataTestId}-heading` }, { children: title })), description && (jsxRuntime.jsx(StyledTip, Object.assign({ link: isValidHttpUrl(link) ? link : undefined, dataTestId: dataTestId && `${dataTestId}-tip`, iconProps: { name: "QuestionMarkCircleIcon" }, renderAs: link ? "a" : "span" }, { children: description })))] }), tag && jsxRuntime.jsx(Tag, Object.assign({ dataTestId: dataTestId }, { children: tag })), showLoading && jsxRuntime.jsx(Spinner, { dataTestId: dataTestId && `${dataTestId}-spinner`, centering: "vertically" }), action] })), jsxRuntime.jsx(ChildContainer$1, { children: children })] })));
1705
+ return (jsxRuntime.jsxs(StyledPageHeader, Object.assign({ className: className, "data-testid": dataTestId }, { children: [jsxRuntime.jsxs(HeadingAndAccessoriesContainer, Object.assign({ "data-testid": dataTestId && `${dataTestId}-heading-container` }, { children: [jsxRuntime.jsxs(HeadingContainer, { children: [backTo && (jsxRuntime.jsx(IconButton, { to: backTo, color: "tertiary", variant: "transparent", size: "small", icon: jsxRuntime.jsx(Icon, { name: "ArrowLeftIcon" }) })), jsxRuntime.jsx(Heading, Object.assign({ "data-testid": dataTestId && `${dataTestId}-heading` }, { children: title })), description && !showLoading && (jsxRuntime.jsx(StyledTip, Object.assign({ link: isValidHttpUrl(link) ? link : undefined, dataTestId: dataTestId && `${dataTestId}-tip`, iconProps: { name: "QuestionMarkCircleIcon" }, renderAs: link ? "a" : "span" }, { children: description })))] }), tag && !showLoading && jsxRuntime.jsx(Tag, Object.assign({ dataTestId: dataTestId }, { children: tag })), showLoading && jsxRuntime.jsx(Spinner, { dataTestId: dataTestId && `${dataTestId}-spinner`, centering: "vertically" }), action] })), jsxRuntime.jsx(ChildContainer$1, { children: children })] })));
1683
1706
  };
1684
1707
  function isValidHttpUrl(link) {
1685
1708
  if (!link) {
@@ -2396,6 +2419,7 @@ exports.useClickOutside = useClickOutside;
2396
2419
  exports.useContainerProps = useContainerProps;
2397
2420
  exports.useDebounce = useDebounce;
2398
2421
  exports.useDevicePixelRatio = useDevicePixelRatio;
2422
+ exports.useHover = useHover;
2399
2423
  exports.useIsFirstRender = useIsFirstRender;
2400
2424
  exports.useLocalStorage = useLocalStorage;
2401
2425
  exports.useLocalStorageReducer = useLocalStorageReducer;
package/index.js CHANGED
@@ -7,7 +7,7 @@ import { cvaMerge } from '@trackunit/css-class-variance-utilities';
7
7
  import { useMeasure, useCopyToClipboard } from 'react-use';
8
8
  import { DayPicker as DayPicker$1 } from 'react-day-picker';
9
9
  import { enGB, enUS, da, de, cs, nl, fr, fi, hu, it, nb, pl, pt, ru, ro, es, sv, ja, th } from 'date-fns/locale';
10
- import { useFloating, autoUpdate, offset, flip, shift, size, useClick, useDismiss, useHover, useRole, useInteractions, useMergeRefs, FloatingPortal, FloatingFocusManager } from '@floating-ui/react';
10
+ import { useFloating, autoUpdate, offset, flip, shift, size, useClick, useDismiss, useHover as useHover$1, useRole, useInteractions, useMergeRefs, FloatingPortal, FloatingFocusManager } from '@floating-ui/react';
11
11
  import { isEqual } from 'lodash';
12
12
  import usePortal from 'react-useportal';
13
13
  import { UNSAFE_NavigationContext } from 'react-router-dom';
@@ -833,7 +833,7 @@ const usePopover = (_a) => {
833
833
  const popoverContext = popoverData.context;
834
834
  const clickInteraction = useClick(popoverContext, { enabled: activation.click, ignoreMouse: activation.hover });
835
835
  const dismissInteraction = useDismiss(popoverContext);
836
- const hoverInteraction = useHover(popoverContext, { enabled: activation.hover });
836
+ const hoverInteraction = useHover$1(popoverContext, { enabled: activation.hover });
837
837
  const roleInteraction = useRole(popoverContext);
838
838
  const combinedInteractions = useInteractions([
839
839
  clickInteraction,
@@ -1201,6 +1201,9 @@ const useClickOutside = (el, options = {}, onClick) => {
1201
1201
  * @param {"in" | "out" | "both"} direction Considers truthiness of value. If set to "in", the value will only be debounced if it is truthy. If set to "out", the value will only be debounced if it is falsy. If set to "both" or if not defined, the value will be debounced regardless of truthiness.
1202
1202
  * @returns {any} The latest value received
1203
1203
  */
1204
+ /**
1205
+ *
1206
+ */
1204
1207
  const useDebounce = (value, delay = 500, direction) => {
1205
1208
  const [debouncedValue, setDebouncedValue] = useState(value);
1206
1209
  useEffect(() => {
@@ -1274,6 +1277,26 @@ function getDevicePixelRatio(options) {
1274
1277
  return rounded;
1275
1278
  }
1276
1279
 
1280
+ /**
1281
+ * The useHover hook returns a onMouseEnter, onMouseLeave and a boolean indicating whether the element is being hovered.
1282
+ * The boolean will be true if the element is being hovered, and false if it is not.
1283
+ * Can be directionally debounced.
1284
+ *
1285
+ * @param {ConditionalUseHoverProps} param0 The options
1286
+ * @returns {Object} The object containing the onMouseEnter, onMouseLeave and hovering props
1287
+ */
1288
+ const useHover = ({ debounced = false, delay = 100, direction = "out" } = { debounced: false }) => {
1289
+ const [hovering, setHovering] = useState(false);
1290
+ const debouncedHovering = useDebounce(hovering, delay, direction);
1291
+ const onMouseEnter = () => {
1292
+ setHovering(true);
1293
+ };
1294
+ const onMouseLeave = () => {
1295
+ setHovering(false);
1296
+ };
1297
+ return { onMouseEnter, onMouseLeave, hovering: debounced ? debouncedHovering : hovering };
1298
+ };
1299
+
1277
1300
  /**
1278
1301
  * Differentiate between the first and subsequent renders.
1279
1302
  *
@@ -1652,7 +1675,7 @@ const TipContainer = tw.text `
1652
1675
  * @returns {JSX.Element} PageHeader component
1653
1676
  */
1654
1677
  const PageHeader = ({ className, dataTestId, action, showLoading, description, link, title, tag, backTo, children, }) => {
1655
- return (jsxs(StyledPageHeader, Object.assign({ className: className, "data-testid": dataTestId }, { children: [jsxs(HeadingAndAccessoriesContainer, Object.assign({ "data-testid": dataTestId && `${dataTestId}-heading-container` }, { children: [jsxs(HeadingContainer, { children: [backTo && (jsx(IconButton, { to: backTo, color: "tertiary", variant: "transparent", size: "small", icon: jsx(Icon, { name: "ArrowLeftIcon" }) })), jsx(Heading, Object.assign({ "data-testid": dataTestId && `${dataTestId}-heading` }, { children: title })), description && (jsx(StyledTip, Object.assign({ link: isValidHttpUrl(link) ? link : undefined, dataTestId: dataTestId && `${dataTestId}-tip`, iconProps: { name: "QuestionMarkCircleIcon" }, renderAs: link ? "a" : "span" }, { children: description })))] }), tag && jsx(Tag, Object.assign({ dataTestId: dataTestId }, { children: tag })), showLoading && jsx(Spinner, { dataTestId: dataTestId && `${dataTestId}-spinner`, centering: "vertically" }), action] })), jsx(ChildContainer$1, { children: children })] })));
1678
+ return (jsxs(StyledPageHeader, Object.assign({ className: className, "data-testid": dataTestId }, { children: [jsxs(HeadingAndAccessoriesContainer, Object.assign({ "data-testid": dataTestId && `${dataTestId}-heading-container` }, { children: [jsxs(HeadingContainer, { children: [backTo && (jsx(IconButton, { to: backTo, color: "tertiary", variant: "transparent", size: "small", icon: jsx(Icon, { name: "ArrowLeftIcon" }) })), jsx(Heading, Object.assign({ "data-testid": dataTestId && `${dataTestId}-heading` }, { children: title })), description && !showLoading && (jsx(StyledTip, Object.assign({ link: isValidHttpUrl(link) ? link : undefined, dataTestId: dataTestId && `${dataTestId}-tip`, iconProps: { name: "QuestionMarkCircleIcon" }, renderAs: link ? "a" : "span" }, { children: description })))] }), tag && !showLoading && jsx(Tag, Object.assign({ dataTestId: dataTestId }, { children: tag })), showLoading && jsx(Spinner, { dataTestId: dataTestId && `${dataTestId}-spinner`, centering: "vertically" }), action] })), jsx(ChildContainer$1, { children: children })] })));
1656
1679
  };
1657
1680
  function isValidHttpUrl(link) {
1658
1681
  if (!link) {
@@ -2306,4 +2329,4 @@ const Layout = tw.div `
2306
2329
  tu-layout-TwoColumnLayout
2307
2330
  `;
2308
2331
 
2309
- export { Alert, Badge, Button, Card, CardBody, CardFooter, CardHeader, Collapse, ContentGridArea, CopyableText, DayPicker, DayPickerPopover, DayRangePicker, DensityContainer, Drawer, ExternalLink, FilterListMapLayout, FullWidthRepeatingLayout, GridArea, Heading$1 as Heading, Icon, IconButton, Indicator, IntrinsicallyResponsiveGrid, MenuItem, MenuList, MinTopFullContentLayout, Modal, ModalBackdrop, MoreMenu, NavGridArea, PageHeader, Pagination, Popover, PopoverContent, PopoverTitle, PopoverTrigger, Prompt, ROLE_CARD, SectionHeader, Sidebar, SkeletonLines, Spacer, Spinner, StarButton, Tag, Text$1 as Text, Timeline, TimelineElement, Tip, TitleGridArea, TitleNavContentLayout, Tooltip, TwoColumnLayout, ValueBar, cvaClickable, docs, getDevicePixelRatio, getValueBarColorByValue, useClickOutside, useContainerProps, useDebounce, useDevicePixelRatio, useIsFirstRender, useLocalStorage, useLocalStorageReducer, useModal, usePopoverContext, usePrompt, useResize, useTimeout };
2332
+ export { Alert, Badge, Button, Card, CardBody, CardFooter, CardHeader, Collapse, ContentGridArea, CopyableText, DayPicker, DayPickerPopover, DayRangePicker, DensityContainer, Drawer, ExternalLink, FilterListMapLayout, FullWidthRepeatingLayout, GridArea, Heading$1 as Heading, Icon, IconButton, Indicator, IntrinsicallyResponsiveGrid, MenuItem, MenuList, MinTopFullContentLayout, Modal, ModalBackdrop, MoreMenu, NavGridArea, PageHeader, Pagination, Popover, PopoverContent, PopoverTitle, PopoverTrigger, Prompt, ROLE_CARD, SectionHeader, Sidebar, SkeletonLines, Spacer, Spinner, StarButton, Tag, Text$1 as Text, Timeline, TimelineElement, Tip, TitleGridArea, TitleNavContentLayout, Tooltip, TwoColumnLayout, ValueBar, cvaClickable, docs, getDevicePixelRatio, getValueBarColorByValue, useClickOutside, useContainerProps, useDebounce, useDevicePixelRatio, useHover, useIsFirstRender, useLocalStorage, useLocalStorageReducer, useModal, usePopoverContext, usePrompt, useResize, useTimeout };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "0.1.111",
3
+ "version": "0.1.113",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -1,6 +1,7 @@
1
1
  export * from "./useClickOutside";
2
2
  export * from "./useDebounce";
3
3
  export * from "./useDevicePixelRatio";
4
+ export * from "./useHover";
4
5
  export * from "./useIsFirstRender";
5
6
  export * from "./useLocalStorage";
6
7
  export * from "./useLocalStorageReducer";
@@ -1,3 +1,4 @@
1
+ export type DebounceDirection = "in" | "out" | "both";
1
2
  /**
2
3
  * The useDebounce hook works like useState, but adds a delay where previous values will be ignored.
3
4
  *
@@ -6,4 +7,7 @@
6
7
  * @param {"in" | "out" | "both"} direction Considers truthiness of value. If set to "in", the value will only be debounced if it is truthy. If set to "out", the value will only be debounced if it is falsy. If set to "both" or if not defined, the value will be debounced regardless of truthiness.
7
8
  * @returns {any} The latest value received
8
9
  */
9
- export declare const useDebounce: <T>(value: T, delay?: number, direction?: "in" | "out" | "both") => T;
10
+ /**
11
+ *
12
+ */
13
+ export declare const useDebounce: <T>(value: T, delay?: number, direction?: DebounceDirection) => T;
@@ -0,0 +1,24 @@
1
+ import { DebounceDirection } from "./useDebounce";
2
+ type ConditionalUseHoverProps = {
3
+ debounced: true;
4
+ delay?: number;
5
+ direction?: DebounceDirection;
6
+ } | {
7
+ debounced: false;
8
+ delay?: never;
9
+ direction?: never;
10
+ };
11
+ /**
12
+ * The useHover hook returns a onMouseEnter, onMouseLeave and a boolean indicating whether the element is being hovered.
13
+ * The boolean will be true if the element is being hovered, and false if it is not.
14
+ * Can be directionally debounced.
15
+ *
16
+ * @param {ConditionalUseHoverProps} param0 The options
17
+ * @returns {Object} The object containing the onMouseEnter, onMouseLeave and hovering props
18
+ */
19
+ export declare const useHover: ({ debounced, delay, direction }?: ConditionalUseHoverProps) => {
20
+ onMouseEnter: () => void;
21
+ onMouseLeave: () => void;
22
+ hovering: boolean;
23
+ };
24
+ export {};