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