@quillsql/react 1.7.5 → 1.7.6
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/ReportBuilder.js +1 -0
- package/lib/ReportBuilder.js.map +1 -1
- package/lib/SQLEditor.js +3 -3
- package/lib/SQLEditor.js.map +1 -1
- package/lib/Table.js +1 -1
- package/lib/Table.js.map +1 -1
- package/lib/components/BigModal/BigModal.js +1 -0
- package/lib/components/BigModal/BigModal.js.map +1 -1
- package/lib/components/Modal/Modal.js +1 -0
- package/lib/components/Modal/Modal.js.map +1 -1
- package/lib/hooks/useQuill.js +1 -0
- package/lib/hooks/useQuill.js.map +1 -1
- package/package.json +11 -4
- package/.eslintrc.json +0 -19
- package/.prettierrc +0 -11
- package/.vscode/settings.json +0 -10
- package/src/AddToDashboardModal.tsx +0 -1220
- package/src/BarList.tsx +0 -580
- package/src/Chart.tsx +0 -1337
- package/src/Context.tsx +0 -252
- package/src/Dashboard.tsx +0 -820
- package/src/DateRangePicker/Calendar.tsx +0 -442
- package/src/DateRangePicker/DateRangePicker.tsx +0 -261
- package/src/DateRangePicker/DateRangePickerButton.tsx +0 -250
- package/src/DateRangePicker/dateRangePickerUtils.tsx +0 -480
- package/src/DateRangePicker/index.ts +0 -4
- package/src/PieChart.tsx +0 -845
- package/src/QuillProvider.tsx +0 -81
- package/src/ReportBuilder.tsx +0 -2208
- package/src/SQLEditor.tsx +0 -1093
- package/src/Table.tsx +0 -1074
- package/src/TableChart.tsx +0 -428
- package/src/assets/ArrowDownHeadIcon.tsx +0 -11
- package/src/assets/ArrowDownIcon.tsx +0 -14
- package/src/assets/ArrowDownRightIcon.tsx +0 -14
- package/src/assets/ArrowLeftHeadIcon.tsx +0 -11
- package/src/assets/ArrowRightHeadIcon.tsx +0 -11
- package/src/assets/ArrowRightIcon.tsx +0 -14
- package/src/assets/ArrowUpHeadIcon.tsx +0 -11
- package/src/assets/ArrowUpIcon.tsx +0 -14
- package/src/assets/ArrowUpRightIcon.tsx +0 -14
- package/src/assets/CalendarIcon.tsx +0 -14
- package/src/assets/DoubleArrowLeftHeadIcon.tsx +0 -18
- package/src/assets/DoubleArrowRightHeadIcon.tsx +0 -20
- package/src/assets/ExclamationFilledIcon.tsx +0 -14
- package/src/assets/LoadingSpinner.tsx +0 -11
- package/src/assets/SearchIcon.tsx +0 -14
- package/src/assets/XCircleIcon.tsx +0 -14
- package/src/assets/index.ts +0 -16
- package/src/components/BigModal/BigModal.tsx +0 -108
- package/src/components/Dropdown/Dropdown.tsx +0 -169
- package/src/components/Dropdown/DropdownItem.tsx +0 -68
- package/src/components/Dropdown/index.ts +0 -2
- package/src/components/Modal/Modal.tsx +0 -132
- package/src/components/Modal/index.ts +0 -1
- package/src/components/selectUtils.ts +0 -60
- package/src/contexts/BaseColorContext.tsx +0 -5
- package/src/contexts/HoveredValueContext.tsx +0 -12
- package/src/contexts/RootStylesContext.tsx +0 -5
- package/src/contexts/SelectedValueContext.tsx +0 -13
- package/src/contexts/index.ts +0 -4
- package/src/hooks/index.ts +0 -4
- package/src/hooks/useInternalState.tsx +0 -18
- package/src/hooks/useOnClickOutside.tsx +0 -23
- package/src/hooks/useOnWindowResize.tsx +0 -17
- package/src/hooks/useQuill.ts +0 -138
- package/src/hooks/useSelectOnKeyDown.tsx +0 -80
- package/src/index.ts +0 -9
- package/src/lib/font.ts +0 -14
- package/src/lib/index.ts +0 -3
- package/src/lib/inputTypes.ts +0 -81
- package/src/lib/utils.tsx +0 -46
- package/tsconfig.json +0 -22
package/src/assets/index.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export { default as ArrowDownHeadIcon } from "./ArrowDownHeadIcon";
|
|
2
|
-
export { default as ArrowDownRightIcon } from "./ArrowDownRightIcon";
|
|
3
|
-
export { default as ArrowDownIcon } from "./ArrowDownIcon";
|
|
4
|
-
export { default as ArrowRightIcon } from "./ArrowRightIcon";
|
|
5
|
-
export { default as ArrowRightHeadIcon } from "./ArrowRightHeadIcon";
|
|
6
|
-
export { default as ArrowLeftHeadIcon } from "./ArrowLeftHeadIcon";
|
|
7
|
-
export { default as DoubleArrowLeftHeadIcon } from "./DoubleArrowLeftHeadIcon";
|
|
8
|
-
export { default as DoubleArrowRightHeadIcon } from "./DoubleArrowRightHeadIcon";
|
|
9
|
-
export { default as ArrowUpHeadIcon } from "./ArrowUpHeadIcon";
|
|
10
|
-
export { default as ArrowUpIcon } from "./ArrowUpIcon";
|
|
11
|
-
export { default as ArrowUpRightIcon } from "./ArrowUpRightIcon";
|
|
12
|
-
export { default as CalendarIcon } from "./CalendarIcon";
|
|
13
|
-
export { default as ExclamationFilledIcon } from "./ExclamationFilledIcon";
|
|
14
|
-
export { default as LoadingSpinner } from "./LoadingSpinner";
|
|
15
|
-
export { default as SearchIcon } from "./SearchIcon";
|
|
16
|
-
export { default as XCircleIcon } from "./XCircleIcon";
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/* eslint-disable react/display-name */
|
|
2
|
-
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
-
|
|
4
|
-
import { useOnClickOutside, useOnWindowResize } from '../../hooks';
|
|
5
|
-
|
|
6
|
-
import { HorizontalPosition } from '../../lib/inputTypes';
|
|
7
|
-
import { mergeRefs } from '../../lib';
|
|
8
|
-
|
|
9
|
-
export interface ModalProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
10
|
-
showModal: boolean;
|
|
11
|
-
setShowModal:
|
|
12
|
-
| React.Dispatch<React.SetStateAction<boolean>>
|
|
13
|
-
| ((nextState: boolean) => void);
|
|
14
|
-
parentRef?: React.RefObject<HTMLElement>;
|
|
15
|
-
width?: number;
|
|
16
|
-
maxHeight?: string;
|
|
17
|
-
anchorPosition?: HorizontalPosition;
|
|
18
|
-
children: React.ReactNode;
|
|
19
|
-
theme: any;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const BigModal = React.forwardRef<HTMLDivElement, ModalProps>((props, ref) => {
|
|
23
|
-
const {
|
|
24
|
-
showModal,
|
|
25
|
-
setShowModal,
|
|
26
|
-
parentRef,
|
|
27
|
-
width,
|
|
28
|
-
maxHeight = '18rem',
|
|
29
|
-
children,
|
|
30
|
-
className,
|
|
31
|
-
theme,
|
|
32
|
-
...other
|
|
33
|
-
} = props;
|
|
34
|
-
const [modalExceedsWindow, setModalExceedsWindow] = useState(false);
|
|
35
|
-
|
|
36
|
-
const modalRef = useRef<HTMLDivElement>(null);
|
|
37
|
-
|
|
38
|
-
const checkModalExceedsWindow = useCallback(
|
|
39
|
-
(modalWidth: number, windowWidth: number): boolean => {
|
|
40
|
-
if (!parentRef.current) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
const modalBoundingRight =
|
|
44
|
-
parentRef.current.getBoundingClientRect().left + modalWidth;
|
|
45
|
-
return windowWidth - modalBoundingRight < 0;
|
|
46
|
-
},
|
|
47
|
-
[parentRef]
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
const getAbsoluteSpacing = () => {
|
|
51
|
-
return modalExceedsWindow ? '0' : '0';
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
useOnClickOutside(modalRef, e => {
|
|
55
|
-
// Exclude click on trigger button (e.g. Dropdown Button) from outside click handler
|
|
56
|
-
const isTriggerElem = parentRef
|
|
57
|
-
? parentRef.current?.contains(e.target)
|
|
58
|
-
: false;
|
|
59
|
-
if (!isTriggerElem) {
|
|
60
|
-
setShowModal(false);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// Execute only when modal is of absolute size
|
|
65
|
-
useEffect(() => {
|
|
66
|
-
if (width) {
|
|
67
|
-
setModalExceedsWindow(checkModalExceedsWindow(width, window.innerWidth));
|
|
68
|
-
}
|
|
69
|
-
}, [checkModalExceedsWindow, parentRef, width]);
|
|
70
|
-
|
|
71
|
-
useOnWindowResize(() => {
|
|
72
|
-
if (width) {
|
|
73
|
-
setModalExceedsWindow(checkModalExceedsWindow(width, window.innerWidth));
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
return showModal ? (
|
|
78
|
-
<div
|
|
79
|
-
ref={mergeRefs([modalRef, ref])}
|
|
80
|
-
style={{
|
|
81
|
-
position: 'absolute',
|
|
82
|
-
zIndex: 10,
|
|
83
|
-
overflowY: 'auto',
|
|
84
|
-
backgroundColor: theme?.backgroundColor || 'white',
|
|
85
|
-
borderColor: theme?.borderColor || '#E5E7EB',
|
|
86
|
-
borderTopStyle: 'solid',
|
|
87
|
-
borderBottomStyle: 'solid',
|
|
88
|
-
borderLeftStyle: 'solid',
|
|
89
|
-
borderRightStyle: 'solid',
|
|
90
|
-
borderTopWidth: 1,
|
|
91
|
-
borderBottomWidth: 1,
|
|
92
|
-
borderLeftWidth: 1,
|
|
93
|
-
borderRightWidth: 1,
|
|
94
|
-
borderRadius: '0.375rem',
|
|
95
|
-
boxShadow:
|
|
96
|
-
'0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)',
|
|
97
|
-
top: '50%',
|
|
98
|
-
left: '50%',
|
|
99
|
-
transform: 'translate(-50%, -50%)',
|
|
100
|
-
}}
|
|
101
|
-
{...other}
|
|
102
|
-
>
|
|
103
|
-
{children}
|
|
104
|
-
</div>
|
|
105
|
-
) : null;
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
export default BigModal;
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
/* eslint-disable react/display-name */
|
|
2
|
-
import React, { useRef, useState } from 'react';
|
|
3
|
-
|
|
4
|
-
import { HoveredValueContext, SelectedValueContext } from '../../contexts';
|
|
5
|
-
|
|
6
|
-
import { useInternalState, useSelectOnKeyDown } from '../../hooks';
|
|
7
|
-
|
|
8
|
-
import { ArrowDownHeadIcon } from '../../assets';
|
|
9
|
-
|
|
10
|
-
import { mergeRefs } from '../../lib';
|
|
11
|
-
import { constructValueToNameMapping, hasValue } from '../selectUtils';
|
|
12
|
-
import { DropdownItemProps } from './DropdownItem';
|
|
13
|
-
import Modal from '../Modal';
|
|
14
|
-
|
|
15
|
-
export interface DropdownProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
16
|
-
value?: string;
|
|
17
|
-
defaultValue?: string;
|
|
18
|
-
onValueChange?: (value: string) => void;
|
|
19
|
-
placeholder?: string;
|
|
20
|
-
disabled?: boolean;
|
|
21
|
-
icon?: React.JSXElementConstructor<any>;
|
|
22
|
-
children: React.ReactElement[] | React.ReactElement;
|
|
23
|
-
theme: any;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const Dropdown = React.forwardRef<HTMLDivElement, DropdownProps>(
|
|
27
|
-
(props, ref) => {
|
|
28
|
-
const {
|
|
29
|
-
defaultValue,
|
|
30
|
-
value,
|
|
31
|
-
onValueChange,
|
|
32
|
-
placeholder = 'Select...',
|
|
33
|
-
disabled = false,
|
|
34
|
-
icon,
|
|
35
|
-
children,
|
|
36
|
-
className,
|
|
37
|
-
theme,
|
|
38
|
-
...other
|
|
39
|
-
} = props;
|
|
40
|
-
const [selectedValue, setSelectedValue] = useInternalState(
|
|
41
|
-
defaultValue,
|
|
42
|
-
value
|
|
43
|
-
);
|
|
44
|
-
const [isFocused, setIsFocused] = useState(false);
|
|
45
|
-
|
|
46
|
-
const dropdownRef = useRef(null);
|
|
47
|
-
|
|
48
|
-
const Icon = icon;
|
|
49
|
-
const valueToNameMapping = constructValueToNameMapping(children);
|
|
50
|
-
const optionValues = React.Children.map(
|
|
51
|
-
children,
|
|
52
|
-
(child: { props: DropdownItemProps }) => child.props.value
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
const handleValueChange = (value: string) => {
|
|
56
|
-
setSelectedValue(value);
|
|
57
|
-
setIsFocused(false);
|
|
58
|
-
onValueChange?.(value);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const [hoveredValue, handleKeyDown] = useSelectOnKeyDown(
|
|
62
|
-
handleValueChange,
|
|
63
|
-
optionValues,
|
|
64
|
-
isFocused,
|
|
65
|
-
setIsFocused,
|
|
66
|
-
selectedValue
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
const hasSelection = hasValue(selectedValue);
|
|
70
|
-
|
|
71
|
-
return (
|
|
72
|
-
<div
|
|
73
|
-
ref={mergeRefs([dropdownRef, ref])}
|
|
74
|
-
onKeyDown={handleKeyDown}
|
|
75
|
-
style={{
|
|
76
|
-
position: 'relative',
|
|
77
|
-
width: '100%',
|
|
78
|
-
minWidth: '10rem',
|
|
79
|
-
}}
|
|
80
|
-
{...other}
|
|
81
|
-
>
|
|
82
|
-
<button
|
|
83
|
-
style={{
|
|
84
|
-
display: 'flex',
|
|
85
|
-
justifyContent: 'space-between',
|
|
86
|
-
alignItems: 'center',
|
|
87
|
-
width: '100%',
|
|
88
|
-
outline: 'none',
|
|
89
|
-
padding: '1.5rem 2rem',
|
|
90
|
-
borderRadius: '0.375rem',
|
|
91
|
-
border: '2px solid',
|
|
92
|
-
boxShadow: '0 1px 2px 0 rgba(0, 0, 0, 0.05)',
|
|
93
|
-
cursor: 'pointer',
|
|
94
|
-
background: 'white',
|
|
95
|
-
}}
|
|
96
|
-
type="button"
|
|
97
|
-
onClick={() => setIsFocused(!isFocused)}
|
|
98
|
-
disabled={disabled}
|
|
99
|
-
>
|
|
100
|
-
<div
|
|
101
|
-
style={{
|
|
102
|
-
display: 'flex',
|
|
103
|
-
justifyContent: 'start',
|
|
104
|
-
alignItems: 'center',
|
|
105
|
-
whiteSpace: 'nowrap',
|
|
106
|
-
overflow: 'hidden',
|
|
107
|
-
textOverflow: 'ellipsis',
|
|
108
|
-
}}
|
|
109
|
-
>
|
|
110
|
-
{Icon ? (
|
|
111
|
-
<Icon
|
|
112
|
-
style={{
|
|
113
|
-
flexShrink: 0,
|
|
114
|
-
height: '1.5rem',
|
|
115
|
-
width: '1.5rem',
|
|
116
|
-
color: theme?.secondaryTextColor || '#6C727F',
|
|
117
|
-
marginRight: '1.5rem',
|
|
118
|
-
}}
|
|
119
|
-
aria-hidden="true"
|
|
120
|
-
/>
|
|
121
|
-
) : null}
|
|
122
|
-
<p
|
|
123
|
-
style={{
|
|
124
|
-
margin: 0,
|
|
125
|
-
fontSize: '0.875rem',
|
|
126
|
-
fontWeight: '500',
|
|
127
|
-
whiteSpace: 'nowrap',
|
|
128
|
-
overflow: 'hidden',
|
|
129
|
-
textOverflow: 'ellipsis',
|
|
130
|
-
}}
|
|
131
|
-
>
|
|
132
|
-
{selectedValue
|
|
133
|
-
? valueToNameMapping.get(selectedValue)
|
|
134
|
-
: placeholder}
|
|
135
|
-
</p>
|
|
136
|
-
</div>
|
|
137
|
-
<ArrowDownHeadIcon
|
|
138
|
-
style={{
|
|
139
|
-
flexShrink: 0,
|
|
140
|
-
height: '1.5rem',
|
|
141
|
-
width: '1.5rem',
|
|
142
|
-
marginRight: '-0.25rem',
|
|
143
|
-
color: theme?.secondaryTextColor || '#6C727F',
|
|
144
|
-
}}
|
|
145
|
-
aria-hidden="true"
|
|
146
|
-
/>
|
|
147
|
-
</button>
|
|
148
|
-
<Modal
|
|
149
|
-
theme={theme}
|
|
150
|
-
showModal={isFocused}
|
|
151
|
-
setShowModal={setIsFocused}
|
|
152
|
-
parentRef={dropdownRef}
|
|
153
|
-
>
|
|
154
|
-
<SelectedValueContext.Provider
|
|
155
|
-
value={{ selectedValue, handleValueChange }}
|
|
156
|
-
>
|
|
157
|
-
<HoveredValueContext.Provider value={{ hoveredValue }}>
|
|
158
|
-
{React.Children.map(children, (child: React.ReactElement) =>
|
|
159
|
-
React.cloneElement(child)
|
|
160
|
-
)}
|
|
161
|
-
</HoveredValueContext.Provider>
|
|
162
|
-
</SelectedValueContext.Provider>
|
|
163
|
-
</Modal>
|
|
164
|
-
</div>
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
export default Dropdown;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/* eslint-disable react/display-name */
|
|
2
|
-
import React, { useContext } from 'react';
|
|
3
|
-
|
|
4
|
-
import { HoveredValueContext, SelectedValueContext } from '../../contexts';
|
|
5
|
-
|
|
6
|
-
export interface DropdownItemProps
|
|
7
|
-
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
8
|
-
value: string;
|
|
9
|
-
text?: string;
|
|
10
|
-
icon?: React.ElementType;
|
|
11
|
-
theme: any;
|
|
12
|
-
lastItem?: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const DropdownItem = React.forwardRef<HTMLButtonElement, DropdownItemProps>(
|
|
16
|
-
(props, ref) => {
|
|
17
|
-
const { value, text, icon, className, theme, lastItem, ...other } = props;
|
|
18
|
-
const { selectedValue, handleValueChange } =
|
|
19
|
-
useContext(SelectedValueContext);
|
|
20
|
-
const { hoveredValue } = useContext(HoveredValueContext);
|
|
21
|
-
const isActive = selectedValue === value;
|
|
22
|
-
const isHovered = hoveredValue === value;
|
|
23
|
-
|
|
24
|
-
const Icon = icon ? icon : null;
|
|
25
|
-
return (
|
|
26
|
-
<button
|
|
27
|
-
ref={ref}
|
|
28
|
-
style={{
|
|
29
|
-
display: 'flex',
|
|
30
|
-
alignItems: 'center',
|
|
31
|
-
justifyContent: 'start',
|
|
32
|
-
width: '100%',
|
|
33
|
-
overflow: 'hidden',
|
|
34
|
-
textOverflow: 'ellipsis',
|
|
35
|
-
padding: '0.75rem 1.25rem',
|
|
36
|
-
fontSize: '0.875rem',
|
|
37
|
-
borderStyle: 'solid',
|
|
38
|
-
borderBottomWidth: lastItem ? '0px' : '1px',
|
|
39
|
-
borderBottomColor: theme?.borderColor || '#E5E7EB',
|
|
40
|
-
background: theme?.backgroundColor || 'white',
|
|
41
|
-
borderTop: 'none',
|
|
42
|
-
borderRight: 'none',
|
|
43
|
-
borderLeft: 'none',
|
|
44
|
-
cursor: 'pointer',
|
|
45
|
-
color: theme?.primaryTextColor || '#364153',
|
|
46
|
-
}}
|
|
47
|
-
type="button"
|
|
48
|
-
onClick={() => handleValueChange?.(value)}
|
|
49
|
-
{...other}
|
|
50
|
-
>
|
|
51
|
-
<p
|
|
52
|
-
style={{
|
|
53
|
-
margin: 0,
|
|
54
|
-
fontFamily: theme?.fontFamily,
|
|
55
|
-
color: theme?.primaryTextColor,
|
|
56
|
-
whiteSpace: 'nowrap',
|
|
57
|
-
overflow: 'hidden',
|
|
58
|
-
textOverflow: 'ellipsis',
|
|
59
|
-
}}
|
|
60
|
-
>
|
|
61
|
-
{text ?? value}
|
|
62
|
-
</p>
|
|
63
|
-
</button>
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
export default DropdownItem;
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/* eslint-disable react/display-name */
|
|
2
|
-
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
-
|
|
4
|
-
import { useOnClickOutside, useOnWindowResize } from '../../hooks';
|
|
5
|
-
|
|
6
|
-
import { HorizontalPosition } from '../../lib/inputTypes';
|
|
7
|
-
import { mergeRefs } from '../../lib';
|
|
8
|
-
|
|
9
|
-
export interface ModalProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
10
|
-
showModal: boolean;
|
|
11
|
-
setShowModal:
|
|
12
|
-
| React.Dispatch<React.SetStateAction<boolean>>
|
|
13
|
-
| ((nextState: boolean) => void);
|
|
14
|
-
parentRef?: React.RefObject<HTMLElement>;
|
|
15
|
-
width?: number;
|
|
16
|
-
maxHeight?: string;
|
|
17
|
-
anchorPosition?: HorizontalPosition;
|
|
18
|
-
children: React.ReactNode;
|
|
19
|
-
theme: any;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const Modal = React.forwardRef<HTMLDivElement, ModalProps>((props, ref) => {
|
|
23
|
-
const {
|
|
24
|
-
showModal,
|
|
25
|
-
setShowModal,
|
|
26
|
-
parentRef,
|
|
27
|
-
width,
|
|
28
|
-
maxHeight = '18rem',
|
|
29
|
-
children,
|
|
30
|
-
className,
|
|
31
|
-
theme,
|
|
32
|
-
...other
|
|
33
|
-
} = props;
|
|
34
|
-
const [modalExceedsWindow, setModalExceedsWindow] = useState(false);
|
|
35
|
-
|
|
36
|
-
const modalRef = useRef<HTMLDivElement>(null);
|
|
37
|
-
|
|
38
|
-
const checkModalExceedsWindow = useCallback(
|
|
39
|
-
(modalWidth: number, windowWidth: number): boolean => {
|
|
40
|
-
if (!parentRef.current) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
const modalBoundingRight =
|
|
44
|
-
parentRef.current.getBoundingClientRect().left + modalWidth;
|
|
45
|
-
return windowWidth - modalBoundingRight < 0;
|
|
46
|
-
},
|
|
47
|
-
[parentRef]
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
const getAbsoluteSpacing = () => {
|
|
51
|
-
return modalExceedsWindow ? '0' : '0';
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
useOnClickOutside(modalRef, e => {
|
|
55
|
-
// Exclude click on trigger button (e.g. Dropdown Button) from outside click handler
|
|
56
|
-
const isTriggerElem = parentRef
|
|
57
|
-
? parentRef.current?.contains(e.target)
|
|
58
|
-
: false;
|
|
59
|
-
if (!isTriggerElem) {
|
|
60
|
-
setShowModal(false);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// Execute only when modal is of absolute size
|
|
65
|
-
useEffect(() => {
|
|
66
|
-
if (width) {
|
|
67
|
-
setModalExceedsWindow(checkModalExceedsWindow(width, window.innerWidth));
|
|
68
|
-
}
|
|
69
|
-
}, [checkModalExceedsWindow, parentRef, width]);
|
|
70
|
-
|
|
71
|
-
useOnWindowResize(() => {
|
|
72
|
-
if (width) {
|
|
73
|
-
setModalExceedsWindow(checkModalExceedsWindow(width, window.innerWidth));
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
return showModal ? (
|
|
78
|
-
<div
|
|
79
|
-
ref={mergeRefs([modalRef, ref])}
|
|
80
|
-
style={{
|
|
81
|
-
position: 'absolute',
|
|
82
|
-
zIndex: 10,
|
|
83
|
-
overflowY: 'auto',
|
|
84
|
-
width: width ? width : '100%',
|
|
85
|
-
left: getAbsoluteSpacing(),
|
|
86
|
-
right: getAbsoluteSpacing(),
|
|
87
|
-
maxHeight: maxHeight,
|
|
88
|
-
backgroundColor: theme?.backgroundColor || 'white',
|
|
89
|
-
borderColor: theme?.borderColor || '#E5E7EB',
|
|
90
|
-
// borderTopColor: getColorClassNames(
|
|
91
|
-
// DEFAULT_COLOR,
|
|
92
|
-
// colorPalette.lightBorder
|
|
93
|
-
// ).borderColor,
|
|
94
|
-
// borderBottomColor: getColorClassNames(
|
|
95
|
-
// DEFAULT_COLOR,
|
|
96
|
-
// colorPalette.lightBorder
|
|
97
|
-
// ).borderColor,
|
|
98
|
-
// borderLeftColor: getColorClassNames(
|
|
99
|
-
// DEFAULT_COLOR,
|
|
100
|
-
// colorPalette.lightBorder
|
|
101
|
-
// ).borderColor,
|
|
102
|
-
// borderRightColor: getColorClassNames(
|
|
103
|
-
// DEFAULT_COLOR,
|
|
104
|
-
// colorPalette.lightBorder
|
|
105
|
-
// ).borderColor,
|
|
106
|
-
borderTopStyle: 'solid',
|
|
107
|
-
borderBottomStyle: 'solid',
|
|
108
|
-
borderLeftStyle: 'solid',
|
|
109
|
-
borderRightStyle: 'solid',
|
|
110
|
-
borderTopWidth: 1,
|
|
111
|
-
borderBottomWidth: 1,
|
|
112
|
-
borderLeftWidth: 1,
|
|
113
|
-
borderRightWidth: 1,
|
|
114
|
-
marginTop: '0.5rem',
|
|
115
|
-
marginBottom: '0.5rem',
|
|
116
|
-
borderRadius: '0.375rem',
|
|
117
|
-
boxShadow:
|
|
118
|
-
'0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)',
|
|
119
|
-
// boxShadow: '0 1px 3px 0 #0000001A, 0 1px 2px 0 #0000000F',
|
|
120
|
-
// borderTopWidth: '2px',
|
|
121
|
-
// borderBottomWidth: '2px',
|
|
122
|
-
// borderLeftWidth: '2px',
|
|
123
|
-
// borderRightWidth: '2px',
|
|
124
|
-
}}
|
|
125
|
-
{...other}
|
|
126
|
-
>
|
|
127
|
-
{children}
|
|
128
|
-
</div>
|
|
129
|
-
) : null;
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
export default Modal;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "./Modal";
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
// import { twMerge } from 'tailwind-merge';
|
|
3
|
-
|
|
4
|
-
export interface SelectItemProps {
|
|
5
|
-
value: string;
|
|
6
|
-
text?: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function constructValueToNameMapping(
|
|
10
|
-
children: React.ReactElement[] | React.ReactElement
|
|
11
|
-
) {
|
|
12
|
-
const valueToNameMapping = new Map<string, string>();
|
|
13
|
-
React.Children.map(children, (child: { props: SelectItemProps }) => {
|
|
14
|
-
valueToNameMapping.set(
|
|
15
|
-
child.props.value,
|
|
16
|
-
child.props.text ?? child.props.value
|
|
17
|
-
);
|
|
18
|
-
});
|
|
19
|
-
return valueToNameMapping;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function getFilteredOptions(
|
|
23
|
-
searchQuery: string,
|
|
24
|
-
options: SelectItemProps[]
|
|
25
|
-
): SelectItemProps[] {
|
|
26
|
-
return searchQuery === ''
|
|
27
|
-
? options
|
|
28
|
-
: options.filter((option: SelectItemProps) => {
|
|
29
|
-
const optionText = option.text ?? option.value;
|
|
30
|
-
return optionText.toLowerCase().includes(searchQuery.toLowerCase());
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const getSelectButtonColors = (
|
|
35
|
-
hasSelection: boolean,
|
|
36
|
-
isDisabled: boolean,
|
|
37
|
-
hasError = false
|
|
38
|
-
) => {
|
|
39
|
-
return null;
|
|
40
|
-
// return twMerge(
|
|
41
|
-
// isDisabled
|
|
42
|
-
// ? getColorClassNames(DEFAULT_COLOR, colorPalette.canvasBackground).bgColor
|
|
43
|
-
// : getColorClassNames(WHITE, colorPalette.background).bgColor,
|
|
44
|
-
// !isDisabled &&
|
|
45
|
-
// getColorClassNames(DEFAULT_COLOR, colorPalette.canvasBackground)
|
|
46
|
-
// .hoverBgColor,
|
|
47
|
-
// hasSelection
|
|
48
|
-
// ? getColorClassNames(DEFAULT_COLOR, colorPalette.darkText).textColor
|
|
49
|
-
// : getColorClassNames(DEFAULT_COLOR, colorPalette.text).textColor,
|
|
50
|
-
// isDisabled &&
|
|
51
|
-
// getColorClassNames(DEFAULT_COLOR, colorPalette.lightText).textColor,
|
|
52
|
-
// hasError && colorClassNames[BaseColors.Rose][colorPalette.text].textColor,
|
|
53
|
-
// hasError
|
|
54
|
-
// ? colorClassNames[BaseColors.Rose][colorPalette.ring].borderColor
|
|
55
|
-
// : getColorClassNames(DEFAULT_COLOR, colorPalette.ring).borderColor
|
|
56
|
-
// );
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export const hasValue = (value: string | null | undefined) =>
|
|
60
|
-
value !== null && value !== undefined && value !== '';
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Dispatch, SetStateAction, createContext } from 'react';
|
|
2
|
-
|
|
3
|
-
export interface HoveredValueContextValue {
|
|
4
|
-
hoveredValue: any | undefined;
|
|
5
|
-
setHoveredValue?: Dispatch<SetStateAction<any>>;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const HoveredValueContext = createContext<HoveredValueContextValue>({
|
|
9
|
-
hoveredValue: undefined,
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
export default HoveredValueContext;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { createContext } from 'react';
|
|
2
|
-
|
|
3
|
-
export interface SelectedValueContextValue {
|
|
4
|
-
selectedValue: any;
|
|
5
|
-
handleValueChange: ((value: any) => void) | undefined;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const SelectedValueContext = createContext<SelectedValueContextValue>({
|
|
9
|
-
selectedValue: undefined,
|
|
10
|
-
handleValueChange: undefined,
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
export default SelectedValueContext;
|
package/src/contexts/index.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { default as BaseColorContext } from './BaseColorContext';
|
|
2
|
-
export { default as HoveredValueContext } from './HoveredValueContext';
|
|
3
|
-
export { default as RootStylesContext } from './RootStylesContext';
|
|
4
|
-
export { default as SelectedValueContext } from './SelectedValueContext';
|
package/src/hooks/index.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { default as useInternalState } from "./useInternalState";
|
|
2
|
-
export { default as useOnClickOutside } from "./useOnClickOutside";
|
|
3
|
-
export { default as useOnWindowResize } from "./useOnWindowResize";
|
|
4
|
-
export { default as useSelectOnKeyDown } from "./useSelectOnKeyDown";
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
2
|
-
|
|
3
|
-
const useInternalState = <T,>(defaultValueProp: T, valueProp: T) => {
|
|
4
|
-
const isControlled = valueProp !== undefined;
|
|
5
|
-
const [valueState, setValueState] = useState(defaultValueProp);
|
|
6
|
-
|
|
7
|
-
const value = isControlled ? valueProp : valueState;
|
|
8
|
-
const setValue = (nextValue: T) => {
|
|
9
|
-
if (isControlled) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
setValueState(nextValue);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return [value, setValue] as [T, React.Dispatch<React.SetStateAction<T>>];
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export default useInternalState;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
|
-
|
|
3
|
-
const useOnClickOutside = (
|
|
4
|
-
ref: React.RefObject<HTMLDivElement>,
|
|
5
|
-
handler: { (event: any): void },
|
|
6
|
-
) => {
|
|
7
|
-
useEffect(() => {
|
|
8
|
-
const listener = (event: any) => {
|
|
9
|
-
if (!ref.current || ref.current.contains(event.target)) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
handler(event);
|
|
13
|
-
};
|
|
14
|
-
document.addEventListener("mousedown", listener);
|
|
15
|
-
document.addEventListener("touchstart", listener);
|
|
16
|
-
return () => {
|
|
17
|
-
document.removeEventListener("mousedown", listener);
|
|
18
|
-
document.removeEventListener("touchstart", listener);
|
|
19
|
-
};
|
|
20
|
-
}, [ref, handler]);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export default useOnClickOutside;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
2
|
-
|
|
3
|
-
const useOnWindowResize = (handler: { (): void }, initialWindowSize?: number) => {
|
|
4
|
-
const [windowSize, setWindowSize] = useState<undefined | number>(initialWindowSize);
|
|
5
|
-
useEffect(() => {
|
|
6
|
-
const handleResize = () => {
|
|
7
|
-
setWindowSize(window.innerWidth);
|
|
8
|
-
handler();
|
|
9
|
-
};
|
|
10
|
-
handleResize();
|
|
11
|
-
window.addEventListener("resize", handleResize);
|
|
12
|
-
|
|
13
|
-
return () => window.removeEventListener("resize", handleResize);
|
|
14
|
-
}, [handler, windowSize]);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export default useOnWindowResize;
|