@etsoo/react 1.2.71 → 1.2.72
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/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/mu/TooltipClick.d.ts +14 -0
- package/lib/mu/TooltipClick.js +29 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/mu/TooltipClick.tsx +62 -0
package/lib/index.d.ts
CHANGED
|
@@ -57,6 +57,7 @@ export * from './mu/TabBox';
|
|
|
57
57
|
export * from './mu/TableEx';
|
|
58
58
|
export * from './mu/TextFieldEx';
|
|
59
59
|
export * from './mu/Tiplist';
|
|
60
|
+
export * from './mu/TooltipClick';
|
|
60
61
|
export * from './mu/UserAvatar';
|
|
61
62
|
export * from './mu/UserAvatarEditor';
|
|
62
63
|
export * from './notifier/Notifier';
|
package/lib/index.js
CHANGED
|
@@ -60,6 +60,7 @@ export * from './mu/TabBox';
|
|
|
60
60
|
export * from './mu/TableEx';
|
|
61
61
|
export * from './mu/TextFieldEx';
|
|
62
62
|
export * from './mu/Tiplist';
|
|
63
|
+
export * from './mu/TooltipClick';
|
|
63
64
|
export * from './mu/UserAvatar';
|
|
64
65
|
export * from './mu/UserAvatarEditor';
|
|
65
66
|
// notifier
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TooltipProps } from '@mui/material';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Tooltip with click visibility props
|
|
5
|
+
*/
|
|
6
|
+
export interface TooltipClickProps extends Omit<TooltipProps, 'children' | 'open' | 'disableFocusListener' | 'disableHoverListener' | 'disableTouchListener'> {
|
|
7
|
+
children: (openTooltip: (newTitle?: string) => void) => React.ReactElement<any, any>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Tooltip with click visibility
|
|
11
|
+
* @param props Props
|
|
12
|
+
* @returns Component
|
|
13
|
+
*/
|
|
14
|
+
export declare function TooltipClick(props: TooltipClickProps): JSX.Element;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ClickAwayListener, Tooltip } from '@mui/material';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Tooltip with click visibility
|
|
5
|
+
* @param props Props
|
|
6
|
+
* @returns Component
|
|
7
|
+
*/
|
|
8
|
+
export function TooltipClick(props) {
|
|
9
|
+
// Destruct
|
|
10
|
+
const { children, onClose, title, ...rest } = props;
|
|
11
|
+
// State
|
|
12
|
+
const [localTitle, setTitle] = React.useState(title);
|
|
13
|
+
const [open, setOpen] = React.useState(false);
|
|
14
|
+
// Callback for open the tooltip
|
|
15
|
+
const openTooltip = (newTitle) => {
|
|
16
|
+
setOpen(true);
|
|
17
|
+
if (newTitle)
|
|
18
|
+
setTitle(newTitle);
|
|
19
|
+
};
|
|
20
|
+
// Layout
|
|
21
|
+
return (React.createElement(ClickAwayListener, { onClickAway: () => setOpen(false) },
|
|
22
|
+
React.createElement(Tooltip, { PopperProps: {
|
|
23
|
+
disablePortal: true
|
|
24
|
+
}, onClose: (event) => {
|
|
25
|
+
setOpen(false);
|
|
26
|
+
if (onClose)
|
|
27
|
+
onClose(event);
|
|
28
|
+
}, title: localTitle, open: open, disableFocusListener: true, disableHoverListener: true, disableTouchListener: true, ...rest }, children(openTooltip))));
|
|
29
|
+
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ClickAwayListener, Tooltip, TooltipProps } from '@mui/material';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Tooltip with click visibility props
|
|
6
|
+
*/
|
|
7
|
+
export interface TooltipClickProps
|
|
8
|
+
extends Omit<
|
|
9
|
+
TooltipProps,
|
|
10
|
+
| 'children'
|
|
11
|
+
| 'open'
|
|
12
|
+
| 'disableFocusListener'
|
|
13
|
+
| 'disableHoverListener'
|
|
14
|
+
| 'disableTouchListener'
|
|
15
|
+
> {
|
|
16
|
+
children: (
|
|
17
|
+
openTooltip: (newTitle?: string) => void
|
|
18
|
+
) => React.ReactElement<any, any>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Tooltip with click visibility
|
|
23
|
+
* @param props Props
|
|
24
|
+
* @returns Component
|
|
25
|
+
*/
|
|
26
|
+
export function TooltipClick(props: TooltipClickProps) {
|
|
27
|
+
// Destruct
|
|
28
|
+
const { children, onClose, title, ...rest } = props;
|
|
29
|
+
|
|
30
|
+
// State
|
|
31
|
+
const [localTitle, setTitle] = React.useState(title);
|
|
32
|
+
const [open, setOpen] = React.useState(false);
|
|
33
|
+
|
|
34
|
+
// Callback for open the tooltip
|
|
35
|
+
const openTooltip = (newTitle?: string) => {
|
|
36
|
+
setOpen(true);
|
|
37
|
+
if (newTitle) setTitle(newTitle);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// Layout
|
|
41
|
+
return (
|
|
42
|
+
<ClickAwayListener onClickAway={() => setOpen(false)}>
|
|
43
|
+
<Tooltip
|
|
44
|
+
PopperProps={{
|
|
45
|
+
disablePortal: true
|
|
46
|
+
}}
|
|
47
|
+
onClose={(event) => {
|
|
48
|
+
setOpen(false);
|
|
49
|
+
if (onClose) onClose(event);
|
|
50
|
+
}}
|
|
51
|
+
title={localTitle}
|
|
52
|
+
open={open}
|
|
53
|
+
disableFocusListener
|
|
54
|
+
disableHoverListener
|
|
55
|
+
disableTouchListener
|
|
56
|
+
{...rest}
|
|
57
|
+
>
|
|
58
|
+
{children(openTooltip)}
|
|
59
|
+
</Tooltip>
|
|
60
|
+
</ClickAwayListener>
|
|
61
|
+
);
|
|
62
|
+
}
|