@etsoo/react 1.2.68 → 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 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
@@ -192,12 +192,16 @@ export function DataGridEx(props) {
192
192
  div.title = '';
193
193
  }
194
194
  };
195
- const handleClick = (event) => {
195
+ const handleMouseDown = (event) => {
196
196
  var _a;
197
197
  const div = event.currentTarget;
198
198
  const row = div.dataset['row'];
199
199
  if (div.parentElement == null || row == null)
200
200
  return;
201
+ const rowIndex = parseFloat(row);
202
+ // No change
203
+ if (isNaN(rowIndex) || rowIndex === state.selectedRowIndex)
204
+ return;
201
205
  if (state.selectedRowIndex != null) {
202
206
  doRowItems(div.parentElement, state.selectedRowIndex, (preDiv) => {
203
207
  preDiv.classList.remove('DataGridEx-Selected');
@@ -206,7 +210,7 @@ export function DataGridEx(props) {
206
210
  rowItems(div, (currentDiv) => {
207
211
  currentDiv.classList.add('DataGridEx-Selected');
208
212
  });
209
- state.selectedRowIndex = parseFloat(row);
213
+ state.selectedRowIndex = rowIndex;
210
214
  (_a = state.ref) === null || _a === void 0 ? void 0 : _a.select(state.selectedRowIndex);
211
215
  };
212
216
  const handleMouseOver = (event) => {
@@ -263,7 +267,7 @@ export function DataGridEx(props) {
263
267
  cellProps,
264
268
  renderProps
265
269
  });
266
- return (React.createElement("div", { className: rowClass, style: style, "data-row": rowIndex, "data-column": columnIndex, onClick: selectable && !checkable ? handleClick : undefined, onMouseOver: selectable ? handleMouseOver : undefined, onMouseOut: selectable ? handleMouseOut : undefined },
270
+ return (React.createElement("div", { className: rowClass, style: style, "data-row": rowIndex, "data-column": columnIndex, onMouseDown: selectable && !checkable ? handleMouseDown : undefined, onMouseOver: selectable ? handleMouseOver : undefined, onMouseOut: selectable ? handleMouseOut : undefined },
267
271
  React.createElement(Box, { ...cellProps, onMouseEnter: handleMouseEnter }, child)));
268
272
  };
269
273
  // Column width calculator
@@ -17,14 +17,18 @@ export interface TabBoxPanel extends Omit<TabProps, 'value' | 'children'> {
17
17
  * Tabs with box props
18
18
  */
19
19
  export interface TabBoxPros extends BoxProps {
20
- /**
21
- * Root props
22
- */
23
- root?: BoxProps;
24
20
  /**
25
21
  * Container props
26
22
  */
27
23
  container?: Omit<TabsProps, 'value'>;
24
+ /**
25
+ * Add a hidden input and its name
26
+ */
27
+ inputName?: string;
28
+ /**
29
+ * Root props
30
+ */
31
+ root?: BoxProps;
28
32
  /**
29
33
  * Tabs
30
34
  */
package/lib/mu/TabBox.js CHANGED
@@ -7,17 +7,18 @@ import React from 'react';
7
7
  */
8
8
  export function TabBox(props) {
9
9
  // Destruct
10
- const { root, container = {}, tabs } = props;
10
+ const { inputName, root, container = {}, tabs } = props;
11
11
  const { onChange, ...rest } = container;
12
12
  // State
13
13
  const [value, setValue] = React.useState(0);
14
14
  // Layout
15
15
  return (React.createElement(React.Fragment, null,
16
+ inputName && (React.createElement("input", { type: "hidden", name: inputName, value: value })),
16
17
  React.createElement(Box, { ...root },
17
18
  React.createElement(Tabs, { value: value, onChange: (event, newValue) => {
18
19
  setValue(newValue);
19
20
  if (onChange)
20
21
  onChange(event, newValue);
21
- }, ...rest }, tabs.map(({ children, panel, ...tabRest }, index) => (React.createElement(Tab, { value: index, ...tabRest }))))),
22
- tabs.map(({ children, panel }, index) => (React.createElement(Box, { hidden: value !== index, ...panel }, children)))));
22
+ }, ...rest }, tabs.map(({ children, panel, ...tabRest }, index) => (React.createElement(Tab, { key: index, value: index, ...tabRest }))))),
23
+ tabs.map(({ children, panel }, index) => (React.createElement(Box, { key: index, hidden: value !== index, ...panel }, children)))));
23
24
  }
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.2.68",
3
+ "version": "1.2.72",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -50,9 +50,9 @@
50
50
  "@emotion/react": "^11.5.0",
51
51
  "@emotion/style": "^0.8.0",
52
52
  "@emotion/styled": "^11.3.0",
53
- "@etsoo/appscript": "^1.1.20",
54
- "@etsoo/notificationbase": "^1.0.88",
55
- "@etsoo/shared": "^1.0.57",
53
+ "@etsoo/appscript": "^1.1.21",
54
+ "@etsoo/notificationbase": "^1.0.89",
55
+ "@etsoo/shared": "^1.0.58",
56
56
  "@mui/icons-material": "^5.0.4",
57
57
  "@mui/material": "^5.0.4",
58
58
  "@reach/router": "^1.3.4",
package/src/index.ts CHANGED
@@ -64,6 +64,7 @@ export * from './mu/TabBox';
64
64
  export * from './mu/TableEx';
65
65
  export * from './mu/TextFieldEx';
66
66
  export * from './mu/Tiplist';
67
+ export * from './mu/TooltipClick';
67
68
  export * from './mu/UserAvatar';
68
69
  export * from './mu/UserAvatarEditor';
69
70
 
@@ -458,11 +458,16 @@ export function DataGridEx<T extends Record<string, any>>(
458
458
  }
459
459
  };
460
460
 
461
- const handleClick = (event: React.MouseEvent<HTMLDivElement>) => {
461
+ const handleMouseDown = (event: React.MouseEvent<HTMLDivElement>) => {
462
462
  const div = event.currentTarget;
463
463
  const row = div.dataset['row'];
464
464
  if (div.parentElement == null || row == null) return;
465
465
 
466
+ const rowIndex = parseFloat(row);
467
+
468
+ // No change
469
+ if (isNaN(rowIndex) || rowIndex === state.selectedRowIndex) return;
470
+
466
471
  if (state.selectedRowIndex != null) {
467
472
  doRowItems(div.parentElement, state.selectedRowIndex, (preDiv) => {
468
473
  preDiv.classList.remove('DataGridEx-Selected');
@@ -472,7 +477,7 @@ export function DataGridEx<T extends Record<string, any>>(
472
477
  rowItems(div, (currentDiv) => {
473
478
  currentDiv.classList.add('DataGridEx-Selected');
474
479
  });
475
- state.selectedRowIndex = parseFloat(row);
480
+ state.selectedRowIndex = rowIndex;
476
481
 
477
482
  state.ref?.select(state.selectedRowIndex);
478
483
  };
@@ -565,7 +570,9 @@ export function DataGridEx<T extends Record<string, any>>(
565
570
  style={style}
566
571
  data-row={rowIndex}
567
572
  data-column={columnIndex}
568
- onClick={selectable && !checkable ? handleClick : undefined}
573
+ onMouseDown={
574
+ selectable && !checkable ? handleMouseDown : undefined
575
+ }
569
576
  onMouseOver={selectable ? handleMouseOver : undefined}
570
577
  onMouseOut={selectable ? handleMouseOut : undefined}
571
578
  >
package/src/mu/TabBox.tsx CHANGED
@@ -21,14 +21,19 @@ export interface TabBoxPanel extends Omit<TabProps, 'value' | 'children'> {
21
21
  */
22
22
  export interface TabBoxPros extends BoxProps {
23
23
  /**
24
- * Root props
24
+ * Container props
25
25
  */
26
- root?: BoxProps;
26
+ container?: Omit<TabsProps, 'value'>;
27
27
 
28
28
  /**
29
- * Container props
29
+ * Add a hidden input and its name
30
30
  */
31
- container?: Omit<TabsProps, 'value'>;
31
+ inputName?: string;
32
+
33
+ /**
34
+ * Root props
35
+ */
36
+ root?: BoxProps;
32
37
 
33
38
  /**
34
39
  * Tabs
@@ -43,7 +48,7 @@ export interface TabBoxPros extends BoxProps {
43
48
  */
44
49
  export function TabBox(props: TabBoxPros) {
45
50
  // Destruct
46
- const { root, container = {}, tabs } = props;
51
+ const { inputName, root, container = {}, tabs } = props;
47
52
  const { onChange, ...rest } = container;
48
53
 
49
54
  // State
@@ -52,6 +57,9 @@ export function TabBox(props: TabBoxPros) {
52
57
  // Layout
53
58
  return (
54
59
  <React.Fragment>
60
+ {inputName && (
61
+ <input type="hidden" name={inputName} value={value} />
62
+ )}
55
63
  <Box {...root}>
56
64
  <Tabs
57
65
  value={value}
@@ -62,12 +70,12 @@ export function TabBox(props: TabBoxPros) {
62
70
  {...rest}
63
71
  >
64
72
  {tabs.map(({ children, panel, ...tabRest }, index) => (
65
- <Tab value={index} {...tabRest} />
73
+ <Tab key={index} value={index} {...tabRest} />
66
74
  ))}
67
75
  </Tabs>
68
76
  </Box>
69
77
  {tabs.map(({ children, panel }, index) => (
70
- <Box hidden={value !== index} {...panel}>
78
+ <Box key={index} hidden={value !== index} {...panel}>
71
79
  {children}
72
80
  </Box>
73
81
  ))}
@@ -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
+ }