@addev-be/ui 0.8.7 → 0.8.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@addev-be/ui",
3
- "version": "0.8.7",
3
+ "version": "0.8.9",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "watch": "tsc -b --watch",
@@ -60,13 +60,18 @@ export const SqlRequestDataGridInner = <R,>(
60
60
 
61
61
  const [columnsKeys, visibleColumnsKeys] = useMemo(
62
62
  () => [
63
- [...Object.keys(props.columns), ...(props.hiddenColumns ?? [])],
64
63
  [
65
- ...Object.keys(props.columns).filter((key) =>
66
- isColumnVisible(props.columns[key])
64
+ ...Object.keys(props.columns).filter(
65
+ (key) => !props.columns[key].ignore
67
66
  ),
68
67
  ...(props.hiddenColumns ?? []),
69
68
  ],
69
+ [
70
+ ...Object.keys(props.columns)
71
+ .filter((key) => !props.columns[key].ignore)
72
+ .filter((key) => isColumnVisible(props.columns[key])),
73
+ ...(props.hiddenColumns ?? []),
74
+ ],
70
75
  ],
71
76
  [props.columns, props.hiddenColumns]
72
77
  );
@@ -27,6 +27,7 @@ export type SqlRequestDataGridColumn<R> = DataGridColumn<R> & {
27
27
  field?: FieldDTO;
28
28
  filterField?: string;
29
29
  sortField?: string;
30
+ ignore?: boolean;
30
31
  };
31
32
 
32
33
  export type SqlRequestDataGridColumns<R> = Record<
@@ -42,11 +42,14 @@ export const SqlRequestGridInner = <R, P extends object = {}>(
42
42
 
43
43
  const [columnsKeys, visibleColumnsKeys] = useMemo(
44
44
  () => [
45
- [...Object.keys(props.fields), ...(props.additionalFields ?? [])],
46
45
  [
47
- ...Object.keys(props.fields).filter((key) =>
48
- isColumnVisible(props.fields[key])
49
- ),
46
+ ...Object.keys(props.fields).filter((key) => !props.fields[key].ignore),
47
+ ...(props.additionalFields ?? []),
48
+ ],
49
+ [
50
+ ...Object.keys(props.fields)
51
+ .filter((key) => !props.fields[key].ignore)
52
+ .filter((key) => isColumnVisible(props.fields[key])),
50
53
  ...(props.additionalFields ?? []),
51
54
  ],
52
55
  ],
@@ -27,6 +27,7 @@ export type SqlRequestGridColumn<R> = DataGridColumn<R> & {
27
27
  field?: FieldDTO;
28
28
  filterField?: string;
29
29
  sortField?: string;
30
+ ignore?: boolean;
30
31
  };
31
32
 
32
33
  export type SqlRequestGridColumns<R> = Record<string, SqlRequestGridColumn<R>>;
@@ -1,6 +1,14 @@
1
1
  import * as styles from './styles';
2
2
 
3
- import { CSSProperties, FC, PropsWithChildren, useMemo } from 'react';
3
+ import {
4
+ CSSProperties,
5
+ FC,
6
+ PropsWithChildren,
7
+ useCallback,
8
+ useEffect,
9
+ useMemo,
10
+ useRef,
11
+ } from 'react';
4
12
 
5
13
  import { usePortals } from '../../../providers';
6
14
 
@@ -57,23 +65,47 @@ const getDropdownStyle = (dropdown: DropdownProps): CSSProperties => {
57
65
  export const Dropdown: FC<DropdownProps> = ({
58
66
  children,
59
67
  onClose,
60
- $backdropAlpha,
61
68
  ...props
62
69
  }) => {
63
70
  const { createPortal } = usePortals();
64
71
 
72
+ const firstClick = useRef(true);
73
+ const containerRef = useRef<HTMLDivElement | null>(null);
65
74
  const style = useMemo(() => getDropdownStyle(props), [props]);
66
75
 
76
+ const onDocumentClick = useCallback(
77
+ (ev: MouseEvent) => {
78
+ if (firstClick.current) {
79
+ firstClick.current = false;
80
+ return;
81
+ }
82
+ if (
83
+ containerRef.current &&
84
+ !containerRef.current.contains(ev.target as Node)
85
+ ) {
86
+ return onClose?.();
87
+ }
88
+ },
89
+ [onClose]
90
+ );
91
+
92
+ useEffect(() => {
93
+ if (containerRef.current) {
94
+ document.addEventListener('click', onDocumentClick);
95
+ return () => {
96
+ document.removeEventListener('click', onDocumentClick);
97
+ };
98
+ }
99
+ }, [onDocumentClick]);
100
+
67
101
  const modalPortal = useMemo(
68
102
  () =>
69
103
  createPortal(
70
- <styles.DropdownBackdrop onClick={onClose} $alpha={$backdropAlpha}>
71
- <styles.DropdownContainer {...props} style={style}>
72
- {children}
73
- </styles.DropdownContainer>
74
- </styles.DropdownBackdrop>
104
+ <styles.DropdownContainer ref={containerRef} {...props} style={style}>
105
+ {children}
106
+ </styles.DropdownContainer>
75
107
  ),
76
- [$backdropAlpha, children, createPortal, onClose, props, style]
108
+ [children, createPortal, props, style]
77
109
  );
78
110
 
79
111
  return <>{modalPortal}</>;