@devtron-labs/devtron-fe-common-lib 0.0.53-beta-2 → 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
@@ -24613,22 +24613,23 @@ var SvgIcErrorCross = function SvgIcErrorCross(props) {
24613
24613
  }))));
24614
24614
  };
24615
24615
 
24616
- var css_248z$4 = ".search-bar {\n margin-right: 0;\n margin-bottom: 0;\n background-color: var(--N0);\n display: block;\n width: 100%;\n min-width: 200px;\n height: 32px;\n position: relative;\n}\n.search-bar:focus, .search-bar:focus-within {\n outline: none;\n border: solid 1px var(--B500);\n}\n.search-bar__input {\n position: absolute;\n width: 100%;\n height: 100%;\n border-radius: 4px;\n border: none;\n padding: 6px 10px 6px 30px;\n font-size: 13px;\n line-height: 20px;\n color: var(--N900);\n}\n.search-bar__input--applied {\n width: calc(100% - 22px);\n}\n.search-bar__input:focus, .search-bar__input:focus-visible {\n border: none;\n outline: none;\n}\n.search-bar__input::placeholder {\n font-weight: 400;\n color: var(--N500);\n}\n.search-bar__icon {\n position: absolute;\n z-index: 1;\n color: var(--N600);\n top: 50%;\n left: 8px;\n transform: translateY(-50%);\n line-height: 1.9;\n}\n.search-bar__clear-button {\n background-color: transparent;\n position: absolute;\n right: 0;\n top: 50%;\n transform: translateY(-50%);\n z-index: 1;\n border: none;\n padding: 2px;\n color: var(--N600);\n margin: 0px 5px;\n}";
24616
+ var css_248z$4 = ".search-bar:focus, .search-bar:focus-within {\n outline: none;\n border: solid 1px var(--B500);\n}\n.search-bar__input:focus, .search-bar__input:focus-visible {\n border: none;\n outline: none;\n}\n.search-bar__icon {\n z-index: 1;\n top: 50%;\n left: 8px;\n transform: translateY(-50%);\n}\n.search-bar__clear-button {\n right: 0;\n top: 50%;\n transform: translateY(-50%);\n z-index: 1;\n}";
24617
24617
  styleInject(css_248z$4);
24618
24618
 
24619
24619
  /**
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;
24624
- var _h = __read(React.useState(!!initialSearchText), 2), isSearchApplied = _h[0], setIsSearchApplied = _h[1];
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
+ var _h = __read(React.useState(!!initialSearchText), 2), showClearButton = _h[0], setShowClearButton = _h[1];
24625
+ var inputRef = React.useRef();
24625
24626
  var debouncedSearchChange = React.useCallback(debounce$2(handleSearchChange, debounceTimeout), [
24626
24627
  handleSearchChange,
24627
24628
  debounceTimeout,
24628
24629
  ]);
24629
24630
  var handleChange = function (e) {
24630
24631
  var value = e.target.value;
24631
- setIsSearchApplied(!!value);
24632
+ setShowClearButton(!!value);
24632
24633
  if (shouldDebounce) {
24633
24634
  debouncedSearchChange(value);
24634
24635
  }
@@ -24636,19 +24637,23 @@ var SearchBar = function (_a) {
24636
24637
  handleSearchChange(value);
24637
24638
  }
24638
24639
  };
24640
+ var _applySearch = function (value) {
24641
+ handleSearchChange(value);
24642
+ handleEnter(value);
24643
+ };
24639
24644
  var handleKeyDown = function (e) {
24640
- var _a;
24641
- var keyCode = e.key;
24642
- if (keyCode === 'Enter') {
24643
- var event_1 = __assign(__assign({}, e), { target: __assign(__assign({}, e.target), { value: (_a = e.target.value) === null || _a === void 0 ? void 0 : _a.trim() }) });
24644
- handleSearchChange(event_1.target.value);
24645
- handleEnter(event_1);
24645
+ var key = e.key;
24646
+ if (key === 'Enter') {
24647
+ var inputTarget = e.target;
24648
+ var value = inputTarget.value.trim();
24649
+ _applySearch(value);
24646
24650
  }
24647
24651
  };
24648
24652
  var clearSearch = function () {
24649
- handleSearchChange('');
24653
+ inputRef.current.value = '';
24654
+ _applySearch('');
24650
24655
  };
24651
- return (jsxRuntime.jsx("div", __assign({ className: containerClassName }, { children: jsxRuntime.jsxs("div", __assign({ className: "search-bar dc__position-rel en-2 bw-1 br-4 h-32" }, { children: [jsxRuntime.jsx(SvgIcSearch, { className: "search-bar__icon icon-dim-18" }), jsxRuntime.jsx("input", __assign({ placeholder: "Search" }, inputProps, { type: "text", "data-testid": "search-bar", defaultValue: initialSearchText, className: "search-bar__input bcn-0 ".concat(isSearchApplied ? 'search-bar__input--applied' : ''), onChange: handleChange, onKeyDown: handleKeyDown })), isSearchApplied && (jsxRuntime.jsx("button", __assign({ className: "flex search-bar__clear-button", type: "button", onClick: clearSearch, "aria-label": "Clear search" }, { children: jsxRuntime.jsx(SvgIcErrorCross, { className: "icon-dim-18 icon-n4 dc__vertical-align-middle" }) })))] })) })));
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" }) })))] })) })));
24652
24657
  };
24653
24658
 
24654
24659
  var css_248z$3 = ".toggle__switch {\n position: relative;\n display: inline-block;\n width: 100%;\n height: 100%;\n}\n.toggle__switch.disabled {\n cursor: not-allowed;\n}\n.toggle__switch.disabled .toggle__slider {\n cursor: not-allowed;\n}\n\n/* Hide default HTML checkbox */\n.toggle__switch input {\n opacity: 0;\n width: 0;\n height: 0;\n}\n\n/* The slider */\n.toggle__slider {\n position: absolute;\n cursor: pointer;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background-color: #ccc;\n transition: all 0.4s ease;\n}\n.toggle__slider.round {\n border-radius: 34px;\n}\n.toggle__slider.round:before {\n border-radius: 50%;\n}\n.toggle__slider:before {\n position: absolute;\n content: \"\";\n height: calc(100% - 8px);\n width: calc(50% - 4px);\n left: 4px;\n bottom: 4px;\n background-color: white;\n transition: all 0.4s ease;\n}\n.toggle__slider.with-icon {\n background-color: var(--N000) !important;\n}\n.toggle__slider.with-icon svg {\n position: absolute;\n content: \"\";\n top: -1px;\n left: -1px;\n background-color: var(--N300);\n transition: all 0.4s ease;\n}\n\ninput:checked + .toggle__slider {\n background-color: var(--color);\n}\ninput:checked + .toggle__slider:before {\n transform: translateX(100%);\n}\ninput:checked + .toggle__slider.with-icon svg {\n transform: translateX(100%);\n background-color: var(--color);\n}\n\ninput:focus + .toggle__slider {\n box-shadow: 0 0 1px var(--color);\n}";
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-2",
3
+ "version": "0.0.53-beta-4",
4
4
  "description": "Supporting common component library",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,23 +1,24 @@
1
- import { ChangeEvent, FunctionComponent, useCallback, useState } 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
- }) => {
20
- const [isSearchApplied, setIsSearchApplied] = useState(!!initialSearchText)
19
+ }: SearchBarProps) => {
20
+ const [showClearButton, setShowClearButton] = useState(!!initialSearchText)
21
+ const inputRef = useRef<HTMLInputElement>()
21
22
  const debouncedSearchChange = useCallback(debounce(handleSearchChange, debounceTimeout), [
22
23
  handleSearchChange,
23
24
  debounceTimeout,
@@ -25,7 +26,7 @@ const SearchBar: FunctionComponent<SearchBarProps> = ({
25
26
 
26
27
  const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
27
28
  const { value } = e.target
28
- setIsSearchApplied(!!value)
29
+ setShowClearButton(!!value)
29
30
  if (shouldDebounce) {
30
31
  debouncedSearchChange(value)
31
32
  } else {
@@ -33,37 +34,46 @@ const SearchBar: FunctionComponent<SearchBarProps> = ({
33
34
  }
34
35
  }
35
36
 
36
- const handleKeyDown = (e) => {
37
- const keyCode = e.key
37
+ const _applySearch = (value: string) => {
38
+ handleSearchChange(value)
39
+ handleEnter(value)
40
+ }
41
+
42
+ const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
43
+ const { key } = e
38
44
 
39
- if (keyCode === 'Enter') {
40
- const event = { ...e, target: { ...e.target, value: e.target.value?.trim() } }
41
- handleSearchChange(event.target.value)
42
- handleEnter(event)
45
+ if (key === 'Enter') {
46
+ const inputTarget = e.target as HTMLInputElement
47
+ const value = inputTarget.value.trim()
48
+ _applySearch(value)
43
49
  }
44
50
  }
45
51
 
46
52
  const clearSearch = () => {
47
- handleSearchChange('')
53
+ inputRef.current.value = ''
54
+ _applySearch('')
48
55
  }
49
56
 
50
57
  return (
51
58
  <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" />
59
+ <div className="search-bar bcn-0 dc__block w-100 min-w-200 dc__position-rel en-2 bw-1 br-4 h-32">
60
+ <Search className="search-bar__icon dc__position-abs icon-color-n6 icon-dim-18" />
54
61
  <input
55
62
  placeholder="Search"
56
- {...inputProps}
57
- type="text"
58
63
  data-testid="search-bar"
64
+ type="text"
65
+ {...inputProps}
59
66
  defaultValue={initialSearchText}
60
- className={`search-bar__input bcn-0 ${isSearchApplied ? 'search-bar__input--applied' : ''}`}
67
+ 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 ${
68
+ showClearButton ? 'pr-30' : 'pr-10'
69
+ }`}
61
70
  onChange={handleChange}
62
71
  onKeyDown={handleKeyDown}
72
+ ref={inputRef}
63
73
  />
64
- {isSearchApplied && (
74
+ {showClearButton && (
65
75
  <button
66
- className="flex search-bar__clear-button"
76
+ className="flex search-bar__clear-button dc__position-abs dc__transparent mt-0 mb-0 mr-5 ml-5"
67
77
  type="button"
68
78
  onClick={clearSearch}
69
79
  aria-label="Clear search"
@@ -0,0 +1,2 @@
1
+ export { default as SearchBar } from './SearchBar.component'
2
+ export type { SearchBarProps } from './types'
@@ -1,65 +1,31 @@
1
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
2
 
11
- &:focus, &:focus-within {
3
+ &:focus,
4
+ &:focus-within {
12
5
  outline: none;
13
6
  border: solid 1px var(--B500);
14
7
  }
15
8
 
16
9
  &__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
10
 
31
11
  &:focus,
32
12
  &:focus-visible {
33
13
  border: none;
34
14
  outline: none;
35
15
  }
36
-
37
- &::placeholder {
38
- font-weight: 400;
39
- color: var(--N500);
40
- }
41
16
  }
42
17
 
43
18
  &__icon {
44
- position: absolute;
45
19
  z-index: 1;
46
- color: var(--N600);
47
20
  top: 50%;
48
21
  left: 8px;
49
22
  transform: translateY(-50%);
50
- line-height: 1.9;
51
23
  }
52
24
 
53
25
  &__clear-button {
54
- background-color: transparent;
55
- position: absolute;
56
26
  right: 0;
57
27
  top: 50%;
58
28
  transform: translateY(-50%);
59
29
  z-index: 1;
60
- border: none;
61
- padding: 2px;
62
- color: var(--N600);
63
- margin: 0px 5px;
64
30
  }
65
31
  }
@@ -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'