@trackunit/react-components 0.0.185 → 0.0.186

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.
@@ -1,6 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { Matcher } from "react-day-picker";
3
- export interface DayPickerProps {
3
+ import { CommonProps } from "../../common/CommonProps";
4
+ export interface DayPickerProps extends CommonProps {
4
5
  /**
5
6
  * A callback function for when a date is selected
6
7
  */
@@ -8,15 +9,18 @@ export interface DayPickerProps {
8
9
  /**
9
10
  * Define any days which may not be selected
10
11
  */
11
- disabledDays: Matcher | Matcher[] | undefined;
12
+ disabledDays?: Matcher | Matcher[];
12
13
  /**
13
14
  * Set any days which are selected
14
15
  */
15
- selectedDays: Matcher | Matcher[] | undefined;
16
+ selectedDays?: Matcher | Matcher[];
16
17
  /**
17
18
  * Set the language
18
19
  */
19
20
  language: string;
21
+ /**
22
+ * The maximum amount of days that can be selected
23
+ */
20
24
  max?: number;
21
25
  }
22
26
  /**
@@ -25,4 +29,4 @@ export interface DayPickerProps {
25
29
  * @param {DayPickerProps} props - The props for the DayPicker component
26
30
  * @returns {JSX.Element} DayPicker component
27
31
  */
28
- export declare const DayPicker: ({ onDaySelect, disabledDays, selectedDays, language, ...rest }: DayPickerProps) => JSX.Element;
32
+ export declare const DayPicker: ({ onDaySelect, disabledDays, selectedDays, language, className, dataTestId, max, }: DayPickerProps) => JSX.Element;
@@ -1,11 +1,10 @@
1
1
  /// <reference types="react" />
2
2
  import { Matcher } from "react-day-picker";
3
- import { Size } from "../../common";
3
+ import { CommonProps, Size } from "../../common/CommonProps";
4
4
  import { ButtonColor } from "../buttons";
5
5
  import { PopoverPlacement } from "../Popover";
6
- export interface DayPickerPopoverProps {
6
+ export interface DayPickerPopoverProps extends CommonProps {
7
7
  disabledDays?: Matcher | Matcher[] | undefined;
8
- className?: string;
9
8
  onDaySelect: (day: Date) => void;
10
9
  selectedDay?: Date;
11
10
  color?: ButtonColor;
@@ -20,4 +19,4 @@ export interface DayPickerPopoverProps {
20
19
  * @param {DayPickerPopoverProps} props - The props for the DayPickerPopover component
21
20
  * @returns {JSX.Element} DayPickerPopover component
22
21
  */
23
- export declare const DayPickerPopover: ({ disabledDays, className, selectedDay, onDaySelect, color, placement, size, buttonContent, language, }: DayPickerPopoverProps) => JSX.Element;
22
+ export declare const DayPickerPopover: ({ disabledDays, className, dataTestId, selectedDay, onDaySelect, color, placement, size, buttonContent, language, }: DayPickerPopoverProps) => JSX.Element;
@@ -1,12 +1,27 @@
1
1
  /// <reference types="react" />
2
2
  import { DateRange, Matcher } from "react-day-picker";
3
+ import { CommonProps } from "../../common/CommonProps";
3
4
  export declare type IDateRange = DateRange;
4
- export interface DayRangePickerProps {
5
+ export interface DayRangePickerProps extends CommonProps {
6
+ /**
7
+ * A callback function for when a range is selected
8
+ */
5
9
  onRangeSelect?: (range: IDateRange | undefined) => void;
6
- selectedDays: IDateRange;
7
- dataTestId?: string;
10
+ /**
11
+ * Define any days which may not be selected
12
+ */
8
13
  disabledDays?: Matcher | Matcher[];
14
+ /**
15
+ * Set any days which are selected
16
+ */
17
+ selectedDays: IDateRange;
18
+ /**
19
+ * Set the language
20
+ */
9
21
  language: string;
22
+ /**
23
+ * The maximum amount of days that can be selected
24
+ */
10
25
  max?: number;
11
26
  }
12
27
  /**
@@ -15,4 +30,4 @@ export interface DayRangePickerProps {
15
30
  * @param {DayRangePickerProps} props - The props for the DayRangePicker component
16
31
  * @returns {JSX.Element} DayRangePicker component
17
32
  */
18
- export declare const DayRangePicker: ({ onRangeSelect, selectedDays, disabledDays, dataTestId, language, max, }: DayRangePickerProps) => JSX.Element;
33
+ export declare const DayRangePicker: ({ onRangeSelect, selectedDays, disabledDays, dataTestId, language, className, max, }: DayRangePickerProps) => JSX.Element;
@@ -0,0 +1,37 @@
1
+ import { Placement } from "@floating-ui/react-dom-interactions";
2
+ import { ReactElement } from "react";
3
+ import { CommonProps } from "../../common";
4
+ declare type Render = (data: {
5
+ close: () => void;
6
+ }) => ReactElement;
7
+ export declare type PopoverPlacement = Placement;
8
+ export declare type PopoverActivation = {
9
+ click?: boolean;
10
+ hover?: boolean;
11
+ };
12
+ export interface PopoverProps extends CommonProps {
13
+ /**
14
+ * What to render indide the popover with callback to close the popover
15
+ */
16
+ render: Render;
17
+ /**
18
+ * Where to preferentially render the popover relative to the invoking element.
19
+ * Will not be respected in case of insufficient space.
20
+ */
21
+ placement?: PopoverPlacement;
22
+ /**
23
+ * Action(s) that activates the tooltip
24
+ */
25
+ activation?: PopoverActivation;
26
+ /**
27
+ * The element, usually a button, that activates the popover.
28
+ * Event handling is automatic and tied to this element. No manual Event handling is necessary.
29
+ */
30
+ children: ReactElement;
31
+ }
32
+ /**
33
+ * @param {PopoverProps} props The children to render in the popover
34
+ * @returns {ReactElement} Popover with specified content and placement
35
+ */
36
+ export declare const Popover: ({ children, render, placement, activation, className, dataTestId, }: PopoverProps) => JSX.Element;
37
+ export {};
@@ -1,5 +1,4 @@
1
- export * from "./AnimatedPopover";
1
+ export * from "./Popover";
2
2
  export * from "./PopoverList";
3
3
  export * from "./PopoverListItem";
4
4
  export * from "./PopoverTitle";
5
- export * from "./usePopover";
@@ -2,7 +2,7 @@ import * as React from "react";
2
2
  import { CommonProps } from "../../common";
3
3
  import { IconProps } from "../Icon/Icon";
4
4
  import { TooltipProps } from "../Tooltip";
5
- export interface TipProps extends CommonProps {
5
+ export interface TipProps extends CommonProps, Pick<TooltipProps, "placement" | "mode"> {
6
6
  /**
7
7
  * Child nodes to render inside the tip.
8
8
  */
@@ -11,10 +11,6 @@ export interface TipProps extends CommonProps {
11
11
  * The props for setting the icon on this tip.
12
12
  */
13
13
  iconProps?: Partial<IconProps>;
14
- /**
15
- * The props for setting the tooltip on this tip.
16
- */
17
- tooltipProps?: Partial<TooltipProps>;
18
14
  /**
19
15
  * The element type the tip will be rendered as.
20
16
  */
@@ -31,4 +27,4 @@ export interface TipProps extends CommonProps {
31
27
  * @param {TipProps} props - The props for the Tip component
32
28
  * @returns {JSX.Element} Tip component
33
29
  */
34
- export declare const Tip: ({ children, iconProps, tooltipProps, dataTestId, link, renderAs, className, }: TipProps) => JSX.Element;
30
+ export declare const Tip: ({ children, iconProps, dataTestId, link, renderAs, className, placement, mode, }: TipProps) => JSX.Element;
@@ -1,23 +1,20 @@
1
1
  import * as React from "react";
2
+ import { CommonProps } from "../../common";
2
3
  import { PopoverPlacement } from "../Popover";
3
4
  import { TextType } from "../Text";
4
- export interface TooltipProps {
5
+ export interface TooltipProps extends CommonProps {
5
6
  /**
6
7
  * The text to be displayed in the tooltip.
7
8
  */
8
9
  label: string | React.ReactNode;
9
10
  /**
10
- * Where the tooltip should be placed.
11
+ * Where the tooltip should preferentially be placed.
11
12
  */
12
13
  placement?: PopoverPlacement;
13
14
  /**
14
15
  * Child nodes
15
16
  */
16
17
  children?: React.ReactNode;
17
- /**
18
- * Id of test component.
19
- */
20
- dataTestId?: string;
21
18
  /**
22
19
  * Whether the tooltip is disabled or not.
23
20
  */
@@ -26,14 +23,6 @@ export interface TooltipProps {
26
23
  * To select either "light" or "dark" mode.
27
24
  */
28
25
  mode?: "light" | "dark";
29
- /**
30
- * Offset value of the tooltip.
31
- */
32
- offset?: [number, number];
33
- /**
34
- * Additional classes to the component.
35
- */
36
- className?: string;
37
26
  /**
38
27
  * Type of content.
39
28
  */
@@ -45,4 +34,4 @@ export interface TooltipProps {
45
34
  * @param {TooltipProps} props - The props for the Tooltip component
46
35
  * @returns {JSX.Element} Tooltip component
47
36
  */
48
- export declare const Tooltip: ({ label, placement, children, dataTestId, disabled, mode, offset, className, contentTextType, }: TooltipProps) => JSX.Element;
37
+ export declare const Tooltip: ({ children, dataTestId, disabled, className, ...rest }: TooltipProps) => JSX.Element;
@@ -24,6 +24,7 @@ export * from "./NumberInput/NumberInput";
24
24
  export * from "./PageHeader";
25
25
  export * from "./Pagination/Pagination";
26
26
  export * from "./Popover";
27
+ export * from "./Popover/Popover";
27
28
  export * from "./Prompt";
28
29
  export * from "./RadioGroup";
29
30
  export * from "./SectionHeader";
package/index.js CHANGED
@@ -1,18 +1,17 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
2
  import { tw, tws, twx } from '@trackunit/tailwind-styled-components';
3
3
  import * as React from 'react';
4
- import React__default, { useState, forwardRef, useRef, Fragment as Fragment$1, useCallback, createElement, memo, useEffect, useContext } from 'react';
4
+ import React__default, { useState, forwardRef, useMemo, cloneElement, useCallback, createElement, useRef, memo, useEffect, useContext } from 'react';
5
5
  import { HeroIconsArray, heroIconLookup, TrackunitSolidIconsArray, TrackunitOutlineIconsArray, trackunitIconLookup } from '@trackunit/ui-icons';
6
6
  import EChart from 'echarts-for-react';
7
7
  import { v4 } from 'uuid';
8
- import { useMeasure, useCopyToClipboard, useKeyPressEvent } from 'react-use';
8
+ import { useMeasure, useCopyToClipboard } from 'react-use';
9
9
  import { format, formatDistance } from 'date-fns';
10
- import { useSpring, animated } from '@react-spring/web';
11
- import usePortal from 'react-useportal';
12
- import { createPopper } from '@popperjs/core';
10
+ import { useFloating, offset, shift, flip, autoUpdate, useInteractions, useClick, useHover, useRole, useDismiss, FloatingPortal, FloatingFocusManager } from '@floating-ui/react-dom-interactions';
13
11
  import { Link, UNSAFE_NavigationContext } from 'react-router-dom';
14
12
  import { DayPicker as DayPicker$1 } from 'react-day-picker';
15
13
  import { enGB, enUS, da, de, cs, nl, fr, fi, hu, it, nb, pl, pt, ru, ro, es, sv, ja, th } from 'date-fns/locale';
14
+ import usePortal from 'react-useportal';
16
15
  import { Helmet } from 'react-helmet';
17
16
  import ReactSelect, { components } from 'react-select';
18
17
  export { default as ValueType } from 'react-select';
@@ -116,7 +115,7 @@ const Spinner = ({
116
115
  containerClassName,
117
116
  dataTestId
118
117
  }) => {
119
- return jsx(Container$9, Object.assign({
118
+ return jsx(Container$8, Object.assign({
120
119
  "$mode": mode,
121
120
  "$centered": centered,
122
121
  className: containerClassName
@@ -152,7 +151,7 @@ const StyledSpinner$1 = tw.span`
152
151
  ${p => p.$mode === "dark" ? tws`tu-spinner--dark` : null}
153
152
  ${getSpinnerStyles()}
154
153
  `;
155
- const Container$9 = tw.div`
154
+ const Container$8 = tw.div`
156
155
  tu-spinner--container
157
156
  ${p => p.$centered ? tws`tu-spinner--container-centered` : null}
158
157
  `;
@@ -359,7 +358,7 @@ const Icon$1 = ({
359
358
  }, {
360
359
  children: jsx(IconComponent, {
361
360
  "data-testid": dataTestId ? `${dataTestId}-${name}` : name,
362
- className: `${iconSizeClassName} ${colorClassNames} ${className} ${name} aspect-square`,
361
+ className: `${iconSizeClassName} ${colorClassNames} ${className !== null && className !== void 0 ? className : ""} ${name} aspect-square`,
363
362
  style: fillColor ? Object.assign(Object.assign({}, style), {
364
363
  fill: fillColor
365
364
  }) : Object.assign({}, style)
@@ -714,7 +713,7 @@ const Alert = ({
714
713
  ref && ref.current && ref.current.scrollIntoView && ref.current.scrollIntoView();
715
714
  }
716
715
  }, [ref, autoScroll]);
717
- return jsxs(Container$8, Object.assign({
716
+ return jsxs(Container$7, Object.assign({
718
717
  "$color": color,
719
718
  className: className,
720
719
  "data-testid": dataTestId,
@@ -802,7 +801,7 @@ const getBackgroundColor = () => ({
802
801
  return colors[$color];
803
802
  };
804
803
 
805
- const Container$8 = tw.div`
804
+ const Container$7 = tw.div`
806
805
  tu-alert
807
806
  ${p => p.$inline ? tws`tu-alert--inline` : null}
808
807
  ${getBackgroundColor()}
@@ -1281,7 +1280,7 @@ const CardHeader = ({
1281
1280
  className: className,
1282
1281
  "$density": density
1283
1282
  }, {
1284
- children: jsxs(Container$7, {
1283
+ children: jsxs(Container$6, {
1285
1284
  children: [jsxs("div", {
1286
1285
  children: [jsxs(HeadingContainer$1, {
1287
1286
  children: [jsx(Heading$1, Object.assign({
@@ -1311,7 +1310,7 @@ const CardHeader = ({
1311
1310
  const BottomBorderedDensityContainer = twx(DensityContainer)`
1312
1311
  tu-card__header-density-container
1313
1312
  `;
1314
- const Container$7 = tw.div`
1313
+ const Container$6 = tw.div`
1315
1314
  tu-card__header
1316
1315
  `;
1317
1316
  const HeadingContainer$1 = tw.div`
@@ -1810,182 +1809,93 @@ const DateInput = forwardRef((_a, ref) => {
1810
1809
  }, rest));
1811
1810
  });
1812
1811
 
1813
- var PopoverLifecycle;
1814
-
1815
- (function (PopoverLifecycle) {
1816
- PopoverLifecycle["closed"] = "closed";
1817
- PopoverLifecycle["open"] = "open";
1818
- PopoverLifecycle["closing"] = "closing";
1819
- })(PopoverLifecycle || (PopoverLifecycle = {}));
1820
1812
  /**
1821
- * The usePopover Hook.
1822
- *
1823
- * @param {UsePopoverProps} props - The props for the usePopover hook
1824
- * @returns {UsePopoverProps} - UsePopoverProps
1813
+ * @param {PopoverProps} props The children to render in the popover
1814
+ * @returns {ReactElement} Popover with specified content and placement
1825
1815
  */
1826
1816
 
1827
-
1828
- const usePopover = ({
1829
- targetRef,
1830
- popoverRef,
1831
- placement = "auto",
1832
- offset = [0, 8]
1833
- }) => {
1834
- const [lifecycle, setLifecycle] = React.useState(PopoverLifecycle.closed);
1835
- const popperRef = React.useRef(null);
1836
- React.useLayoutEffect(() => {
1837
- if (targetRef.current && popoverRef.current) {
1838
- popperRef.current = createPopper(targetRef.current, popoverRef.current, {
1839
- placement,
1840
- strategy: "fixed",
1841
- modifiers: [{
1842
- name: "offset",
1843
- options: {
1844
- offset
1845
- }
1846
- }, {
1847
- name: "flip",
1848
- options: {
1849
- flipVariations: true
1850
- }
1851
- }]
1852
- });
1853
- }
1854
-
1855
- return () => {
1856
- var _a;
1857
-
1858
- (_a = popperRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
1859
- };
1860
- }, [popoverRef, targetRef, lifecycle, placement, offset]);
1861
-
1862
- const onShow = () => {
1863
- if (lifecycle !== PopoverLifecycle.open) {
1864
- setLifecycle(PopoverLifecycle.open);
1865
- }
1866
- };
1867
-
1868
- const onHide = () => {
1869
- setLifecycle(PopoverLifecycle.closing);
1870
- };
1871
-
1872
- const onClosed = () => {
1873
- setLifecycle(PopoverLifecycle.closed);
1874
- };
1875
-
1876
- return {
1877
- targetRef,
1878
- popoverRef,
1879
- onShow,
1880
- onHide,
1881
- popoverProps: {
1882
- lifecycle,
1883
- onClosed
1884
- }
1885
- };
1886
- };
1887
-
1888
- /**
1889
- * The Popover component is used to display some content on top of another.
1890
- * Use a popover to expose a small amount of information or functionality.
1891
- *
1892
- * @param {AnimatedPopoverProps} props - The props for the Card component
1893
- * @returns {JSX.Element} Popover component
1894
- */
1895
-
1896
- const AnimatedPopover = React.forwardRef(({
1897
- lifecycle,
1898
- onRequestClose,
1817
+ const Popover = ({
1899
1818
  children,
1900
- onClosed,
1901
- enterDelay,
1902
- exitDelay,
1819
+ render,
1820
+ placement,
1821
+ activation = {
1822
+ click: true,
1823
+ hover: false
1824
+ },
1903
1825
  className,
1904
- dataTestId,
1905
- bindTo,
1906
- enableBackdrop = true
1907
- }, ref) => {
1826
+ dataTestId
1827
+ }) => {
1828
+ const [open, setOpen] = useState(false);
1908
1829
  const {
1909
- Portal
1910
- } = usePortal({
1911
- bindTo
1830
+ x,
1831
+ y,
1832
+ reference,
1833
+ floating,
1834
+ strategy,
1835
+ context
1836
+ } = useFloating({
1837
+ open,
1838
+ onOpenChange: setOpen,
1839
+ middleware: [offset(8), shift(), flip({
1840
+ crossAxis: true,
1841
+ fallbackPlacements: ["top", "bottom", "left", "right"]
1842
+ })],
1843
+ placement,
1844
+ whileElementsMounted: autoUpdate
1912
1845
  });
1913
-
1914
- const onClose = e => {
1915
- if (lifecycle === PopoverLifecycle.open) {
1916
- e.preventDefault();
1917
- e.stopPropagation();
1918
- onRequestClose === null || onRequestClose === void 0 ? void 0 : onRequestClose();
1919
- }
1920
- };
1921
-
1922
- useKeyPressEvent("Escape", onClose);
1923
-
1924
- if (lifecycle === PopoverLifecycle.closed) {
1925
- // eslint-disable-next-line react/jsx-no-useless-fragment
1926
- return jsx(Fragment, {});
1927
- }
1928
-
1929
- return jsxs(Portal, {
1930
- children: [lifecycle !== PopoverLifecycle.closing && enableBackdrop && jsx(Backdrop$1, {
1931
- onClick: onClose
1932
- }), jsx(StyledContainer, Object.assign({
1933
- ref: ref,
1934
- className: className,
1935
- "data-testid": dataTestId
1936
- }, {
1937
- children: jsx(AnimatedContainer, Object.assign({
1938
- lifecycle: lifecycle,
1939
- onClosed: onClosed,
1940
- enterDelay: enterDelay,
1941
- exitDelay: exitDelay
1846
+ const {
1847
+ getReferenceProps,
1848
+ getFloatingProps
1849
+ } = useInteractions([useClick(context, {
1850
+ enabled: activation.click
1851
+ }), useHover(context, {
1852
+ enabled: activation.hover
1853
+ }), useRole(context), useDismiss(context)]); // Preserve the consumer's ref
1854
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1855
+
1856
+ const ref = useMemo(() => mergeRefs([reference, children.ref]), [reference, children]);
1857
+ return jsxs(Fragment, {
1858
+ children: [cloneElement(children, getReferenceProps(Object.assign({
1859
+ ref
1860
+ }, children.props))), jsx(FloatingPortal, {
1861
+ children: open && jsx(FloatingFocusManager, Object.assign({
1862
+ context: context,
1863
+ modal: false,
1864
+ order: ["reference", "content"],
1865
+ returnFocus: false
1942
1866
  }, {
1943
- children: children
1867
+ children: jsx("div", Object.assign({
1868
+ ref: floating,
1869
+ className: `tu-popover-container animate-fade-in-fast ${className !== null && className !== void 0 ? className : ""}`,
1870
+ "data-testid": dataTestId,
1871
+ style: {
1872
+ position: strategy,
1873
+ top: y !== null && y !== void 0 ? y : 0,
1874
+ left: x !== null && x !== void 0 ? x : 0
1875
+ }
1876
+ }, getFloatingProps(), {
1877
+ children: render({
1878
+ close: () => {
1879
+ setOpen(false);
1880
+ }
1881
+ })
1882
+ }))
1944
1883
  }))
1945
- }))]
1946
- });
1947
- });
1948
- const Backdrop$1 = tw.div`
1949
- tu-popover-backdrop
1950
- `;
1951
-
1952
- const AnimatedContainer = ({
1953
- lifecycle,
1954
- onClosed,
1955
- enterDelay = 0,
1956
- exitDelay = 0,
1957
- children
1958
- }) => {
1959
- const props = useSpring({
1960
- config: {
1961
- tension: lifecycle === PopoverLifecycle.closing ? 2000 : 1500,
1962
- friction: 100,
1963
- precision: 0.1
1964
- },
1965
- from: {
1966
- opacity: 0,
1967
- transform: "scale(0.98)"
1968
- },
1969
- to: lifecycle === PopoverLifecycle.open ? {
1970
- opacity: 1,
1971
- transform: "scale(1)"
1972
- } : lifecycle === PopoverLifecycle.closing ? {
1973
- opacity: 0,
1974
- transform: "scale(0.98)"
1975
- } : {},
1976
- delay: lifecycle === PopoverLifecycle.open ? enterDelay : exitDelay,
1977
- onRest: () => lifecycle === PopoverLifecycle.closing && (onClosed === null || onClosed === void 0 ? void 0 : onClosed())
1884
+ })]
1978
1885
  });
1979
- return jsx(animated.div, Object.assign({
1980
- style: props
1981
- }, {
1982
- children: children
1983
- }));
1984
- };
1985
-
1986
- const StyledContainer = tw.div`
1987
- tu-popover-container
1988
- `;
1886
+ }; // Utility to merge refs — Heavily inspired by https://github.com/gregberge/react-merge-refs
1887
+
1888
+ function mergeRefs(refs) {
1889
+ return value => {
1890
+ refs.forEach(ref => {
1891
+ if (typeof ref === "function") {
1892
+ ref(value);
1893
+ } else if (ref !== null) {
1894
+ ref.current = value;
1895
+ }
1896
+ });
1897
+ };
1898
+ }
1989
1899
 
1990
1900
  /**
1991
1901
  * The PopoverList component.
@@ -2093,7 +2003,7 @@ const PopoverTitle = ({
2093
2003
  className,
2094
2004
  dataTestId
2095
2005
  }) => {
2096
- return jsxs(Container$6, Object.assign({
2006
+ return jsxs(Container$5, Object.assign({
2097
2007
  "$divider": divider,
2098
2008
  className: className,
2099
2009
  "data-testid": dataTestId
@@ -2109,7 +2019,7 @@ const PopoverTitle = ({
2109
2019
  })), action]
2110
2020
  }));
2111
2021
  };
2112
- const Container$6 = tw.div`
2022
+ const Container$5 = tw.div`
2113
2023
  tu-popover-title-container
2114
2024
  ${p => p.$divider && `tu-popover-title-container--divider`}
2115
2025
  `;
@@ -2124,65 +2034,65 @@ tu-popover-title-text
2124
2034
  * @returns {JSX.Element} Tooltip component
2125
2035
  */
2126
2036
 
2127
- const Tooltip = ({
2037
+ const Tooltip = _a => {
2038
+ var {
2039
+ children,
2040
+ dataTestId,
2041
+ disabled,
2042
+ className
2043
+ } = _a,
2044
+ rest = __rest(_a, ["children", "dataTestId", "disabled", "className"]);
2045
+
2046
+ const wrappedChildren = jsx(Flex$1, Object.assign({
2047
+ className: className,
2048
+ "data-testid": dataTestId && `${dataTestId}-parent`
2049
+ }, {
2050
+ children: children
2051
+ }));
2052
+
2053
+ if (disabled) {
2054
+ return wrappedChildren;
2055
+ }
2056
+
2057
+ return jsx(TooltipContainer, Object.assign({
2058
+ dataTestId: dataTestId
2059
+ }, rest, {
2060
+ children: wrappedChildren
2061
+ }));
2062
+ };
2063
+
2064
+ const TooltipContainer = ({
2128
2065
  label,
2129
2066
  placement = "bottom",
2130
- children,
2131
- dataTestId,
2132
- disabled,
2133
2067
  mode = "dark",
2134
- offset,
2135
- className,
2136
- contentTextType = "p"
2137
- }) => {
2138
- const target = React.useRef(null);
2139
- const popover = React.useRef(null);
2140
- const {
2141
- popoverRef,
2142
- targetRef,
2143
- onShow,
2144
- onHide,
2145
- popoverProps
2146
- } = usePopover({
2147
- targetRef: target,
2148
- popoverRef: popover,
2149
- placement,
2150
- offset
2151
- });
2152
- return jsxs(Fragment, {
2153
- children: [jsx(Flex$1, Object.assign({
2154
- className: className,
2155
- onMouseEnter: onShow,
2156
- onMouseLeave: onHide,
2157
- ref: targetRef,
2158
- "data-testid": dataTestId && `${dataTestId}-parent`
2159
- }, {
2160
- children: children
2161
- })), !disabled && jsx(Container$5, Object.assign({
2162
- ref: popoverRef,
2163
- onRequestClose: onHide,
2164
- enterDelay: 450
2165
- }, popoverProps, {
2166
- dataTestId: dataTestId,
2167
- enableBackdrop: false
2068
+ contentTextType = "p",
2069
+ children,
2070
+ dataTestId
2071
+ }) => jsx(StyledPopover, Object.assign({
2072
+ className: "tu-tooltip__container",
2073
+ placement: placement,
2074
+ activation: {
2075
+ hover: true
2076
+ },
2077
+ dataTestId: dataTestId !== null && dataTestId !== void 0 ? dataTestId : "",
2078
+ render: () => jsx(Content, Object.assign({
2079
+ "$mode": mode
2080
+ }, {
2081
+ children: jsx(Text$1, Object.assign({
2082
+ inverted: mode === "dark",
2083
+ type: contentTextType
2168
2084
  }, {
2169
- children: jsx(Content, Object.assign({
2170
- "$mode": mode
2171
- }, {
2172
- children: jsx(Text$1, Object.assign({
2173
- inverted: mode === "dark",
2174
- type: contentTextType
2175
- }, {
2176
- children: label
2177
- }))
2178
- }))
2179
- }))]
2180
- });
2181
- };
2085
+ children: label
2086
+ }))
2087
+ }))
2088
+ }, {
2089
+ children: children
2090
+ }));
2091
+
2182
2092
  const Flex$1 = tw.div`
2183
2093
  inline-flex
2184
2094
  `;
2185
- const Container$5 = twx(AnimatedPopover)`
2095
+ const StyledPopover = twx(Popover)`
2186
2096
  tu-tooltip__container
2187
2097
  `;
2188
2098
  const Content = tw.div`
@@ -2201,30 +2111,27 @@ const Content = tw.div`
2201
2111
  const Tip = ({
2202
2112
  children,
2203
2113
  iconProps,
2204
- tooltipProps,
2205
2114
  dataTestId,
2206
2115
  link,
2207
2116
  renderAs = "span",
2208
- className
2117
+ className,
2118
+ placement = "bottom",
2119
+ mode
2209
2120
  }) => {
2210
- var _a;
2211
-
2212
- const ifAnchorTag = () => {
2213
- return renderAs === "a";
2214
- };
2215
-
2121
+ const ifAnchorTag = renderAs === "a";
2216
2122
  return jsx(TipContainer, Object.assign({
2217
2123
  "data-testid": dataTestId,
2218
2124
  "$as": renderAs,
2219
- href: ifAnchorTag() ? link : undefined,
2220
- target: ifAnchorTag() ? "_blank" : undefined,
2125
+ href: ifAnchorTag ? link : undefined,
2126
+ target: ifAnchorTag ? "_blank" : undefined,
2221
2127
  className: className
2222
2128
  }, {
2223
2129
  children: jsx(Tooltip, Object.assign({
2224
2130
  label: children,
2225
- dataTestId: `${dataTestId}-tooltip`
2226
- }, tooltipProps, {
2227
- className: `${(_a = tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.className) !== null && _a !== void 0 ? _a : ""} tu-tip-tooltip`
2131
+ dataTestId: `${dataTestId}-tooltip`,
2132
+ mode: mode,
2133
+ className: "tu-tip-tooltip",
2134
+ placement: placement
2228
2135
  }, {
2229
2136
  children: jsx(Icon$1, Object.assign({
2230
2137
  name: "QuestionMarkCircleIcon",
@@ -2391,23 +2298,27 @@ const useLocale = language => {
2391
2298
  * @returns {JSX.Element} DayPicker component
2392
2299
  */
2393
2300
 
2394
- const DayPicker = _a => {
2395
- var {
2396
- onDaySelect,
2397
- disabledDays,
2398
- selectedDays,
2399
- language
2400
- } = _a,
2401
- rest = __rest(_a, ["onDaySelect", "disabledDays", "selectedDays", "language"]);
2402
-
2301
+ const DayPicker = ({
2302
+ onDaySelect,
2303
+ disabledDays,
2304
+ selectedDays,
2305
+ language,
2306
+ className,
2307
+ dataTestId,
2308
+ max
2309
+ }) => {
2403
2310
  const locale = useLocale(language);
2404
- return jsx(DayPicker$1, Object.assign({
2311
+ return jsx(DayPicker$1, {
2405
2312
  onDayClick: onDaySelect,
2406
2313
  selected: selectedDays,
2407
2314
  locale: locale,
2408
2315
  disabled: disabledDays,
2409
- className: "custom-day-picker"
2410
- }, rest));
2316
+ className: `custom-day-picker ${className !== null && className !== void 0 ? className : ""}`,
2317
+ max: max,
2318
+ footer: jsx("div", {
2319
+ "data-testid": dataTestId
2320
+ })
2321
+ });
2411
2322
  };
2412
2323
 
2413
2324
  /**
@@ -2420,29 +2331,27 @@ const DayPicker = _a => {
2420
2331
  const DayPickerPopover = ({
2421
2332
  disabledDays,
2422
2333
  className,
2334
+ dataTestId,
2423
2335
  selectedDay,
2424
2336
  onDaySelect,
2425
2337
  color = "secondary",
2426
- placement = "bottom",
2338
+ placement,
2427
2339
  size = "small",
2428
2340
  buttonContent,
2429
2341
  language
2430
2342
  }) => {
2431
- const target = useRef(null);
2432
- const popover = useRef(null);
2433
- const {
2434
- popoverRef,
2435
- targetRef,
2436
- onShow,
2437
- onHide,
2438
- popoverProps
2439
- } = usePopover({
2440
- targetRef: target,
2441
- popoverRef: popover,
2442
- placement: placement
2443
- });
2444
- return jsxs(Fragment$1, {
2445
- children: [jsx(Button, Object.assign({
2343
+ return jsx(Popover, Object.assign({
2344
+ placement: placement,
2345
+ render: () => jsx(PopoverList, {
2346
+ children: jsx(DayPicker, {
2347
+ disabledDays: disabledDays,
2348
+ onDaySelect: onDaySelect,
2349
+ selectedDays: selectedDay,
2350
+ language: language
2351
+ })
2352
+ })
2353
+ }, {
2354
+ children: jsx(Button, Object.assign({
2446
2355
  color: color,
2447
2356
  size: size,
2448
2357
  className: className,
@@ -2450,29 +2359,11 @@ const DayPickerPopover = ({
2450
2359
  name: "CalendarIcon",
2451
2360
  size: "small"
2452
2361
  }),
2453
- ref: targetRef,
2454
- onClick: onShow
2362
+ dataTestId: dataTestId !== null && dataTestId !== void 0 ? dataTestId : "show-day-picker"
2455
2363
  }, {
2456
2364
  children: buttonContent
2457
- })), jsx(AnimatedPopover, Object.assign({
2458
- ref: popoverRef,
2459
- onRequestClose: () => {
2460
- var _a;
2461
-
2462
- onHide();
2463
- (_a = targetRef === null || targetRef === void 0 ? void 0 : targetRef.current) === null || _a === void 0 ? void 0 : _a.blur();
2464
- }
2465
- }, popoverProps, {
2466
- children: jsx(PopoverList, {
2467
- children: jsx(DayPicker, {
2468
- disabledDays: disabledDays,
2469
- onDaySelect: onDaySelect,
2470
- selectedDays: selectedDay,
2471
- language: language
2472
- })
2473
- })
2474
- }))]
2475
- });
2365
+ }))
2366
+ }));
2476
2367
  };
2477
2368
 
2478
2369
  /**
@@ -2488,6 +2379,7 @@ const DayRangePicker = ({
2488
2379
  disabledDays,
2489
2380
  dataTestId,
2490
2381
  language,
2382
+ className,
2491
2383
  max
2492
2384
  }) => {
2493
2385
  const locale = useLocale(language);
@@ -2505,20 +2397,19 @@ const DayRangePicker = ({
2505
2397
  });
2506
2398
  }
2507
2399
  }, [onRangeSelect]);
2508
- return jsx("div", Object.assign({
2509
- "data-testid": dataTestId
2510
- }, {
2511
- children: jsx(DayPicker$1, {
2512
- mode: "range",
2513
- onSelect: onSelect,
2514
- selected: selectedDays,
2515
- defaultMonth: selectedDays && selectedDays.from,
2516
- locale: locale,
2517
- disabled: disabledDays,
2518
- className: "custom-day-picker range-picker",
2519
- max: max
2400
+ return jsx(DayPicker$1, {
2401
+ mode: "range",
2402
+ onSelect: onSelect,
2403
+ selected: selectedDays,
2404
+ defaultMonth: selectedDays && selectedDays.from,
2405
+ locale: locale,
2406
+ disabled: disabledDays,
2407
+ className: `custom-day-picker range-picker ${className !== null && className !== void 0 ? className : ""}`,
2408
+ max: max,
2409
+ footer: jsx("div", {
2410
+ "data-testid": dataTestId
2520
2411
  })
2521
- }));
2412
+ });
2522
2413
  };
2523
2414
 
2524
2415
  /**
@@ -5542,4 +5433,4 @@ const Layout = tw.div`
5542
5433
  tu-layout-TwoColumnLayout
5543
5434
  `;
5544
5435
 
5545
- export { ActionButton, Alert, AnimatedPopover, Badge, BaseInput, Button, Card, CardBody, CardFooter, CardHeader, Chart, Checkbox, Collapse, CopyableText, CreatableSelect, DateField, DateInput, DayPicker, DayPickerPopover, DayRangePicker, DensityContainer, 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, MultiSelectMenuItem, NumberField, NumberInput, PageHeader, Pagination, PopoverLifecycle, PopoverList, PopoverListItem, PopoverTitle, Prompt, ROLE_CARD, RadioGroup, RadioItem, SectionHeader, Select, SelectPrefix, SingleSelectMenuItem, SkeletonLines, Spacer, Spinner, StarButton, Tag, Text$1 as Text, TextArea, TextAreaField, TextField, TextInput, Timeline, TimelineElement, Tip, TitleNavContentLayout, Toggle, Tooltip, TwoColumnLayout, ValueBar, docs, getOrderedOptions, getValueBarColorByValue, isMultiValue, useContainerProps, useCustomComponents, useDebounce, useLocalStorage, useModal, usePopover, usePrompt, useTimeout };
5436
+ export { ActionButton, Alert, Badge, BaseInput, Button, Card, CardBody, CardFooter, CardHeader, Chart, Checkbox, Collapse, CopyableText, CreatableSelect, DateField, DateInput, DayPicker, DayPickerPopover, DayRangePicker, DensityContainer, 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, MultiSelectMenuItem, NumberField, NumberInput, PageHeader, Pagination, Popover, PopoverList, PopoverListItem, PopoverTitle, Prompt, ROLE_CARD, RadioGroup, RadioItem, SectionHeader, Select, SelectPrefix, SingleSelectMenuItem, SkeletonLines, Spacer, Spinner, StarButton, Tag, Text$1 as Text, TextArea, TextAreaField, TextField, TextInput, Timeline, TimelineElement, Tip, TitleNavContentLayout, Toggle, Tooltip, TwoColumnLayout, ValueBar, docs, getOrderedOptions, getValueBarColorByValue, isMultiValue, useContainerProps, useCustomComponents, useDebounce, useLocalStorage, useModal, usePrompt, useTimeout };
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "0.0.185",
3
+ "version": "0.0.186",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "dependencies": {
7
- "@trackunit/css-core": "0.0.60",
7
+ "@trackunit/css-core": "0.0.61",
8
8
  "@trackunit/tailwind-styled-components": "0.0.48",
9
9
  "react": "17.0.2",
10
10
  "@trackunit/ui-design-tokens": "0.0.49",
@@ -16,9 +16,8 @@
16
16
  "react-day-picker": "^8.3.0",
17
17
  "@trackunit/ui-icons": "0.0.52",
18
18
  "react-useportal": "1.0.17",
19
- "@react-spring/web": "9.5.4",
19
+ "@floating-ui/react-dom-interactions": "^0.10.1",
20
20
  "react-router-dom": "6.4.1",
21
- "@popperjs/core": "^2.11.6",
22
21
  "react-helmet": "^6.1.0",
23
22
  "react-select": "^5.4.0",
24
23
  "jest-canvas-mock": "^2.4.0"
@@ -1,43 +0,0 @@
1
- import * as React from "react";
2
- import { CommonProps } from "../../common/CommonProps";
3
- import { PopoverLifecycle } from "./usePopover";
4
- export interface AnimatedPopoverProps extends CommonProps {
5
- /**
6
- * Controls the lifecycle of the popover.
7
- */
8
- lifecycle: PopoverLifecycle;
9
- /**
10
- * Sets the popover to closing state.
11
- */
12
- onRequestClose: () => void;
13
- /**
14
- * Sets the popover to closed state.
15
- */
16
- onClosed: () => void;
17
- /**
18
- * Child nodes
19
- */
20
- children: React.ReactNode;
21
- /**
22
- * The delay(in seconds) for triggering the popover state when entering it.
23
- */
24
- enterDelay?: number;
25
- /**
26
- * The delay(in seconds) for triggering the popover state when exiting it.
27
- */
28
- exitDelay?: number;
29
- /** An element to use as the portal root for the popover component */
30
- bindTo?: HTMLElement;
31
- /**
32
- * Whether the popover should have a backdrop or not.
33
- */
34
- enableBackdrop?: boolean;
35
- }
36
- /**
37
- * The Popover component is used to display some content on top of another.
38
- * Use a popover to expose a small amount of information or functionality.
39
- *
40
- * @param {AnimatedPopoverProps} props - The props for the Card component
41
- * @returns {JSX.Element} Popover component
42
- */
43
- export declare const AnimatedPopover: React.ForwardRefExoticComponent<AnimatedPopoverProps & React.RefAttributes<HTMLDivElement>>;
@@ -1,42 +0,0 @@
1
- import { Placement } from "@popperjs/core";
2
- import * as React from "react";
3
- export declare type PopoverPlacement = Placement;
4
- export interface UsePopoverProps<T, Y> {
5
- /**
6
- * Reference to the target component.
7
- */
8
- targetRef: React.RefObject<T>;
9
- /**
10
- * Reference to the popover component.
11
- */
12
- popoverRef: React.RefObject<Y>;
13
- /**
14
- * Placement of the popover.
15
- */
16
- placement?: PopoverPlacement;
17
- /**
18
- * The positional offset of the popover from the target component.
19
- */
20
- offset?: [number, number];
21
- }
22
- export declare enum PopoverLifecycle {
23
- closed = "closed",
24
- open = "open",
25
- closing = "closing"
26
- }
27
- /**
28
- * The usePopover Hook.
29
- *
30
- * @param {UsePopoverProps} props - The props for the usePopover hook
31
- * @returns {UsePopoverProps} - UsePopoverProps
32
- */
33
- export declare const usePopover: <T extends HTMLElement, Y extends HTMLElement>({ targetRef, popoverRef, placement, offset, }: UsePopoverProps<T, Y>) => {
34
- targetRef: React.RefObject<T>;
35
- popoverRef: React.RefObject<Y>;
36
- onShow: () => void;
37
- onHide: () => void;
38
- popoverProps: {
39
- lifecycle: PopoverLifecycle;
40
- onClosed: () => void;
41
- };
42
- };