@skbkontur/react-ui 4.4.0 → 4.5.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/CHANGELOG.md +43 -1
- package/README.md +27 -4
- package/cjs/components/Autocomplete/Autocomplete.md +15 -1
- package/cjs/components/ComboBox/ComboBox.md +32 -0
- package/cjs/components/DatePicker/DatePicker.md +18 -0
- package/cjs/components/FileUploader/FileUploader.d.ts +2 -1
- package/cjs/components/FileUploader/FileUploader.js +15 -2
- package/cjs/components/FileUploader/FileUploader.js.map +1 -1
- package/cjs/components/FxInput/FxInput.md +13 -0
- package/cjs/components/Input/Input.js +2 -1
- package/cjs/components/Input/Input.js.map +1 -1
- package/cjs/components/Input/Input.md +12 -0
- package/cjs/components/Input/Input.styles.d.ts +1 -0
- package/cjs/components/Input/Input.styles.js +17 -10
- package/cjs/components/Input/Input.styles.js.map +1 -1
- package/cjs/components/Loader/Loader.d.ts +11 -2
- package/cjs/components/Loader/Loader.js +10 -1
- package/cjs/components/Loader/Loader.js.map +1 -1
- package/cjs/components/Loader/Loader.md +30 -23
- package/cjs/components/ResponsiveLayout/ResponsiveLayout.d.ts +6 -5
- package/cjs/components/ResponsiveLayout/ResponsiveLayout.js +5 -9
- package/cjs/components/ResponsiveLayout/ResponsiveLayout.js.map +1 -1
- package/cjs/components/ResponsiveLayout/ResponsiveLayout.md +31 -0
- package/cjs/components/ResponsiveLayout/decorator.d.ts +1 -1
- package/cjs/components/ResponsiveLayout/types.d.ts +9 -1
- package/cjs/components/ResponsiveLayout/useResponsiveLayout.d.ts +2 -2
- package/cjs/components/ResponsiveLayout/useResponsiveLayout.js +31 -15
- package/cjs/components/ResponsiveLayout/useResponsiveLayout.js.map +1 -1
- package/cjs/components/Select/Select.md +14 -0
- package/cjs/components/Spinner/Spinner.d.ts +11 -2
- package/cjs/components/Spinner/Spinner.js +10 -1
- package/cjs/components/Spinner/Spinner.js.map +1 -1
- package/cjs/components/Textarea/Textarea.md +19 -0
- package/cjs/components/Token/Token.styles.js +2 -1
- package/cjs/components/Token/Token.styles.js.map +1 -1
- package/cjs/components/TokenInput/TokenInput.d.ts +3 -0
- package/cjs/components/TokenInput/TokenInput.js +56 -13
- package/cjs/components/TokenInput/TokenInput.js.map +1 -1
- package/cjs/components/TokenInput/TokenInput.md +26 -0
- package/cjs/components/TokenInput/TokenInput.styles.js +2 -1
- package/cjs/components/TokenInput/TokenInput.styles.js.map +1 -1
- package/cjs/internal/ThemeShowcase/VariablesCollector.d.ts +1 -1
- package/cjs/internal/ZIndex/ZIndex.d.ts +17 -3
- package/cjs/internal/ZIndex/ZIndex.js +55 -14
- package/cjs/internal/ZIndex/ZIndex.js.map +1 -1
- package/cjs/internal/themes/DefaultTheme.d.ts +2 -0
- package/cjs/internal/themes/DefaultTheme.js +8 -2
- package/cjs/internal/themes/DefaultTheme.js.map +1 -1
- package/cjs/lib/rootNode/getRootNode.d.ts +1 -1
- package/cjs/lib/rootNode/getRootNode.js +37 -12
- package/cjs/lib/rootNode/getRootNode.js.map +1 -1
- package/components/Autocomplete/Autocomplete.md +15 -1
- package/components/ComboBox/ComboBox.md +32 -0
- package/components/DatePicker/DatePicker.md +18 -0
- package/components/FileUploader/FileUploader/FileUploader.js +8 -3
- package/components/FileUploader/FileUploader/FileUploader.js.map +1 -1
- package/components/FileUploader/FileUploader.d.ts +2 -1
- package/components/FxInput/FxInput.md +13 -0
- package/components/Input/Input/Input.js +1 -1
- package/components/Input/Input/Input.js.map +1 -1
- package/components/Input/Input.md +12 -0
- package/components/Input/Input.styles/Input.styles.js +13 -10
- package/components/Input/Input.styles/Input.styles.js.map +1 -1
- package/components/Input/Input.styles.d.ts +1 -0
- package/components/Loader/Loader/Loader.js +3 -1
- package/components/Loader/Loader/Loader.js.map +1 -1
- package/components/Loader/Loader.d.ts +11 -2
- package/components/Loader/Loader.md +30 -23
- package/components/ResponsiveLayout/ResponsiveLayout/ResponsiveLayout.js +5 -8
- package/components/ResponsiveLayout/ResponsiveLayout/ResponsiveLayout.js.map +1 -1
- package/components/ResponsiveLayout/ResponsiveLayout.d.ts +6 -5
- package/components/ResponsiveLayout/ResponsiveLayout.md +31 -0
- package/components/ResponsiveLayout/decorator.d.ts +1 -1
- package/components/ResponsiveLayout/types.d.ts +9 -1
- package/components/ResponsiveLayout/useResponsiveLayout/useResponsiveLayout.js +42 -17
- package/components/ResponsiveLayout/useResponsiveLayout/useResponsiveLayout.js.map +1 -1
- package/components/ResponsiveLayout/useResponsiveLayout.d.ts +2 -2
- package/components/Select/Select.md +14 -0
- package/components/Spinner/Spinner/Spinner.js +1 -1
- package/components/Spinner/Spinner/Spinner.js.map +1 -1
- package/components/Spinner/Spinner.d.ts +11 -2
- package/components/Textarea/Textarea.md +19 -0
- package/components/Token/Token.styles/Token.styles.js +1 -1
- package/components/Token/Token.styles/Token.styles.js.map +1 -1
- package/components/TokenInput/TokenInput/TokenInput.js +82 -19
- package/components/TokenInput/TokenInput/TokenInput.js.map +1 -1
- package/components/TokenInput/TokenInput.d.ts +3 -0
- package/components/TokenInput/TokenInput.md +26 -0
- package/components/TokenInput/TokenInput.styles/TokenInput.styles.js +1 -1
- package/components/TokenInput/TokenInput.styles/TokenInput.styles.js.map +1 -1
- package/internal/ThemeShowcase/VariablesCollector.d.ts +1 -1
- package/internal/ZIndex/ZIndex/ZIndex.js +46 -27
- package/internal/ZIndex/ZIndex/ZIndex.js.map +1 -1
- package/internal/ZIndex/ZIndex.d.ts +17 -3
- package/internal/themes/DefaultTheme/DefaultTheme.js +11 -1
- package/internal/themes/DefaultTheme/DefaultTheme.js.map +1 -1
- package/internal/themes/DefaultTheme.d.ts +2 -0
- package/lib/rootNode/getRootNode/getRootNode.js +28 -10
- package/lib/rootNode/getRootNode/getRootNode.js.map +1 -1
- package/lib/rootNode/getRootNode.d.ts +1 -1
- package/package.json +3 -20
|
@@ -1,34 +1,48 @@
|
|
|
1
|
-
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.useResponsiveLayout = useResponsiveLayout;var
|
|
1
|
+
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.useResponsiveLayout = useResponsiveLayout;var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));var _react = require("react");
|
|
2
2
|
|
|
3
3
|
var _ThemeContext = require("../../lib/theming/ThemeContext");
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _ResponsiveLayoutEvents = require("./ResponsiveLayoutEvents");
|
|
7
7
|
|
|
8
|
-
function useResponsiveLayout()
|
|
8
|
+
function useResponsiveLayout(_temp)
|
|
9
|
+
|
|
10
|
+
{var _ref = _temp === void 0 ? {} : _temp,customMediaQueries = _ref.customMediaQueries;
|
|
9
11
|
var theme = (0, _react.useContext)(_ThemeContext.ThemeContext);
|
|
10
12
|
|
|
13
|
+
var allMediaQueries = Object.entries((0, _extends3.default)({
|
|
14
|
+
isMobile: theme.mobileMediaQuery },
|
|
15
|
+
customMediaQueries)).
|
|
16
|
+
map(function (_ref2) {var key = _ref2[0],value = _ref2[1];return {
|
|
17
|
+
flag: key,
|
|
18
|
+
query: value,
|
|
19
|
+
ref: /*#__PURE__*/(0, _react.createRef)() };});
|
|
20
|
+
|
|
21
|
+
|
|
11
22
|
var getLayoutFromGlobal = function getLayoutFromGlobal() {
|
|
12
|
-
|
|
23
|
+
return allMediaQueries.reduce(
|
|
24
|
+
function (result, mediaQuery) {var _Object$assign;return Object.assign(result, (_Object$assign = {}, _Object$assign[mediaQuery.flag] = (0, _ResponsiveLayoutEvents.checkMatches)(mediaQuery.query), _Object$assign));},
|
|
25
|
+
{});
|
|
13
26
|
|
|
14
|
-
return { isMobile: !!isMobile };
|
|
15
27
|
};
|
|
16
28
|
|
|
17
29
|
var _useState = (0, _react.useState)(getLayoutFromGlobal()),state = _useState[0],setState = _useState[1];
|
|
18
30
|
|
|
19
|
-
var mobileListener = (0, _react.useRef)(null);
|
|
20
|
-
|
|
21
31
|
var prepareMediaQueries = (0, _react.useCallback)(function () {
|
|
22
32
|
if (!theme) {
|
|
23
33
|
return;
|
|
24
34
|
}
|
|
25
35
|
|
|
26
|
-
|
|
36
|
+
allMediaQueries.forEach(
|
|
37
|
+
function (mediaQuery) {return (
|
|
38
|
+
mediaQuery.ref.current = (0, _ResponsiveLayoutEvents.addResponsiveLayoutListener)(mediaQuery.query, checkLayoutsMediaQueries));});
|
|
39
|
+
|
|
27
40
|
|
|
28
41
|
// Checking for SSR use case
|
|
29
42
|
var globalLayout = getLayoutFromGlobal();
|
|
43
|
+
var hasChangedQuery = Object.entries(globalLayout).find(function (_ref3) {var key = _ref3[0],value = _ref3[1];return state[key] !== value;});
|
|
30
44
|
|
|
31
|
-
if (
|
|
45
|
+
if (hasChangedQuery) {
|
|
32
46
|
setState(globalLayout);
|
|
33
47
|
}
|
|
34
48
|
}, [theme]);
|
|
@@ -39,12 +53,14 @@ function useResponsiveLayout() {
|
|
|
39
53
|
return;
|
|
40
54
|
}
|
|
41
55
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
prevState, {
|
|
45
|
-
|
|
56
|
+
allMediaQueries.forEach(function (mediaQuery) {
|
|
57
|
+
if (e.media === mediaQuery.query) {
|
|
58
|
+
setState(function (prevState) {var _extends2;return (0, _extends3.default)({},
|
|
59
|
+
prevState, (_extends2 = {}, _extends2[
|
|
60
|
+
mediaQuery.flag] = e.matches, _extends2));});
|
|
46
61
|
|
|
47
|
-
|
|
62
|
+
}
|
|
63
|
+
});
|
|
48
64
|
},
|
|
49
65
|
[theme]);
|
|
50
66
|
|
|
@@ -52,8 +68,8 @@ function useResponsiveLayout() {
|
|
|
52
68
|
(0, _react.useEffect)(function () {
|
|
53
69
|
prepareMediaQueries();
|
|
54
70
|
|
|
55
|
-
return function () {
|
|
56
|
-
(
|
|
71
|
+
return function () {
|
|
72
|
+
allMediaQueries.forEach(function (mediaQuery) {var _mediaQuery$ref$curre;return (_mediaQuery$ref$curre = mediaQuery.ref.current) == null ? void 0 : _mediaQuery$ref$curre.remove();});
|
|
57
73
|
};
|
|
58
74
|
}, []);
|
|
59
75
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useResponsiveLayout.ts"],"names":["useResponsiveLayout","theme","ThemeContext","
|
|
1
|
+
{"version":3,"sources":["useResponsiveLayout.ts"],"names":["useResponsiveLayout","customMediaQueries","theme","ThemeContext","allMediaQueries","Object","entries","isMobile","mobileMediaQuery","map","key","value","flag","query","ref","getLayoutFromGlobal","reduce","result","mediaQuery","assign","state","setState","prepareMediaQueries","forEach","current","checkLayoutsMediaQueries","globalLayout","hasChangedQuery","find","e","media","prevState","matches","remove"],"mappings":"gQAAA;;AAEA;;;AAGA;;AAEO,SAASA,mBAAT;;AAE6B,+BAAJ,EAAI,SADlCC,kBACkC,QADlCA,kBACkC;AAClC,MAAMC,KAAK,GAAG,uBAAWC,0BAAX,CAAd;;AAEA,MAAMC,eAAe,GAAGC,MAAM,CAACC,OAAP;AACtBC,IAAAA,QAAQ,EAAEL,KAAK,CAACM,gBADM;AAEnBP,EAAAA,kBAFmB;AAGrBQ,EAAAA,GAHqB,CAGjB,sBAAEC,GAAF,YAAOC,KAAP,mBAAmB;AACxBC,MAAAA,IAAI,EAAEF,GADkB;AAExBG,MAAAA,KAAK,EAAEF,KAFiB;AAGxBG,MAAAA,GAAG,eAAE,uBAHmB,EAAnB,EAHiB,CAAxB;;;AASA,MAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB,GAAgC;AAC1D,WAAOX,eAAe,CAACY,MAAhB;AACL,cAACC,MAAD,EAASC,UAAT,6BAAwBb,MAAM,CAACc,MAAP,CAAcF,MAAd,uCAAyBC,UAAU,CAACN,IAApC,IAA2C,0CAAaM,UAAU,CAACL,KAAxB,CAA3C,kBAAxB,EADK;AAEL,MAFK,CAAP;;AAID,GALD;;AAOA,kBAA0B,qBAASE,mBAAmB,EAA5B,CAA1B,CAAOK,KAAP,gBAAcC,QAAd;;A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GD,GAND,EAMG,EANH;;AAQA,SAAOb,KAAP;AACD","sourcesContent":["import React, { createRef, useCallback, useContext, useEffect, useState } from 'react';\n\nimport { ThemeContext } from '../../lib/theming/ThemeContext';\n\nimport { EmptyObject, MediaQueriesType, ResponsiveLayoutFlags, ResponsiveLayoutOptions } from './types';\nimport { addResponsiveLayoutListener, checkMatches } from './ResponsiveLayoutEvents';\n\nexport function useResponsiveLayout<T extends MediaQueriesType = EmptyObject>({\n customMediaQueries,\n}: ResponsiveLayoutOptions<T> = {}) {\n const theme = useContext(ThemeContext);\n\n const allMediaQueries = Object.entries({\n isMobile: theme.mobileMediaQuery,\n ...customMediaQueries,\n }).map(([key, value]) => ({\n flag: key,\n query: value,\n ref: createRef() as React.MutableRefObject<{ remove: () => void } | null>,\n }));\n\n const getLayoutFromGlobal = (): ResponsiveLayoutFlags<T> => {\n return allMediaQueries.reduce(\n (result, mediaQuery) => Object.assign(result, { [mediaQuery.flag]: checkMatches(mediaQuery.query) }),\n {},\n ) as ResponsiveLayoutFlags<T>;\n };\n\n const [state, setState] = useState(getLayoutFromGlobal());\n\n const prepareMediaQueries = useCallback(() => {\n if (!theme) {\n return;\n }\n\n allMediaQueries.forEach(\n (mediaQuery) =>\n (mediaQuery.ref.current = addResponsiveLayoutListener(mediaQuery.query, checkLayoutsMediaQueries)),\n );\n\n // Checking for SSR use case\n const globalLayout = getLayoutFromGlobal();\n const hasChangedQuery = Object.entries(globalLayout).find(([key, value]) => state[key] !== value);\n\n if (hasChangedQuery) {\n setState(globalLayout);\n }\n }, [theme]);\n\n const checkLayoutsMediaQueries = useCallback(\n (e: MediaQueryListEvent) => {\n if (!theme) {\n return;\n }\n\n allMediaQueries.forEach((mediaQuery) => {\n if (e.media === mediaQuery.query) {\n setState((prevState: ResponsiveLayoutFlags<T>) => ({\n ...prevState,\n [mediaQuery.flag]: e.matches,\n }));\n }\n });\n },\n [theme],\n );\n\n useEffect(() => {\n prepareMediaQueries();\n\n return () => {\n allMediaQueries.forEach((mediaQuery) => mediaQuery.ref.current?.remove());\n };\n }, []);\n\n return state;\n}\n"]}
|
|
@@ -8,6 +8,20 @@ const items = [Select.static(() => <Select.Item>Not selectable</Select.Item>), '
|
|
|
8
8
|
<Select items={items} value={value} onValueChange={setValue} />;
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
Очистить значение в `Select`'е можно только с помощью `null`
|
|
12
|
+
```jsx harmony
|
|
13
|
+
import { Button, Group } from '@skbkontur/react-ui';
|
|
14
|
+
|
|
15
|
+
const [value, setValue] = React.useState();
|
|
16
|
+
|
|
17
|
+
const items = ['One', 'Two', 'Three', 'Four'];
|
|
18
|
+
|
|
19
|
+
<Group>
|
|
20
|
+
<Select items={items} value={value} onValueChange={setValue} />
|
|
21
|
+
<Button onClick={() => setValue(null)}>Очистить</Button>
|
|
22
|
+
</Group>
|
|
23
|
+
```
|
|
24
|
+
|
|
11
25
|
Пример с полем поиска.
|
|
12
26
|
|
|
13
27
|
```jsx harmony
|
|
@@ -4,10 +4,19 @@ import { CommonProps } from '../../internal/CommonWrapper';
|
|
|
4
4
|
declare const types: Record<SpinnerType, SpinnerType>;
|
|
5
5
|
export declare type SpinnerType = 'mini' | 'normal' | 'big';
|
|
6
6
|
export interface SpinnerProps extends CommonProps {
|
|
7
|
+
/**
|
|
8
|
+
* Подпись под спиннером
|
|
9
|
+
*/
|
|
7
10
|
caption?: React.ReactNode;
|
|
11
|
+
/**
|
|
12
|
+
* Переводит спиннер в "затемнённый режим"
|
|
13
|
+
*
|
|
14
|
+
* Цвет спиннера в "затемнённом режиме" определяется переменной `spinnerDimmedColor`
|
|
15
|
+
*/
|
|
8
16
|
dimmed?: boolean;
|
|
9
17
|
/**
|
|
10
|
-
*
|
|
18
|
+
* Размер спиннера и текста
|
|
19
|
+
*
|
|
11
20
|
* @default normal
|
|
12
21
|
*/
|
|
13
22
|
type?: SpinnerType;
|
|
@@ -26,7 +35,7 @@ export declare const SpinnerDataTids: {
|
|
|
26
35
|
};
|
|
27
36
|
declare type DefaultProps = Required<Pick<SpinnerProps, 'type'>>;
|
|
28
37
|
/**
|
|
29
|
-
*
|
|
38
|
+
* Используйте компонент `Spinner`, если вам нужен спиннер, без дополнительного функционала, который предоставляет компонент [Loader](https://tech.skbkontur.ru/react-ui/#/Components/Loader)
|
|
30
39
|
*/
|
|
31
40
|
export declare class Spinner extends React.Component<SpinnerProps> {
|
|
32
41
|
static __KONTUR_REACT_UI__: string;
|
|
@@ -30,6 +30,15 @@ var types = {
|
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
33
42
|
|
|
34
43
|
|
|
35
44
|
|
|
@@ -47,7 +56,7 @@ var SpinnerDataTids = {
|
|
|
47
56
|
|
|
48
57
|
|
|
49
58
|
/**
|
|
50
|
-
*
|
|
59
|
+
* Используйте компонент `Spinner`, если вам нужен спиннер, без дополнительного функционала, который предоставляет компонент [Loader](https://tech.skbkontur.ru/react-ui/#/Components/Loader)
|
|
51
60
|
*/var
|
|
52
61
|
|
|
53
62
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Spinner.tsx"],"names":["types","big","mini","normal","SpinnerDataTids","root","Spinner","SpinnerLocaleHelper","rootNode","getProps","defaultProps","renderSpinner","type","dimmed","inline","styles","circle","theme","props","color","circleDimmedColor","circleWithoutColorAnimation","width","renderCaption","caption","captionColor","render","renderMain","locale","loading","setRootNode","spinner","inner","React","Component","__KONTUR_REACT_UI__","propTypes","PropTypes","node","bool","oneOf","Object","keys","Types"],"mappings":"+VAAA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,kC;;AAEA,IAAMA,KAAuC,GAAG;AAC9CC,EAAAA,GAAG,EAAE,KADyC;AAE9CC,EAAAA,IAAI,EAAE,MAFwC;AAG9CC,EAAAA,MAAM,EAAE,QAHsC,EAAhD
|
|
1
|
+
{"version":3,"sources":["Spinner.tsx"],"names":["types","big","mini","normal","SpinnerDataTids","root","Spinner","SpinnerLocaleHelper","rootNode","getProps","defaultProps","renderSpinner","type","dimmed","inline","styles","circle","theme","props","color","circleDimmedColor","circleWithoutColorAnimation","width","renderCaption","caption","captionColor","render","renderMain","locale","loading","setRootNode","spinner","inner","React","Component","__KONTUR_REACT_UI__","propTypes","PropTypes","node","bool","oneOf","Object","keys","Types"],"mappings":"+VAAA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,kC;;AAEA,IAAMA,KAAuC,GAAG;AAC9CC,EAAAA,GAAG,EAAE,KADyC;AAE9CC,EAAAA,IAAI,EAAE,MAFwC;AAG9CC,EAAAA,MAAM,EAAE,QAHsC,EAAhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCO,IAAMC,eAAe,GAAG;AAC7BC,EAAAA,IAAI,EAAE,eADuB,EAAxB,C;;;;;AAMP;AACA;AACA,G;;;;AAIaC,O,WADZ,wBAAO,SAAP,EAAkBC,2BAAlB,C,MADAC,kB;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BSC,IAAAA,Q,GAAW,0CAAkBH,OAAO,CAACI,YAA1B,C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCXC,IAAAA,a,GAAgB,UAACC,IAAD,EAAoBC,MAApB,EAAsCC,MAAtC,EAA2D;AACjF;AACE,qCAAC,wBAAD;AACE,UAAA,IAAI,EAAEF,IADR;AAEE,UAAA,SAAS,EAAE;AACRG,0BAAOC,MAAP,CAAc,MAAKC,KAAnB,CADQ,IACoB,CAACJ,MAAD,IAAW,CAAC,MAAKK,KAAL,CAAWC,KAD3C;AAERJ,0BAAOK,iBAAP,CAAyB,MAAKH,KAA9B,CAFQ,IAE+BJ,MAF/B;AAGRE,0BAAOM,2BAAP,EAHQ,IAG+BR,MAAM,IAAI,CAAC,CAAC,MAAKK,KAA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C,S,WACnBC,mB,GAAsB,S,UAEtBC,S,GAAY,EACxB;AACJ;AACA;AACA;AACA,KACIZ,OAAO,EAAEa,mBAAUC,IANK,EAQxBzB,MAAM,EAAEwB,mBAAUE,IARM,EAUxB;AACJ;AACA;AACA;AACA;AACA;AACA,KACI3B,IAAI,EAAEyB,mBAAUG,KAAV,CAAgBC,MAAM,CAACC,IAAP,CAAY1C,KAAZ,CAAhB,CAjBkB,E,UAoBZU,Y,GAA6B,EACzCE,IAAI,EAAE,QADmC,E,UAM7B+B,K,GAAsB3C,K","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\n\nimport { locale } from '../../lib/locale/decorators';\nimport { Theme } from '../../lib/theming/Theme';\nimport { ThemeContext } from '../../lib/theming/ThemeContext';\nimport { SpinnerIcon } from '../../internal/icons/SpinnerIcon';\nimport { CommonProps, CommonWrapper } from '../../internal/CommonWrapper';\nimport { cx } from '../../lib/theming/Emotion';\nimport { rootNode, TSetRootNode } from '../../lib/rootNode';\nimport { createPropsGetter } from '../../lib/createPropsGetter';\n\nimport { styles } from './Spinner.styles';\nimport { SpinnerLocale, SpinnerLocaleHelper } from './locale';\n\nconst types: Record<SpinnerType, SpinnerType> = {\n big: 'big',\n mini: 'mini',\n normal: 'normal',\n};\n\nexport type SpinnerType = 'mini' | 'normal' | 'big';\n\nexport interface SpinnerProps extends CommonProps {\n /**\n * Подпись под спиннером\n */\n caption?: React.ReactNode;\n /**\n * Переводит спиннер в \"затемнённый режим\"\n *\n * Цвет спиннера в \"затемнённом режиме\" определяется переменной `spinnerDimmedColor`\n */\n dimmed?: boolean;\n /**\n * Размер спиннера и текста\n *\n * @default normal\n */\n type?: SpinnerType;\n inline?: boolean;\n /**\n * Толщина спиннера\n */\n width?: number;\n /**\n * Цвет спиннера\n */\n color?: React.CSSProperties['color'];\n}\n\nexport const SpinnerDataTids = {\n root: 'Spinner__root',\n} as const;\n\ntype DefaultProps = Required<Pick<SpinnerProps, 'type'>>;\n\n/**\n * Используйте компонент `Spinner`, если вам нужен спиннер, без дополнительного функционала, который предоставляет компонент [Loader](https://tech.skbkontur.ru/react-ui/#/Components/Loader)\n */\n\n@rootNode\n@locale('Spinner', SpinnerLocaleHelper)\nexport class Spinner extends React.Component<SpinnerProps> {\n public static __KONTUR_REACT_UI__ = 'Spinner';\n\n public static propTypes = {\n /**\n * Текст рядом с мини-лоадером.\n *\n * 'Загрузка' - значение по-умолчанию\n */\n caption: PropTypes.node,\n\n dimmed: PropTypes.bool,\n\n /**\n * Тип спиннера: mini, normal, big\n *\n * Значение по-умолчанию - normal\n *\n * Spinner.types - все доступные типы\n */\n type: PropTypes.oneOf(Object.keys(types)),\n };\n\n public static defaultProps: DefaultProps = {\n type: 'normal',\n };\n\n private getProps = createPropsGetter(Spinner.defaultProps);\n\n public static Types: typeof types = types;\n private theme!: Theme;\n private readonly locale!: SpinnerLocale;\n private setRootNode!: TSetRootNode;\n\n public render() {\n return (\n <ThemeContext.Consumer>\n {(theme) => {\n this.theme = theme;\n return this.renderMain();\n }}\n </ThemeContext.Consumer>\n );\n }\n\n private renderMain() {\n const { caption = this.locale.loading, dimmed, inline } = this.props;\n const type = this.getProps().type;\n\n return (\n <CommonWrapper rootNodeRef={this.setRootNode} {...this.props}>\n <div data-tid={SpinnerDataTids.root} className={styles.spinner()}>\n <span className={styles.inner()}>{this.renderSpinner(type, dimmed, inline)}</span>\n {caption && this.renderCaption(type, caption)}\n </div>\n </CommonWrapper>\n );\n }\n\n private renderSpinner = (type: SpinnerType, dimmed?: boolean, inline?: boolean) => {\n return (\n <SpinnerIcon\n size={type}\n className={cx({\n [styles.circle(this.theme)]: !dimmed && !this.props.color,\n [styles.circleDimmedColor(this.theme)]: dimmed,\n [styles.circleWithoutColorAnimation()]: dimmed || !!this.props.color,\n })}\n dimmed={dimmed}\n width={this.props.width}\n color={this.props.color}\n inline={inline}\n />\n );\n };\n\n private renderCaption = (type: SpinnerType, caption: React.ReactNode) => (\n <span className={cx(styles[type](this.theme), styles.captionColor(this.theme))}>{caption}</span>\n );\n}\n"]}
|
|
@@ -9,6 +9,25 @@ const [value, setValue] = React.useState('');
|
|
|
9
9
|
/>;
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
+
Очистить значение в `Textarea` можно только с помощью пустой строки
|
|
13
|
+
|
|
14
|
+
```jsx harmony
|
|
15
|
+
import { Group, Button } from '@skbkontur/react-ui';
|
|
16
|
+
|
|
17
|
+
const [value, setValue] = React.useState('Значение');
|
|
18
|
+
|
|
19
|
+
<Group>
|
|
20
|
+
<Textarea
|
|
21
|
+
value={value}
|
|
22
|
+
onValueChange={setValue}
|
|
23
|
+
autoResize
|
|
24
|
+
rows={1}
|
|
25
|
+
placeholder="Плейсхолдер"
|
|
26
|
+
/>
|
|
27
|
+
<Button style={{ height: '52px' }} onClick={() => setValue('')}>Очистить значение</Button>
|
|
28
|
+
</Group>
|
|
29
|
+
```
|
|
30
|
+
|
|
12
31
|
Счетчик введенных символов
|
|
13
32
|
|
|
14
33
|
```jsx harmony
|
|
@@ -27,13 +27,14 @@ var styles = (0, _Emotion.memoizeStyle)({
|
|
|
27
27
|
},
|
|
28
28
|
|
|
29
29
|
disabled: function disabled(t) {
|
|
30
|
-
return (0, _Emotion.css)(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteralLoose2.default)(["\n padding: ", " ", ";\n margin: ", " ", ";\n user-select: text;\n cursor: text;\n color: ", ";\n\n .", " {\n visibility: hidden;\n }\n "])),
|
|
30
|
+
return (0, _Emotion.css)(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteralLoose2.default)(["\n padding: ", " ", ";\n margin: ", " ", ";\n user-select: text;\n cursor: text;\n color: ", ";\n pointer-events: none;\n\n .", " {\n visibility: hidden;\n }\n "])),
|
|
31
31
|
t.tokenPaddingYDisabled, t.tokenPaddingXDisabled,
|
|
32
32
|
t.tokenMarginYDisabled, t.tokenMarginXDisabled,
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
t.tokenTextColorDisabled,
|
|
36
36
|
|
|
37
|
+
|
|
37
38
|
globalClasses.removeIcon);
|
|
38
39
|
|
|
39
40
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Token.styles.ts"],"names":["globalClasses","removeIcon","styles","token","t","css","tokenBorderRadius","tokenPaddingY","tokenPaddingX","tokenLineHeight","tokenFontSize","tokenMarginY","tokenMarginX","disabled","tokenPaddingYDisabled","tokenPaddingXDisabled","tokenMarginYDisabled","tokenMarginXDisabled","tokenTextColorDisabled","text","tokenLegacyTextShift","tokenRemoveIconSize","tokenRemoveIconPaddingY","tokenRemoveIconPaddingX","tokenRemoveIconBoxSizing","tokenRemoveIconGap","colorStyles","name","color","tokenDefaultIdle","tokenDefaultActive","tokenGrayIdle","tokenGrayActive","tokenBlueIdle","tokenBlueActive","tokenGreenIdle","tokenGreenActive","tokenYellowIdle","tokenYellowActive","tokenRedIdle","tokenRedActive","tokenWhite","tokenBlack","reduce","colors","v","getVStyle","tokenOutlineWidth","tokenBorderColorError","tokenBorderColorWarning","ColorFunctions","contrast","tokenBorderWidth","darken","defaultDisabled","tokenDisabledBg","tokenShadowDisabled","defaultDisabledWarning","defaultDisabledError"],"mappings":"4YAAA;;AAEA,yF;;AAEO,IAAMA,aAAa,GAAG,qBAAO,OAAP,EAAgB;AAC3CC,EAAAA,UAAU,EAAE,aAD+B,EAAhB,CAAtB,C;;;AAIA,IAAMC,MAAM,GAAG,2BAAa;AACjCC,EAAAA,KADiC,iBAC3BC,CAD2B,EACjB;AACd,eAAOC,YAAP;;;AAGmBD,IAAAA,CAAC,CAACE,iBAHrB;AAIaF,IAAAA,CAAC,CAACG,aAJf,EAIgCH,CAAC,CAACI,aAJlC;AAKiBJ,IAAAA,CAAC,CAACK,eALnB;AAMeL,IAAAA,CAAC,CAACM,aANjB;AAOYN,IAAAA,CAAC,CAACO,YAPd,EAO8BP,CAAC,CAACQ,YAPhC;;;;;;;;;AAgBD,GAlBgC;;AAoBjCC,EAAAA,QApBiC,o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BtD,CAZvB,EAYiC;AAC7B,eAAOC,YAAP;AACsBD,IAAAA,CAAC,CAAC2C,iBADxB,EAC6C3C,CAAC,CAAC4C,qBAD/C,EACyF5C,CAAC,CAACmD,eAD3F;;AAGD,GAhBH,EA9CyB,CAApB,C","sourcesContent":["import { css, memoizeStyle, prefix } from '../../lib/theming/Emotion';\nimport { Theme } from '../../lib/theming/Theme';\nimport * as ColorFunctions from '../../lib/styles/ColorFunctions';\n\nexport const globalClasses = prefix('token')({\n removeIcon: 'remove-icon',\n});\n\nexport const styles = memoizeStyle({\n token(t: Theme) {\n return css`\n display: inline-flex;\n align-items: center;\n border-radius: ${t.tokenBorderRadius};\n padding: ${t.tokenPaddingY} ${t.tokenPaddingX};\n line-height: ${t.tokenLineHeight};\n font-size: ${t.tokenFontSize};\n margin: ${t.tokenMarginY} ${t.tokenMarginX};\n min-width: 0;\n word-break: break-all;\n user-select: none;\n\n &:hover {\n cursor: pointer;\n }\n `;\n },\n\n disabled(t: Theme) {\n return css`\n padding: ${t.tokenPaddingYDisabled} ${t.tokenPaddingXDisabled};\n margin: ${t.tokenMarginYDisabled} ${t.tokenMarginXDisabled};\n user-select: text;\n cursor: text;\n color: ${t.tokenTextColorDisabled};\n\n .${globalClasses.removeIcon} {\n visibility: hidden;\n }\n `;\n },\n\n text(t: Theme) {\n return css`\n display: inline-block;\n padding-bottom: ${t.tokenLegacyTextShift};\n `;\n },\n\n removeIcon(t: Theme) {\n return css`\n height: ${t.tokenRemoveIconSize};\n width: ${t.tokenRemoveIconSize};\n flex-shrink: 0;\n padding: ${t.tokenRemoveIconPaddingY} ${t.tokenRemoveIconPaddingX};\n box-sizing: ${t.tokenRemoveIconBoxSizing};\n margin-left: ${t.tokenRemoveIconGap};\n transition: none;\n fill: currentColor;\n opacity: 0.5;\n line-height: 0;\n\n &:hover {\n opacity: 1;\n }\n `;\n },\n});\n\ninterface TokenColors {\n defaultIdle: (t: Theme, v: 'error' | 'warning' | null) => string;\n defaultActive: (t: Theme, v: 'error' | 'warning' | null) => string;\n defaultDisabled: (t: Theme) => string;\n defaultDisabledWarning: (t: Theme) => string;\n defaultDisabledError: (t: Theme) => string;\n grayIdle: (t: Theme, v: 'error' | 'warning' | null) => string;\n grayActive: (t: Theme, v: 'error' | 'warning' | null) => string;\n blueIdle: (t: Theme, v: 'error' | 'warning' | null) => string;\n blueActive: (t: Theme, v: 'error' | 'warning' | null) => string;\n greenIdle: (t: Theme, v: 'error' | 'warning' | null) => string;\n greenActive: (t: Theme, v: 'error' | 'warning' | null) => string;\n yellowIdle: (t: Theme, v: 'error' | 'warning' | null) => string;\n yellowActive: (t: Theme, v: 'error' | 'warning' | null) => string;\n redIdle: (t: Theme, v: 'error' | 'warning' | null) => string;\n redActive: (t: Theme, v: 'error' | 'warning' | null) => string;\n white: (t: Theme, v: 'error' | 'warning' | null) => string;\n black: (t: Theme, v: 'error' | 'warning' | null) => string;\n}\n\nexport const colorStyles = [\n { name: 'defaultIdle', color: (t: Theme) => t.tokenDefaultIdle },\n { name: 'defaultActive', color: (t: Theme) => t.tokenDefaultActive },\n { name: 'grayIdle', color: (t: Theme) => t.tokenGrayIdle },\n { name: 'grayActive', color: (t: Theme) => t.tokenGrayActive },\n { name: 'blueIdle', color: (t: Theme) => t.tokenBlueIdle },\n { name: 'blueActive', color: (t: Theme) => t.tokenBlueActive },\n { name: 'greenIdle', color: (t: Theme) => t.tokenGreenIdle },\n { name: 'greenActive', color: (t: Theme) => t.tokenGreenActive },\n { name: 'yellowIdle', color: (t: Theme) => t.tokenYellowIdle },\n { name: 'yellowActive', color: (t: Theme) => t.tokenYellowActive },\n { name: 'redIdle', color: (t: Theme) => t.tokenRedIdle },\n { name: 'redActive', color: (t: Theme) => t.tokenRedActive },\n { name: 'white', color: (t: Theme) => t.tokenWhite },\n { name: 'black', color: (t: Theme) => t.tokenBlack },\n].reduce(\n (colors: TokenColors, { name, color }) => ({\n ...colors,\n [name](t: Theme, v: 'error' | 'warning') {\n const getVStyle = () => {\n if (v === 'error') {\n return css`\n box-shadow: 0 0 0 ${t.tokenOutlineWidth} ${t.tokenBorderColorError}, inset 0 0 0 1px ${color(t)};\n `;\n } else if (v === 'warning') {\n return css`\n box-shadow: 0 0 0 ${t.tokenOutlineWidth} ${t.tokenBorderColorWarning}, inset 0 0 0 1px ${color(t)};\n `;\n }\n\n return '';\n };\n\n return css`\n background-color: ${color(t)};\n color: ${ColorFunctions.contrast(color(t))};\n box-shadow: 0 0 0 ${t.tokenBorderWidth} ${ColorFunctions.darken(color(t), '5%')}, inset 0 0 0 1px ${color(t)};\n\n ${getVStyle()}\n\n .${globalClasses.removeIcon}:hover {\n color: ${ColorFunctions.contrast(color(t))};\n }\n `;\n },\n }),\n {\n defaultDisabled(t: Theme) {\n return css`\n background-color: ${t.tokenDisabledBg};\n box-shadow: ${t.tokenShadowDisabled};\n `;\n },\n defaultDisabledWarning(t: Theme) {\n return css`\n box-shadow: 0 0 0 ${t.tokenOutlineWidth} ${t.tokenBorderColorWarning}, inset 0 0 0 1px ${t.tokenDisabledBg};\n `;\n },\n defaultDisabledError(t: Theme) {\n return css`\n box-shadow: 0 0 0 ${t.tokenOutlineWidth} ${t.tokenBorderColorError}, inset 0 0 0 1px ${t.tokenDisabledBg};\n `;\n },\n } as TokenColors,\n);\n"]}
|
|
1
|
+
{"version":3,"sources":["Token.styles.ts"],"names":["globalClasses","removeIcon","styles","token","t","css","tokenBorderRadius","tokenPaddingY","tokenPaddingX","tokenLineHeight","tokenFontSize","tokenMarginY","tokenMarginX","disabled","tokenPaddingYDisabled","tokenPaddingXDisabled","tokenMarginYDisabled","tokenMarginXDisabled","tokenTextColorDisabled","text","tokenLegacyTextShift","tokenRemoveIconSize","tokenRemoveIconPaddingY","tokenRemoveIconPaddingX","tokenRemoveIconBoxSizing","tokenRemoveIconGap","colorStyles","name","color","tokenDefaultIdle","tokenDefaultActive","tokenGrayIdle","tokenGrayActive","tokenBlueIdle","tokenBlueActive","tokenGreenIdle","tokenGreenActive","tokenYellowIdle","tokenYellowActive","tokenRedIdle","tokenRedActive","tokenWhite","tokenBlack","reduce","colors","v","getVStyle","tokenOutlineWidth","tokenBorderColorError","tokenBorderColorWarning","ColorFunctions","contrast","tokenBorderWidth","darken","defaultDisabled","tokenDisabledBg","tokenShadowDisabled","defaultDisabledWarning","defaultDisabledError"],"mappings":"4YAAA;;AAEA,yF;;AAEO,IAAMA,aAAa,GAAG,qBAAO,OAAP,EAAgB;AAC3CC,EAAAA,UAAU,EAAE,aAD+B,EAAhB,CAAtB,C;;;AAIA,IAAMC,MAAM,GAAG,2BAAa;AACjCC,EAAAA,KADiC,iBAC3BC,CAD2B,EACjB;AACd,eAAOC,YAAP;;;AAGmBD,IAAAA,CAAC,CAACE,iBAHrB;AAIaF,IAAAA,CAAC,CAACG,aAJf,EAIgCH,CAAC,CAACI,aAJlC;AAKiBJ,IAAAA,CAAC,CAACK,eALnB;AAMeL,IAAAA,CAAC,CAACM,aANjB;AAOYN,IAAAA,CAAC,CAACO,YAPd,EAO8BP,CAAC,CAACQ,YAPhC;;;;;;;;;AAgBD,GAlBgC;;AAoBjCC,EAAAA,QApBiC,oBAoBxBT,CApBwB,EAoBd;AACjB,eAAOC,YAAP;AACaD,IAAAA,CAAC,CAACU,qBADf,EACwCV,CAAC,CAACW,qBAD1C;AAEYX,IAAAA,CAAC,CAACY,oBAFd,EAEsCZ,CAAC,CAACa,oBAFxC;;;AAKWb,IAAAA,CAAC,CAACc,sBALb;;;AAQKlB,IAAAA,aAAa,CAACC,UARnB;;;;AAYD,GAjCgC;;AAmCjCkB,EAAAA,IAnCiC,gBAmC5Bf,CAnC4B,EAmClB;AACb,eAAOC,YAAP;;AAEoBD,IAAAA,CAAC,CAACgB,oBAFtB;;AAID,GAxCgC;;AA0CjCnB,EAAAA,UA1CiC,sBA0CtBG,CA1CsB,EA0CZ;AACnB,eAAOC,YAAP;AACYD,IAAAA,CAAC,CAACiB,mBADd;AAEWjB,IAAAA,CAAC,CAACiB,mBAFb;;AAIaj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B,CAAD,CAA7B,CAFX;AAGsBA,IAAAA,CAAC,CAACgD,gBAHxB,EAG4CF,cAAc,CAACG,MAAf,CAAsBzB,KAAK,CAACxB,CAAD,CAA3B,EAAgC,IAAhC,CAH5C,EAGsGwB,KAAK,CAACxB,CAAD,CAH3G;;AAKI0C,IAAAA,SAAS,EALb;;AAOK9C,IAAAA,aAAa,CAACC,UAPnB;AAQaiD,IAAAA,cAAc,CAACC,QAAf,CAAwBvB,KAAK,CAACxB,CAAD,CAA7B,CARb;;;AAWD,GA5BH,eAhByB;;AA8CzB;AACEkD,EAAAA,eADF,2BACkBlD,CADlB,EAC4B;AACxB,eAAOC,YAAP;AACsBD,IAAAA,CAAC,CAACmD,eADxB;AAEgBnD,IAAAA,CAAC,CAACoD,mBAFlB;;AAID,GANH;AAOEC,EAAAA,sBAPF,kCAOyBrD,CAPzB,EAOmC;AAC/B,eAAOC,YAAP;AACsBD,IAAAA,CAAC,CAAC2C,iBADxB,EAC6C3C,CAAC,CAAC6C,uBAD/C,EAC2F7C,CAAC,CAACmD,eAD7F;;AAGD,GAXH;AAYEG,EAAAA,oBAZF,gCAYuBtD,CAZvB,EAYiC;AAC7B,eAAOC,YAAP;AACsBD,IAAAA,CAAC,CAAC2C,iBADxB,EAC6C3C,CAAC,CAAC4C,qBAD/C,EACyF5C,CAAC,CAACmD,eAD3F;;AAGD,GAhBH,EA9CyB,CAApB,C","sourcesContent":["import { css, memoizeStyle, prefix } from '../../lib/theming/Emotion';\nimport { Theme } from '../../lib/theming/Theme';\nimport * as ColorFunctions from '../../lib/styles/ColorFunctions';\n\nexport const globalClasses = prefix('token')({\n removeIcon: 'remove-icon',\n});\n\nexport const styles = memoizeStyle({\n token(t: Theme) {\n return css`\n display: inline-flex;\n align-items: center;\n border-radius: ${t.tokenBorderRadius};\n padding: ${t.tokenPaddingY} ${t.tokenPaddingX};\n line-height: ${t.tokenLineHeight};\n font-size: ${t.tokenFontSize};\n margin: ${t.tokenMarginY} ${t.tokenMarginX};\n min-width: 0;\n word-break: break-all;\n user-select: none;\n\n &:hover {\n cursor: pointer;\n }\n `;\n },\n\n disabled(t: Theme) {\n return css`\n padding: ${t.tokenPaddingYDisabled} ${t.tokenPaddingXDisabled};\n margin: ${t.tokenMarginYDisabled} ${t.tokenMarginXDisabled};\n user-select: text;\n cursor: text;\n color: ${t.tokenTextColorDisabled};\n pointer-events: none;\n\n .${globalClasses.removeIcon} {\n visibility: hidden;\n }\n `;\n },\n\n text(t: Theme) {\n return css`\n display: inline-block;\n padding-bottom: ${t.tokenLegacyTextShift};\n `;\n },\n\n removeIcon(t: Theme) {\n return css`\n height: ${t.tokenRemoveIconSize};\n width: ${t.tokenRemoveIconSize};\n flex-shrink: 0;\n padding: ${t.tokenRemoveIconPaddingY} ${t.tokenRemoveIconPaddingX};\n box-sizing: ${t.tokenRemoveIconBoxSizing};\n margin-left: ${t.tokenRemoveIconGap};\n transition: none;\n fill: currentColor;\n opacity: 0.5;\n line-height: 0;\n\n &:hover {\n opacity: 1;\n }\n `;\n },\n});\n\ninterface TokenColors {\n defaultIdle: (t: Theme, v: 'error' | 'warning' | null) => string;\n defaultActive: (t: Theme, v: 'error' | 'warning' | null) => string;\n defaultDisabled: (t: Theme) => string;\n defaultDisabledWarning: (t: Theme) => string;\n defaultDisabledError: (t: Theme) => string;\n grayIdle: (t: Theme, v: 'error' | 'warning' | null) => string;\n grayActive: (t: Theme, v: 'error' | 'warning' | null) => string;\n blueIdle: (t: Theme, v: 'error' | 'warning' | null) => string;\n blueActive: (t: Theme, v: 'error' | 'warning' | null) => string;\n greenIdle: (t: Theme, v: 'error' | 'warning' | null) => string;\n greenActive: (t: Theme, v: 'error' | 'warning' | null) => string;\n yellowIdle: (t: Theme, v: 'error' | 'warning' | null) => string;\n yellowActive: (t: Theme, v: 'error' | 'warning' | null) => string;\n redIdle: (t: Theme, v: 'error' | 'warning' | null) => string;\n redActive: (t: Theme, v: 'error' | 'warning' | null) => string;\n white: (t: Theme, v: 'error' | 'warning' | null) => string;\n black: (t: Theme, v: 'error' | 'warning' | null) => string;\n}\n\nexport const colorStyles = [\n { name: 'defaultIdle', color: (t: Theme) => t.tokenDefaultIdle },\n { name: 'defaultActive', color: (t: Theme) => t.tokenDefaultActive },\n { name: 'grayIdle', color: (t: Theme) => t.tokenGrayIdle },\n { name: 'grayActive', color: (t: Theme) => t.tokenGrayActive },\n { name: 'blueIdle', color: (t: Theme) => t.tokenBlueIdle },\n { name: 'blueActive', color: (t: Theme) => t.tokenBlueActive },\n { name: 'greenIdle', color: (t: Theme) => t.tokenGreenIdle },\n { name: 'greenActive', color: (t: Theme) => t.tokenGreenActive },\n { name: 'yellowIdle', color: (t: Theme) => t.tokenYellowIdle },\n { name: 'yellowActive', color: (t: Theme) => t.tokenYellowActive },\n { name: 'redIdle', color: (t: Theme) => t.tokenRedIdle },\n { name: 'redActive', color: (t: Theme) => t.tokenRedActive },\n { name: 'white', color: (t: Theme) => t.tokenWhite },\n { name: 'black', color: (t: Theme) => t.tokenBlack },\n].reduce(\n (colors: TokenColors, { name, color }) => ({\n ...colors,\n [name](t: Theme, v: 'error' | 'warning') {\n const getVStyle = () => {\n if (v === 'error') {\n return css`\n box-shadow: 0 0 0 ${t.tokenOutlineWidth} ${t.tokenBorderColorError}, inset 0 0 0 1px ${color(t)};\n `;\n } else if (v === 'warning') {\n return css`\n box-shadow: 0 0 0 ${t.tokenOutlineWidth} ${t.tokenBorderColorWarning}, inset 0 0 0 1px ${color(t)};\n `;\n }\n\n return '';\n };\n\n return css`\n background-color: ${color(t)};\n color: ${ColorFunctions.contrast(color(t))};\n box-shadow: 0 0 0 ${t.tokenBorderWidth} ${ColorFunctions.darken(color(t), '5%')}, inset 0 0 0 1px ${color(t)};\n\n ${getVStyle()}\n\n .${globalClasses.removeIcon}:hover {\n color: ${ColorFunctions.contrast(color(t))};\n }\n `;\n },\n }),\n {\n defaultDisabled(t: Theme) {\n return css`\n background-color: ${t.tokenDisabledBg};\n box-shadow: ${t.tokenShadowDisabled};\n `;\n },\n defaultDisabledWarning(t: Theme) {\n return css`\n box-shadow: 0 0 0 ${t.tokenOutlineWidth} ${t.tokenBorderColorWarning}, inset 0 0 0 1px ${t.tokenDisabledBg};\n `;\n },\n defaultDisabledError(t: Theme) {\n return css`\n box-shadow: 0 0 0 ${t.tokenOutlineWidth} ${t.tokenBorderColorError}, inset 0 0 0 1px ${t.tokenDisabledBg};\n `;\n },\n } as TokenColors,\n);\n"]}
|
|
@@ -141,6 +141,7 @@ export declare class TokenInput<T = string> extends React.PureComponent<TokenInp
|
|
|
141
141
|
private textHelper;
|
|
142
142
|
private wrapper;
|
|
143
143
|
private setRootNode;
|
|
144
|
+
private memoizedTokens;
|
|
144
145
|
componentDidMount(): void;
|
|
145
146
|
componentDidUpdate(prevProps: TokenInputProps<T> & DefaultProps<T>, prevState: TokenInputState<T>): void;
|
|
146
147
|
componentWillUnmount(): void;
|
|
@@ -207,5 +208,7 @@ export declare class TokenInput<T = string> extends React.PureComponent<TokenInp
|
|
|
207
208
|
private renderTokensEnd;
|
|
208
209
|
private renderToken;
|
|
209
210
|
private renderAddButton;
|
|
211
|
+
private isTokenDisabled;
|
|
212
|
+
private getAvailableTokenIndex;
|
|
210
213
|
}
|
|
211
214
|
export {};
|
|
@@ -240,6 +240,8 @@ TokenInput = (_dec = (0, _decorators.locale)('TokenInput', _locale.TokenInputLoc
|
|
|
240
240
|
textHelper = null;_this.
|
|
241
241
|
wrapper = null;_this.
|
|
242
242
|
|
|
243
|
+
memoizedTokens = new Map();_this.
|
|
244
|
+
|
|
243
245
|
|
|
244
246
|
|
|
245
247
|
|
|
@@ -706,7 +708,7 @@ TokenInput = (_dec = (0, _decorators.locale)('TokenInput', _locale.TokenInputLoc
|
|
|
706
708
|
}
|
|
707
709
|
}
|
|
708
710
|
}
|
|
709
|
-
|
|
711
|
+
var isRightmostTokenNotDisabled = !_this.isTokenDisabled(_this.getProps().selectedItems.length - 1);
|
|
710
712
|
switch (true) {
|
|
711
713
|
case (0, _identifiers.isKeyEnter)(e):
|
|
712
714
|
if (_this.menuRef) {
|
|
@@ -730,13 +732,17 @@ TokenInput = (_dec = (0, _decorators.locale)('TokenInput', _locale.TokenInputLoc
|
|
|
730
732
|
(_this$input3 = _this.input) == null ? void 0 : _this$input3.blur();
|
|
731
733
|
break;
|
|
732
734
|
case (0, _identifiers.isKeyBackspace)(e):
|
|
733
|
-
if (!_this.isEditingMode) {
|
|
735
|
+
if (!_this.isEditingMode && isRightmostTokenNotDisabled) {
|
|
734
736
|
_this.moveFocusToLastToken();
|
|
735
737
|
}
|
|
736
738
|
break;
|
|
737
739
|
case (0, _identifiers.isKeyArrowLeft)(e):
|
|
738
740
|
if (((_this$input4 = _this.input) == null ? void 0 : _this$input4.selectionStart) === 0) {
|
|
739
|
-
_this.
|
|
741
|
+
var index = _this.getAvailableTokenIndex(_this.getProps().selectedItems.length);
|
|
742
|
+
var itemNew = _this.getProps().selectedItems[index];
|
|
743
|
+
if (itemNew) {
|
|
744
|
+
_this.dispatch({ type: 'SET_ACTIVE_TOKENS', payload: [itemNew] });
|
|
745
|
+
}
|
|
740
746
|
}
|
|
741
747
|
break;}
|
|
742
748
|
|
|
@@ -764,7 +770,10 @@ TokenInput = (_dec = (0, _decorators.locale)('TokenInput', _locale.TokenInputLoc
|
|
|
764
770
|
switch (true) {
|
|
765
771
|
case (0, _identifiers.isKeyBackspace)(e):
|
|
766
772
|
case (0, _identifiers.isKeyDelete)(e):{
|
|
767
|
-
|
|
773
|
+
var indexOfActiveToken = _this.getProps().selectedItems.indexOf(
|
|
774
|
+
_this.state.activeTokens[_this.state.activeTokens.length - 1]);
|
|
775
|
+
|
|
776
|
+
if (!_this.isEditingMode && !_this.isTokenDisabled(indexOfActiveToken)) {
|
|
768
777
|
var itemsNew = selectedItems.filter(function (item) {return !_this.hasValueInItems(_this.state.activeTokens, item);});
|
|
769
778
|
onValueChange(itemsNew);
|
|
770
779
|
_this.dispatch({ type: 'REMOVE_ALL_ACTIVE_TOKENS' }, function () {var _this$input6;
|
|
@@ -790,7 +799,7 @@ TokenInput = (_dec = (0, _decorators.locale)('TokenInput', _locale.TokenInputLoc
|
|
|
790
799
|
e.preventDefault();
|
|
791
800
|
_this.dispatch({
|
|
792
801
|
type: 'SET_ACTIVE_TOKENS',
|
|
793
|
-
payload: selectedItems });
|
|
802
|
+
payload: selectedItems.filter(function (item) {return !_this.isTokenDisabled(selectedItems.indexOf(item));}) });
|
|
794
803
|
|
|
795
804
|
break;}
|
|
796
805
|
|
|
@@ -801,9 +810,9 @@ TokenInput = (_dec = (0, _decorators.locale)('TokenInput', _locale.TokenInputLoc
|
|
|
801
810
|
var selectedItems = _this.getProps().selectedItems;
|
|
802
811
|
var activeTokens = _this.state.activeTokens;
|
|
803
812
|
var activeItemIndex = selectedItems.indexOf(activeTokens[0]);
|
|
804
|
-
var newItemIndex = activeItemIndex
|
|
813
|
+
var newItemIndex = _this.getAvailableTokenIndex(activeItemIndex, (0, _identifiers.isKeyArrowLeft)(e));
|
|
805
814
|
var isLeftEdge = activeItemIndex === 0 && (0, _identifiers.isKeyArrowLeft)(e);
|
|
806
|
-
var isRightEdge =
|
|
815
|
+
var isRightEdge = newItemIndex === selectedItems.length && (0, _identifiers.isKeyArrowRight)(e);
|
|
807
816
|
if (!e.shiftKey && activeTokens.length === 1) {
|
|
808
817
|
_this.handleWrapperArrowsWithoutShift(isLeftEdge, isRightEdge, newItemIndex);
|
|
809
818
|
} else {
|
|
@@ -990,7 +999,7 @@ TokenInput = (_dec = (0, _decorators.locale)('TokenInput', _locale.TokenInputLoc
|
|
|
990
999
|
}
|
|
991
1000
|
};_this.
|
|
992
1001
|
|
|
993
|
-
renderToken = function (item) {
|
|
1002
|
+
renderToken = function (item) {var _this$props$selectedI;
|
|
994
1003
|
var _this$props = _this.props,_this$props$renderTok = _this$props.renderToken,renderToken = _this$props$renderTok === void 0 ? defaultRenderToken : _this$props$renderTok,disabled = _this$props.disabled;
|
|
995
1004
|
|
|
996
1005
|
var isActive = _this.state.activeTokens.includes(item);
|
|
@@ -1013,18 +1022,21 @@ TokenInput = (_dec = (0, _decorators.locale)('TokenInput', _locale.TokenInputLoc
|
|
|
1013
1022
|
|
|
1014
1023
|
var handleTokenDoubleClick = function handleTokenDoubleClick(event) {
|
|
1015
1024
|
event.stopPropagation();
|
|
1016
|
-
if (!_this.isEditingMode) {
|
|
1025
|
+
if (!_this.isEditingMode && !disabled) {
|
|
1017
1026
|
_this.handleTokenEdit(item);
|
|
1018
1027
|
}
|
|
1019
1028
|
};
|
|
1020
1029
|
|
|
1021
|
-
|
|
1030
|
+
var renderedToken = renderToken(item, {
|
|
1022
1031
|
isActive: isActive,
|
|
1023
1032
|
onClick: handleTokenClick,
|
|
1024
1033
|
onDoubleClick: handleTokenDoubleClick,
|
|
1025
1034
|
onRemove: handleIconClick,
|
|
1026
1035
|
disabled: disabled });
|
|
1027
1036
|
|
|
1037
|
+
|
|
1038
|
+
_this.memoizedTokens.set((_this$props$selectedI = _this.props.selectedItems) == null ? void 0 : _this$props$selectedI.indexOf(item), renderedToken);
|
|
1039
|
+
return renderedToken;
|
|
1028
1040
|
};_this.
|
|
1029
1041
|
|
|
1030
1042
|
renderAddButton = function (value) {if (value === void 0) {value = _this.state.inputValue;}
|
|
@@ -1043,11 +1055,42 @@ TokenInput = (_dec = (0, _decorators.locale)('TokenInput', _locale.TokenInputLoc
|
|
|
1043
1055
|
addButtonTitle, " ", value));
|
|
1044
1056
|
|
|
1045
1057
|
|
|
1046
|
-
};
|
|
1058
|
+
};_this.
|
|
1059
|
+
|
|
1060
|
+
isTokenDisabled = function (itemIndex) {
|
|
1061
|
+
var renderedToken;
|
|
1062
|
+
if (_this.memoizedTokens.has(itemIndex)) {
|
|
1063
|
+
renderedToken = _this.memoizedTokens.get(itemIndex);
|
|
1064
|
+
} else if (itemIndex < 0 || itemIndex > _this.getProps().selectedItems.length - 1) {
|
|
1065
|
+
return false;
|
|
1066
|
+
} else {
|
|
1067
|
+
renderedToken = _this.renderToken(_this.getProps().selectedItems[itemIndex]);
|
|
1068
|
+
|
|
1069
|
+
|
|
1070
|
+
}
|
|
1071
|
+
return renderedToken.props.disabled;
|
|
1072
|
+
};_this.
|
|
1073
|
+
|
|
1074
|
+
getAvailableTokenIndex = function (startIndex, isDirectionLeft) {if (isDirectionLeft === void 0) {isDirectionLeft = true;}
|
|
1075
|
+
var _this$getProps7 = _this.getProps(),selectedItems = _this$getProps7.selectedItems;
|
|
1076
|
+
var step = isDirectionLeft ? -1 : +1;
|
|
1077
|
+
var availableIndex = startIndex + step;
|
|
1078
|
+
|
|
1079
|
+
while (_this.isTokenDisabled(availableIndex)) {
|
|
1080
|
+
availableIndex += step;
|
|
1081
|
+
if (availableIndex === selectedItems.length) {
|
|
1082
|
+
return availableIndex;
|
|
1083
|
+
} else if (availableIndex === -1) {
|
|
1084
|
+
return startIndex;
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
return availableIndex;
|
|
1089
|
+
};return _this;}var _proto = TokenInput.prototype;_proto.componentDidMount = function componentDidMount() {this.updateInputTextWidth();document.addEventListener('copy', this.handleCopy);if (this.props.autoFocus) {this.focusInput();}};_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {if (prevState.inputValue !== this.state.inputValue) {this.updateInputTextWidth();}if (prevState.activeTokens.length === 0 && this.state.activeTokens.length > 0) {this.dispatch({ type: 'SET_AUTOCOMPLETE_ITEMS', payload: undefined });}if (prevProps.selectedItems.length !== this.getProps().selectedItems.length) {LayoutEvents.emit();this.memoizedTokens.clear();}if (!this.isCursorVisibleForState(prevState) && this.isCursorVisible) {this.tryGetItems(this.isEditingMode ? '' : this.state.inputValue);}};_proto.componentWillUnmount = function componentWillUnmount() {document.removeEventListener('copy', this.handleCopy);} /**
|
|
1047
1090
|
* @public
|
|
1048
1091
|
*/;_proto.focus = function focus() {var _this$input8;(_this$input8 = this.input) == null ? void 0 : _this$input8.focus();} /**
|
|
1049
1092
|
* @public
|
|
1050
|
-
*/;_proto.blur = function blur() {var _this$input9;(_this$input9 = this.input) == null ? void 0 : _this$input9.blur();};_proto.render = function render() {var _this2 = this;return /*#__PURE__*/_react.default.createElement(_ThemeContext.ThemeContext.Consumer, null, function (theme) {_this2.theme = theme;return _this2.renderMain();});};_proto.renderMain = function renderMain() {var _cx, _cx2, _cx3;if (this.type !== TokenInputType.WithoutReference && !this.props.getItems) {throw Error('Missed getItems for type ' + this.type);}var _this$props2 = this.props,maxMenuHeight = _this$props2.maxMenuHeight,error = _this$props2.error,warning = _this$props2.warning,disabled = _this$props2.disabled,placeholder = _this$props2.placeholder,renderNotFound = _this$props2.renderNotFound,hideMenuIfEmptyInputValue = _this$props2.hideMenuIfEmptyInputValue,inputMode = _this$props2.inputMode,renderTotalCount = _this$props2.renderTotalCount,totalCount = _this$props2.totalCount;var _this$
|
|
1093
|
+
*/;_proto.blur = function blur() {var _this$input9;(_this$input9 = this.input) == null ? void 0 : _this$input9.blur();};_proto.render = function render() {var _this2 = this;return /*#__PURE__*/_react.default.createElement(_ThemeContext.ThemeContext.Consumer, null, function (theme) {_this2.theme = theme;return _this2.renderMain();});};_proto.renderMain = function renderMain() {var _cx, _cx2, _cx3;if (this.type !== TokenInputType.WithoutReference && !this.props.getItems) {throw Error('Missed getItems for type ' + this.type);}var _this$props2 = this.props,maxMenuHeight = _this$props2.maxMenuHeight,error = _this$props2.error,warning = _this$props2.warning,disabled = _this$props2.disabled,placeholder = _this$props2.placeholder,renderNotFound = _this$props2.renderNotFound,hideMenuIfEmptyInputValue = _this$props2.hideMenuIfEmptyInputValue,inputMode = _this$props2.inputMode,renderTotalCount = _this$props2.renderTotalCount,totalCount = _this$props2.totalCount;var _this$getProps8 = this.getProps(),selectedItems = _this$getProps8.selectedItems,width = _this$getProps8.width,onMouseEnter = _this$getProps8.onMouseEnter,onMouseLeave = _this$getProps8.onMouseLeave,menuWidth = _this$getProps8.menuWidth,menuAlign = _this$getProps8.menuAlign,renderItem = _this$getProps8.renderItem;var _this$state3 = this.state,activeTokens = _this$state3.activeTokens,inFocus = _this$state3.inFocus,inputValueWidth = _this$state3.inputValueWidth,inputValue = _this$state3.inputValue,reservedInputValue = _this$state3.reservedInputValue,autocompleteItems = _this$state3.autocompleteItems,loading = _this$state3.loading,inputValueHeight = _this$state3.inputValueHeight;var showMenu = this.type !== TokenInputType.WithoutReference && this.isCursorVisible && activeTokens.length === 0 && (inputValue !== '' || !hideMenuIfEmptyInputValue);var theme = this.theme;var lineHeight = parseInt(theme.tokenInputLineHeight, 10) || 0;var inputInlineStyles = { // вычисляем ширину чтобы input автоматически перенёсся на следующую строку при необходимости
|
|
1051
1094
|
width: inputValueWidth, height: Math.max(lineHeight, inputValueHeight), // input растягивается на всю ширину чтобы placeholder не обрезался
|
|
1052
1095
|
flex: selectedItems && selectedItems.length === 0 ? 1 : undefined, // в ie не работает, но альтернативный способ --- дать tabindex для label --- предположительно ещё сложнее
|
|
1053
1096
|
caretColor: this.isCursorVisible ? undefined : 'transparent' };var labelClassName = (0, _Emotion.cx)(_TokenInput.styles.label(theme), (_cx = {}, _cx[_TokenInput.styles.labelDisabled(theme)] = !!disabled, _cx[_TokenInput.styles.labelFocused(theme)] = !!inFocus, _cx[_TokenInput.styles.error(theme)] = !!error, _cx[_TokenInput.styles.warning(theme)] = !!warning, _cx));var inputClassName = (0, _Emotion.cx)(_TokenInput.styles.input(theme), (_cx2 = {}, _cx2[_TokenInput.styles.inputDisabled(theme)] = !!disabled, _cx2[_TokenInput.styles.inputEditing(theme)] = this.isEditingMode, _cx2));return /*#__PURE__*/_react.default.createElement(_CommonWrapper.CommonWrapper, (0, _extends2.default)({ rootNodeRef: this.setRootNode }, this.props), /*#__PURE__*/_react.default.createElement("div", { "data-tid": TokenInputDataTids.root, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave }, /*#__PURE__*/_react.default.createElement("label", { ref: this.wrapperRef, style: { width: width }, className: labelClassName, onMouseDown: this.handleWrapperMouseDown, onMouseUp: this.handleWrapperMouseUp }, /*#__PURE__*/_react.default.createElement(_TextWidthHelper.TextWidthHelper, { ref: this.textHelperRef, classHelp: (0, _Emotion.cx)(_TokenInput.styles.helperText(theme), (_cx3 = {}, _cx3[_TokenInput.styles.helperTextEditing(theme)] = this.isEditingMode, _cx3)), text: inputValue, theme: this.theme }), this.renderTokensStart(), /*#__PURE__*/_react.default.createElement("textarea", { ref: this.inputRef, value: inputValue, style: inputInlineStyles, spellCheck: false, disabled: disabled, className: inputClassName, placeholder: selectedItems.length > 0 ? undefined : placeholder, onFocus: this.handleInputFocus, onBlur: this.handleInputBlur, onChange: this.handleChangeInputValue, onKeyDown: this.handleKeyDown, onPaste: this.handleInputPaste, inputMode: inputMode }), showMenu && /*#__PURE__*/_react.default.createElement(_TokenInputMenu.TokenInputMenu, { ref: this.tokensInputMenuRef, items: autocompleteItems, loading: loading, opened: showMenu, maxMenuHeight: maxMenuHeight, anchorElement: menuAlign === 'cursor' ? this.input : this.wrapper, renderNotFound: renderNotFound, renderItem: renderItem, onValueChange: this.selectItem, renderAddButton: this.renderAddButton, menuWidth: menuWidth, menuAlign: menuAlign, renderTotalCount: renderTotalCount, totalCount: totalCount }), this.renderTokensEnd(), this.isEditingMode ? /*#__PURE__*/_react.default.createElement("span", { className: _TokenInput.styles.reservedInput(theme) }, reservedInputValue) : null)));} /**
|
|
@@ -1055,4 +1098,4 @@ TokenInput = (_dec = (0, _decorators.locale)('TokenInput', _locale.TokenInputLoc
|
|
|
1055
1098
|
* @public
|
|
1056
1099
|
*/;_proto.reset = function reset() {this.dispatch({ type: 'RESET' });};_proto.isCursorVisibleForState = function isCursorVisibleForState(state) {return state.inFocus && (state.inputValue !== '' || state.activeTokens.length === 0);};_proto.updateInputTextWidth = function updateInputTextWidth() {if (this.textHelper) {// в IE текст иногда не помещается в input
|
|
1057
1100
|
// из-за округления, поэтому округляем явно
|
|
1058
|
-
var inputValueWidth = parseFloat(this.textHelper.getTextWidth().toFixed(2));var inputValueHeight = parseFloat(this.textHelper.getTextHeight().toFixed(2));this.dispatch({ type: 'SET_INPUT_VALUE_WIDTH', payload: inputValueWidth }, LayoutEvents.emit);this.dispatch({ type: 'SET_INPUT_VALUE_HEIGHT', payload: inputValueHeight }, LayoutEvents.emit);}};_proto.moveFocusToLastToken = function moveFocusToLastToken() {var items = this.getProps().selectedItems;if (this.state.inputValue === '' && items && items.length > 0) {this.dispatch({ type: 'SET_ACTIVE_TOKENS', payload: items.slice(-1) });}};(0, _createClass2.default)(TokenInput, [{ key: "showAddItemHint", get: function get() {var items = this.state.autocompleteItems;var value = this.getProps().valueToItem(this.state.inputValue);if (items && this.hasValueInItems(items, value)) {return false;}var selectedItems = this.getProps().selectedItems;if (selectedItems && this.hasValueInItems(selectedItems, value)) {return false;}if (this.type === TokenInputType.Combined && this.state.inputValue !== '') {return true;}} }, { key: "type", get: function get() {return this.props.type ? this.props.type : TokenInputType.WithReference;} }, { key: "menuRef", get: function get() {return this.tokensInputMenu && this.tokensInputMenu.getMenuRef();} }, { key: "isCursorVisible", get: function get() {return this.isCursorVisibleForState(this.state);} }, { key: "isEditingMode", get: function get() {return this.state.editingTokenIndex > -1;} }, { key: "isInputChanged", get: function get() {if (this.isEditingMode) {return this.isTokenValueChanged;}return this.isInputValueChanged;} }, { key: "isInputValueChanged", get: function get() {var inputValue = this.state.inputValue;return inputValue !== '';} }, { key: "isTokenValueChanged", get: function get() {var _this$state4 = this.state,inputValue = _this$state4.inputValue,editingTokenIndex = _this$state4.editingTokenIndex;var _this$
|
|
1101
|
+
var inputValueWidth = parseFloat(this.textHelper.getTextWidth().toFixed(2));var inputValueHeight = parseFloat(this.textHelper.getTextHeight().toFixed(2));this.dispatch({ type: 'SET_INPUT_VALUE_WIDTH', payload: inputValueWidth }, LayoutEvents.emit);this.dispatch({ type: 'SET_INPUT_VALUE_HEIGHT', payload: inputValueHeight }, LayoutEvents.emit);}};_proto.moveFocusToLastToken = function moveFocusToLastToken() {var items = this.getProps().selectedItems;if (this.state.inputValue === '' && items && items.length > 0) {this.dispatch({ type: 'SET_ACTIVE_TOKENS', payload: items.slice(-1) });}};(0, _createClass2.default)(TokenInput, [{ key: "showAddItemHint", get: function get() {var items = this.state.autocompleteItems;var value = this.getProps().valueToItem(this.state.inputValue);if (items && this.hasValueInItems(items, value)) {return false;}var selectedItems = this.getProps().selectedItems;if (selectedItems && this.hasValueInItems(selectedItems, value)) {return false;}if (this.type === TokenInputType.Combined && this.state.inputValue !== '') {return true;}} }, { key: "type", get: function get() {return this.props.type ? this.props.type : TokenInputType.WithReference;} }, { key: "menuRef", get: function get() {return this.tokensInputMenu && this.tokensInputMenu.getMenuRef();} }, { key: "isCursorVisible", get: function get() {return this.isCursorVisibleForState(this.state);} }, { key: "isEditingMode", get: function get() {return this.state.editingTokenIndex > -1;} }, { key: "isInputChanged", get: function get() {if (this.isEditingMode) {return this.isTokenValueChanged;}return this.isInputValueChanged;} }, { key: "isInputValueChanged", get: function get() {var inputValue = this.state.inputValue;return inputValue !== '';} }, { key: "isTokenValueChanged", get: function get() {var _this$state4 = this.state,inputValue = _this$state4.inputValue,editingTokenIndex = _this$state4.editingTokenIndex;var _this$getProps9 = this.getProps(),valueToString = _this$getProps9.valueToString,selectedItems = _this$getProps9.selectedItems;if (this.isEditingMode) {return valueToString(selectedItems[editingTokenIndex]) !== inputValue;}return false;} }]);return TokenInput;}(_react.default.PureComponent), _class2.__KONTUR_REACT_UI__ = 'TokenInput', _class2.defaultProps = { selectedItems: [], delimiters: [',', ' '], renderItem: identity, renderValue: identity, valueToString: identity, valueToItem: function valueToItem(item) {return item;}, toKey: defaultToKey, onValueChange: function onValueChange() {return void 0;}, width: 250, onBlur: _utils.emptyHandler, onFocus: _utils.emptyHandler, onMouseEnter: _utils.emptyHandler, onMouseLeave: _utils.emptyHandler, menuWidth: 'auto', menuAlign: 'cursor' }, _temp)) || _class) || _class);exports.TokenInput = TokenInput;
|