@devtron-labs/devtron-fe-common-lib 0.0.51-beta-2 → 0.0.51-beta-3
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/Constants.d.ts +4 -1
- package/dist/Common/CustomInput/CustomInput.d.ts +1 -1
- package/dist/Common/CustomInput/Types.d.ts +1 -0
- package/dist/Common/EmptyState/GenericEmptyState.d.ts +1 -1
- package/dist/Common/Grid/Grid.d.ts +1 -1
- package/dist/Common/Grid/types.d.ts +2 -2
- package/dist/Common/Hooks/index.d.ts +0 -1
- package/dist/Common/index.d.ts +0 -1
- package/dist/index.js +153 -267
- package/package.json +2 -3
- package/src/Common/Constants.ts +4 -1
- package/src/Common/CustomInput/CustomInput.tsx +3 -2
- package/src/Common/CustomInput/Types.ts +1 -0
- package/src/Common/EmptyState/GenericEmptyState.tsx +37 -13
- package/src/Common/Grid/Grid.tsx +2 -7
- package/src/Common/Grid/types.ts +1 -3
- package/src/Common/Hooks/index.ts +0 -1
- package/src/Common/index.ts +0 -1
- package/dist/Common/DraggableWrapper/DraggableButton.d.ts +0 -3
- package/dist/Common/DraggableWrapper/DraggableWrapper.d.ts +0 -9
- package/dist/Common/DraggableWrapper/index.d.ts +0 -3
- package/dist/Common/DraggableWrapper/types.d.ts +0 -19
- package/dist/Common/Hooks/UseWindowSize/UseWindowSize.d.ts +0 -4
- package/src/Assets/Icon/ic-drag.svg +0 -8
- package/src/Common/DraggableWrapper/DraggableButton.tsx +0 -11
- package/src/Common/DraggableWrapper/DraggableWrapper.tsx +0 -109
- package/src/Common/DraggableWrapper/index.ts +0 -3
- package/src/Common/DraggableWrapper/types.ts +0 -22
- package/src/Common/Hooks/UseWindowSize/UseWindowSize.tsx +0 -30
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devtron-labs/devtron-fe-common-lib",
|
|
3
|
-
"version": "0.0.51-beta-
|
|
3
|
+
"version": "0.0.51-beta-3",
|
|
4
4
|
"description": "Supporting common component library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -47,8 +47,7 @@
|
|
|
47
47
|
"react": "^17.0.2",
|
|
48
48
|
"react-dom": "^17.0.2",
|
|
49
49
|
"react-router": "^5.3.0",
|
|
50
|
-
"react-router-dom": "^5.3.0"
|
|
51
|
-
"react-draggable": "^4.4.5"
|
|
50
|
+
"react-router-dom": "^5.3.0"
|
|
52
51
|
},
|
|
53
52
|
"dependencies": {
|
|
54
53
|
"fast-json-patch": "^3.1.1",
|
package/src/Common/Constants.ts
CHANGED
|
@@ -28,7 +28,8 @@ export function CustomInput({
|
|
|
28
28
|
defaultValue,
|
|
29
29
|
onKeyDown,
|
|
30
30
|
required,
|
|
31
|
-
additionalErrorInfo
|
|
31
|
+
additionalErrorInfo,
|
|
32
|
+
inputWrapClassname = '',
|
|
32
33
|
}: CustomInputProps) {
|
|
33
34
|
|
|
34
35
|
function handleError(error: any): any[] {
|
|
@@ -92,7 +93,7 @@ export function CustomInput({
|
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
return (
|
|
95
|
-
<div className=
|
|
96
|
+
<div className={`flex column left top ${inputWrapClassname}`}>
|
|
96
97
|
{renderInputLabel()}
|
|
97
98
|
<input
|
|
98
99
|
data-testid={dataTestid}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react'
|
|
1
|
+
import React from 'react'
|
|
2
2
|
import AppNotDeployed from '../../Assets/Img/app-not-deployed.png'
|
|
3
3
|
import { GenericEmptyStateType, ImageType } from '../Types'
|
|
4
4
|
|
|
@@ -19,24 +19,48 @@ function GenericEmptyState({
|
|
|
19
19
|
SvgImage,
|
|
20
20
|
noImage,
|
|
21
21
|
layout = 'column',
|
|
22
|
-
contentClassName = ''
|
|
22
|
+
contentClassName = '',
|
|
23
23
|
}: GenericEmptyStateType): JSX.Element {
|
|
24
|
-
const isRowLayout = layout === 'row'
|
|
25
|
-
|
|
24
|
+
const isRowLayout = layout === 'row'
|
|
25
|
+
|
|
26
|
+
const getImageSize = () => {
|
|
27
|
+
switch (imageType) {
|
|
28
|
+
case ImageType.Medium:
|
|
29
|
+
return { width: '200', height: '160' }
|
|
30
|
+
case ImageType.Large:
|
|
31
|
+
return { width: '250', height: '200' }
|
|
32
|
+
default:
|
|
33
|
+
return { width: '200', height: '160' }
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
26
37
|
return (
|
|
27
38
|
<div
|
|
28
|
-
className={`flex ${isRowLayout ? 'dc__gap-32' : 'column dc__gap-20'} empty-state ${
|
|
39
|
+
className={`flex ${isRowLayout ? 'dc__gap-32' : 'column dc__gap-20'} empty-state ${
|
|
40
|
+
classname ? classname : ''
|
|
41
|
+
}`}
|
|
29
42
|
style={styles}
|
|
30
43
|
data-testid="generic-empty-state"
|
|
31
44
|
{...(heightToDeduct >= 0 && { style: { ...styles, height: `calc(100vh - ${heightToDeduct}px)` } })}
|
|
32
|
-
>
|
|
33
|
-
{!SvgImage ?
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
45
|
+
>
|
|
46
|
+
{!SvgImage ? (
|
|
47
|
+
!noImage && (
|
|
48
|
+
<img
|
|
49
|
+
className={imageClassName ? imageClassName : ''}
|
|
50
|
+
src={image || AppNotDeployed}
|
|
51
|
+
width={getImageSize().width}
|
|
52
|
+
height={getImageSize().height}
|
|
53
|
+
alt="empty-state"
|
|
54
|
+
/>
|
|
55
|
+
)
|
|
56
|
+
) : (
|
|
57
|
+
<SvgImage style={{ width: `${getImageSize().width}px`, height: `${getImageSize().height}px` }} />
|
|
58
|
+
)}
|
|
59
|
+
<div
|
|
60
|
+
className={`flex column dc__gap-10 dc__mxw-300 ${
|
|
61
|
+
isRowLayout ? 'dc__align-start' : ''
|
|
62
|
+
} ${contentClassName}`}
|
|
63
|
+
>
|
|
40
64
|
<h4 className="title fw-6 cn-9 mt-0 mb-0">{title}</h4>
|
|
41
65
|
{subTitle && <p className={`subtitle ${isRowLayout ? 'subtitle--text-start' : ''}`}>{subTitle}</p>}
|
|
42
66
|
{isButtonAvailable && renderButton()}
|
package/src/Common/Grid/Grid.tsx
CHANGED
|
@@ -10,7 +10,6 @@ export default function Grid({
|
|
|
10
10
|
containerClass = '',
|
|
11
11
|
itemClass = '',
|
|
12
12
|
children,
|
|
13
|
-
...containerDivProps
|
|
14
13
|
}: GridProps) {
|
|
15
14
|
const containerStyles = container ? { gap: spacing + 'px' } : {}
|
|
16
15
|
|
|
@@ -26,18 +25,14 @@ export default function Grid({
|
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
return (
|
|
29
|
-
<div className={`p-0 ${itemClass}`} style={itemStyles}
|
|
28
|
+
<div className={`p-0 ${itemClass}`} style={itemStyles}>
|
|
30
29
|
{children}
|
|
31
30
|
</div>
|
|
32
31
|
)
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
return (
|
|
36
|
-
<div
|
|
37
|
-
className={`flex-wrap flexbox ${container ? containerClass : ''}`}
|
|
38
|
-
style={containerStyles}
|
|
39
|
-
{...containerDivProps}
|
|
40
|
-
>
|
|
35
|
+
<div className={`flex-wrap flexbox ${container ? containerClass : ''}`} style={containerStyles}>
|
|
41
36
|
{children}
|
|
42
37
|
</div>
|
|
43
38
|
)
|
package/src/Common/Grid/types.ts
CHANGED
package/src/Common/index.ts
CHANGED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { DraggableWrapperProps } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* TODO: import it as lazy, after it is supported in common
|
|
5
|
-
* 1. If using react select please use menuPlacement='auto'
|
|
6
|
-
* 2. dragClassName will be used to identify the grabbable button that will grab the div to drag
|
|
7
|
-
* 3. parentRef is the reference point from which we will derive the base top:0 ,left: 0 position
|
|
8
|
-
*/
|
|
9
|
-
export default function DraggableWrapper({ children, zIndex, positionVariant, dragClassName, parentRef, boundaryGap, childDivProps, }: DraggableWrapperProps): JSX.Element;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { HTMLAttributes } from 'react';
|
|
2
|
-
export declare enum DraggablePositionVariant {
|
|
3
|
-
PARENT_BOTTOM_CENTER = "PARENT_BOTTOM_CENTER",
|
|
4
|
-
SCREEN_BOTTOM_CENTER = "SCREEN_BOTTOM_CENTER"
|
|
5
|
-
}
|
|
6
|
-
export interface DraggableWrapperProps {
|
|
7
|
-
children: React.ReactNode;
|
|
8
|
-
zIndex?: number;
|
|
9
|
-
positionVariant?: DraggablePositionVariant;
|
|
10
|
-
dragClassName: string;
|
|
11
|
-
parentRef?: React.RefObject<HTMLDivElement>;
|
|
12
|
-
boundaryGap?: number;
|
|
13
|
-
childDivProps?: HTMLAttributes<HTMLDivElement>;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* dragClassName is the class that we feed to Draggable to identify dragging buttons
|
|
17
|
-
*/
|
|
18
|
-
export interface DraggableButtonProps extends Pick<DraggableWrapperProps, 'dragClassName'> {
|
|
19
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
-
<path d="M10.3335 9.33325C10.8858 9.33325 11.3335 8.88554 11.3335 8.33325C11.3335 7.78097 10.8858 7.33325 10.3335 7.33325C9.78121 7.33325 9.3335 7.78097 9.3335 8.33325C9.3335 8.88554 9.78121 9.33325 10.3335 9.33325Z" fill="#596168"/>
|
|
3
|
-
<path d="M5.66675 9.33325C6.21903 9.33325 6.66675 8.88554 6.66675 8.33325C6.66675 7.78097 6.21903 7.33325 5.66675 7.33325C5.11446 7.33325 4.66675 7.78097 4.66675 8.33325C4.66675 8.88554 5.11446 9.33325 5.66675 9.33325Z" fill="#596168"/>
|
|
4
|
-
<path d="M10.3335 5.33325C10.8858 5.33325 11.3335 4.88554 11.3335 4.33325C11.3335 3.78097 10.8858 3.33325 10.3335 3.33325C9.78121 3.33325 9.3335 3.78097 9.3335 4.33325C9.3335 4.88554 9.78121 5.33325 10.3335 5.33325Z" fill="#596168"/>
|
|
5
|
-
<path d="M5.66675 5.33325C6.21903 5.33325 6.66675 4.88554 6.66675 4.33325C6.66675 3.78097 6.21903 3.33325 5.66675 3.33325C5.11446 3.33325 4.66675 3.78097 4.66675 4.33325C4.66675 4.88554 5.11446 5.33325 5.66675 5.33325Z" fill="#596168"/>
|
|
6
|
-
<path d="M10.3335 13.3333C10.8858 13.3333 11.3335 12.8855 11.3335 12.3333C11.3335 11.781 10.8858 11.3333 10.3335 11.3333C9.78121 11.3333 9.3335 11.781 9.3335 12.3333C9.3335 12.8855 9.78121 13.3333 10.3335 13.3333Z" fill="#596168"/>
|
|
7
|
-
<path d="M5.66675 13.3333C6.21903 13.3333 6.66675 12.8855 6.66675 12.3333C6.66675 11.781 6.21903 11.3333 5.66675 11.3333C5.11446 11.3333 4.66675 11.781 4.66675 12.3333C4.66675 12.8855 5.11446 13.3333 5.66675 13.3333Z" fill="#596168"/>
|
|
8
|
-
</svg>
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { ReactComponent as ICDrag } from '../../Assets/Icon/ic-drag.svg'
|
|
3
|
-
import { DraggableButtonProps } from './types'
|
|
4
|
-
|
|
5
|
-
export default function DraggableButton({ dragClassName }: DraggableButtonProps) {
|
|
6
|
-
return (
|
|
7
|
-
<button type="button" className="dc__outline-none-imp dc__no-border p-0 dc__transparent h-20">
|
|
8
|
-
<ICDrag className={`${dragClassName} dc__grabbable icon-dim-20 fcn-6`} />
|
|
9
|
-
</button>
|
|
10
|
-
)
|
|
11
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useRef, useState } from 'react'
|
|
2
|
-
import Draggable, { ControlPosition, DraggableData } from 'react-draggable'
|
|
3
|
-
import { DraggableWrapperProps, DraggablePositionVariant } from './types'
|
|
4
|
-
import { useWindowSize } from '../Hooks'
|
|
5
|
-
import { MAX_Z_INDEX } from '../Constants'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* TODO: import it as lazy, after it is supported in common
|
|
9
|
-
* 1. If using react select please use menuPlacement='auto'
|
|
10
|
-
* 2. dragClassName will be used to identify the grabbable button that will grab the div to drag
|
|
11
|
-
* 3. parentRef is the reference point from which we will derive the base top:0 ,left: 0 position
|
|
12
|
-
*/
|
|
13
|
-
export default function DraggableWrapper({
|
|
14
|
-
children,
|
|
15
|
-
zIndex = MAX_Z_INDEX,
|
|
16
|
-
positionVariant,
|
|
17
|
-
dragClassName,
|
|
18
|
-
parentRef,
|
|
19
|
-
boundaryGap = 16,
|
|
20
|
-
childDivProps = {},
|
|
21
|
-
}: DraggableWrapperProps) {
|
|
22
|
-
const windowSize = useWindowSize()
|
|
23
|
-
const nodeRef = useRef<HTMLDivElement>(null)
|
|
24
|
-
|
|
25
|
-
const getDefaultPosition = (positionVariant: DraggablePositionVariant): ControlPosition => {
|
|
26
|
-
// if i return x: 0, y: 0 then it will be top left corner of parentDiv
|
|
27
|
-
const parentRect = parentRef?.current?.getBoundingClientRect() ?? {
|
|
28
|
-
width: 0,
|
|
29
|
-
height: 0,
|
|
30
|
-
top: 0,
|
|
31
|
-
left: 0,
|
|
32
|
-
bottom: 0,
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
switch (positionVariant) {
|
|
36
|
-
case DraggablePositionVariant.PARENT_BOTTOM_CENTER: {
|
|
37
|
-
const x = parentRect.width / 2 - nodeRef.current?.getBoundingClientRect().width / 2
|
|
38
|
-
const y =
|
|
39
|
-
Math.min(parentRect.height, windowSize.height) -
|
|
40
|
-
parentRect.top -
|
|
41
|
-
nodeRef.current?.getBoundingClientRect().height -
|
|
42
|
-
boundaryGap
|
|
43
|
-
return { x, y }
|
|
44
|
-
}
|
|
45
|
-
case DraggablePositionVariant.SCREEN_BOTTOM_CENTER: {
|
|
46
|
-
const x = windowSize.width / 2 - parentRect.left - nodeRef.current?.getBoundingClientRect().width / 2
|
|
47
|
-
const y =
|
|
48
|
-
windowSize.height - parentRect.top - nodeRef.current?.getBoundingClientRect().height - boundaryGap
|
|
49
|
-
|
|
50
|
-
return { x, y }
|
|
51
|
-
}
|
|
52
|
-
// Add more cases for other variants if needed
|
|
53
|
-
default:
|
|
54
|
-
throw new Error('Please use DraggablePositionVariant enum')
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const [position, setPosition] = useState<ControlPosition>({
|
|
59
|
-
x: 0,
|
|
60
|
-
y: 0,
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
// On change of windowSize we will reset the position to default
|
|
64
|
-
useEffect(() => {
|
|
65
|
-
const defaultPosition = getDefaultPosition(positionVariant)
|
|
66
|
-
setPosition(defaultPosition)
|
|
67
|
-
}, [nodeRef, positionVariant, windowSize])
|
|
68
|
-
|
|
69
|
-
function handlePositionChange(e, data: DraggableData) {
|
|
70
|
-
const offsetX = parentRef?.current?.getBoundingClientRect().left ?? 0
|
|
71
|
-
const offsetY = parentRef?.current?.getBoundingClientRect().top ?? 0
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
offsetX + data.x + nodeRef.current?.getBoundingClientRect().width + boundaryGap > windowSize.width ||
|
|
75
|
-
offsetY + data.y + nodeRef.current?.getBoundingClientRect().height + boundaryGap > windowSize.height ||
|
|
76
|
-
offsetX + data.x < 0 ||
|
|
77
|
-
offsetY + data.y < 0
|
|
78
|
-
) {
|
|
79
|
-
return
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
setPosition({
|
|
83
|
-
x: data.x,
|
|
84
|
-
y: data.y,
|
|
85
|
-
})
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return (
|
|
89
|
-
// Check there might be a case if we need it to be absolute?
|
|
90
|
-
<div
|
|
91
|
-
className="dc__position-fixed"
|
|
92
|
-
style={{
|
|
93
|
-
zIndex,
|
|
94
|
-
}}
|
|
95
|
-
>
|
|
96
|
-
<Draggable handle={`.${dragClassName}`} nodeRef={nodeRef} position={position} onDrag={handlePositionChange}>
|
|
97
|
-
<div
|
|
98
|
-
ref={nodeRef}
|
|
99
|
-
{...childDivProps}
|
|
100
|
-
style={{
|
|
101
|
-
zIndex,
|
|
102
|
-
}}
|
|
103
|
-
>
|
|
104
|
-
{children}
|
|
105
|
-
</div>
|
|
106
|
-
</Draggable>
|
|
107
|
-
</div>
|
|
108
|
-
)
|
|
109
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { HTMLAttributes } from 'react'
|
|
2
|
-
|
|
3
|
-
export enum DraggablePositionVariant {
|
|
4
|
-
PARENT_BOTTOM_CENTER = 'PARENT_BOTTOM_CENTER',
|
|
5
|
-
SCREEN_BOTTOM_CENTER = 'SCREEN_BOTTOM_CENTER',
|
|
6
|
-
// Can add more based on requirement
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface DraggableWrapperProps {
|
|
10
|
-
children: React.ReactNode
|
|
11
|
-
zIndex?: number
|
|
12
|
-
positionVariant?: DraggablePositionVariant
|
|
13
|
-
dragClassName: string
|
|
14
|
-
parentRef?: React.RefObject<HTMLDivElement>
|
|
15
|
-
boundaryGap?: number
|
|
16
|
-
childDivProps?: HTMLAttributes<HTMLDivElement>
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* dragClassName is the class that we feed to Draggable to identify dragging buttons
|
|
21
|
-
*/
|
|
22
|
-
export interface DraggableButtonProps extends Pick<DraggableWrapperProps, 'dragClassName'> {}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react'
|
|
2
|
-
|
|
3
|
-
function getSize() {
|
|
4
|
-
return {
|
|
5
|
-
width: window.innerWidth,
|
|
6
|
-
height: window.innerHeight,
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function useWindowSize() {
|
|
11
|
-
let timeout
|
|
12
|
-
const [windowSize, setWindowSize] = useState(getSize)
|
|
13
|
-
|
|
14
|
-
function handleResize(e) {
|
|
15
|
-
if (timeout) {
|
|
16
|
-
window.cancelAnimationFrame(timeout)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
timeout = window.requestAnimationFrame(function () {
|
|
20
|
-
setWindowSize(getSize())
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
window.addEventListener('resize', handleResize, false)
|
|
26
|
-
return () => window.removeEventListener('resize', handleResize, false)
|
|
27
|
-
}, [])
|
|
28
|
-
|
|
29
|
-
return windowSize
|
|
30
|
-
}
|