armtek-uikit-react 1.0.44 → 1.0.45
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/assets/Tooltip.scss +2 -2
- package/lib/hooks/useEnhancedEffect.d.ts +10 -0
- package/lib/hooks/useEnhancedEffect.js +13 -0
- package/lib/hooks/useEventCallback.d.ts +7 -0
- package/lib/hooks/useEventCallback.js +21 -0
- package/lib/hooks/useLazyRef.d.ts +1 -0
- package/lib/hooks/useLazyRef.js +11 -0
- package/lib/hooks/useTimeout.d.ts +11 -0
- package/lib/hooks/useTimeout.js +35 -0
- package/package.json +1 -1
- package/ui/Button/Button.d.ts +1 -1
- package/ui/Button/Button.js +4 -1
- package/ui/ButtonIcon/ButtonIcon.js +1 -1
- package/ui/Form/Select/Select.js +0 -1
- package/ui/Popper/Popper.d.ts +9 -0
- package/ui/Popper/Popper.js +38 -0
- package/ui/Popper/index.d.ts +1 -0
- package/ui/Popper/index.js +1 -0
- package/ui/Tooltip/Tooltip.d.ts +1 -0
- package/ui/Tooltip/Tooltip.js +65 -14
package/assets/Tooltip.scss
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
position: relative;
|
|
6
6
|
}
|
|
7
7
|
.tooltip__item{
|
|
8
|
-
position: absolute;
|
|
8
|
+
//position: absolute;
|
|
9
9
|
padding: $size-step;
|
|
10
10
|
border-radius: $radius;
|
|
11
11
|
background: $color-gray-700;
|
|
@@ -14,5 +14,5 @@
|
|
|
14
14
|
font-size: 12px;
|
|
15
15
|
left: 50%;
|
|
16
16
|
bottom: 100%;
|
|
17
|
-
transform: translateX(-50%);
|
|
17
|
+
//transform: translateX(-50%);
|
|
18
18
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A version of `React.useLayoutEffect` that does not show a warning when server-side rendering.
|
|
4
|
+
* This is useful for effects that are only needed for client-side rendering but not for SSR.
|
|
5
|
+
*
|
|
6
|
+
* Before you use this hook, make sure to read https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85
|
|
7
|
+
* and confirm it doesn't apply to your use-case.
|
|
8
|
+
*/
|
|
9
|
+
declare const useEnhancedEffect: typeof React.useEffect;
|
|
10
|
+
export default useEnhancedEffect;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A version of `React.useLayoutEffect` that does not show a warning when server-side rendering.
|
|
7
|
+
* This is useful for effects that are only needed for client-side rendering but not for SSR.
|
|
8
|
+
*
|
|
9
|
+
* Before you use this hook, make sure to read https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85
|
|
10
|
+
* and confirm it doesn't apply to your use-case.
|
|
11
|
+
*/
|
|
12
|
+
const useEnhancedEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
|
|
13
|
+
export default useEnhancedEffect;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inspired by https://github.com/facebook/react/issues/14099#issuecomment-440013892
|
|
3
|
+
* See RFC in https://github.com/reactjs/rfcs/pull/220
|
|
4
|
+
*/
|
|
5
|
+
declare function useEventCallback<Fn extends (...args: any[]) => any = (...args: unknown[]) => unknown>(fn: Fn): Fn;
|
|
6
|
+
declare function useEventCallback<Args extends unknown[], Return>(fn: (...args: Args) => Return): (...args: Args) => Return;
|
|
7
|
+
export default useEventCallback;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import useEnhancedEffect from "./useEnhancedEffect";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Inspired by https://github.com/facebook/react/issues/14099#issuecomment-440013892
|
|
8
|
+
* See RFC in https://github.com/reactjs/rfcs/pull/220
|
|
9
|
+
*/
|
|
10
|
+
function useEventCallback<Fn extends (...args: any[]) => any = (...args: unknown[]) => unknown>(fn: Fn): Fn;
|
|
11
|
+
function useEventCallback<Args extends unknown[], Return>(fn: (...args: Args) => Return): (...args: Args) => Return;
|
|
12
|
+
function useEventCallback<Args extends unknown[], Return>(fn: (...args: Args) => Return): (...args: Args) => Return {
|
|
13
|
+
const ref = React.useRef(fn);
|
|
14
|
+
useEnhancedEffect(() => {
|
|
15
|
+
ref.current = fn;
|
|
16
|
+
});
|
|
17
|
+
return React.useRef((...args: Args) =>
|
|
18
|
+
// @ts-expect-error hide `this`
|
|
19
|
+
(0, ref.current!)(...args)).current;
|
|
20
|
+
}
|
|
21
|
+
export default useEventCallback;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useLazyRef<T, U>(init: (arg?: U) => T, initArg?: U): import("react").MutableRefObject<T>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useRef } from 'react';
|
|
4
|
+
const UNINITIALIZED = {};
|
|
5
|
+
export default function useLazyRef<T, U>(init: (arg?: U) => T, initArg?: U) {
|
|
6
|
+
const ref = useRef(((UNINITIALIZED as unknown) as T));
|
|
7
|
+
if (ref.current === UNINITIALIZED) {
|
|
8
|
+
ref.current = init(initArg);
|
|
9
|
+
}
|
|
10
|
+
return ref;
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class Timeout {
|
|
2
|
+
static create(): Timeout;
|
|
3
|
+
currentId: number;
|
|
4
|
+
/**
|
|
5
|
+
* Executes `fn` after `delay`, clearing any previously scheduled call.
|
|
6
|
+
*/
|
|
7
|
+
start(delay: number, fn: Function): void;
|
|
8
|
+
clear: () => void;
|
|
9
|
+
disposeEffect: () => () => void;
|
|
10
|
+
}
|
|
11
|
+
export default function useTimeout(): Timeout;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import useLazyRef from "./useLazyRef";
|
|
4
|
+
import { useEffect } from 'react';
|
|
5
|
+
export class Timeout {
|
|
6
|
+
static create() {
|
|
7
|
+
return new Timeout();
|
|
8
|
+
}
|
|
9
|
+
currentId: number = 0;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Executes `fn` after `delay`, clearing any previously scheduled call.
|
|
13
|
+
*/
|
|
14
|
+
start(delay: number, fn: Function) {
|
|
15
|
+
this.clear();
|
|
16
|
+
this.currentId = ((setTimeout(() => {
|
|
17
|
+
this.currentId = 0;
|
|
18
|
+
fn();
|
|
19
|
+
}, delay) as unknown) as number);
|
|
20
|
+
}
|
|
21
|
+
clear = () => {
|
|
22
|
+
if (this.currentId !== 0) {
|
|
23
|
+
clearTimeout(this.currentId);
|
|
24
|
+
this.currentId = 0;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
disposeEffect = () => {
|
|
28
|
+
return this.clear;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export default function useTimeout() {
|
|
32
|
+
const timeout = useLazyRef(Timeout.create).current;
|
|
33
|
+
useEffect(timeout.disposeEffect, []);
|
|
34
|
+
return timeout;
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"armtek-uikit-react","version":"1.0.
|
|
1
|
+
{"name":"armtek-uikit-react","version":"1.0.45","description":"Armtek UIKit for React","repository":{"type":"git","url":"ssh://git@gl.corp:10022/int/uikit/uikit_react.git"},"author":"","license":"ISC","dependencies":{"build":"^0.1.4","clsx":"^2.0.0","rc-slider":"^10.2.1","react":"*","react-datepicker":"^4.16.0","react-dom":"*"},"peerDependencies":{"react":"*","react-dom":"*"},"scripts":{"pub":"npm version patch && npm publish"}}
|
package/ui/Button/Button.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ type OwnProps<T extends ElementType = ElementType> = {
|
|
|
9
9
|
endAdornment?: string | ReactNode;
|
|
10
10
|
group?: 'inline' | 'column';
|
|
11
11
|
radius?: boolean;
|
|
12
|
-
|
|
12
|
+
asIcon?: boolean;
|
|
13
13
|
as?: T;
|
|
14
14
|
};
|
|
15
15
|
export type ButtonProps<T extends ElementType = ElementType<HTMLAttributes<HTMLButtonElement>>> = OwnProps<T> & Omit<ComponentPropsWithoutRef<T>, keyof OwnProps>;
|
package/ui/Button/Button.js
CHANGED
|
@@ -18,6 +18,7 @@ const Button = props => {
|
|
|
18
18
|
className,
|
|
19
19
|
group,
|
|
20
20
|
radius,
|
|
21
|
+
asIcon,
|
|
21
22
|
as,
|
|
22
23
|
...restProps
|
|
23
24
|
} = props;
|
|
@@ -34,7 +35,9 @@ const Button = props => {
|
|
|
34
35
|
className: clsx(css.button__adornment, css.button__adornment_start),
|
|
35
36
|
children: startAdornment
|
|
36
37
|
}), /*#__PURE__*/_jsx("div", {
|
|
37
|
-
className:
|
|
38
|
+
className: clsx({
|
|
39
|
+
[css.button__iconWrapper]: !!asIcon
|
|
40
|
+
}),
|
|
38
41
|
children: children
|
|
39
42
|
}), endAdornment && /*#__PURE__*/_jsx("div", {
|
|
40
43
|
className: clsx(css.button__adornment, css.button__adornment_end),
|
|
@@ -11,7 +11,7 @@ const ButtonIcon = props => {
|
|
|
11
11
|
return /*#__PURE__*/_jsx(_Fragment, {
|
|
12
12
|
children: /*#__PURE__*/_jsx(Button, {
|
|
13
13
|
...props,
|
|
14
|
-
|
|
14
|
+
asIcon: true,
|
|
15
15
|
className: clsx(css.button_icon, css['button_icon_' + props.size], props.className),
|
|
16
16
|
children: props.children
|
|
17
17
|
})
|
package/ui/Form/Select/Select.js
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { MutableRefObject, ReactNode } from 'react';
|
|
2
|
+
type PopperProps = {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
anchorEl: MutableRefObject<any>;
|
|
5
|
+
open?: boolean;
|
|
6
|
+
placement?: 'bottom-end' | 'bottom-start' | 'bottom' | 'left-end' | 'left-start' | 'left' | 'right-end' | 'right-start' | 'right' | 'top-end' | 'top-start' | 'top';
|
|
7
|
+
};
|
|
8
|
+
export declare const Popper: (props: PopperProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
import { createPortal } from 'react-dom';
|
|
5
|
+
import { createPopper } from '@popperjs/core';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
8
|
+
export const Popper = props => {
|
|
9
|
+
const {
|
|
10
|
+
anchorEl,
|
|
11
|
+
children,
|
|
12
|
+
placement,
|
|
13
|
+
open
|
|
14
|
+
} = props;
|
|
15
|
+
const tooltipRef = useRef(null);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
const popper = createPopper(anchorEl.current, tooltipRef.current, {
|
|
18
|
+
placement: placement,
|
|
19
|
+
modifiers: [{
|
|
20
|
+
name: 'offset',
|
|
21
|
+
options: {
|
|
22
|
+
offset: [0, 5]
|
|
23
|
+
}
|
|
24
|
+
}]
|
|
25
|
+
});
|
|
26
|
+
return () => {
|
|
27
|
+
popper.destroy();
|
|
28
|
+
// handlePopperRefRef.current!(null)
|
|
29
|
+
};
|
|
30
|
+
}, [open, placement]);
|
|
31
|
+
if (!open) return null;
|
|
32
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
|
33
|
+
children: /*#__PURE__*/createPortal( /*#__PURE__*/_jsx("div", {
|
|
34
|
+
ref: tooltipRef,
|
|
35
|
+
children: children
|
|
36
|
+
}), document.body)
|
|
37
|
+
});
|
|
38
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Popper } from './Popper';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Popper } from "./Popper";
|
package/ui/Tooltip/Tooltip.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ReactNode } from 'react';
|
|
|
2
2
|
export type TooltipProps = {
|
|
3
3
|
text: string;
|
|
4
4
|
children: ReactNode;
|
|
5
|
+
placement?: 'bottom-end' | 'bottom-start' | 'bottom' | 'left-end' | 'left-start' | 'left' | 'right-end' | 'right-start' | 'right' | 'top-end' | 'top-start' | 'top';
|
|
5
6
|
};
|
|
6
7
|
declare function Tooltip(props: TooltipProps): import("react/jsx-runtime").JSX.Element;
|
|
7
8
|
export default Tooltip;
|
package/ui/Tooltip/Tooltip.js
CHANGED
|
@@ -1,32 +1,83 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { useState } from 'react';
|
|
3
|
+
import { cloneElement, isValidElement, useRef, useState } from 'react';
|
|
4
|
+
import useTimeout from "../../lib/hooks/useTimeout";
|
|
5
|
+
import useEventCallback from "../../lib/hooks/useEventCallback";
|
|
6
|
+
import { Popper } from "../Popper";
|
|
4
7
|
import css from "./Tooltip.module.scss";
|
|
5
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
9
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
10
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
11
|
const CssClasses = ['tooltip', 'tooltip__item'];
|
|
9
12
|
|
|
10
13
|
// const css = getCssPrefix(CssClasses)
|
|
11
14
|
|
|
15
|
+
function composeEventHandler(handler, eventHandler) {
|
|
16
|
+
return event => {
|
|
17
|
+
if (eventHandler) {
|
|
18
|
+
eventHandler(event);
|
|
19
|
+
}
|
|
20
|
+
handler(event);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
let cursorPosition = {
|
|
24
|
+
x: 0,
|
|
25
|
+
y: 0
|
|
26
|
+
};
|
|
12
27
|
function Tooltip(props) {
|
|
13
28
|
let {
|
|
14
29
|
text,
|
|
15
|
-
children
|
|
30
|
+
children: childrenProp,
|
|
31
|
+
placement
|
|
16
32
|
} = props;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
33
|
+
const children = /*#__PURE__*/isValidElement(childrenProp) ? childrenProp : /*#__PURE__*/_jsx("span", {
|
|
34
|
+
children: childrenProp
|
|
35
|
+
});
|
|
36
|
+
const [openState, setOpenState] = useState(false);
|
|
37
|
+
const anchorEl = useRef();
|
|
38
|
+
const closeTimer = useTimeout();
|
|
39
|
+
const enterTimer = useTimeout();
|
|
40
|
+
const leaveTimer = useTimeout();
|
|
41
|
+
const handleOpen = event => {
|
|
42
|
+
setOpenState(true);
|
|
43
|
+
};
|
|
44
|
+
const handleClose = useEventCallback(event => {
|
|
45
|
+
setOpenState(false);
|
|
46
|
+
|
|
47
|
+
// closeTimer.start(theme.transitions.duration.shortest, () => {
|
|
48
|
+
// ignoreNonTouchEvents.current = false;
|
|
49
|
+
// });
|
|
50
|
+
});
|
|
51
|
+
const handleEnter = event => {
|
|
52
|
+
enterTimer.clear();
|
|
53
|
+
leaveTimer.clear();
|
|
54
|
+
handleOpen(event);
|
|
55
|
+
};
|
|
56
|
+
const handleLeave = event => {
|
|
57
|
+
setOpenState(false);
|
|
58
|
+
enterTimer.clear();
|
|
59
|
+
leaveTimer.start(0, () => {
|
|
60
|
+
handleClose(event);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
const handleMouseOver = handleEnter;
|
|
64
|
+
const handleMouseLeave = handleLeave;
|
|
65
|
+
const childrenProps = {
|
|
66
|
+
...children.props
|
|
67
|
+
};
|
|
68
|
+
childrenProps.onMouseOver = composeEventHandler(handleMouseOver, childrenProps.onMouseOver);
|
|
69
|
+
childrenProps.onMouseLeave = composeEventHandler(handleMouseLeave, childrenProps.onMouseLeave);
|
|
70
|
+
childrenProps.ref = anchorEl;
|
|
71
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
72
|
+
children: [/*#__PURE__*/cloneElement(children, childrenProps), /*#__PURE__*/_jsx(Popper, {
|
|
73
|
+
placement: placement,
|
|
74
|
+
open: openState,
|
|
75
|
+
anchorEl: anchorEl,
|
|
76
|
+
children: /*#__PURE__*/_jsx("span", {
|
|
26
77
|
className: css.tooltip__item,
|
|
27
78
|
children: text
|
|
28
|
-
})
|
|
29
|
-
})
|
|
79
|
+
})
|
|
80
|
+
})]
|
|
30
81
|
});
|
|
31
82
|
}
|
|
32
83
|
export default Tooltip;
|