@devtron-labs/devtron-fe-common-lib 0.0.52 → 0.0.53-beta-2
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/.eslintignore +96 -0
- package/.eslintrc.js +84 -16
- package/.github/pull_request_template.md +25 -0
- package/.github/workflows/ci.yml +31 -0
- package/.github/workflows/release-package.yml +2 -3
- package/.husky/pre-commit +5 -0
- package/.lintstagedrc +3 -0
- package/.nvmrc +1 -0
- package/dist/Common/DebouncedSearch/DebouncedSearch.d.ts +2 -0
- package/dist/Common/Helper.d.ts +4 -0
- package/dist/Common/SearchBar/SearchBar.component.d.ts +8 -0
- package/dist/Common/SearchBar/types.d.ts +35 -0
- package/dist/Common/index.d.ts +1 -0
- package/dist/index.js +269 -183
- package/package.json +19 -2
- package/src/Assets/Icon/ic-search.svg +6 -0
- package/src/Common/DebouncedSearch/DebouncedSearch.tsx +2 -0
- package/src/Common/Helper.tsx +15 -0
- package/src/Common/SearchBar/SearchBar.component.tsx +79 -0
- package/src/Common/SearchBar/searchBar.scss +65 -0
- package/src/Common/SearchBar/types.ts +36 -0
- package/src/Common/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devtron-labs/devtron-fe-common-lib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.53-beta-2",
|
|
4
4
|
"description": "Supporting common component library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
+
"prepare": "node -e \"try { require('husky').install() } catch (e) {}\"",
|
|
8
|
+
"lint": "tsc --noEmit && eslint 'src/**/*.{js,jsx,ts,tsx}' --max-warnings 0",
|
|
9
|
+
"lint-fix": "eslint 'src/**/*.{js,jsx,ts,tsx}' --fix",
|
|
7
10
|
"test": "exit 0",
|
|
8
11
|
"build-lib": "rollup -c --bundleConfigAsCjs",
|
|
9
|
-
"build-watch": "rollup -c --bundleConfigAsCjs -w"
|
|
12
|
+
"build-watch": "rollup -c --bundleConfigAsCjs -w",
|
|
13
|
+
"lint-staged": "lint-staged"
|
|
10
14
|
},
|
|
11
15
|
"repository": {
|
|
12
16
|
"type": "git",
|
|
@@ -30,7 +34,20 @@
|
|
|
30
34
|
"@types/react": "17.0.39",
|
|
31
35
|
"@types/react-dom": "17.0.13",
|
|
32
36
|
"@types/react-router-dom": "^5.3.3",
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "^6.17.0",
|
|
38
|
+
"@typescript-eslint/parser": "^6.17.0",
|
|
39
|
+
"eslint": "^8.56.0",
|
|
40
|
+
"eslint-config-airbnb": "^19.0.4",
|
|
41
|
+
"eslint-config-prettier": "^9.1.0",
|
|
42
|
+
"eslint-plugin-import": "^2.29.1",
|
|
43
|
+
"eslint-plugin-jsx-a11y": "^6.8.0",
|
|
44
|
+
"eslint-plugin-prettier": "^5.1.2",
|
|
45
|
+
"eslint-plugin-react": "^7.33.2",
|
|
46
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
47
|
+
"husky": "^7.0.4",
|
|
48
|
+
"lint-staged": "^12.5.0",
|
|
33
49
|
"moment": "^2.29.4",
|
|
50
|
+
"prettier": "^3.1.1",
|
|
34
51
|
"react-select": "5.2.2",
|
|
35
52
|
"react-toastify": "^8.2.0",
|
|
36
53
|
"rollup": "^3.10.0",
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
|
2
|
+
<g fill="none" fill-rule="evenodd">
|
|
3
|
+
<path d="M0 0h24v24H0z"/>
|
|
4
|
+
<path fill="#959BA1" d="M10 2a8 8 0 0 1 6.32 12.905l5.044 5.045a1 1 0 1 1-1.414 1.414l-5.045-5.043A8 8 0 1 1 10 2zm0 2a6 6 0 1 0 0 12 6 6 0 0 0 0-12z"/>
|
|
5
|
+
</g>
|
|
6
|
+
</svg>
|
|
@@ -4,6 +4,8 @@ import { ReactComponent as ICClear } from '../../Assets/Icon/ic-error-cross.svg'
|
|
|
4
4
|
import { DebouncedSearchProps } from './Types'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
+
* @deprecated Use `SearchBar` component instead.
|
|
8
|
+
*
|
|
7
9
|
* @param onSearch - Callback function to be called on search
|
|
8
10
|
* @param Icon - (Optional) Icon to be shown before the input
|
|
9
11
|
* @param iconClass - (Optional) Class for the icon
|
package/src/Common/Helper.tsx
CHANGED
|
@@ -559,3 +559,18 @@ export function getLockedJSON(json, jsonPathArray: string[]) {
|
|
|
559
559
|
return resultJson['$']
|
|
560
560
|
}
|
|
561
561
|
|
|
562
|
+
/**
|
|
563
|
+
* Returns a debounced variant of the function
|
|
564
|
+
*/
|
|
565
|
+
export const debounce = (func, timeout = 500) => {
|
|
566
|
+
let timer
|
|
567
|
+
|
|
568
|
+
return function (this, ...args) {
|
|
569
|
+
const context = this
|
|
570
|
+
if (timer) clearTimeout(timer)
|
|
571
|
+
timer = setTimeout(() => {
|
|
572
|
+
timer = null
|
|
573
|
+
func.apply(context, args)
|
|
574
|
+
}, timeout)
|
|
575
|
+
}
|
|
576
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ChangeEvent, FunctionComponent, useCallback, useState } from 'react'
|
|
2
|
+
import { ReactComponent as Search } from '../../Assets/Icon/ic-search.svg'
|
|
3
|
+
import { ReactComponent as Clear } from '../../Assets/Icon/ic-error-cross.svg'
|
|
4
|
+
import { SearchBarProps } from './types'
|
|
5
|
+
import './searchBar.scss'
|
|
6
|
+
import { debounce, noop } from '../Helper'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Generic search input component with support for enter based and debounced search
|
|
10
|
+
*/
|
|
11
|
+
const SearchBar: FunctionComponent<SearchBarProps> = ({
|
|
12
|
+
initialSearchText = '',
|
|
13
|
+
handleSearchChange = noop,
|
|
14
|
+
handleEnter = noop,
|
|
15
|
+
inputProps = {},
|
|
16
|
+
containerClassName,
|
|
17
|
+
shouldDebounce = false,
|
|
18
|
+
debounceTimeout = 300,
|
|
19
|
+
}) => {
|
|
20
|
+
const [isSearchApplied, setIsSearchApplied] = useState(!!initialSearchText)
|
|
21
|
+
const debouncedSearchChange = useCallback(debounce(handleSearchChange, debounceTimeout), [
|
|
22
|
+
handleSearchChange,
|
|
23
|
+
debounceTimeout,
|
|
24
|
+
])
|
|
25
|
+
|
|
26
|
+
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
27
|
+
const { value } = e.target
|
|
28
|
+
setIsSearchApplied(!!value)
|
|
29
|
+
if (shouldDebounce) {
|
|
30
|
+
debouncedSearchChange(value)
|
|
31
|
+
} else {
|
|
32
|
+
handleSearchChange(value)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const handleKeyDown = (e) => {
|
|
37
|
+
const keyCode = e.key
|
|
38
|
+
|
|
39
|
+
if (keyCode === 'Enter') {
|
|
40
|
+
const event = { ...e, target: { ...e.target, value: e.target.value?.trim() } }
|
|
41
|
+
handleSearchChange(event.target.value)
|
|
42
|
+
handleEnter(event)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const clearSearch = () => {
|
|
47
|
+
handleSearchChange('')
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<div className={containerClassName}>
|
|
52
|
+
<div className="search-bar dc__position-rel en-2 bw-1 br-4 h-32">
|
|
53
|
+
<Search className="search-bar__icon icon-dim-18" />
|
|
54
|
+
<input
|
|
55
|
+
placeholder="Search"
|
|
56
|
+
{...inputProps}
|
|
57
|
+
type="text"
|
|
58
|
+
data-testid="search-bar"
|
|
59
|
+
defaultValue={initialSearchText}
|
|
60
|
+
className={`search-bar__input bcn-0 ${isSearchApplied ? 'search-bar__input--applied' : ''}`}
|
|
61
|
+
onChange={handleChange}
|
|
62
|
+
onKeyDown={handleKeyDown}
|
|
63
|
+
/>
|
|
64
|
+
{isSearchApplied && (
|
|
65
|
+
<button
|
|
66
|
+
className="flex search-bar__clear-button"
|
|
67
|
+
type="button"
|
|
68
|
+
onClick={clearSearch}
|
|
69
|
+
aria-label="Clear search"
|
|
70
|
+
>
|
|
71
|
+
<Clear className="icon-dim-18 icon-n4 dc__vertical-align-middle" />
|
|
72
|
+
</button>
|
|
73
|
+
)}
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export default SearchBar
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
.search-bar {
|
|
2
|
+
margin-right: 0;
|
|
3
|
+
margin-bottom: 0;
|
|
4
|
+
background-color: var(--N0);
|
|
5
|
+
display: block;
|
|
6
|
+
width: 100%;
|
|
7
|
+
min-width: 200px;
|
|
8
|
+
height: 32px;
|
|
9
|
+
position: relative;
|
|
10
|
+
|
|
11
|
+
&:focus, &:focus-within {
|
|
12
|
+
outline: none;
|
|
13
|
+
border: solid 1px var(--B500);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
&__input {
|
|
17
|
+
position: absolute;
|
|
18
|
+
width: 100%;
|
|
19
|
+
height: 100%;
|
|
20
|
+
border-radius: 4px;
|
|
21
|
+
border: none;
|
|
22
|
+
padding: 6px 10px 6px 30px;
|
|
23
|
+
font-size: 13px;
|
|
24
|
+
line-height: 20px;
|
|
25
|
+
color: var(--N900);
|
|
26
|
+
|
|
27
|
+
&--applied {
|
|
28
|
+
width: calc(100% - 22px);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
&:focus,
|
|
32
|
+
&:focus-visible {
|
|
33
|
+
border: none;
|
|
34
|
+
outline: none;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
&::placeholder {
|
|
38
|
+
font-weight: 400;
|
|
39
|
+
color: var(--N500);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
&__icon {
|
|
44
|
+
position: absolute;
|
|
45
|
+
z-index: 1;
|
|
46
|
+
color: var(--N600);
|
|
47
|
+
top: 50%;
|
|
48
|
+
left: 8px;
|
|
49
|
+
transform: translateY(-50%);
|
|
50
|
+
line-height: 1.9;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
&__clear-button {
|
|
54
|
+
background-color: transparent;
|
|
55
|
+
position: absolute;
|
|
56
|
+
right: 0;
|
|
57
|
+
top: 50%;
|
|
58
|
+
transform: translateY(-50%);
|
|
59
|
+
z-index: 1;
|
|
60
|
+
border: none;
|
|
61
|
+
padding: 2px;
|
|
62
|
+
color: var(--N600);
|
|
63
|
+
margin: 0px 5px;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { InputHTMLAttributes, SyntheticEvent } from 'react'
|
|
2
|
+
|
|
3
|
+
export interface SearchBarProps {
|
|
4
|
+
/**
|
|
5
|
+
* Initial search text
|
|
6
|
+
*
|
|
7
|
+
* @default ''
|
|
8
|
+
*/
|
|
9
|
+
initialSearchText?: string
|
|
10
|
+
/**
|
|
11
|
+
* Search handler for the search input
|
|
12
|
+
*/
|
|
13
|
+
handleSearchChange?: (searchText: string) => void
|
|
14
|
+
/**
|
|
15
|
+
* Enter event handler for the search input
|
|
16
|
+
*/
|
|
17
|
+
handleEnter?: (event: SyntheticEvent) => void
|
|
18
|
+
/**
|
|
19
|
+
* Input props for the search input
|
|
20
|
+
*/
|
|
21
|
+
inputProps?: InputHTMLAttributes<HTMLInputElement>
|
|
22
|
+
/**
|
|
23
|
+
* Class name for the container; can be used for handling width
|
|
24
|
+
*/
|
|
25
|
+
containerClassName?: string
|
|
26
|
+
/**
|
|
27
|
+
* If true, the change handler would be triggered with debounce
|
|
28
|
+
*
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
31
|
+
shouldDebounce?: boolean
|
|
32
|
+
/**
|
|
33
|
+
* Timeout for the debounce handler to be triggered
|
|
34
|
+
*/
|
|
35
|
+
debounceTimeout?: number
|
|
36
|
+
}
|
package/src/Common/index.ts
CHANGED
|
@@ -26,6 +26,7 @@ export * from './Common.service'
|
|
|
26
26
|
export * from './Checkbox'
|
|
27
27
|
export { default as EmptyState } from './EmptyState/EmptyState'
|
|
28
28
|
export { default as GenericEmptyState } from './EmptyState/GenericEmptyState'
|
|
29
|
+
export { default as SearchBar } from './SearchBar/SearchBar.component'
|
|
29
30
|
export { default as Toggle } from './Toggle/Toggle'
|
|
30
31
|
export { default as ScanVulnerabilitiesTable } from './Security/ScanVulnerabilitiesTable'
|
|
31
32
|
export { default as StyledRadioGroup } from './RadioGroup/RadioGroup'
|