@rio-cloud/rio-uikit 1.2.1 → 1.3.0

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.
Files changed (127) hide show
  1. package/.DS_Store +0 -0
  2. package/DateRangePicker.d.ts +6 -7
  3. package/DateRangePicker.js +7 -3
  4. package/README.md +3 -3
  5. package/components/actionBarItem/ActionBarItem.js +5 -1
  6. package/components/actionBarItem/ActionBarItemIcon.d.ts +6 -8
  7. package/components/actionBarItem/ActionBarItemIcon.js +4 -4
  8. package/components/actionBarItem/ActionBarOverlay.d.ts +3 -2
  9. package/components/actionBarItem/ActionBarOverlay.js +7 -7
  10. package/components/applicationLayout/ApplicationLayout.js +1 -0
  11. package/components/applicationLayout/ApplicationLayoutHeader.js +0 -4
  12. package/components/assetTree/TreeOptions.js +1 -1
  13. package/components/assetTree/treeUtils.js +1 -1
  14. package/components/calendarStripe/CalendarStripe.d.ts +8 -0
  15. package/components/calendarStripe/CalendarStripe.js +7 -4
  16. package/components/dataTabs/DataTab.js +2 -1
  17. package/components/dialog/SimpleDialog.d.ts +2 -2
  18. package/components/dialog/SplitDialog.d.ts +6 -0
  19. package/components/expander/ExpanderList.js +2 -1
  20. package/components/listMenu/ListMenu.js +1 -1
  21. package/components/map/components/features/settings/MapSettingsTile.js +1 -1
  22. package/components/map/components/features/settings/items/MapSettingsDropdownHeader.d.ts +4 -1
  23. package/components/map/components/features/settings/items/MapSettingsDropdownHeader.js +1 -0
  24. package/components/onboarding/OnboardingTip.d.ts +2 -2
  25. package/components/onboarding/OnboardingTip.js +2 -0
  26. package/components/overlay/OverlayTrigger.d.ts +92 -3
  27. package/components/overlay/OverlayTrigger.js +140 -8
  28. package/components/popover/Popover.d.ts +27 -9
  29. package/components/popover/Popover.js +18 -5
  30. package/components/slider/RangeSlider.d.ts +7 -0
  31. package/components/slider/RangeSlider.js +10 -4
  32. package/components/slider/Slider.d.ts +7 -0
  33. package/components/slider/Slider.js +5 -3
  34. package/components/states/CustomState.js +4 -5
  35. package/components/switch/Switch.d.ts +7 -0
  36. package/components/switch/Switch.js +4 -3
  37. package/components/tooltip/SimpleTooltip.d.ts +2 -2
  38. package/components/tooltip/Tooltip.d.ts +2 -2
  39. package/components/tooltip/Tooltip.js +6 -2
  40. package/hooks/useClickOutside.d.ts +1 -0
  41. package/hooks/useClickOutside.js +9 -3
  42. package/hooks/useElapsedTime.d.ts +26 -0
  43. package/hooks/useElapsedTime.js +36 -0
  44. package/hooks/useEvent.d.ts +1 -1
  45. package/hooks/useTimeout.d.ts +5 -0
  46. package/hooks/useTimeout.js +39 -1
  47. package/hooks/useUncontrollable.d.ts +13 -0
  48. package/hooks/useUncontrollable.js +41 -0
  49. package/lib/es/DateRangePicker.d.ts +6 -7
  50. package/lib/es/DateRangePicker.js +5 -1
  51. package/lib/es/components/actionBarItem/ActionBarItem.js +5 -1
  52. package/lib/es/components/actionBarItem/ActionBarItemIcon.d.ts +6 -8
  53. package/lib/es/components/actionBarItem/ActionBarItemIcon.js +4 -4
  54. package/lib/es/components/actionBarItem/ActionBarOverlay.d.ts +3 -2
  55. package/lib/es/components/actionBarItem/ActionBarOverlay.js +7 -7
  56. package/lib/es/components/applicationLayout/ApplicationLayout.js +1 -0
  57. package/lib/es/components/applicationLayout/ApplicationLayoutHeader.js +0 -4
  58. package/lib/es/components/assetTree/TreeOptions.js +1 -1
  59. package/lib/es/components/assetTree/treeUtils.js +1 -1
  60. package/lib/es/components/calendarStripe/CalendarStripe.d.ts +8 -0
  61. package/lib/es/components/calendarStripe/CalendarStripe.js +7 -4
  62. package/lib/es/components/dataTabs/DataTab.js +2 -1
  63. package/lib/es/components/dialog/SimpleDialog.d.ts +2 -2
  64. package/lib/es/components/dialog/SplitDialog.d.ts +6 -0
  65. package/lib/es/components/expander/ExpanderList.js +2 -1
  66. package/lib/es/components/listMenu/ListMenu.js +1 -1
  67. package/lib/es/components/map/components/features/settings/MapSettingsTile.js +1 -1
  68. package/lib/es/components/map/components/features/settings/items/MapSettingsDropdownHeader.d.ts +4 -1
  69. package/lib/es/components/map/components/features/settings/items/MapSettingsDropdownHeader.js +1 -0
  70. package/lib/es/components/onboarding/OnboardingTip.d.ts +2 -2
  71. package/lib/es/components/onboarding/OnboardingTip.js +2 -0
  72. package/lib/es/components/overlay/OverlayTrigger.d.ts +92 -3
  73. package/lib/es/components/overlay/OverlayTrigger.js +139 -7
  74. package/lib/es/components/popover/Popover.d.ts +27 -9
  75. package/lib/es/components/popover/Popover.js +20 -6
  76. package/lib/es/components/slider/RangeSlider.d.ts +7 -0
  77. package/lib/es/components/slider/RangeSlider.js +10 -4
  78. package/lib/es/components/slider/Slider.d.ts +7 -0
  79. package/lib/es/components/slider/Slider.js +5 -3
  80. package/lib/es/components/states/CustomState.js +4 -5
  81. package/lib/es/components/switch/Switch.d.ts +7 -0
  82. package/lib/es/components/switch/Switch.js +4 -3
  83. package/lib/es/components/tooltip/SimpleTooltip.d.ts +2 -2
  84. package/lib/es/components/tooltip/Tooltip.d.ts +2 -2
  85. package/lib/es/components/tooltip/Tooltip.js +5 -1
  86. package/lib/es/hooks/useClickOutside.d.ts +1 -0
  87. package/lib/es/hooks/useClickOutside.js +11 -3
  88. package/lib/es/hooks/useElapsedTime.d.ts +26 -0
  89. package/lib/es/hooks/useElapsedTime.js +38 -0
  90. package/lib/es/hooks/useEvent.d.ts +1 -1
  91. package/lib/es/hooks/useTimeout.d.ts +5 -0
  92. package/lib/es/hooks/useTimeout.js +40 -0
  93. package/lib/es/hooks/useUncontrollable.d.ts +13 -0
  94. package/lib/es/hooks/useUncontrollable.js +46 -0
  95. package/lib/es/styles/variables/colors/colors.json +3 -3
  96. package/lib/es/useElapsedTime.d.ts +2 -0
  97. package/lib/es/useElapsedTime.js +7 -0
  98. package/lib/es/utils/currentColors.d.ts +3 -0
  99. package/lib/es/utils/currentColors.js +14 -0
  100. package/lib/es/utils/hasUtilityClass.d.ts +30 -0
  101. package/lib/es/utils/hasUtilityClass.js +71 -0
  102. package/lib/es/utils/init/initCSS.js +12 -0
  103. package/lib/es/utils/mergeRefs.d.ts +1 -1
  104. package/lib/es/values/Trigger.d.ts +1 -2
  105. package/lib/es/version.json +1 -1
  106. package/package.json +18 -12
  107. package/styles/variables/colors/colors.json +3 -3
  108. package/useElapsedTime.d.ts +2 -0
  109. package/useElapsedTime.js +2 -0
  110. package/utils/currentColors.d.ts +3 -0
  111. package/utils/currentColors.js +10 -0
  112. package/utils/hasUtilityClass.d.ts +30 -0
  113. package/utils/hasUtilityClass.js +40 -0
  114. package/utils/init/initCSS.js +12 -0
  115. package/utils/mergeRefs.d.ts +1 -1
  116. package/values/Trigger.d.ts +1 -2
  117. package/version.json +1 -1
  118. package/components/.DS_Store +0 -0
  119. package/components/feedback/Feedback.d.ts +0 -2
  120. package/components/feedback/Feedback.js +0 -5
  121. package/components/map/.DS_Store +0 -0
  122. package/components/map/components/.DS_Store +0 -0
  123. package/lib/.DS_Store +0 -0
  124. package/lib/es/.DS_Store +0 -0
  125. package/lib/es/components/.DS_Store +0 -0
  126. package/lib/es/components/feedback/Feedback.d.ts +0 -2
  127. package/lib/es/components/feedback/Feedback.js +0 -7
@@ -3,16 +3,148 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  // @ts-ignore-next-line importsNotUsedAsValues
6
- require("react");
7
- const OverlayTrigger_1 = tslib_1.__importDefault(require("react-bootstrap/OverlayTrigger"));
8
- const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
6
+ const react_1 = tslib_1.__importStar(require("react"));
7
+ const react_dom_1 = tslib_1.__importDefault(require("react-dom"));
8
+ const react_popper_1 = require("react-popper");
9
9
  const Placement_1 = require("../../values/Placement");
10
10
  const Trigger_1 = require("../../values/Trigger");
11
+ const mergeRefs_1 = tslib_1.__importDefault(require("../../utils/mergeRefs"));
12
+ const useClickOutside_1 = require("../../hooks/useClickOutside");
13
+ const useTimeout_1 = require("../../hooks/useTimeout");
14
+ const useUncontrollable_1 = require("../../hooks/useUncontrollable");
11
15
  const OverlayTrigger = (props) => {
12
- const usedProps = Object.assign({ rootClose: true }, (0, omit_1.default)(props, 'children'));
13
- const { children } = props;
14
- // @ts-ignore
15
- return (0, jsx_runtime_1.jsx)(OverlayTrigger_1.default, Object.assign({}, usedProps, { children: children }));
16
+ var _a, _b;
17
+ const { show: propsShow, defaultShow = false, enablePortal = true, trigger = Trigger_1.TRIGGER.HOVER, delay, overlay, placement = 'top', popperConfig, onToggle = () => { }, rootClose = true, children, } = props;
18
+ // Use a hook to handle controlled props that work in pairs like in this case the "show" and "onToggle"
19
+ // props. It returns a setter function that automatically triggers the callback.
20
+ const [show, setShow] = (0, useUncontrollable_1.useUncontrolledProp)(propsShow, defaultShow, onToggle);
21
+ const hoverStateRef = (0, react_1.useRef)('');
22
+ const timeout = (0, useTimeout_1.useChainedTimeout)();
23
+ const { onFocus, onBlur, onClick } = typeof children !== 'function' ? react_1.default.Children.only(children).props : {};
24
+ // Simple implementation of mouseEnter and mouseLeave.
25
+ // React's built version is broken: https://github.com/facebook/react/issues/4251
26
+ // for cases when the trigger is disabled and mouseOut/Over can cause flicker
27
+ // moving from one child element to another.
28
+ const handleMouseOverOut = (handler, args, relatedNative) => {
29
+ const [event] = args;
30
+ const target = event.currentTarget;
31
+ const related = event.relatedTarget;
32
+ if ((!related || related !== target) && !target.contains(related)) {
33
+ handler(...args);
34
+ }
35
+ };
36
+ const handleShow = () => {
37
+ timeout.clear();
38
+ hoverStateRef.current = 'show';
39
+ if (typeof delay === 'number' || !(delay === null || delay === void 0 ? void 0 : delay.show)) {
40
+ setShow(true);
41
+ return;
42
+ }
43
+ timeout.set(() => {
44
+ if (hoverStateRef.current === 'show') {
45
+ setShow(true);
46
+ }
47
+ }, typeof delay === 'number' ? delay : delay === null || delay === void 0 ? void 0 : delay.show);
48
+ };
49
+ const handleHide = () => {
50
+ timeout.clear();
51
+ hoverStateRef.current = 'hide';
52
+ if (typeof delay === 'number' || !(delay === null || delay === void 0 ? void 0 : delay.hide)) {
53
+ setShow(false);
54
+ return;
55
+ }
56
+ timeout.set(() => {
57
+ if (hoverStateRef.current === 'hide') {
58
+ setShow(false);
59
+ }
60
+ }, typeof delay === 'number' ? delay : delay === null || delay === void 0 ? void 0 : delay.hide);
61
+ };
62
+ const handleFocus = (0, react_1.useCallback)((...args) => {
63
+ handleShow();
64
+ onFocus === null || onFocus === void 0 ? void 0 : onFocus(...args);
65
+ }, [handleShow, onFocus]);
66
+ const handleBlur = (0, react_1.useCallback)((...args) => {
67
+ handleHide();
68
+ onBlur === null || onBlur === void 0 ? void 0 : onBlur(...args);
69
+ }, [handleHide, onBlur]);
70
+ const handleClick = (0, react_1.useCallback)((...args) => {
71
+ setShow(!show);
72
+ onClick === null || onClick === void 0 ? void 0 : onClick(...args);
73
+ }, [onClick, setShow, show]);
74
+ const handleMouseOver = (0, react_1.useCallback)((...args) => {
75
+ handleMouseOverOut(handleShow, args, 'fromElement');
76
+ }, [handleShow]);
77
+ const handleMouseOut = (0, react_1.useCallback)((...args) => {
78
+ handleMouseOverOut(handleHide, args, 'toElement');
79
+ }, [handleHide]);
80
+ const [triggerNode, setTriggerNode] = (0, react_1.useState)(null);
81
+ const [popperElement, setPopperElement] = (0, react_1.useState)(null);
82
+ const [arrowElement, setArrowElement] = (0, react_1.useState)(null);
83
+ const [arrowPlacement, setArrowPlacement] = (0, react_1.useState)(placement);
84
+ const handleClickOutside = (0, react_1.useCallback)((event) => {
85
+ const isToggleTarget = triggerNode === null || triggerNode === void 0 ? void 0 : triggerNode.contains(event.target);
86
+ const isOverlayTarget = popperElement === null || popperElement === void 0 ? void 0 : popperElement.contains(event.target);
87
+ // Check if the click occurred outside the trigger element. Clicking on the trigger
88
+ // itself is handled by the onClick handler
89
+ if (show && rootClose && !isToggleTarget && !isOverlayTarget) {
90
+ handleHide();
91
+ }
92
+ }, [triggerNode, popperElement, rootClose, handleHide]);
93
+ (0, useClickOutside_1.useClickOutsideWithRef)(triggerNode, handleClickOutside);
94
+ const triggerProps = {
95
+ ref: (0, mergeRefs_1.default)([children.ref, setTriggerNode]),
96
+ };
97
+ if (trigger === 'click') {
98
+ triggerProps.onClick = handleClick;
99
+ }
100
+ else if (trigger === 'focus') {
101
+ triggerProps.onFocus = handleFocus;
102
+ triggerProps.onBlur = handleBlur;
103
+ }
104
+ else if (trigger === 'hover') {
105
+ triggerProps.onMouseOver = handleMouseOver;
106
+ triggerProps.onMouseOut = handleMouseOut;
107
+ }
108
+ const defaultPopperConfig = {
109
+ placement,
110
+ modifiers: [
111
+ {
112
+ name: 'arrow',
113
+ options: {
114
+ element: arrowElement,
115
+ },
116
+ },
117
+ {
118
+ name: 'flip',
119
+ options: {
120
+ fallbackPlacements: ['right', 'left', 'top'],
121
+ },
122
+ },
123
+ ],
124
+ };
125
+ if (popperConfig) {
126
+ popperConfig.placement = placement;
127
+ // if it has an arrow modifier, inject the arrow element
128
+ const updatedModifiers = [];
129
+ (_a = popperConfig.modifiers) === null || _a === void 0 ? void 0 : _a.forEach((mod) => {
130
+ if (mod.name !== 'arrow') {
131
+ return updatedModifiers.push(mod);
132
+ }
133
+ return updatedModifiers.push(Object.assign(Object.assign({}, mod), { options: Object.assign(Object.assign({}, mod.options), { element: arrowElement }) }));
134
+ });
135
+ popperConfig.modifiers = updatedModifiers;
136
+ }
137
+ const popper = (0, react_popper_1.usePopper)(triggerNode, popperElement, popperConfig || defaultPopperConfig);
138
+ // In case the overlay causes an overflow and the "flip" modifier
139
+ // changes the overlays placement, we nee to update the arrow placement as well
140
+ (0, react_1.useEffect)(() => {
141
+ if (popper.state) {
142
+ // Adjust arrow styles based on placement if necessary
143
+ setArrowPlacement(popper.state.placement);
144
+ }
145
+ }, [(_b = popper.state) === null || _b === void 0 ? void 0 : _b.placement]);
146
+ const overlayElement = react_1.default.cloneElement(overlay, Object.assign(Object.assign({}, popper.attributes.popper), { ref: setPopperElement, placement: arrowPlacement, style: Object.assign({}, popper.styles.popper), arrowProps: Object.assign(Object.assign({}, popper.attributes.arrow), { style: popper.styles.arrow, ref: setArrowElement }) }));
147
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [show && (enablePortal ? react_dom_1.default.createPortal(overlayElement, document.body) : overlayElement), react_1.default.cloneElement(children, triggerProps)] }));
16
148
  };
17
149
  OverlayTrigger.TRIGGER_CLICK = Trigger_1.TRIGGER.CLICK;
18
150
  OverlayTrigger.TRIGGER_HOVER = Trigger_1.TRIGGER.HOVER;
@@ -1,6 +1,12 @@
1
- import React, { type ReactNode } from 'react';
2
- import type { RefComponent } from '../../utils/RefComponent';
3
- export type PopoverProps = {
1
+ import React, { type ForwardRefExoticComponent, type RefAttributes, type PropsWithChildren, type ReactNode, type ComponentProps } from 'react';
2
+ export declare const PLACEMENT_MAP: {
3
+ readonly AUTO: "auto";
4
+ readonly TOP: "top";
5
+ readonly RIGHT: "right";
6
+ readonly BOTTOM: "bottom";
7
+ readonly LEFT: "left";
8
+ };
9
+ export type PopoverProps = Omit<ComponentProps<'div'>, 'title'> & {
4
10
  /**
5
11
  * HTML ID attribute, necessary for accessibility.
6
12
  */
@@ -18,6 +24,10 @@ export type PopoverProps = {
18
24
  * - `left`
19
25
  */
20
26
  placement?: 'auto' | 'top' | 'right' | 'bottom' | 'left';
27
+ /**
28
+ * Additional props assigned to the arrow element. Internally used.
29
+ */
30
+ arrowProps?: Record<string, unknown>;
21
31
  /**
22
32
  * Any element to be rendered as the title of the Popover.
23
33
  *
@@ -32,12 +42,20 @@ export type PopoverProps = {
32
42
  * Additional classes to be set on the `Popover.Content` element.
33
43
  */
34
44
  contentClassName?: string;
45
+ /**
46
+ * Additional class names for the wrapper element.
47
+ */
48
+ className?: string;
35
49
  };
36
- declare const Popover: RefComponent<React.PropsWithChildren<PopoverProps>, HTMLDivElement> & {
37
- readonly AUTO: "auto";
38
- readonly TOP: "top";
39
- readonly RIGHT: "right";
40
- readonly BOTTOM: "bottom";
41
- readonly LEFT: "left";
50
+ declare const PopoverTitle: ({ className, children }: React.PropsWithChildren<{
51
+ className?: string | undefined;
52
+ }>) => import("react/jsx-runtime").JSX.Element;
53
+ declare const PopoverContent: ({ className, children }: React.PropsWithChildren<{
54
+ className?: string | undefined;
55
+ }>) => import("react/jsx-runtime").JSX.Element;
56
+ type PopoverType = ForwardRefExoticComponent<PropsWithChildren<PopoverProps> & RefAttributes<HTMLDivElement>> & {
57
+ Title: typeof PopoverTitle;
58
+ Content: typeof PopoverContent;
42
59
  };
60
+ declare const Popover: PopoverType;
43
61
  export default Popover;
@@ -1,20 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PLACEMENT_MAP = void 0;
3
4
  const tslib_1 = require("tslib");
4
5
  const jsx_runtime_1 = require("react/jsx-runtime");
5
- const react_1 = require("react");
6
- const Popover_1 = tslib_1.__importDefault(require("react-bootstrap/Popover"));
6
+ const react_1 = tslib_1.__importStar(require("react"));
7
+ require("framer-motion");
7
8
  const Placement_1 = require("../../values/Placement");
8
- const PLACEMENT_MAP = {
9
+ exports.PLACEMENT_MAP = {
9
10
  AUTO: Placement_1.PLACEMENT.AUTO,
10
11
  TOP: Placement_1.PLACEMENT.TOP,
11
12
  RIGHT: Placement_1.PLACEMENT.RIGHT,
12
13
  BOTTOM: Placement_1.PLACEMENT.BOTTOM,
13
14
  LEFT: Placement_1.PLACEMENT.LEFT,
14
15
  };
16
+ const PopoverTitle = ({ className = '', children }) => ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: `popover-header popover-title ${className}` }, { children: children })));
17
+ const PopoverContent = ({ className = '', children }) => ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: `popover-content popover-body ${className}` }, { children: children })));
18
+ const isPopoverTitleOrContent = (element) => {
19
+ return (0, react_1.isValidElement)(element) && (element.type === PopoverTitle || element.type === PopoverContent);
20
+ };
15
21
  const Popover = (0, react_1.forwardRef)((props, ref) => {
16
- const { title, titleClassName = '', contentClassName = '', children } = props, remainingProps = tslib_1.__rest(props, ["title", "titleClassName", "contentClassName", "children"]);
17
- return ((0, jsx_runtime_1.jsxs)(Popover_1.default, Object.assign({ ref: ref }, remainingProps, { children: [title && (0, jsx_runtime_1.jsx)(Popover_1.default.Title, Object.assign({ className: `popover-title ${titleClassName}` }, { children: title })), children && ((0, jsx_runtime_1.jsx)(Popover_1.default.Content, Object.assign({ className: `popover-content ${contentClassName}` }, { children: children })))] })));
22
+ const { placement = 'bottom', arrowProps, title, titleClassName = '', contentClassName = '', children, className = '' } = props, remainingProps = tslib_1.__rest(props, ["placement", "arrowProps", "title", "titleClassName", "contentClassName", "children", "className"]);
23
+ const hasTitle = !!title;
24
+ const hasCustomContent = react_1.default.Children.toArray(children).some(isPopoverTitleOrContent);
25
+ // Mount the component but don't show it yet via CSS.
26
+ // After it is mounted, we set the visibility class to use CSS animation
27
+ const [isMounted, setIsMounted] = (0, react_1.useState)(false);
28
+ (0, react_1.useEffect)(() => setIsMounted(true), []);
29
+ return ((0, jsx_runtime_1.jsxs)("div", Object.assign({}, remainingProps, { role: 'tooltip', "x-placement": placement, ref: ref, className: `popover fade ${isMounted ? 'show' : ''} ${className}` }, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ className: 'arrow' }, arrowProps)), hasTitle && (0, jsx_runtime_1.jsx)(PopoverTitle, Object.assign({ className: titleClassName }, { children: title })), hasCustomContent ? children : (0, jsx_runtime_1.jsx)(PopoverContent, Object.assign({ className: contentClassName }, { children: children }))] })));
18
30
  });
19
- Object.assign(Popover, PLACEMENT_MAP);
31
+ Popover.Title = PopoverTitle;
32
+ Popover.Content = PopoverContent;
33
+ Object.assign(Popover, exports.PLACEMENT_MAP);
20
34
  exports.default = Popover;
@@ -1,4 +1,5 @@
1
1
  import React, { type HTMLAttributes } from 'react';
2
+ import { type CurrentColor } from '../../utils/currentColors';
2
3
  export type RangeSliderProps = {
3
4
  /**
4
5
  * The current left value of the selected range.
@@ -36,6 +37,12 @@ export type RangeSliderProps = {
36
37
  * @default 1
37
38
  */
38
39
  step?: number;
40
+ /**
41
+ * Defines the color of the slider.
42
+ *
43
+ * @default 'primary'
44
+ */
45
+ color?: CurrentColor;
39
46
  /**
40
47
  * Disables all pointer events.
41
48
  *
@@ -5,13 +5,14 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
6
  const classnames_1 = tslib_1.__importDefault(require("classnames"));
7
7
  const noop_1 = tslib_1.__importDefault(require("lodash/noop"));
8
+ const currentColors_1 = require("../../utils/currentColors");
8
9
  const getRangeValues = (valueLeft, valueRight) => {
9
10
  const finalLeftValue = valueRight <= valueLeft ? valueRight : valueLeft;
10
11
  const finalRightValue = valueLeft >= valueRight ? valueLeft : valueRight;
11
12
  return [finalLeftValue, finalRightValue];
12
13
  };
13
14
  const RangeSlider = (props) => {
14
- const { minValue = 0, maxValue = Number.MAX_VALUE, valueLabels = false, valueLabelUnit, step = 1, leftValue, rightValue, className, disabled = false, onChange = noop_1.default, onDragEnd = noop_1.default } = props, remainingProps = tslib_1.__rest(props, ["minValue", "maxValue", "valueLabels", "valueLabelUnit", "step", "leftValue", "rightValue", "className", "disabled", "onChange", "onDragEnd"]);
15
+ const { minValue = 0, maxValue = Number.MAX_VALUE, valueLabels = false, valueLabelUnit, step = 1, color = 'primary', leftValue, rightValue, className, disabled = false, onChange = noop_1.default, onDragEnd = noop_1.default } = props, remainingProps = tslib_1.__rest(props, ["minValue", "maxValue", "valueLabels", "valueLabelUnit", "step", "color", "leftValue", "rightValue", "className", "disabled", "onChange", "onDragEnd"]);
15
16
  const [activeLeft, setActiveLeft] = (0, react_1.useState)(false);
16
17
  const [activeRight, setActiveRight] = (0, react_1.useState)(false);
17
18
  const [valueLeft, setValueLeft] = (0, react_1.useState)(leftValue ? leftValue : minValue);
@@ -34,8 +35,12 @@ const RangeSlider = (props) => {
34
35
  const [newLeftValue, newRightValue] = getRangeValues(newValueLeft, newValueRight);
35
36
  onChange(newLeftValue, newRightValue);
36
37
  };
37
- const handleChangeValueLeft = (event) => changeValues({ valueLeft: parseInt(event.target.value, 10) });
38
- const handleChangeValueRight = (event) => changeValues({ valueRight: parseInt(event.target.value, 10) });
38
+ const handleChangeValueLeft = (event) => {
39
+ changeValues({ valueLeft: Number.parseInt(event.target.value, 10) });
40
+ };
41
+ const handleChangeValueRight = (event) => {
42
+ changeValues({ valueRight: Number.parseInt(event.target.value, 10) });
43
+ };
39
44
  const onMouseDownLeft = () => {
40
45
  setIsChangingLeft(true);
41
46
  setIsChangingRight(false);
@@ -100,6 +105,7 @@ const RangeSlider = (props) => {
100
105
  const trackWidth = (100 * (finalRightValue - finalLeftValue)) / (maxValue - minValue);
101
106
  const trackLeft = (100 * (finalLeftValue - minValue)) / (maxValue - minValue);
102
107
  const wrapperClassNames = (0, classnames_1.default)('range-slider', disabled && 'disabled', valueLabels && 'show-value-labels', className && className);
103
- return ((0, jsx_runtime_1.jsxs)("div", Object.assign({}, remainingProps, { className: wrapperClassNames }, { children: [(0, jsx_runtime_1.jsx)("div", { className: 'range-whole-track' }), (0, jsx_runtime_1.jsx)("div", Object.assign({ className: 'range-track', style: { width: `${trackWidth}%`, left: `${trackLeft}%` } }, { children: valueLabels && ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: 'user-select-none' }, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ className: 'range-value' }, { children: valueLabelUnit ? `${finalLeftValue} ${valueLabelUnit}` : finalLeftValue })), (0, jsx_runtime_1.jsx)("div", Object.assign({ className: 'range-value' }, { children: valueLabelUnit ? `${finalRightValue} ${valueLabelUnit}` : finalRightValue }))] }))) })), (0, jsx_runtime_1.jsx)("input", { className: `${isChangingLeft ? 'changing' : ''}`, style: { zIndex: activeLeft ? '6' : '5' }, value: valueLeft, min: minValue, max: maxValue, step: step, type: 'range', onChange: handleChangeValueLeft, onMouseDown: onMouseDownLeft, onMouseMove: onMouseMoveLeft, onMouseUp: onMouseUpLeft }), (0, jsx_runtime_1.jsx)("input", { className: `${isChangingRight ? 'changing' : ''}`, style: { zIndex: activeRight ? '6' : '5' }, value: valueRight, min: minValue, max: maxValue, step: step, type: 'range', onChange: handleChangeValueRight, onMouseDown: onMouseDownRight, onMouseMove: onMouseMoveRight, onMouseUp: onMouseUpRight })] })));
108
+ const sliderBackgroundColor = (0, currentColors_1.getCurrentBackgroundColor)(color);
109
+ return ((0, jsx_runtime_1.jsxs)("div", Object.assign({}, remainingProps, { className: wrapperClassNames, style: { color: sliderBackgroundColor } }, { children: [(0, jsx_runtime_1.jsx)("div", { className: 'range-whole-track' }), (0, jsx_runtime_1.jsx)("div", Object.assign({ className: 'range-track', style: { width: `${trackWidth}%`, left: `${trackLeft}%` } }, { children: valueLabels && ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: 'user-select-none' }, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ className: 'range-value' }, { children: (0, jsx_runtime_1.jsx)("span", { children: valueLabelUnit ? `${finalLeftValue} ${valueLabelUnit}` : finalLeftValue }) })), (0, jsx_runtime_1.jsx)("div", Object.assign({ className: 'range-value' }, { children: (0, jsx_runtime_1.jsx)("span", { children: valueLabelUnit ? `${finalRightValue} ${valueLabelUnit}` : finalRightValue }) }))] }))) })), (0, jsx_runtime_1.jsx)("input", { className: `${isChangingLeft ? 'changing' : ''}`, style: { zIndex: activeLeft ? '6' : '5' }, value: valueLeft, min: minValue, max: maxValue, step: step, type: 'range', onChange: handleChangeValueLeft, onMouseDown: onMouseDownLeft, onMouseMove: onMouseMoveLeft, onMouseUp: onMouseUpLeft }), (0, jsx_runtime_1.jsx)("input", { className: `${isChangingRight ? 'changing' : ''}`, style: { zIndex: activeRight ? '6' : '5' }, value: valueRight, min: minValue, max: maxValue, step: step, type: 'range', onChange: handleChangeValueRight, onMouseDown: onMouseDownRight, onMouseMove: onMouseMoveRight, onMouseUp: onMouseUpRight })] })));
104
110
  };
105
111
  exports.default = RangeSlider;
@@ -1,4 +1,5 @@
1
1
  import React, { type HTMLAttributes } from 'react';
2
+ import { type CurrentColor } from '../../utils/currentColors';
2
3
  export type SliderProps = {
3
4
  /**
4
5
  * The current value.
@@ -46,6 +47,12 @@ export type SliderProps = {
46
47
  * @default 1
47
48
  */
48
49
  step?: number;
50
+ /**
51
+ * Defines the color of the slider.
52
+ *
53
+ * @default 'primary'
54
+ */
55
+ color?: CurrentColor;
49
56
  /**
50
57
  * Disables all pointer events.
51
58
  *
@@ -5,8 +5,9 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
6
  const classnames_1 = tslib_1.__importDefault(require("classnames"));
7
7
  const noop_1 = tslib_1.__importDefault(require("lodash/noop"));
8
+ const currentColors_1 = require("../../utils/currentColors");
8
9
  const Slider = (props) => {
9
- const { value = 0, minValue = 0, maxValue = Number.MAX_VALUE, valueLabels = false, valueLabelUnit, largeValueLabels = false, hideValueBar = false, step = 1, onChange = noop_1.default, onDragEnd = noop_1.default, className, disabled = false } = props, remainingProps = tslib_1.__rest(props, ["value", "minValue", "maxValue", "valueLabels", "valueLabelUnit", "largeValueLabels", "hideValueBar", "step", "onChange", "onDragEnd", "className", "disabled"]);
10
+ const { value = 0, minValue = 0, maxValue = Number.MAX_VALUE, valueLabels = false, valueLabelUnit, largeValueLabels = false, hideValueBar = false, color = 'primary', step = 1, onChange = noop_1.default, onDragEnd = noop_1.default, className, disabled = false } = props, remainingProps = tslib_1.__rest(props, ["value", "minValue", "maxValue", "valueLabels", "valueLabelUnit", "largeValueLabels", "hideValueBar", "color", "step", "onChange", "onDragEnd", "className", "disabled"]);
10
11
  const [currentValue, setCurrentValue] = (0, react_1.useState)(value ? value : minValue);
11
12
  const [isChanging, setIsChanging] = (0, react_1.useState)(false);
12
13
  (0, react_1.useEffect)(() => {
@@ -15,7 +16,7 @@ const Slider = (props) => {
15
16
  }
16
17
  }, [value, minValue, maxValue]);
17
18
  const handleChange = (event) => {
18
- const newValue = parseInt(event.target.value, 10);
19
+ const newValue = Number.parseInt(event.target.value, 10);
19
20
  setCurrentValue(newValue);
20
21
  setIsChanging(true);
21
22
  onChange(newValue);
@@ -29,6 +30,7 @@ const Slider = (props) => {
29
30
  };
30
31
  const wrapperClassNames = (0, classnames_1.default)('range-slider', disabled && 'disabled', valueLabels && 'show-value-labels', hideValueBar && 'hide-value-bar', largeValueLabels && 'large-value-labels', className && className);
31
32
  const trackWidth = (100 * (currentValue - minValue)) / (maxValue - minValue);
32
- return ((0, jsx_runtime_1.jsxs)("div", Object.assign({}, remainingProps, { className: wrapperClassNames }, { children: [(0, jsx_runtime_1.jsx)("div", { className: 'range-whole-track' }), (0, jsx_runtime_1.jsx)("div", Object.assign({ className: 'range-track', style: { width: `${trackWidth}%` } }, { children: valueLabels && ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: 'range-value' }, { children: (0, jsx_runtime_1.jsx)("div", { children: valueLabelUnit ? `${currentValue} ${valueLabelUnit}` : currentValue }) }))) })), (0, jsx_runtime_1.jsx)("input", { className: `${isChanging ? 'changing' : ''}`, value: currentValue, min: minValue, max: maxValue, step: step, type: 'range', onChange: handleChange, onMouseDown: onMouseDown, onMouseUp: onMouseUp })] })));
33
+ const sliderBackgroundColor = (0, currentColors_1.getCurrentBackgroundColor)(color);
34
+ return ((0, jsx_runtime_1.jsxs)("div", Object.assign({}, remainingProps, { className: wrapperClassNames, style: { color: sliderBackgroundColor } }, { children: [(0, jsx_runtime_1.jsx)("div", { className: 'range-whole-track' }), (0, jsx_runtime_1.jsx)("div", Object.assign({ className: 'range-track', style: { width: `${trackWidth}%` } }, { children: valueLabels && ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: 'range-value' }, { children: (0, jsx_runtime_1.jsx)("span", { children: valueLabelUnit ? `${currentValue} ${valueLabelUnit}` : currentValue }) }))) })), (0, jsx_runtime_1.jsx)("input", { className: `${isChanging ? 'changing' : ''}`, value: currentValue, min: minValue, max: maxValue, step: step, type: 'range', onChange: handleChange, onMouseDown: onMouseDown, onMouseUp: onMouseUp })] })));
33
35
  };
34
36
  exports.default = Slider;
@@ -8,6 +8,7 @@ const classnames_1 = tslib_1.__importDefault(require("classnames"));
8
8
  const isEmpty_1 = tslib_1.__importDefault(require("lodash/fp/isEmpty"));
9
9
  const StateButton_1 = tslib_1.__importDefault(require("./StateButton"));
10
10
  const StateIcon_1 = tslib_1.__importDefault(require("./StateIcon"));
11
+ const hasUtilityClass_1 = require("../../utils/hasUtilityClass");
11
12
  const justify = {
12
13
  left: 'justify-content-start',
13
14
  center: 'justify-content-center',
@@ -28,11 +29,9 @@ const renderButtons = (buttons) => {
28
29
  }) }))] }));
29
30
  };
30
31
  const CustomState = (props) => {
31
- const { icon, icons = [], image, headline, message, buttons = [], alignment = 'center', fullWidth = false, condensed = false, outerClassName, innerClassName, children } = props, remainingProps = tslib_1.__rest(props, ["icon", "icons", "image", "headline", "message", "buttons", "alignment", "fullWidth", "condensed", "outerClassName", "innerClassName", "children"]);
32
- const hasCustomInnerPadding = innerClassName === null || innerClassName === void 0 ? void 0 : innerClassName.includes('padding');
33
- const hasCustomOuterPadding = outerClassName === null || outerClassName === void 0 ? void 0 : outerClassName.includes('padding');
34
- const wrapperClasses = (0, classnames_1.default)('margin-0', 'width-100pct', !fullWidth && 'max-width-600', 'panel-default', 'panel', !hasCustomOuterPadding && condensed ? 'padding-10' : 'padding-15', outerClassName && outerClassName);
35
- const innerClassNames = (0, classnames_1.default)('display-flex', 'flex-column', 'align-items-center', 'text-center', !hasCustomInnerPadding && condensed ? 'padding-15' : 'padding-25', innerClassName && innerClassName);
32
+ const { icon, icons = [], image, headline, message, buttons = [], alignment = 'center', fullWidth = false, condensed = false, outerClassName = '', innerClassName = '', children } = props, remainingProps = tslib_1.__rest(props, ["icon", "icons", "image", "headline", "message", "buttons", "alignment", "fullWidth", "condensed", "outerClassName", "innerClassName", "children"]);
33
+ const wrapperClasses = (0, classnames_1.default)('margin-0', 'width-100pct', !fullWidth && 'max-width-600', 'panel-default', 'panel', !(0, hasUtilityClass_1.hasPaddingClass)(outerClassName) && condensed ? 'padding-10' : 'padding-15', outerClassName);
34
+ const innerClassNames = (0, classnames_1.default)('display-flex', 'flex-column', 'align-items-center', 'text-center', !(0, hasUtilityClass_1.hasPaddingClass)(innerClassName) && condensed ? 'padding-15' : 'padding-25', innerClassName);
36
35
  const iconClasses = (0, classnames_1.default)(condensed ? 'text-size-16 margin-bottom-10' : 'text-size-h2 margin-bottom-20');
37
36
  const iconsClasses = (0, classnames_1.default)(condensed ? 'text-size-16 margin-bottom-10' : 'text-size-h2 margin-bottom-20', 'display-flex', 'align-items-center', 'max-width-100pct');
38
37
  const headlineClassNames = (0, classnames_1.default)(condensed ? 'text-size-h4' : 'text-size-h3 text-size-h2-xl', 'line-height-125rel', 'text-color-dark', 'text-medium', 'width-500', 'max-width-100pct', 'text-wrap-balance');
@@ -1,4 +1,5 @@
1
1
  import { type PropsWithChildren } from 'react';
2
+ import { type CurrentColor } from '../../utils/currentColors';
2
3
  export type SwitchProps = {
3
4
  /**
4
5
  * Optional key that is used as key and as the id on the internal input.
@@ -14,6 +15,12 @@ export type SwitchProps = {
14
15
  * @default false
15
16
  */
16
17
  checked?: boolean;
18
+ /**
19
+ * Defines the color of the switch.
20
+ *
21
+ * @default 'primary'
22
+ */
23
+ color?: CurrentColor;
17
24
  /**
18
25
  * The min-width of the switch.
19
26
  */
@@ -6,8 +6,9 @@ const jsx_runtime_1 = require("react/jsx-runtime");
6
6
  require("react");
7
7
  const classnames_1 = tslib_1.__importDefault(require("classnames"));
8
8
  const noop_1 = tslib_1.__importDefault(require("lodash/fp/noop"));
9
+ const currentColors_1 = require("../../utils/currentColors");
9
10
  const Switch = (props) => {
10
- const { keyName, checked = false, enabledText, minWidth = 40, disabled = false, disabledText, children, labelPosition = !!children ? 'right' : undefined, onChange = noop_1.default } = props, remainingProps = tslib_1.__rest(props, ["keyName", "checked", "enabledText", "minWidth", "disabled", "disabledText", "children", "labelPosition", "onChange"]);
11
+ const { keyName, checked = false, enabledText, minWidth = 40, disabled = false, color = 'primary', disabledText, children, labelPosition = !!children ? 'right' : undefined, onChange = noop_1.default } = props, remainingProps = tslib_1.__rest(props, ["keyName", "checked", "enabledText", "minWidth", "disabled", "color", "disabledText", "children", "labelPosition", "onChange"]);
11
12
  const handleChange = (event) => {
12
13
  onChange(event.target.checked);
13
14
  };
@@ -17,8 +18,8 @@ const Switch = (props) => {
17
18
  const switchContentClasses = (0, classnames_1.default)('switch-content'
18
19
  // !hasMultipleText && !hasSingleText && 'width-40'
19
20
  );
20
- const switchContentStyles = { minWidth };
21
- return ((0, jsx_runtime_1.jsx)("div", Object.assign({}, remainingProps, { className: 'uikit-switch' }, { children: (0, jsx_runtime_1.jsxs)("label", Object.assign({ className: switchLabelClasses }, { children: [(0, jsx_runtime_1.jsx)("input", { onChange: handleChange, checked: checked, type: 'checkbox', id: keyName, className: 'switch-input', disabled: disabled }, keyName), (0, jsx_runtime_1.jsxs)("div", Object.assign({ className: switchContentClasses, style: switchContentStyles }, { children: [hasMultipleText ? ((0, jsx_runtime_1.jsx)("div", { className: 'switch-text', "data-on": enabledText, "data-off": disabledText })) : (hasSingleText && (0, jsx_runtime_1.jsx)("div", { className: 'switch-text', "data-on": enabledText, "data-off": enabledText })), (0, jsx_runtime_1.jsx)("div", { className: 'switch-handle' })] })), children && children] })) })));
21
+ const switchBackgroundColor = (0, currentColors_1.getCurrentBackgroundColor)(color);
22
+ return ((0, jsx_runtime_1.jsx)("div", Object.assign({}, remainingProps, { className: 'uikit-switch' }, { children: (0, jsx_runtime_1.jsxs)("label", Object.assign({ className: switchLabelClasses }, { children: [(0, jsx_runtime_1.jsx)("input", { onChange: handleChange, checked: checked, type: 'checkbox', id: keyName, className: 'switch-input', disabled: disabled }, keyName), (0, jsx_runtime_1.jsxs)("div", Object.assign({ className: switchContentClasses, style: { color: switchBackgroundColor, minWidth } }, { children: [hasMultipleText ? ((0, jsx_runtime_1.jsx)("div", { className: 'switch-text', "data-on": enabledText, "data-off": disabledText })) : (hasSingleText && (0, jsx_runtime_1.jsx)("div", { className: 'switch-text', "data-on": enabledText, "data-off": enabledText })), (0, jsx_runtime_1.jsx)("div", { className: 'switch-handle' })] })), children && children] })) })));
22
23
  };
23
24
  Switch.LABEL_POSITION_LEFT = 'left';
24
25
  Switch.LABEL_POSITION_RIGHT = 'right';
@@ -1,6 +1,6 @@
1
1
  import React, { type MutableRefObject, type PropsWithChildren } from 'react';
2
2
  import { type TooltipProps } from './Tooltip';
3
- import { type Trigger } from '../../values/Trigger';
3
+ import { type TriggerType } from '../../values/Trigger';
4
4
  export type delayProp = {
5
5
  show: number;
6
6
  hide: number;
@@ -15,7 +15,7 @@ export type SimpleTooltipProps = Omit<TooltipProps, 'content'> & {
15
15
  * Possible values are: `hover`, `click`, `focus`
16
16
  * @default 'hover'
17
17
  */
18
- trigger?: Trigger;
18
+ trigger?: TriggerType;
19
19
  /**
20
20
  * The react ref object assigned to the target of the tooltip.
21
21
  */
@@ -47,9 +47,9 @@ export type TooltipProps = {
47
47
  */
48
48
  allowOnTouch?: boolean;
49
49
  /**
50
- * Additional props assigned to the arrow element.
50
+ * Additional props assigned to the arrow element. Internally used.
51
51
  */
52
- arrowProps?: {};
52
+ arrowProps?: Record<string, unknown>;
53
53
  /**
54
54
  * Additional style properties assigned to the wrapper element.
55
55
  */
@@ -19,13 +19,17 @@ const TEXT_ALIGNMENT_MAP = {
19
19
  };
20
20
  const Tooltip = (0, react_1.forwardRef)((props, ref) => {
21
21
  const _a = (0, omit_1.default)(['popper', 'positionLeft', 'positionTop'], props), { allowOnTouch = false, arrowProps, children, className = '', innerClassName = '', placement = 'bottom', style, textAlignment = 'center', tooltipStyle = 'default', width = 'auto' } = _a, remainingProps = tslib_1.__rest(_a, ["allowOnTouch", "arrowProps", "children", "className", "innerClassName", "placement", "style", "textAlignment", "tooltipStyle", "width"]);
22
+ // Mount the component but don't show it yet via CSS.
23
+ // After it is mounted, we set the visibility class to use CSS animation
24
+ const [isMounted, setIsMounted] = (0, react_1.useState)(false);
25
+ (0, react_1.useEffect)(() => setIsMounted(true), []);
22
26
  if (!(0, deviceUtils_1.isDesktop)() && !allowOnTouch) {
23
27
  // Workaround: we have to return a DOM node as otherwise the
24
28
  // react-transition library would throw an error on mobile
25
29
  // when triggering a browser reflow and accessing the node directly.
26
30
  return (0, jsx_runtime_1.jsx)("span", { className: 'display-none' });
27
31
  }
28
- const wrapperClasses = (0, classnames_1.default)('tooltip', tooltipStyle && `tooltip-${tooltipStyle}`, placement, className);
32
+ const wrapperClasses = (0, classnames_1.default)('tooltip', tooltipStyle && `tooltip-${tooltipStyle}`, placement, 'fade', isMounted && 'show', className);
29
33
  const innerClasses = (0, classnames_1.default)('tooltip-inner', textAlignment && `text-${textAlignment}`, width && `width-${width}`, innerClassName && innerClassName);
30
34
  /* eslint-disable react/no-unknown-property */
31
35
  return ((0, jsx_runtime_1.jsxs)("div", Object.assign({}, remainingProps, { role: 'tooltip', "x-placement": placement, ref: ref, className: wrapperClasses, style: Object.assign({}, style), "data-offset": 20 }, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ className: 'tooltip-arrow' }, arrowProps)), (0, jsx_runtime_1.jsx)("div", Object.assign({ className: innerClasses }, { children: children }))] })));
@@ -9,4 +9,5 @@ export type EventListenerType = keyof DocumentEventMap;
9
9
  * @returns A mutable ref object representing the target element.
10
10
  */
11
11
  declare const useClickOutside: <T extends HTMLElement = any>(callback: (event: MouseEvent | TouchEvent) => void, events?: EventListenerType[]) => import("react").MutableRefObject<T>;
12
+ export declare const useClickOutsideWithRef: <T extends HTMLElement = any>(ref: React.MutableRefObject<HTMLElement | null> | HTMLElement | null, callback: (event: MouseEvent | TouchEvent) => void, events?: EventListenerType[]) => void;
12
13
  export default useClickOutside;
@@ -3,6 +3,7 @@
3
3
  // eslint-disable-next-line max-len
4
4
  // Inspired from https://github.com/mantinedev/mantine/blob/master/src/mantine-hooks/src/use-click-outside/use-click-outside.ts
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useClickOutsideWithRef = void 0;
6
7
  const react_1 = require("react");
7
8
  /**
8
9
  * Custom hook to detect clicks outside a specified element.
@@ -14,10 +15,17 @@ const react_1 = require("react");
14
15
  */
15
16
  const useClickOutside = (callback, events = ['mousedown', 'touchstart']) => {
16
17
  const targetRef = (0, react_1.useRef)(null);
18
+ (0, exports.useClickOutsideWithRef)(targetRef, callback, events);
19
+ return targetRef;
20
+ };
21
+ // Internal use for now - extend it later to be used outside
22
+ const useClickOutsideWithRef = (ref, callback, events = ['mousedown', 'touchstart']) => {
17
23
  (0, react_1.useEffect)(() => {
24
+ // In case the ref is actually a state and will be set via the state setter function
25
+ const element = ref && 'current' in ref ? ref.current : ref;
18
26
  // Event listener function to check if the click is outside the target element
19
27
  const listener = (event) => {
20
- if (targetRef.current && !targetRef.current.contains(event.target)) {
28
+ if (element && !element.contains(event.target)) {
21
29
  callback(event);
22
30
  }
23
31
  };
@@ -27,7 +35,7 @@ const useClickOutside = (callback, events = ['mousedown', 'touchstart']) => {
27
35
  return () => {
28
36
  events.forEach(eventType => document.removeEventListener(eventType, listener));
29
37
  };
30
- }, [targetRef, callback, events]);
31
- return targetRef;
38
+ }, [ref, callback, events]);
32
39
  };
40
+ exports.useClickOutsideWithRef = useClickOutsideWithRef;
33
41
  exports.default = useClickOutside;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Custom React hook to measure the elapsed time since a specified start time or the component's mount time.
3
+ *
4
+ * @param {number} [startTime=Date.now()] - The start time in milliseconds from which to measure the elapsed time.
5
+ * @returns {Function} A function that returns the elapsed time in milliseconds since the specified start time
6
+ * or the component's mount time.
7
+ *
8
+ * @example
9
+ * import useElapsedTime from '@rio-cloud/rio-uikit/useElapsedTime';
10
+ * import Button from '@rio-cloud/rio-uikit/Button';
11
+ *
12
+ * const MyComponent = () => {
13
+ * const getElapsedTime = useElapsedTime();
14
+ *
15
+ * const handleClick = () => {
16
+ * const elapsedTime = getElapsedTime();
17
+ * console.log(`Elapsed time: ${elapsedTime} ms`);
18
+ * };
19
+ *
20
+ * return (
21
+ * <Button onClick={handleClick}>Get elapsed time</Button>
22
+ * );
23
+ * };
24
+ */
25
+ declare const useElapsedTime: (startTime?: number) => (() => number);
26
+ export default useElapsedTime;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const react_1 = require("react");
4
+ /**
5
+ * Custom React hook to measure the elapsed time since a specified start time or the component's mount time.
6
+ *
7
+ * @param {number} [startTime=Date.now()] - The start time in milliseconds from which to measure the elapsed time.
8
+ * @returns {Function} A function that returns the elapsed time in milliseconds since the specified start time
9
+ * or the component's mount time.
10
+ *
11
+ * @example
12
+ * import useElapsedTime from '@rio-cloud/rio-uikit/useElapsedTime';
13
+ * import Button from '@rio-cloud/rio-uikit/Button';
14
+ *
15
+ * const MyComponent = () => {
16
+ * const getElapsedTime = useElapsedTime();
17
+ *
18
+ * const handleClick = () => {
19
+ * const elapsedTime = getElapsedTime();
20
+ * console.log(`Elapsed time: ${elapsedTime} ms`);
21
+ * };
22
+ *
23
+ * return (
24
+ * <Button onClick={handleClick}>Get elapsed time</Button>
25
+ * );
26
+ * };
27
+ */
28
+ const useElapsedTime = (startTime = Date.now()) => {
29
+ const startTimeRef = (0, react_1.useRef)(startTime);
30
+ const getElapsedTime = () => {
31
+ return Date.now() - startTimeRef.current;
32
+ };
33
+ (0, react_1.useEffect)(() => {
34
+ startTimeRef.current = startTime;
35
+ }, [startTime]);
36
+ return getElapsedTime;
37
+ };
38
+ exports.default = useElapsedTime;
@@ -14,5 +14,5 @@ type WindowEventMapWithFullscreen = {
14
14
  * @param options - Optional. An object that specifies characteristics about the event listener.
15
15
  * @param target - Optional. The target element to which to attach the event listener.
16
16
  */
17
- declare const useEvent: <K extends keyof WindowEventMap, W extends keyof WindowEventMapWithFullscreen, T extends HTMLElement = HTMLDivElement>(eventType: K | W, callback: EventListener, options?: boolean | AddEventListenerOptions, target?: Window | Document | T | null) => void;
17
+ declare const useEvent: <K extends keyof WindowEventMap, W extends keyof WindowEventMapWithFullscreen, T extends HTMLElement = HTMLDivElement>(eventType: K | W, callback: EventListener, options?: boolean | AddEventListenerOptions, target?: Document | Window | T | null) => void;
18
18
  export default useEvent;
@@ -8,4 +8,9 @@ import React from 'react';
8
8
  * @returns A mutable ref object to manage the timeout ID.
9
9
  */
10
10
  declare const useTimeout: (callback: () => void, delay: number | null) => React.MutableRefObject<number | null>;
11
+ export declare const useChainedTimeout: () => {
12
+ set: (fn: () => void, delayMs?: number) => void;
13
+ clear: () => void;
14
+ handleRef: React.MutableRefObject<any>;
15
+ };
11
16
  export default useTimeout;