@devtron-labs/devtron-fe-common-lib 0.0.6-beta-20 → 0.0.6-beta-22
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/dist/Common/Checkbox.d.ts +18 -0
- package/dist/Common/Constants.d.ts +16 -0
- package/dist/Common/CustomTagSelector/PropagateTagInfo.d.ts +3 -1
- package/dist/Common/CustomTagSelector/ResizableTagTextArea.d.ts +3 -0
- package/dist/Common/CustomTagSelector/TagDetails.d.ts +1 -1
- package/dist/Common/CustomTagSelector/TagLabelSelect.d.ts +1 -1
- package/dist/Common/CustomTagSelector/TagLabelValueSelector.d.ts +1 -1
- package/dist/Common/Error.d.ts +5 -3
- package/dist/Common/Helper.d.ts +2 -0
- package/dist/Common/Modals/Modal.d.ts +2 -1
- package/dist/Common/PopupMenu.d.ts +5 -3
- package/dist/Common/Types.d.ts +33 -8
- package/dist/Common/index.d.ts +1 -0
- package/dist/index.js +224 -70
- package/package.json +1 -1
- package/src/Assets/Icon/ic-cross.svg +3 -0
- package/src/Common/Checkbox.tsx +49 -0
- package/src/Common/Constants.ts +14 -1
- package/src/Common/CustomTagSelector/PropagateTagInfo.tsx +16 -7
- package/src/Common/CustomTagSelector/ResizableTagTextArea.tsx +74 -0
- package/src/Common/CustomTagSelector/TagDetails.tsx +19 -7
- package/src/Common/CustomTagSelector/TagLabelSelect.tsx +5 -3
- package/src/Common/CustomTagSelector/TagLabelValueSelector.tsx +49 -30
- package/src/Common/Error.tsx +12 -4
- package/src/Common/Helper.tsx +23 -0
- package/src/Common/Modals/Modal.tsx +39 -30
- package/src/Common/PopupMenu.tsx +114 -63
- package/src/Common/TippyCustomized.tsx +2 -2
- package/src/Common/Types.ts +42 -18
- package/src/Common/index.ts +2 -1
package/src/Common/PopupMenu.tsx
CHANGED
|
@@ -3,126 +3,177 @@ import {Modal} from './Modals/Modal';
|
|
|
3
3
|
const PopupContext = React.createContext(null);
|
|
4
4
|
|
|
5
5
|
function usePopupContext() {
|
|
6
|
-
const context = React.useContext(PopupContext)
|
|
6
|
+
const context = React.useContext(PopupContext)
|
|
7
7
|
if (!context) {
|
|
8
|
-
throw new Error(
|
|
9
|
-
`Select compound components cannot be rendered outside popupmenup`,
|
|
10
|
-
)
|
|
8
|
+
throw new Error(`Select compound components cannot be rendered outside popupmenup`)
|
|
11
9
|
}
|
|
12
10
|
return context
|
|
13
11
|
}
|
|
14
12
|
|
|
15
|
-
function PopupMenu({ children = null, onToggleCallback = null, autoClose = false}) {
|
|
16
|
-
const [popupPosition, setPopupPosition]=React.useState(null)
|
|
13
|
+
function PopupMenu({ children = null, onToggleCallback = null, autoClose = false, autoPosition = false }) {
|
|
14
|
+
const [popupPosition, setPopupPosition] = React.useState(null)
|
|
17
15
|
const [opacity, setOpacity] = React.useState(0)
|
|
18
|
-
const observer = React.useRef<IntersectionObserver | null>(null)
|
|
19
|
-
const buttonRef = React.useRef(null)
|
|
20
|
-
const buttonWidth = React.useRef(null)
|
|
16
|
+
const observer = React.useRef<IntersectionObserver | null>(null)
|
|
17
|
+
const buttonRef = React.useRef(null)
|
|
18
|
+
const buttonWidth = React.useRef(null)
|
|
21
19
|
|
|
22
|
-
React.useEffect(()=>{
|
|
20
|
+
React.useEffect(() => {
|
|
23
21
|
observer.current = window.IntersectionObserver ? new IntersectionObserver(intersectionCallback, options) : null
|
|
24
|
-
return ()=>{
|
|
25
|
-
if(observer && observer.current && observer.current.disconnect) observer.current.disconnect()
|
|
22
|
+
return () => {
|
|
23
|
+
if (observer && observer.current && observer.current.disconnect) observer.current.disconnect()
|
|
26
24
|
}
|
|
27
|
-
},[])
|
|
25
|
+
}, [])
|
|
28
26
|
|
|
29
27
|
useEffect(() => {
|
|
30
28
|
if (typeof onToggleCallback === 'function') {
|
|
31
29
|
if (popupPosition) {
|
|
32
30
|
onToggleCallback(true)
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
31
|
+
} else {
|
|
35
32
|
onToggleCallback(false)
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
35
|
}, [popupPosition])
|
|
39
36
|
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (buttonRef?.current && autoPosition && popupPosition) {
|
|
39
|
+
const { height, x, y } = buttonRef.current.getBoundingClientRect()
|
|
40
|
+
setPopupPosition({ left: x, top: y + height })
|
|
41
|
+
}
|
|
42
|
+
}, [buttonRef?.current?.clientHeight])
|
|
43
|
+
|
|
40
44
|
let options = {
|
|
41
45
|
root: null,
|
|
42
46
|
rootMargin: '0px',
|
|
43
|
-
threshold: 1.0
|
|
47
|
+
threshold: 1.0,
|
|
44
48
|
}
|
|
45
49
|
|
|
46
|
-
if(!children) return children
|
|
50
|
+
if (!children) return children
|
|
47
51
|
|
|
48
52
|
function intersectionCallback(entries, observer) {
|
|
49
|
-
entries.forEach(entry => {
|
|
53
|
+
entries.forEach((entry) => {
|
|
50
54
|
if (entry.isIntersecting && entry.intersectionRatio >= 1) {
|
|
51
55
|
setOpacity(1)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const {
|
|
55
|
-
const {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
} else {
|
|
57
|
+
const { boundingClientRect, rootBounds } = entry
|
|
58
|
+
const { x, y, height, width } = boundingClientRect
|
|
59
|
+
const {
|
|
60
|
+
x: buttonX,
|
|
61
|
+
y: buttonY,
|
|
62
|
+
height: buttonHeight,
|
|
63
|
+
width: buttonWidth,
|
|
64
|
+
left: buttonLeft,
|
|
65
|
+
right: buttonRight,
|
|
66
|
+
top: buttonTop,
|
|
67
|
+
bottom: buttonBottom,
|
|
68
|
+
} = buttonRef.current.getBoundingClientRect()
|
|
69
|
+
if (y + height > rootBounds.height) {
|
|
70
|
+
setPopupPosition({ left: buttonX, bottom: document.documentElement.clientHeight - buttonY })
|
|
59
71
|
setOpacity(1)
|
|
60
72
|
}
|
|
61
|
-
if(x + width > rootBounds.width){
|
|
73
|
+
if (x + width > rootBounds.width) {
|
|
62
74
|
// setPopupPosition(position => ({ right: document.documentElement.clientWidth - buttonLeft,...position, left:'unset' }))
|
|
63
|
-
setPopupPosition(position=>({...position, right: '20px', left:'unset'}))
|
|
75
|
+
setPopupPosition((position) => ({ ...position, right: '20px', left: 'unset' }))
|
|
64
76
|
setOpacity(1)
|
|
65
77
|
}
|
|
66
78
|
}
|
|
67
|
-
})
|
|
79
|
+
})
|
|
68
80
|
}
|
|
69
81
|
|
|
70
|
-
const handleOpen = (e)=>{
|
|
71
|
-
e.stopPropagation()
|
|
82
|
+
const handleOpen = (e) => {
|
|
83
|
+
e.stopPropagation()
|
|
72
84
|
setOpacity(0)
|
|
73
|
-
const {
|
|
74
|
-
setPopupPosition({left: x, top: y + height})
|
|
85
|
+
const { height, x, y } = e.currentTarget.getBoundingClientRect()
|
|
86
|
+
setPopupPosition({ left: x, top: y + height })
|
|
75
87
|
}
|
|
76
88
|
|
|
77
|
-
const handleClose = (e, inOrOut) =>{
|
|
78
|
-
if(autoClose || inOrOut === 'out'){
|
|
79
|
-
if(observer && observer.current && observer.current.disconnect) observer.current.disconnect()
|
|
89
|
+
const handleClose = (e, inOrOut) => {
|
|
90
|
+
if (autoClose || inOrOut === 'out') {
|
|
91
|
+
if (observer && observer.current && observer.current.disconnect) observer.current.disconnect()
|
|
80
92
|
setOpacity(0)
|
|
81
93
|
setPopupPosition(null)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
e.stopPropagation();
|
|
94
|
+
} else {
|
|
95
|
+
e.stopPropagation()
|
|
85
96
|
}
|
|
86
97
|
}
|
|
87
98
|
|
|
88
|
-
|
|
89
99
|
function callbackRef(element) {
|
|
90
|
-
if (element && observer?.current?.observe){
|
|
100
|
+
if (element && observer?.current?.observe) {
|
|
91
101
|
observer.current.observe(element)
|
|
92
|
-
}
|
|
93
|
-
else observer.current.disconnect();
|
|
102
|
+
} else observer.current.disconnect()
|
|
94
103
|
}
|
|
95
104
|
|
|
96
|
-
function initialiseButtonWidth(buttonEl){
|
|
97
|
-
if(!buttonEl) return
|
|
105
|
+
function initialiseButtonWidth(buttonEl) {
|
|
106
|
+
if (!buttonEl) return
|
|
98
107
|
buttonRef.current = buttonEl
|
|
99
108
|
const { bottom, height, left, right, top, width, x, y } = buttonEl.getBoundingClientRect()
|
|
100
|
-
buttonWidth.current=width
|
|
109
|
+
buttonWidth.current = width
|
|
101
110
|
}
|
|
102
111
|
|
|
103
|
-
return
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
112
|
+
return (
|
|
113
|
+
<PopupContext.Provider
|
|
114
|
+
value={{
|
|
115
|
+
handleOpen,
|
|
116
|
+
popupPosition,
|
|
117
|
+
handleClose,
|
|
118
|
+
opacity,
|
|
119
|
+
setPopupPosition,
|
|
120
|
+
callbackRef,
|
|
121
|
+
buttonRef,
|
|
122
|
+
initialiseButtonWidth,
|
|
123
|
+
buttonWidth,
|
|
124
|
+
}}
|
|
125
|
+
>
|
|
126
|
+
{children}
|
|
127
|
+
</PopupContext.Provider>
|
|
128
|
+
)
|
|
107
129
|
}
|
|
108
130
|
|
|
109
|
-
function Button({
|
|
131
|
+
function Button({
|
|
132
|
+
children = null,
|
|
133
|
+
disabled = false,
|
|
134
|
+
rootClassName = '',
|
|
135
|
+
tabIndex = 0,
|
|
136
|
+
onHover = false,
|
|
137
|
+
isKebab = false,
|
|
138
|
+
}) {
|
|
110
139
|
const { handleOpen, popupPosition, buttonRef, initialiseButtonWidth } = usePopupContext()
|
|
111
|
-
return
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
140
|
+
return (
|
|
141
|
+
<button
|
|
142
|
+
ref={initialiseButtonWidth}
|
|
143
|
+
type="button"
|
|
144
|
+
tabIndex={tabIndex}
|
|
145
|
+
disabled={disabled}
|
|
146
|
+
className={`${rootClassName} ${popupPosition ? 'focused' : ''} ${
|
|
147
|
+
isKebab ? 'popup-button-kebab' : 'popup-button'
|
|
148
|
+
}`}
|
|
149
|
+
onMouseEnter={onHover ? (disabled ? null : handleOpen) : () => {}}
|
|
150
|
+
onClick={disabled ? null : handleOpen}
|
|
151
|
+
>
|
|
152
|
+
{children}
|
|
153
|
+
</button>
|
|
154
|
+
)
|
|
119
155
|
}
|
|
120
156
|
|
|
121
|
-
function Body({children=null, rootClassName=
|
|
122
|
-
const {handleClose, popupPosition, opacity, callbackRef, buttonWidth} = usePopupContext()
|
|
123
|
-
return popupPosition ?
|
|
124
|
-
|
|
125
|
-
|
|
157
|
+
function Body({ children = null, rootClassName = '', style = {}, autoWidth = false, preventWheelDisable = false }) {
|
|
158
|
+
const { handleClose, popupPosition, opacity, callbackRef, buttonWidth } = usePopupContext()
|
|
159
|
+
return popupPosition ? (
|
|
160
|
+
<Modal
|
|
161
|
+
callbackRef={callbackRef}
|
|
162
|
+
onClick={handleClose}
|
|
163
|
+
rootClassName={`${rootClassName} popup-body ${!children ? 'popup-body--empty' : ''} ${Object.keys(
|
|
164
|
+
popupPosition,
|
|
165
|
+
).join(' ')}`}
|
|
166
|
+
style={{
|
|
167
|
+
...popupPosition,
|
|
168
|
+
...style,
|
|
169
|
+
...(autoWidth ? { width: buttonWidth.current } : {}),
|
|
170
|
+
opacity: opacity,
|
|
171
|
+
}}
|
|
172
|
+
preventWheelDisable={preventWheelDisable}
|
|
173
|
+
>
|
|
174
|
+
{children}
|
|
175
|
+
</Modal>
|
|
176
|
+
) : null
|
|
126
177
|
}
|
|
127
178
|
|
|
128
179
|
PopupMenu.Button = Button
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { ReactNode, useRef } from 'react'
|
|
2
2
|
import Tippy from '@tippyjs/react'
|
|
3
3
|
import { Placement } from 'tippy.js'
|
|
4
|
-
import { ReactComponent as CloseIcon } from '../Assets/Icon/ic-
|
|
4
|
+
import { ReactComponent as CloseIcon } from '../Assets/Icon/ic-cross.svg'
|
|
5
5
|
import 'tippy.js/animations/shift-toward-subtle.css'
|
|
6
6
|
import { TippyTheme } from './Types'
|
|
7
7
|
|
|
@@ -133,7 +133,7 @@ export function TippyCustomized(props: TippyCustomizedProps) {
|
|
|
133
133
|
href={documentationLink}
|
|
134
134
|
target="_blank"
|
|
135
135
|
rel="noreferrer noopener"
|
|
136
|
-
className="cb-5"
|
|
136
|
+
className="fs-13 cb-5"
|
|
137
137
|
onClick={closeTippy}
|
|
138
138
|
>
|
|
139
139
|
{documentationLinkText || 'Learn more'}
|
package/src/Common/Types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { KEY_VALUE } from './Constants'
|
|
2
2
|
|
|
3
3
|
export interface ResponseType {
|
|
4
4
|
code: number
|
|
@@ -13,16 +13,6 @@ export interface APIOptions {
|
|
|
13
13
|
preventAutoLogout?: boolean
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export interface TagType {
|
|
17
|
-
key: string
|
|
18
|
-
value?: string
|
|
19
|
-
description?: string
|
|
20
|
-
propagate: boolean
|
|
21
|
-
mandatoryProjectIdsCsv?: string[]
|
|
22
|
-
isInvalidKey?: boolean
|
|
23
|
-
isInvalidValue?: boolean
|
|
24
|
-
}
|
|
25
|
-
|
|
26
16
|
export interface OptionType {
|
|
27
17
|
label: string
|
|
28
18
|
value: string
|
|
@@ -33,16 +23,33 @@ export enum TippyTheme {
|
|
|
33
23
|
white = 'white',
|
|
34
24
|
}
|
|
35
25
|
|
|
26
|
+
export interface TagType {
|
|
27
|
+
key: string
|
|
28
|
+
value?: string
|
|
29
|
+
description?: string
|
|
30
|
+
propagate: boolean
|
|
31
|
+
mandatoryProjectIdsCsv?: string[]
|
|
32
|
+
isInvalidKey?: boolean
|
|
33
|
+
isInvalidValue?: boolean
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface TagErrorType {
|
|
37
|
+
isValid: boolean
|
|
38
|
+
messages: string[]
|
|
39
|
+
}
|
|
36
40
|
export interface TagLabelSelectType {
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
isCreateApp?: boolean
|
|
42
|
+
labelTags: TagType[]
|
|
43
|
+
setLabelTags: (tagList: TagType[]) => void
|
|
44
|
+
tabIndex?: number
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
export interface TagDetailType {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
index: number
|
|
49
|
+
tagData: TagType
|
|
50
|
+
setTagData: (index: number, tagData: TagType) => void
|
|
51
|
+
removeTag: (index: number) => void
|
|
52
|
+
tabIndex?: number
|
|
46
53
|
}
|
|
47
54
|
|
|
48
55
|
export interface TagLabelValueSelectorType {
|
|
@@ -51,8 +58,25 @@ export interface TagLabelValueSelectorType {
|
|
|
51
58
|
setTagData: (index: number, tagData: TagType) => void
|
|
52
59
|
tagOptions?: OptionType[]
|
|
53
60
|
isRequired?: boolean
|
|
54
|
-
|
|
61
|
+
tagInputType?: KEY_VALUE
|
|
62
|
+
placeholder?: string
|
|
63
|
+
tabIndex?: number
|
|
64
|
+
refVar?: React.MutableRefObject<HTMLTextAreaElement>
|
|
65
|
+
dependentRef?: React.MutableRefObject<HTMLTextAreaElement>
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface ResizableTagTextAreaProps {
|
|
69
|
+
className?: string
|
|
70
|
+
minHeight?: number
|
|
71
|
+
maxHeight?: number
|
|
72
|
+
value?: string
|
|
73
|
+
onChange?: (e) => void
|
|
74
|
+
onBlur?: (e) => void
|
|
75
|
+
onFocus?: (e) => void
|
|
55
76
|
placeholder?: string
|
|
77
|
+
tabIndex?: number
|
|
78
|
+
refVar?: React.MutableRefObject<HTMLTextAreaElement>
|
|
79
|
+
dependentRef?: React.MutableRefObject<HTMLTextAreaElement>
|
|
56
80
|
}
|
|
57
81
|
|
|
58
82
|
export interface TeamList extends ResponseType {
|
package/src/Common/index.ts
CHANGED
|
@@ -22,4 +22,5 @@ export * from './CustomTagSelector'
|
|
|
22
22
|
export * from './Dialogs'
|
|
23
23
|
export * from './MultiSelectCustomization'
|
|
24
24
|
export {default as InfoColourBar} from './InfoColorBar/InfoColourbar'
|
|
25
|
-
export * from './Common.service'
|
|
25
|
+
export * from './Common.service'
|
|
26
|
+
export * from './Checkbox'
|