@snack-uikit/search 0.6.4 → 0.6.5-preview-85d9bbdc.0
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/README.md +0 -23
- package/dist/components/Search/Search.d.ts +1 -1
- package/dist/components/SearchAutocomplete/SearchAutocomplete.d.ts +1 -1
- package/dist/components/SearchAutocomplete/SearchAutocomplete.js +1 -1
- package/dist/components/SearchFieldText/SearchFieldText.d.ts +1 -1
- package/dist/components/SearchFieldText/SearchFieldText.js +1 -1
- package/dist/components/index.d.ts +0 -1
- package/dist/components/index.js +0 -1
- package/package.json +4 -7
- package/src/components/Search/Search.tsx +1 -1
- package/src/components/SearchAutocomplete/SearchAutocomplete.tsx +1 -1
- package/src/components/SearchFieldText/SearchFieldText.tsx +2 -1
- package/src/components/index.ts +0 -1
- package/dist/components/SearchPrivate/SearchPrivate.d.ts +0 -26
- package/dist/components/SearchPrivate/SearchPrivate.js +0 -61
- package/dist/components/SearchPrivate/index.d.ts +0 -1
- package/dist/components/SearchPrivate/index.js +0 -1
- package/dist/components/SearchPrivate/styles.module.css +0 -68
- package/src/components/SearchPrivate/SearchPrivate.tsx +0 -125
- package/src/components/SearchPrivate/index.ts +0 -1
- package/src/components/SearchPrivate/styles.module.scss +0 -43
package/README.md
CHANGED
|
@@ -24,13 +24,6 @@ import { Search, SearchPrivate } from "@snack-uikit/search";
|
|
|
24
24
|
autocomplete
|
|
25
25
|
/>
|
|
26
26
|
|
|
27
|
-
<SearchPrivate
|
|
28
|
-
value={value}
|
|
29
|
-
onChange={handleSearchChange}
|
|
30
|
-
loading={loading}
|
|
31
|
-
onSubmit={onSubmit}
|
|
32
|
-
size='s'
|
|
33
|
-
/>
|
|
34
27
|
```
|
|
35
28
|
|
|
36
29
|
[//]: DOCUMENTATION_SECTION_START
|
|
@@ -53,22 +46,6 @@ import { Search, SearchPrivate } from "@snack-uikit/search";
|
|
|
53
46
|
| autocomplete | `boolean` | - | Работа в режиме Autocomplete в значении true Работа в режиме FieldText в значении false \| undefined |
|
|
54
47
|
| ref | `Ref<HTMLInputElement>` | - | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). @see https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom |
|
|
55
48
|
| key | `Key` | - | |
|
|
56
|
-
## SearchPrivate
|
|
57
|
-
### Props
|
|
58
|
-
| name | type | default value | description |
|
|
59
|
-
|------|------|---------------|-------------|
|
|
60
|
-
| size | enum Size: `"s"`, `"m"`, `"l"` | s | Размер |
|
|
61
|
-
| loading | `boolean` | - | Состояние загрузки |
|
|
62
|
-
| onSubmit | `(value: string) => void` | - | Колбек на подтверждение поиска по строке |
|
|
63
|
-
| className | `string` | - | CSS-класс |
|
|
64
|
-
| value | `string` | - | Значение input |
|
|
65
|
-
| onChange | `(value: string, e?: ChangeEvent<HTMLInputElement>) => void` | - | Колбек смены значения |
|
|
66
|
-
| placeholder | `string` | - | Значение плейсхолдера |
|
|
67
|
-
| onFocus | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки получения фокуса |
|
|
68
|
-
| onBlur | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки потери фокуса |
|
|
69
|
-
| onKeyDown | `KeyboardEventHandler<HTMLInputElement>` | - | Колбек обработки нажатия клавиши клавиатуры |
|
|
70
|
-
| ref | `Ref<HTMLInputElement>` | - | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). @see https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom |
|
|
71
|
-
| key | `Key` | - | |
|
|
72
49
|
|
|
73
50
|
|
|
74
51
|
[//]: DOCUMENTATION_SECTION_END
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { SearchPrivateProps } from '@snack-uikit/search-private';
|
|
2
3
|
import { SearchAutocompleteProps } from '../SearchAutocomplete';
|
|
3
|
-
import { SearchPrivateProps } from '../SearchPrivate';
|
|
4
4
|
export type SearchProps = Omit<SearchPrivateProps, 'onKeyDown'> & {
|
|
5
5
|
/** Внешний бордер */
|
|
6
6
|
outline?: boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ItemSingleProps } from '@snack-uikit/droplist';
|
|
3
|
-
import { SearchPrivateProps } from '
|
|
3
|
+
import { SearchPrivateProps } from '@snack-uikit/search-private';
|
|
4
4
|
export type SearchAutocompleteProps = Omit<SearchPrivateProps, 'onKeyDown'> & {
|
|
5
5
|
/**
|
|
6
6
|
* Элементы выпадающие в Droplist в режиме Autocomplete.
|
|
@@ -15,9 +15,9 @@ import cn from 'classnames';
|
|
|
15
15
|
import mergeRefs from 'merge-refs';
|
|
16
16
|
import { forwardRef, useCallback, useRef, useState } from 'react';
|
|
17
17
|
import { Droplist } from '@snack-uikit/droplist';
|
|
18
|
+
import { SearchPrivate } from '@snack-uikit/search-private';
|
|
18
19
|
import { PRIVATE_SEARCH_TEST_IDS, SIZE, TEST_IDS } from '../../constants';
|
|
19
20
|
import { SearchDecorator } from '../SearchDecorator';
|
|
20
|
-
import { SearchPrivate } from '../SearchPrivate';
|
|
21
21
|
import styles from './styles.module.css';
|
|
22
22
|
export const SearchAutocomplete = forwardRef(function SearchAutocomplete(_a, ref) {
|
|
23
23
|
var _b, _c;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { SearchPrivateProps } from '
|
|
2
|
+
import { SearchPrivateProps } from '@snack-uikit/search-private';
|
|
3
3
|
export type SearchTextFieldProps = Omit<SearchPrivateProps, 'onKeyDown'> & {
|
|
4
4
|
/** Внешний бордер */
|
|
5
5
|
outline?: boolean;
|
|
@@ -11,9 +11,9 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
import { forwardRef } from 'react';
|
|
14
|
+
import { SearchPrivate } from '@snack-uikit/search-private';
|
|
14
15
|
import { PRIVATE_SEARCH_TEST_IDS, SIZE } from '../../constants';
|
|
15
16
|
import { SearchDecorator } from '../SearchDecorator';
|
|
16
|
-
import { SearchPrivate } from '../SearchPrivate';
|
|
17
17
|
export const SearchFieldText = forwardRef(function SearchFieldText(_a, ref) {
|
|
18
18
|
var { value, onChange, onBlur, onFocus, size = SIZE.S, outline, loading, placeholder, onSubmit, className } = _a, rest = __rest(_a, ["value", "onChange", "onBlur", "onFocus", "size", "outline", "loading", "placeholder", "onSubmit", "className"]);
|
|
19
19
|
return (_jsx(SearchDecorator, Object.assign({ outline: outline, size: size, className: className }, rest, { children: _jsx(SearchPrivate, { ref: ref, size: size, value: value, onChange: onChange, onBlur: onBlur, onFocus: onFocus, onSubmit: onSubmit, placeholder: placeholder, loading: loading, "data-test-id": PRIVATE_SEARCH_TEST_IDS.field }) })));
|
package/dist/components/index.js
CHANGED
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Search",
|
|
7
|
-
"version": "0.6.
|
|
7
|
+
"version": "0.6.5-preview-85d9bbdc.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -33,16 +33,13 @@
|
|
|
33
33
|
"scripts": {},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@snack-uikit/droplist": "0.12.4",
|
|
36
|
-
"@snack-uikit/
|
|
37
|
-
"@snack-uikit/input-private": "3.0.2",
|
|
38
|
-
"@snack-uikit/loaders": "0.5.0",
|
|
36
|
+
"@snack-uikit/search-private": "0.0.1-preview-85d9bbdc.0",
|
|
39
37
|
"@snack-uikit/utils": "3.2.0",
|
|
40
38
|
"classnames": "2.3.2",
|
|
41
|
-
"merge-refs": "1.0.0"
|
|
42
|
-
"uncontrollable": "8.0.4"
|
|
39
|
+
"merge-refs": "1.0.0"
|
|
43
40
|
},
|
|
44
41
|
"devDependencies": {
|
|
45
42
|
"@types/merge-refs": "1.0.0"
|
|
46
43
|
},
|
|
47
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "4328a9b2d2b79da1e9179707e7a230a1556ff78c"
|
|
48
45
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { forwardRef } from 'react';
|
|
2
2
|
|
|
3
|
+
import { SearchPrivateProps } from '@snack-uikit/search-private';
|
|
3
4
|
import { extractSupportProps } from '@snack-uikit/utils';
|
|
4
5
|
|
|
5
6
|
import { SIZE } from '../../constants';
|
|
6
7
|
import { SearchAutocomplete, SearchAutocompleteProps } from '../SearchAutocomplete';
|
|
7
8
|
import { SearchFieldText } from '../SearchFieldText';
|
|
8
|
-
import { SearchPrivateProps } from '../SearchPrivate';
|
|
9
9
|
|
|
10
10
|
export type SearchProps = Omit<SearchPrivateProps, 'onKeyDown'> & {
|
|
11
11
|
/** Внешний бордер */
|
|
@@ -3,10 +3,10 @@ import mergeRefs from 'merge-refs';
|
|
|
3
3
|
import { forwardRef, KeyboardEvent, useCallback, useRef, useState } from 'react';
|
|
4
4
|
|
|
5
5
|
import { Droplist, ItemSingleProps } from '@snack-uikit/droplist';
|
|
6
|
+
import { SearchPrivate, SearchPrivateProps } from '@snack-uikit/search-private';
|
|
6
7
|
|
|
7
8
|
import { PRIVATE_SEARCH_TEST_IDS, SIZE, TEST_IDS } from '../../constants';
|
|
8
9
|
import { SearchDecorator } from '../SearchDecorator';
|
|
9
|
-
import { SearchPrivate, SearchPrivateProps } from '../SearchPrivate';
|
|
10
10
|
import styles from './styles.module.scss';
|
|
11
11
|
|
|
12
12
|
export type SearchAutocompleteProps = Omit<SearchPrivateProps, 'onKeyDown'> & {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { forwardRef } from 'react';
|
|
2
2
|
|
|
3
|
+
import { SearchPrivate, SearchPrivateProps } from '@snack-uikit/search-private';
|
|
4
|
+
|
|
3
5
|
import { PRIVATE_SEARCH_TEST_IDS, SIZE } from '../../constants';
|
|
4
6
|
import { SearchDecorator } from '../SearchDecorator';
|
|
5
|
-
import { SearchPrivate, SearchPrivateProps } from '../SearchPrivate';
|
|
6
7
|
|
|
7
8
|
export type SearchTextFieldProps = Omit<SearchPrivateProps, 'onKeyDown'> & {
|
|
8
9
|
/** Внешний бордер */
|
package/src/components/index.ts
CHANGED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { InputPrivateProps } from '@snack-uikit/input-private';
|
|
3
|
-
import { WithSupportProps } from '@snack-uikit/utils';
|
|
4
|
-
import { Size } from '../../types';
|
|
5
|
-
export type SearchPrivateProps = WithSupportProps<{
|
|
6
|
-
/** Размер */
|
|
7
|
-
size?: Size;
|
|
8
|
-
/** Состояние загрузки */
|
|
9
|
-
loading?: boolean;
|
|
10
|
-
/** Колбек на подтверждение поиска по строке */
|
|
11
|
-
onSubmit?(value: string): void;
|
|
12
|
-
/** CSS-класс */
|
|
13
|
-
className?: string;
|
|
14
|
-
} & Pick<Partial<InputPrivateProps>, 'value' | 'onChange' | 'placeholder' | 'onFocus' | 'onBlur' | 'onKeyDown'>>;
|
|
15
|
-
export declare const SearchPrivate: import("react").ForwardRefExoticComponent<{
|
|
16
|
-
'data-test-id'?: string | undefined;
|
|
17
|
-
} & import("react").AriaAttributes & {
|
|
18
|
-
/** Размер */
|
|
19
|
-
size?: Size | undefined;
|
|
20
|
-
/** Состояние загрузки */
|
|
21
|
-
loading?: boolean | undefined;
|
|
22
|
-
/** Колбек на подтверждение поиска по строке */
|
|
23
|
-
onSubmit?(value: string): void;
|
|
24
|
-
/** CSS-класс */
|
|
25
|
-
className?: string | undefined;
|
|
26
|
-
} & Pick<Partial<InputPrivateProps>, "value" | "onChange" | "placeholder" | "onFocus" | "onBlur" | "onKeyDown"> & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
-
import cn from 'classnames';
|
|
14
|
-
import mergeRefs from 'merge-refs';
|
|
15
|
-
import { forwardRef, useCallback, useMemo, useRef } from 'react';
|
|
16
|
-
import { useUncontrolledProp } from 'uncontrollable';
|
|
17
|
-
import { SearchSVG } from '@snack-uikit/icons';
|
|
18
|
-
import { InputPrivate, moveCursorToEnd, useButtonNavigation, useClearButton, } from '@snack-uikit/input-private';
|
|
19
|
-
import { Sun } from '@snack-uikit/loaders';
|
|
20
|
-
import { extractSupportProps } from '@snack-uikit/utils';
|
|
21
|
-
import { PRIVATE_SEARCH_TEST_IDS, SIZE } from '../../constants';
|
|
22
|
-
import styles from './styles.module.css';
|
|
23
|
-
export const SearchPrivate = forwardRef(function SearchPrivate(_a, ref) {
|
|
24
|
-
var { size = SIZE.S, value: valueProp = '', onChange: onChangeProp, loading, placeholder, onKeyDown, onFocus, onBlur, onSubmit, className } = _a, rest = __rest(_a, ["size", "value", "onChange", "loading", "placeholder", "onKeyDown", "onFocus", "onBlur", "onSubmit", "className"]);
|
|
25
|
-
const [value, onValueChange] = useUncontrolledProp(valueProp, '', onChangeProp);
|
|
26
|
-
const localRef = useRef(null);
|
|
27
|
-
const clearButtonRef = useRef(null);
|
|
28
|
-
const showClearButton = Boolean(value);
|
|
29
|
-
const onClear = () => {
|
|
30
|
-
var _a;
|
|
31
|
-
onValueChange('');
|
|
32
|
-
(_a = localRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
33
|
-
};
|
|
34
|
-
const clearButtonSettings = useClearButton({
|
|
35
|
-
clearButtonRef,
|
|
36
|
-
showClearButton,
|
|
37
|
-
size,
|
|
38
|
-
onClear,
|
|
39
|
-
});
|
|
40
|
-
const { buttons, inputTabIndex, onInputKeyDown } = useButtonNavigation({
|
|
41
|
-
inputRef: localRef,
|
|
42
|
-
buttons: useMemo(() => [clearButtonSettings], [clearButtonSettings]),
|
|
43
|
-
readonly: false,
|
|
44
|
-
submitKeys: ['Enter', 'Space'],
|
|
45
|
-
});
|
|
46
|
-
const handleKeyDown = useCallback((e) => {
|
|
47
|
-
var _a, _b;
|
|
48
|
-
onKeyDown && onKeyDown(e);
|
|
49
|
-
onInputKeyDown(e);
|
|
50
|
-
if (e.key === 'Enter' && ((_a = localRef.current) === null || _a === void 0 ? void 0 : _a.value)) {
|
|
51
|
-
onSubmit && onSubmit(localRef.current.value);
|
|
52
|
-
// TODO: think about remove blur behavior
|
|
53
|
-
(_b = localRef.current) === null || _b === void 0 ? void 0 : _b.blur();
|
|
54
|
-
}
|
|
55
|
-
}, [onInputKeyDown, onKeyDown, onSubmit]);
|
|
56
|
-
const handleOnFocus = useCallback((e) => {
|
|
57
|
-
onFocus && onFocus(e);
|
|
58
|
-
moveCursorToEnd(localRef.current);
|
|
59
|
-
}, [onFocus]);
|
|
60
|
-
return (_jsxs("div", Object.assign({ className: cn(styles.container, className) }, extractSupportProps(rest), { "data-size": size, children: [_jsx("span", { className: styles.prefix, children: loading ? (_jsx(Sun, { "data-test-id": PRIVATE_SEARCH_TEST_IDS.iconSun })) : (_jsx(SearchSVG, { "data-test-id": PRIVATE_SEARCH_TEST_IDS.iconSearch })) }), _jsx(InputPrivate, { value: value, onChange: onValueChange, onKeyDown: handleKeyDown, onFocus: handleOnFocus, onBlur: onBlur, tabIndex: inputTabIndex, ref: mergeRefs(ref, localRef), placeholder: placeholder, type: 'text', "data-test-id": PRIVATE_SEARCH_TEST_IDS.input }), _jsx("span", { className: styles.postfix, children: buttons })] })));
|
|
61
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './SearchPrivate';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './SearchPrivate';
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
.container{
|
|
2
|
-
display:flex;
|
|
3
|
-
flex-grow:1;
|
|
4
|
-
align-items:center;
|
|
5
|
-
box-sizing:border-box;
|
|
6
|
-
}
|
|
7
|
-
.container[data-size=s]{
|
|
8
|
-
gap:var(--space-search-search-private-s, 4px);
|
|
9
|
-
}
|
|
10
|
-
.container[data-size=s] input{
|
|
11
|
-
font-family:var(--sans-body-s-font-family, SB Sans Interface);
|
|
12
|
-
font-weight:var(--sans-body-s-font-weight, Regular);
|
|
13
|
-
line-height:var(--sans-body-s-line-height, 16px);
|
|
14
|
-
font-size:var(--sans-body-s-font-size, 12px);
|
|
15
|
-
letter-spacing:var(--sans-body-s-letter-spacing, 0.1px);
|
|
16
|
-
paragraph-spacing:var(--sans-body-s-paragraph-spacing, 6.6px);
|
|
17
|
-
cursor:text;
|
|
18
|
-
}
|
|
19
|
-
.container[data-size=s] svg{
|
|
20
|
-
width:var(--dimension-3m, 24px) !important;
|
|
21
|
-
height:var(--dimension-3m, 24px) !important;
|
|
22
|
-
}
|
|
23
|
-
.container[data-size=m]{
|
|
24
|
-
gap:var(--space-search-search-private-m, 4px);
|
|
25
|
-
}
|
|
26
|
-
.container[data-size=m] input{
|
|
27
|
-
font-family:var(--sans-body-m-font-family, SB Sans Interface);
|
|
28
|
-
font-weight:var(--sans-body-m-font-weight, Regular);
|
|
29
|
-
line-height:var(--sans-body-m-line-height, 20px);
|
|
30
|
-
font-size:var(--sans-body-m-font-size, 14px);
|
|
31
|
-
letter-spacing:var(--sans-body-m-letter-spacing, 0.1px);
|
|
32
|
-
paragraph-spacing:var(--sans-body-m-paragraph-spacing, 7.7px);
|
|
33
|
-
cursor:text;
|
|
34
|
-
}
|
|
35
|
-
.container[data-size=m] svg{
|
|
36
|
-
width:var(--dimension-3m, 24px) !important;
|
|
37
|
-
height:var(--dimension-3m, 24px) !important;
|
|
38
|
-
}
|
|
39
|
-
.container[data-size=l]{
|
|
40
|
-
gap:var(--space-search-search-private-l, 8px);
|
|
41
|
-
}
|
|
42
|
-
.container[data-size=l] input{
|
|
43
|
-
font-family:var(--sans-body-l-font-family, SB Sans Interface);
|
|
44
|
-
font-weight:var(--sans-body-l-font-weight, Regular);
|
|
45
|
-
line-height:var(--sans-body-l-line-height, 24px);
|
|
46
|
-
font-size:var(--sans-body-l-font-size, 16px);
|
|
47
|
-
letter-spacing:var(--sans-body-l-letter-spacing, 0.1px);
|
|
48
|
-
paragraph-spacing:var(--sans-body-l-paragraph-spacing, 8.8px);
|
|
49
|
-
cursor:text;
|
|
50
|
-
}
|
|
51
|
-
.container[data-size=l] svg{
|
|
52
|
-
width:var(--dimension-3m, 24px) !important;
|
|
53
|
-
height:var(--dimension-3m, 24px) !important;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
.prefix{
|
|
57
|
-
display:inline-flex;
|
|
58
|
-
flex-shrink:0;
|
|
59
|
-
align-items:center;
|
|
60
|
-
justify-content:center;
|
|
61
|
-
color:var(--sys-neutral-text-light, #898989);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
.postfix{
|
|
65
|
-
display:inline-flex;
|
|
66
|
-
flex-shrink:0;
|
|
67
|
-
gap:var(--space-fields-postfix-gap, 4px);
|
|
68
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import cn from 'classnames';
|
|
2
|
-
import mergeRefs from 'merge-refs';
|
|
3
|
-
import { FocusEvent, forwardRef, KeyboardEvent, useCallback, useMemo, useRef } from 'react';
|
|
4
|
-
import { useUncontrolledProp } from 'uncontrollable';
|
|
5
|
-
|
|
6
|
-
import { SearchSVG } from '@snack-uikit/icons';
|
|
7
|
-
import {
|
|
8
|
-
InputPrivate,
|
|
9
|
-
InputPrivateProps,
|
|
10
|
-
moveCursorToEnd,
|
|
11
|
-
useButtonNavigation,
|
|
12
|
-
useClearButton,
|
|
13
|
-
} from '@snack-uikit/input-private';
|
|
14
|
-
import { Sun } from '@snack-uikit/loaders';
|
|
15
|
-
import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
|
|
16
|
-
|
|
17
|
-
import { PRIVATE_SEARCH_TEST_IDS, SIZE } from '../../constants';
|
|
18
|
-
import { Size } from '../../types';
|
|
19
|
-
import styles from './styles.module.scss';
|
|
20
|
-
|
|
21
|
-
export type SearchPrivateProps = WithSupportProps<
|
|
22
|
-
{
|
|
23
|
-
/** Размер */
|
|
24
|
-
size?: Size;
|
|
25
|
-
/** Состояние загрузки */
|
|
26
|
-
loading?: boolean;
|
|
27
|
-
/** Колбек на подтверждение поиска по строке */
|
|
28
|
-
onSubmit?(value: string): void;
|
|
29
|
-
/** CSS-класс */
|
|
30
|
-
className?: string;
|
|
31
|
-
} & Pick<Partial<InputPrivateProps>, 'value' | 'onChange' | 'placeholder' | 'onFocus' | 'onBlur' | 'onKeyDown'>
|
|
32
|
-
>;
|
|
33
|
-
|
|
34
|
-
export const SearchPrivate = forwardRef<HTMLInputElement, SearchPrivateProps>(function SearchPrivate(
|
|
35
|
-
{
|
|
36
|
-
size = SIZE.S,
|
|
37
|
-
value: valueProp = '',
|
|
38
|
-
onChange: onChangeProp,
|
|
39
|
-
loading,
|
|
40
|
-
placeholder,
|
|
41
|
-
onKeyDown,
|
|
42
|
-
onFocus,
|
|
43
|
-
onBlur,
|
|
44
|
-
onSubmit,
|
|
45
|
-
className,
|
|
46
|
-
...rest
|
|
47
|
-
},
|
|
48
|
-
ref,
|
|
49
|
-
) {
|
|
50
|
-
const [value, onValueChange] = useUncontrolledProp(valueProp, '', onChangeProp);
|
|
51
|
-
|
|
52
|
-
const localRef = useRef<HTMLInputElement>(null);
|
|
53
|
-
const clearButtonRef = useRef<HTMLButtonElement>(null);
|
|
54
|
-
|
|
55
|
-
const showClearButton = Boolean(value);
|
|
56
|
-
|
|
57
|
-
const onClear = () => {
|
|
58
|
-
onValueChange('');
|
|
59
|
-
|
|
60
|
-
localRef.current?.focus();
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const clearButtonSettings = useClearButton({
|
|
64
|
-
clearButtonRef,
|
|
65
|
-
showClearButton,
|
|
66
|
-
size,
|
|
67
|
-
onClear,
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
const { buttons, inputTabIndex, onInputKeyDown } = useButtonNavigation({
|
|
71
|
-
inputRef: localRef,
|
|
72
|
-
buttons: useMemo(() => [clearButtonSettings], [clearButtonSettings]),
|
|
73
|
-
readonly: false,
|
|
74
|
-
submitKeys: ['Enter', 'Space'],
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
const handleKeyDown = useCallback(
|
|
78
|
-
(e: KeyboardEvent<HTMLInputElement>) => {
|
|
79
|
-
onKeyDown && onKeyDown(e);
|
|
80
|
-
onInputKeyDown(e);
|
|
81
|
-
|
|
82
|
-
if (e.key === 'Enter' && localRef.current?.value) {
|
|
83
|
-
onSubmit && onSubmit(localRef.current.value);
|
|
84
|
-
// TODO: think about remove blur behavior
|
|
85
|
-
localRef.current?.blur();
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
[onInputKeyDown, onKeyDown, onSubmit],
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
const handleOnFocus = useCallback(
|
|
92
|
-
(e: FocusEvent<HTMLInputElement, Element>) => {
|
|
93
|
-
onFocus && onFocus(e);
|
|
94
|
-
moveCursorToEnd(localRef.current);
|
|
95
|
-
},
|
|
96
|
-
[onFocus],
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
return (
|
|
100
|
-
<div className={cn(styles.container, className)} {...extractSupportProps(rest)} data-size={size}>
|
|
101
|
-
<span className={styles.prefix}>
|
|
102
|
-
{loading ? (
|
|
103
|
-
<Sun data-test-id={PRIVATE_SEARCH_TEST_IDS.iconSun} />
|
|
104
|
-
) : (
|
|
105
|
-
<SearchSVG data-test-id={PRIVATE_SEARCH_TEST_IDS.iconSearch} />
|
|
106
|
-
)}
|
|
107
|
-
</span>
|
|
108
|
-
|
|
109
|
-
<InputPrivate
|
|
110
|
-
value={value}
|
|
111
|
-
onChange={onValueChange}
|
|
112
|
-
onKeyDown={handleKeyDown}
|
|
113
|
-
onFocus={handleOnFocus}
|
|
114
|
-
onBlur={onBlur}
|
|
115
|
-
tabIndex={inputTabIndex}
|
|
116
|
-
ref={mergeRefs(ref, localRef)}
|
|
117
|
-
placeholder={placeholder}
|
|
118
|
-
type='text'
|
|
119
|
-
data-test-id={PRIVATE_SEARCH_TEST_IDS.input}
|
|
120
|
-
/>
|
|
121
|
-
|
|
122
|
-
<span className={styles.postfix}>{buttons}</span>
|
|
123
|
-
</div>
|
|
124
|
-
);
|
|
125
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './SearchPrivate';
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
@import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-search';
|
|
2
|
-
@import "@snack-uikit/figma-tokens/build/scss/components/styles-tokens-element";
|
|
3
|
-
|
|
4
|
-
$sizes: 's', 'm', 'l';
|
|
5
|
-
|
|
6
|
-
.container {
|
|
7
|
-
display: flex;
|
|
8
|
-
flex-grow: 1;
|
|
9
|
-
align-items: center;
|
|
10
|
-
box-sizing: border-box;
|
|
11
|
-
|
|
12
|
-
@each $size in $sizes {
|
|
13
|
-
&[data-size='#{$size}'] {
|
|
14
|
-
@include composite-var($search-private, $size);
|
|
15
|
-
|
|
16
|
-
input {
|
|
17
|
-
@include composite-var($theme-variables, 'sans', 'body', $size);
|
|
18
|
-
|
|
19
|
-
cursor: text;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
svg {
|
|
23
|
-
width: $icon-s !important; /* stylelint-disable-line declaration-no-important */
|
|
24
|
-
height: $icon-s !important; /* stylelint-disable-line declaration-no-important */
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
.prefix {
|
|
31
|
-
display: inline-flex;
|
|
32
|
-
flex-shrink: 0;
|
|
33
|
-
align-items: center;
|
|
34
|
-
justify-content: center;
|
|
35
|
-
|
|
36
|
-
color: $sys-neutral-text-light;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
.postfix {
|
|
40
|
-
display: inline-flex;
|
|
41
|
-
flex-shrink: 0;
|
|
42
|
-
gap: $space-fields-postfix-gap;
|
|
43
|
-
}
|