@devtron-labs/devtron-fe-common-lib 0.0.53-beta-2 → 0.0.53-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/index.js
CHANGED
|
@@ -24613,7 +24613,7 @@ var SvgIcErrorCross = function SvgIcErrorCross(props) {
|
|
|
24613
24613
|
}))));
|
|
24614
24614
|
};
|
|
24615
24615
|
|
|
24616
|
-
var css_248z$4 = ".search-bar
|
|
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
|
/**
|
|
@@ -24621,14 +24621,15 @@ styleInject(css_248z$4);
|
|
|
24621
24621
|
*/
|
|
24622
24622
|
var SearchBar = function (_a) {
|
|
24623
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),
|
|
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
|
-
|
|
24632
|
+
setShowClearButton(!!value);
|
|
24632
24633
|
if (shouldDebounce) {
|
|
24633
24634
|
debouncedSearchChange(value);
|
|
24634
24635
|
}
|
|
@@ -24637,18 +24638,19 @@ var SearchBar = function (_a) {
|
|
|
24637
24638
|
}
|
|
24638
24639
|
};
|
|
24639
24640
|
var handleKeyDown = function (e) {
|
|
24640
|
-
var
|
|
24641
|
-
|
|
24642
|
-
|
|
24643
|
-
var event_1 = __assign(__assign({}, e), { target: __assign(__assign({},
|
|
24641
|
+
var key = e.key;
|
|
24642
|
+
if (key === 'Enter') {
|
|
24643
|
+
var inputTarget = e.target;
|
|
24644
|
+
var event_1 = __assign(__assign({}, e), { target: __assign(__assign({}, inputTarget), { value: inputTarget.value.trim() }) });
|
|
24644
24645
|
handleSearchChange(event_1.target.value);
|
|
24645
24646
|
handleEnter(event_1);
|
|
24646
24647
|
}
|
|
24647
24648
|
};
|
|
24648
24649
|
var clearSearch = function () {
|
|
24650
|
+
inputRef.current.value = '';
|
|
24649
24651
|
handleSearchChange('');
|
|
24650
24652
|
};
|
|
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"
|
|
24653
|
+
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
24654
|
};
|
|
24653
24655
|
|
|
24654
24656
|
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,4 +1,4 @@
|
|
|
1
|
-
import { ChangeEvent, FunctionComponent, useCallback, useState } from 'react'
|
|
1
|
+
import { ChangeEvent, FunctionComponent, 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'
|
|
@@ -17,7 +17,8 @@ const SearchBar: FunctionComponent<SearchBarProps> = ({
|
|
|
17
17
|
shouldDebounce = false,
|
|
18
18
|
debounceTimeout = 300,
|
|
19
19
|
}) => {
|
|
20
|
-
const [
|
|
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
|
-
|
|
29
|
+
setShowClearButton(!!value)
|
|
29
30
|
if (shouldDebounce) {
|
|
30
31
|
debouncedSearchChange(value)
|
|
31
32
|
} else {
|
|
@@ -33,37 +34,42 @@ const SearchBar: FunctionComponent<SearchBarProps> = ({
|
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
const handleKeyDown = (e) => {
|
|
37
|
-
const
|
|
37
|
+
const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
|
|
38
|
+
const { key } = e
|
|
38
39
|
|
|
39
|
-
if (
|
|
40
|
-
const
|
|
40
|
+
if (key === 'Enter') {
|
|
41
|
+
const inputTarget = e.target as HTMLInputElement
|
|
42
|
+
const event = { ...e, target: { ...inputTarget, value: inputTarget.value.trim() } }
|
|
41
43
|
handleSearchChange(event.target.value)
|
|
42
44
|
handleEnter(event)
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
const clearSearch = () => {
|
|
49
|
+
inputRef.current.value = ''
|
|
47
50
|
handleSearchChange('')
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
return (
|
|
51
54
|
<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" />
|
|
55
|
+
<div className="search-bar bcn-0 dc__block w-100 min-w-200 dc__position-rel en-2 bw-1 br-4 h-32">
|
|
56
|
+
<Search className="search-bar__icon dc__position-abs icon-color-n6 icon-dim-18" />
|
|
54
57
|
<input
|
|
55
58
|
placeholder="Search"
|
|
56
|
-
{...inputProps}
|
|
57
|
-
type="text"
|
|
58
59
|
data-testid="search-bar"
|
|
60
|
+
type="text"
|
|
61
|
+
{...inputProps}
|
|
59
62
|
defaultValue={initialSearchText}
|
|
60
|
-
className={`search-bar__input bcn-0
|
|
63
|
+
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 ${
|
|
64
|
+
showClearButton ? 'pr-30' : 'pr-10'
|
|
65
|
+
}`}
|
|
61
66
|
onChange={handleChange}
|
|
62
67
|
onKeyDown={handleKeyDown}
|
|
68
|
+
ref={inputRef}
|
|
63
69
|
/>
|
|
64
|
-
{
|
|
70
|
+
{showClearButton && (
|
|
65
71
|
<button
|
|
66
|
-
className="flex search-bar__clear-button"
|
|
72
|
+
className="flex search-bar__clear-button dc__position-abs dc__transparent mt-0 mb-0 mr-5 ml-5"
|
|
67
73
|
type="button"
|
|
68
74
|
onClick={clearSearch}
|
|
69
75
|
aria-label="Clear search"
|
|
@@ -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,
|
|
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
|
}
|