@devtron-labs/devtron-fe-common-lib 0.0.53-beta-3 → 0.0.53-beta-4

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.
@@ -1,8 +1,8 @@
1
- import { FunctionComponent } from 'react';
1
+ /// <reference types="react" />
2
2
  import { SearchBarProps } from './types';
3
3
  import './searchBar.scss';
4
4
  /**
5
5
  * Generic search input component with support for enter based and debounced search
6
6
  */
7
- declare const SearchBar: FunctionComponent<SearchBarProps>;
7
+ declare const SearchBar: ({ initialSearchText, handleSearchChange, handleEnter, inputProps, containerClassName, shouldDebounce, debounceTimeout, }: SearchBarProps) => JSX.Element;
8
8
  export default SearchBar;
@@ -0,0 +1,2 @@
1
+ export { default as SearchBar } from './SearchBar.component';
2
+ export type { SearchBarProps } from './types';
@@ -1,4 +1,4 @@
1
- import { InputHTMLAttributes, SyntheticEvent } from 'react';
1
+ import { InputHTMLAttributes } from 'react';
2
2
  export interface SearchBarProps {
3
3
  /**
4
4
  * Initial search text
@@ -13,7 +13,7 @@ export interface SearchBarProps {
13
13
  /**
14
14
  * Enter event handler for the search input
15
15
  */
16
- handleEnter?: (event: SyntheticEvent) => void;
16
+ handleEnter?: (searchText: string) => void;
17
17
  /**
18
18
  * Input props for the search input
19
19
  */
@@ -26,7 +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
+ export * from './SearchBar';
30
30
  export { default as Toggle } from './Toggle/Toggle';
31
31
  export { default as ScanVulnerabilitiesTable } from './Security/ScanVulnerabilitiesTable';
32
32
  export { default as StyledRadioGroup } from './RadioGroup/RadioGroup';
package/dist/index.js CHANGED
@@ -24620,7 +24620,7 @@ styleInject(css_248z$4);
24620
24620
  * Generic search input component with support for enter based and debounced search
24621
24621
  */
24622
24622
  var SearchBar = function (_a) {
24623
- var _b = _a.initialSearchText, initialSearchText = _b === void 0 ? '' : _b, _c = _a.handleSearchChange, handleSearchChange = _c === void 0 ? noop$1 : _c, _d = _a.handleEnter, handleEnter = _d === void 0 ? noop$1 : _d, _e = _a.inputProps, inputProps = _e === void 0 ? {} : _e, containerClassName = _a.containerClassName, _f = _a.shouldDebounce, shouldDebounce = _f === void 0 ? false : _f, _g = _a.debounceTimeout, debounceTimeout = _g === void 0 ? 300 : _g;
24623
+ var _b = _a.initialSearchText, initialSearchText = _b === void 0 ? '' : _b, _c = _a.handleSearchChange, handleSearchChange = _c === void 0 ? function () { } : _c, _d = _a.handleEnter, handleEnter = _d === void 0 ? function () { } : _d, _e = _a.inputProps, inputProps = _e === void 0 ? {} : _e, containerClassName = _a.containerClassName, _f = _a.shouldDebounce, shouldDebounce = _f === void 0 ? false : _f, _g = _a.debounceTimeout, debounceTimeout = _g === void 0 ? 300 : _g;
24624
24624
  var _h = __read(React.useState(!!initialSearchText), 2), showClearButton = _h[0], setShowClearButton = _h[1];
24625
24625
  var inputRef = React.useRef();
24626
24626
  var debouncedSearchChange = React.useCallback(debounce$2(handleSearchChange, debounceTimeout), [
@@ -24637,18 +24637,21 @@ var SearchBar = function (_a) {
24637
24637
  handleSearchChange(value);
24638
24638
  }
24639
24639
  };
24640
+ var _applySearch = function (value) {
24641
+ handleSearchChange(value);
24642
+ handleEnter(value);
24643
+ };
24640
24644
  var handleKeyDown = function (e) {
24641
24645
  var key = e.key;
24642
24646
  if (key === 'Enter') {
24643
24647
  var inputTarget = e.target;
24644
- var event_1 = __assign(__assign({}, e), { target: __assign(__assign({}, inputTarget), { value: inputTarget.value.trim() }) });
24645
- handleSearchChange(event_1.target.value);
24646
- handleEnter(event_1);
24648
+ var value = inputTarget.value.trim();
24649
+ _applySearch(value);
24647
24650
  }
24648
24651
  };
24649
24652
  var clearSearch = function () {
24650
24653
  inputRef.current.value = '';
24651
- handleSearchChange('');
24654
+ _applySearch('');
24652
24655
  };
24653
24656
  return (jsxRuntime.jsx("div", __assign({ className: containerClassName }, { children: jsxRuntime.jsxs("div", __assign({ className: "search-bar bcn-0 dc__block w-100 min-w-200 dc__position-rel en-2 bw-1 br-4 h-32" }, { children: [jsxRuntime.jsx(SvgIcSearch, { className: "search-bar__icon dc__position-abs icon-color-n6 icon-dim-18" }), jsxRuntime.jsx("input", __assign({ placeholder: "Search", "data-testid": "search-bar", type: "text" }, inputProps, { defaultValue: initialSearchText, className: "search-bar__input bcn-0 dc__position-abs w-100 h-100 br-4 dc__no-border pt-6 pr-10 pb-6 pl-30 fs-13 lh-20 fw-4 cn-9 placeholder-cn5 ".concat(showClearButton ? 'pr-30' : 'pr-10'), onChange: handleChange, onKeyDown: handleKeyDown, ref: inputRef })), showClearButton && (jsxRuntime.jsx("button", __assign({ className: "flex search-bar__clear-button dc__position-abs dc__transparent mt-0 mb-0 mr-5 ml-5", type: "button", onClick: clearSearch, "aria-label": "Clear search" }, { children: jsxRuntime.jsx(SvgIcErrorCross, { className: "icon-dim-18 icon-n4 dc__vertical-align-middle" }) })))] })) })));
24654
24657
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtron-labs/devtron-fe-common-lib",
3
- "version": "0.0.53-beta-3",
3
+ "version": "0.0.53-beta-4",
4
4
  "description": "Supporting common component library",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,22 +1,22 @@
1
- import { ChangeEvent, FunctionComponent, useCallback, useRef, useState, KeyboardEvent } from 'react'
1
+ import { ChangeEvent, useCallback, useRef, useState, KeyboardEvent } from 'react'
2
2
  import { ReactComponent as Search } from '../../Assets/Icon/ic-search.svg'
3
3
  import { ReactComponent as Clear } from '../../Assets/Icon/ic-error-cross.svg'
4
4
  import { SearchBarProps } from './types'
5
5
  import './searchBar.scss'
6
- import { debounce, noop } from '../Helper'
6
+ import { debounce } from '../Helper'
7
7
 
8
8
  /**
9
9
  * Generic search input component with support for enter based and debounced search
10
10
  */
11
- const SearchBar: FunctionComponent<SearchBarProps> = ({
11
+ const SearchBar = ({
12
12
  initialSearchText = '',
13
- handleSearchChange = noop,
14
- handleEnter = noop,
13
+ handleSearchChange = () => {},
14
+ handleEnter = () => {},
15
15
  inputProps = {},
16
16
  containerClassName,
17
17
  shouldDebounce = false,
18
18
  debounceTimeout = 300,
19
- }) => {
19
+ }: SearchBarProps) => {
20
20
  const [showClearButton, setShowClearButton] = useState(!!initialSearchText)
21
21
  const inputRef = useRef<HTMLInputElement>()
22
22
  const debouncedSearchChange = useCallback(debounce(handleSearchChange, debounceTimeout), [
@@ -34,20 +34,24 @@ const SearchBar: FunctionComponent<SearchBarProps> = ({
34
34
  }
35
35
  }
36
36
 
37
+ const _applySearch = (value: string) => {
38
+ handleSearchChange(value)
39
+ handleEnter(value)
40
+ }
41
+
37
42
  const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
38
43
  const { key } = e
39
44
 
40
45
  if (key === 'Enter') {
41
46
  const inputTarget = e.target as HTMLInputElement
42
- const event = { ...e, target: { ...inputTarget, value: inputTarget.value.trim() } }
43
- handleSearchChange(event.target.value)
44
- handleEnter(event)
47
+ const value = inputTarget.value.trim()
48
+ _applySearch(value)
45
49
  }
46
50
  }
47
51
 
48
52
  const clearSearch = () => {
49
53
  inputRef.current.value = ''
50
- handleSearchChange('')
54
+ _applySearch('')
51
55
  }
52
56
 
53
57
  return (
@@ -0,0 +1,2 @@
1
+ export { default as SearchBar } from './SearchBar.component'
2
+ export type { SearchBarProps } from './types'
@@ -1,4 +1,4 @@
1
- import { InputHTMLAttributes, SyntheticEvent } from 'react'
1
+ import { InputHTMLAttributes } from 'react'
2
2
 
3
3
  export interface SearchBarProps {
4
4
  /**
@@ -14,7 +14,7 @@ export interface SearchBarProps {
14
14
  /**
15
15
  * Enter event handler for the search input
16
16
  */
17
- handleEnter?: (event: SyntheticEvent) => void
17
+ handleEnter?: (searchText: string) => void
18
18
  /**
19
19
  * Input props for the search input
20
20
  */
@@ -26,7 +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
+ export * from './SearchBar'
30
30
  export { default as Toggle } from './Toggle/Toggle'
31
31
  export { default as ScanVulnerabilitiesTable } from './Security/ScanVulnerabilitiesTable'
32
32
  export { default as StyledRadioGroup } from './RadioGroup/RadioGroup'