@alfalab/core-components-with-suffix 4.0.33 → 4.1.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/Component.d.ts +3 -32
- package/Component.js +5 -5
- package/cssm/Component.d.ts +3 -32
- package/cssm/Component.js +4 -4
- package/cssm/index.module.css +2 -0
- package/esm/Component.d.ts +3 -32
- package/esm/Component.js +6 -6
- package/esm/index.css +11 -9
- package/index.css +11 -9
- package/modern/Component.d.ts +3 -32
- package/modern/Component.js +5 -5
- package/modern/index.css +11 -9
- package/package.json +3 -3
- package/src/Component.tsx +124 -0
- package/src/index.module.css +42 -0
- package/src/index.ts +1 -0
package/Component.d.ts
CHANGED
|
@@ -13,38 +13,9 @@ type withSuffixProps = InputProps & {
|
|
|
13
13
|
*/
|
|
14
14
|
suffixContainerClassName?: string;
|
|
15
15
|
};
|
|
16
|
-
declare const withSuffix: (Input: FC<InputProps & RefAttributes<HTMLInputElement>>) => React.ForwardRefExoticComponent<Omit<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
block?: boolean | undefined;
|
|
20
|
-
clear?: boolean | undefined;
|
|
21
|
-
size?: "s" | "m" | "l" | "xl" | undefined;
|
|
22
|
-
colors?: "default" | "inverted" | undefined;
|
|
23
|
-
error?: React.ReactNode;
|
|
24
|
-
success?: boolean | undefined;
|
|
25
|
-
hint?: React.ReactNode;
|
|
26
|
-
label?: React.ReactNode;
|
|
27
|
-
labelView?: "inner" | "outer" | undefined;
|
|
28
|
-
type?: "number" | "text" | "tel" | "email" | "card" | "money" | "password" | undefined;
|
|
29
|
-
wrapperRef?: React.Ref<HTMLDivElement> | undefined;
|
|
30
|
-
leftAddons?: React.ReactNode;
|
|
31
|
-
rightAddons?: React.ReactNode;
|
|
32
|
-
bottomAddons?: React.ReactNode;
|
|
33
|
-
className?: string | undefined;
|
|
34
|
-
fieldClassName?: string | undefined;
|
|
35
|
-
inputClassName?: string | undefined;
|
|
36
|
-
labelClassName?: string | undefined;
|
|
37
|
-
addonsClassName?: string | undefined;
|
|
38
|
-
focusedClassName?: string | undefined;
|
|
39
|
-
filledClassName?: string | undefined;
|
|
40
|
-
onChange?: ((event: React.ChangeEvent<HTMLInputElement>, payload: {
|
|
41
|
-
value: string;
|
|
42
|
-
}) => void) | undefined;
|
|
43
|
-
onClear?: ((event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void) | undefined;
|
|
44
|
-
onClick?: ((event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void) | undefined;
|
|
45
|
-
onMouseDown?: ((event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void) | undefined;
|
|
46
|
-
onMouseUp?: ((event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void) | undefined;
|
|
47
|
-
dataTestId?: string | undefined;
|
|
16
|
+
declare const withSuffix: (Input: FC<InputProps & RefAttributes<HTMLInputElement>>) => React.ForwardRefExoticComponent<Omit<import("packages/input/src/components/base-input").BaseInputProps, "FormControlComponent" | "colorStyles"> & {
|
|
17
|
+
breakpoint?: number | undefined;
|
|
18
|
+
defaultMatchMediaValue?: boolean | (() => boolean) | undefined;
|
|
48
19
|
} & {
|
|
49
20
|
/**
|
|
50
21
|
* Дополнительный закрепленный текст справа от основного значения.
|
package/Component.js
CHANGED
|
@@ -14,7 +14,7 @@ var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
|
14
14
|
var mergeRefs__default = /*#__PURE__*/_interopDefaultCompat(mergeRefs);
|
|
15
15
|
var cn__default = /*#__PURE__*/_interopDefaultCompat(cn);
|
|
16
16
|
|
|
17
|
-
var styles = {"suffixContainer":"with-
|
|
17
|
+
var styles = {"suffixContainer":"with-suffix__suffixContainer_b4nsz","suffixVisible":"with-suffix__suffixVisible_b4nsz","hasSuffix":"with-suffix__hasSuffix_b4nsz","spacer":"with-suffix__spacer_b4nsz","suffix":"with-suffix__suffix_b4nsz","disabled":"with-suffix__disabled_b4nsz","readOnly":"with-suffix__readOnly_b4nsz"};
|
|
18
18
|
require('./index.css')
|
|
19
19
|
|
|
20
20
|
var withSuffix = function (Input) {
|
|
@@ -22,8 +22,8 @@ var withSuffix = function (Input) {
|
|
|
22
22
|
var _b, _c;
|
|
23
23
|
var value = _a.value, defaultValue = _a.defaultValue, onChange = _a.onChange, onClear = _a.onClear, _d = _a.suffix, suffix = _d === void 0 ? '' : _d, placeholder = _a.placeholder, className = _a.className, disabled = _a.disabled, readOnly = _a.readOnly, suffixContainerClassName = _a.suffixContainerClassName, restProps = tslib.__rest(_a, ["value", "defaultValue", "onChange", "onClear", "suffix", "placeholder", "className", "disabled", "readOnly", "suffixContainerClassName"]);
|
|
24
24
|
var uncontrolled = value === undefined;
|
|
25
|
-
var
|
|
26
|
-
var
|
|
25
|
+
var _e = React.useState(null), inputNode = _e[0], setInputNode = _e[1];
|
|
26
|
+
var _f = React.useState(defaultValue || ''), stateValue = _f[0], setStateValue = _f[1];
|
|
27
27
|
var handleInputChange = React.useCallback(function (event, payload) {
|
|
28
28
|
if (onChange) {
|
|
29
29
|
onChange(event, payload);
|
|
@@ -42,10 +42,10 @@ var withSuffix = function (Input) {
|
|
|
42
42
|
}, [onClear, uncontrolled]);
|
|
43
43
|
var getPortalContainer = React.useCallback(
|
|
44
44
|
// TODO: Изменить сигнатуру getPortalContainer в Portal
|
|
45
|
-
function () { return
|
|
45
|
+
function () { return inputNode === null || inputNode === void 0 ? void 0 : inputNode.parentElement; }, [inputNode]);
|
|
46
46
|
var visibleValue = uncontrolled ? stateValue : value;
|
|
47
47
|
return (React__default.default.createElement(React.Fragment, null,
|
|
48
|
-
React__default.default.createElement(Input, tslib.__assign({ ref: mergeRefs__default.default([ref,
|
|
48
|
+
React__default.default.createElement(Input, tslib.__assign({ ref: mergeRefs__default.default([ref, setInputNode]), value: visibleValue, disabled: disabled, readOnly: readOnly, onChange: handleInputChange, onClear: handleClear, placeholder: placeholder, className: cn__default.default(className, (_b = {},
|
|
49
49
|
_b[styles.suffixVisible] = Boolean(visibleValue),
|
|
50
50
|
_b[styles.hasSuffix] = suffix,
|
|
51
51
|
_b)) }, restProps)),
|
package/cssm/Component.d.ts
CHANGED
|
@@ -13,38 +13,9 @@ type withSuffixProps = InputProps & {
|
|
|
13
13
|
*/
|
|
14
14
|
suffixContainerClassName?: string;
|
|
15
15
|
};
|
|
16
|
-
declare const withSuffix: (Input: FC<InputProps & RefAttributes<HTMLInputElement>>) => React.ForwardRefExoticComponent<Omit<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
block?: boolean | undefined;
|
|
20
|
-
clear?: boolean | undefined;
|
|
21
|
-
size?: "s" | "m" | "l" | "xl" | undefined;
|
|
22
|
-
colors?: "default" | "inverted" | undefined;
|
|
23
|
-
error?: React.ReactNode;
|
|
24
|
-
success?: boolean | undefined;
|
|
25
|
-
hint?: React.ReactNode;
|
|
26
|
-
label?: React.ReactNode;
|
|
27
|
-
labelView?: "inner" | "outer" | undefined;
|
|
28
|
-
type?: "number" | "text" | "tel" | "email" | "card" | "money" | "password" | undefined;
|
|
29
|
-
wrapperRef?: React.Ref<HTMLDivElement> | undefined;
|
|
30
|
-
leftAddons?: React.ReactNode;
|
|
31
|
-
rightAddons?: React.ReactNode;
|
|
32
|
-
bottomAddons?: React.ReactNode;
|
|
33
|
-
className?: string | undefined;
|
|
34
|
-
fieldClassName?: string | undefined;
|
|
35
|
-
inputClassName?: string | undefined;
|
|
36
|
-
labelClassName?: string | undefined;
|
|
37
|
-
addonsClassName?: string | undefined;
|
|
38
|
-
focusedClassName?: string | undefined;
|
|
39
|
-
filledClassName?: string | undefined;
|
|
40
|
-
onChange?: ((event: React.ChangeEvent<HTMLInputElement>, payload: {
|
|
41
|
-
value: string;
|
|
42
|
-
}) => void) | undefined;
|
|
43
|
-
onClear?: ((event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void) | undefined;
|
|
44
|
-
onClick?: ((event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void) | undefined;
|
|
45
|
-
onMouseDown?: ((event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void) | undefined;
|
|
46
|
-
onMouseUp?: ((event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void) | undefined;
|
|
47
|
-
dataTestId?: string | undefined;
|
|
16
|
+
declare const withSuffix: (Input: FC<InputProps & RefAttributes<HTMLInputElement>>) => React.ForwardRefExoticComponent<Omit<import("packages/input/src/components/base-input").BaseInputProps, "FormControlComponent" | "colorStyles"> & {
|
|
17
|
+
breakpoint?: number | undefined;
|
|
18
|
+
defaultMatchMediaValue?: boolean | (() => boolean) | undefined;
|
|
48
19
|
} & {
|
|
49
20
|
/**
|
|
50
21
|
* Дополнительный закрепленный текст справа от основного значения.
|
package/cssm/Component.js
CHANGED
|
@@ -21,8 +21,8 @@ var withSuffix = function (Input) {
|
|
|
21
21
|
var _b, _c;
|
|
22
22
|
var value = _a.value, defaultValue = _a.defaultValue, onChange = _a.onChange, onClear = _a.onClear, _d = _a.suffix, suffix = _d === void 0 ? '' : _d, placeholder = _a.placeholder, className = _a.className, disabled = _a.disabled, readOnly = _a.readOnly, suffixContainerClassName = _a.suffixContainerClassName, restProps = tslib.__rest(_a, ["value", "defaultValue", "onChange", "onClear", "suffix", "placeholder", "className", "disabled", "readOnly", "suffixContainerClassName"]);
|
|
23
23
|
var uncontrolled = value === undefined;
|
|
24
|
-
var
|
|
25
|
-
var
|
|
24
|
+
var _e = React.useState(null), inputNode = _e[0], setInputNode = _e[1];
|
|
25
|
+
var _f = React.useState(defaultValue || ''), stateValue = _f[0], setStateValue = _f[1];
|
|
26
26
|
var handleInputChange = React.useCallback(function (event, payload) {
|
|
27
27
|
if (onChange) {
|
|
28
28
|
onChange(event, payload);
|
|
@@ -41,10 +41,10 @@ var withSuffix = function (Input) {
|
|
|
41
41
|
}, [onClear, uncontrolled]);
|
|
42
42
|
var getPortalContainer = React.useCallback(
|
|
43
43
|
// TODO: Изменить сигнатуру getPortalContainer в Portal
|
|
44
|
-
function () { return
|
|
44
|
+
function () { return inputNode === null || inputNode === void 0 ? void 0 : inputNode.parentElement; }, [inputNode]);
|
|
45
45
|
var visibleValue = uncontrolled ? stateValue : value;
|
|
46
46
|
return (React__default.default.createElement(React.Fragment, null,
|
|
47
|
-
React__default.default.createElement(Input, tslib.__assign({ ref: mergeRefs__default.default([ref,
|
|
47
|
+
React__default.default.createElement(Input, tslib.__assign({ ref: mergeRefs__default.default([ref, setInputNode]), value: visibleValue, disabled: disabled, readOnly: readOnly, onChange: handleInputChange, onClear: handleClear, placeholder: placeholder, className: cn__default.default(className, (_b = {},
|
|
48
48
|
_b[styles__default.default.suffixVisible] = Boolean(visibleValue),
|
|
49
49
|
_b[styles__default.default.hasSuffix] = suffix,
|
|
50
50
|
_b)) }, restProps)),
|
package/cssm/index.module.css
CHANGED
package/esm/Component.d.ts
CHANGED
|
@@ -13,38 +13,9 @@ type withSuffixProps = InputProps & {
|
|
|
13
13
|
*/
|
|
14
14
|
suffixContainerClassName?: string;
|
|
15
15
|
};
|
|
16
|
-
declare const withSuffix: (Input: FC<InputProps & RefAttributes<HTMLInputElement>>) => React.ForwardRefExoticComponent<Omit<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
block?: boolean | undefined;
|
|
20
|
-
clear?: boolean | undefined;
|
|
21
|
-
size?: "s" | "m" | "l" | "xl" | undefined;
|
|
22
|
-
colors?: "default" | "inverted" | undefined;
|
|
23
|
-
error?: React.ReactNode;
|
|
24
|
-
success?: boolean | undefined;
|
|
25
|
-
hint?: React.ReactNode;
|
|
26
|
-
label?: React.ReactNode;
|
|
27
|
-
labelView?: "inner" | "outer" | undefined;
|
|
28
|
-
type?: "number" | "text" | "tel" | "email" | "card" | "money" | "password" | undefined;
|
|
29
|
-
wrapperRef?: React.Ref<HTMLDivElement> | undefined;
|
|
30
|
-
leftAddons?: React.ReactNode;
|
|
31
|
-
rightAddons?: React.ReactNode;
|
|
32
|
-
bottomAddons?: React.ReactNode;
|
|
33
|
-
className?: string | undefined;
|
|
34
|
-
fieldClassName?: string | undefined;
|
|
35
|
-
inputClassName?: string | undefined;
|
|
36
|
-
labelClassName?: string | undefined;
|
|
37
|
-
addonsClassName?: string | undefined;
|
|
38
|
-
focusedClassName?: string | undefined;
|
|
39
|
-
filledClassName?: string | undefined;
|
|
40
|
-
onChange?: ((event: React.ChangeEvent<HTMLInputElement>, payload: {
|
|
41
|
-
value: string;
|
|
42
|
-
}) => void) | undefined;
|
|
43
|
-
onClear?: ((event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void) | undefined;
|
|
44
|
-
onClick?: ((event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void) | undefined;
|
|
45
|
-
onMouseDown?: ((event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void) | undefined;
|
|
46
|
-
onMouseUp?: ((event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void) | undefined;
|
|
47
|
-
dataTestId?: string | undefined;
|
|
16
|
+
declare const withSuffix: (Input: FC<InputProps & RefAttributes<HTMLInputElement>>) => React.ForwardRefExoticComponent<Omit<import("packages/input/src/components/base-input").BaseInputProps, "FormControlComponent" | "colorStyles"> & {
|
|
17
|
+
breakpoint?: number | undefined;
|
|
18
|
+
defaultMatchMediaValue?: boolean | (() => boolean) | undefined;
|
|
48
19
|
} & {
|
|
49
20
|
/**
|
|
50
21
|
* Дополнительный закрепленный текст справа от основного значения.
|
package/esm/Component.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { __rest, __assign } from 'tslib';
|
|
2
|
-
import React, { forwardRef,
|
|
2
|
+
import React, { forwardRef, useState, useCallback, Fragment } from 'react';
|
|
3
3
|
import mergeRefs from 'react-merge-refs';
|
|
4
4
|
import cn from 'classnames';
|
|
5
5
|
import { Portal } from '@alfalab/core-components-portal/esm';
|
|
6
6
|
|
|
7
|
-
var styles = {"suffixContainer":"with-
|
|
7
|
+
var styles = {"suffixContainer":"with-suffix__suffixContainer_b4nsz","suffixVisible":"with-suffix__suffixVisible_b4nsz","hasSuffix":"with-suffix__hasSuffix_b4nsz","spacer":"with-suffix__spacer_b4nsz","suffix":"with-suffix__suffix_b4nsz","disabled":"with-suffix__disabled_b4nsz","readOnly":"with-suffix__readOnly_b4nsz"};
|
|
8
8
|
require('./index.css')
|
|
9
9
|
|
|
10
10
|
var withSuffix = function (Input) {
|
|
@@ -12,8 +12,8 @@ var withSuffix = function (Input) {
|
|
|
12
12
|
var _b, _c;
|
|
13
13
|
var value = _a.value, defaultValue = _a.defaultValue, onChange = _a.onChange, onClear = _a.onClear, _d = _a.suffix, suffix = _d === void 0 ? '' : _d, placeholder = _a.placeholder, className = _a.className, disabled = _a.disabled, readOnly = _a.readOnly, suffixContainerClassName = _a.suffixContainerClassName, restProps = __rest(_a, ["value", "defaultValue", "onChange", "onClear", "suffix", "placeholder", "className", "disabled", "readOnly", "suffixContainerClassName"]);
|
|
14
14
|
var uncontrolled = value === undefined;
|
|
15
|
-
var
|
|
16
|
-
var
|
|
15
|
+
var _e = useState(null), inputNode = _e[0], setInputNode = _e[1];
|
|
16
|
+
var _f = useState(defaultValue || ''), stateValue = _f[0], setStateValue = _f[1];
|
|
17
17
|
var handleInputChange = useCallback(function (event, payload) {
|
|
18
18
|
if (onChange) {
|
|
19
19
|
onChange(event, payload);
|
|
@@ -32,10 +32,10 @@ var withSuffix = function (Input) {
|
|
|
32
32
|
}, [onClear, uncontrolled]);
|
|
33
33
|
var getPortalContainer = useCallback(
|
|
34
34
|
// TODO: Изменить сигнатуру getPortalContainer в Portal
|
|
35
|
-
function () { return
|
|
35
|
+
function () { return inputNode === null || inputNode === void 0 ? void 0 : inputNode.parentElement; }, [inputNode]);
|
|
36
36
|
var visibleValue = uncontrolled ? stateValue : value;
|
|
37
37
|
return (React.createElement(Fragment, null,
|
|
38
|
-
React.createElement(Input, __assign({ ref: mergeRefs([ref,
|
|
38
|
+
React.createElement(Input, __assign({ ref: mergeRefs([ref, setInputNode]), value: visibleValue, disabled: disabled, readOnly: readOnly, onChange: handleInputChange, onClear: handleClear, placeholder: placeholder, className: cn(className, (_b = {},
|
|
39
39
|
_b[styles.suffixVisible] = Boolean(visibleValue),
|
|
40
40
|
_b[styles.hasSuffix] = suffix,
|
|
41
41
|
_b)) }, restProps)),
|
package/esm/index.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* hash:
|
|
1
|
+
/* hash: jgwhf */
|
|
2
2
|
:root {
|
|
3
3
|
} /* deprecated */ :root {
|
|
4
4
|
--color-light-text-secondary: rgba(60, 60, 67, 0.66); /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
/* display */
|
|
29
29
|
|
|
30
30
|
/* управляет видимостью иконки ошибки, если она стоит рядом с другой иконкой */
|
|
31
|
-
|
|
31
|
+
|
|
32
|
+
/* mobile */
|
|
33
|
+
} .with-suffix__suffixContainer_b4nsz {
|
|
32
34
|
font-size: 16px;
|
|
33
35
|
line-height: 20px;
|
|
34
36
|
font-weight: 400;
|
|
@@ -40,20 +42,20 @@
|
|
|
40
42
|
align-items: center;
|
|
41
43
|
display: none;
|
|
42
44
|
pointer-events: none;
|
|
43
|
-
} input:focus:not(:read-only) + .with-
|
|
44
|
-
.with-
|
|
45
|
+
} input:focus:not(:read-only) + .with-suffix__suffixContainer_b4nsz,
|
|
46
|
+
.with-suffix__suffixVisible_b4nsz .with-suffix__suffixContainer_b4nsz {
|
|
45
47
|
display: inline-flex;
|
|
46
|
-
} .with-
|
|
48
|
+
} .with-suffix__hasSuffix_b4nsz input:focus::placeholder {
|
|
47
49
|
color: transparent;
|
|
48
50
|
transition: none;
|
|
49
|
-
} .with-
|
|
51
|
+
} .with-suffix__spacer_b4nsz {
|
|
50
52
|
visibility: hidden;
|
|
51
53
|
flex-shrink: 0;
|
|
52
54
|
white-space: pre;
|
|
53
|
-
} .with-
|
|
55
|
+
} .with-suffix__suffix_b4nsz {
|
|
54
56
|
white-space: pre;
|
|
55
|
-
} .with-
|
|
57
|
+
} .with-suffix__disabled_b4nsz {
|
|
56
58
|
color: var(--input-disabled-color);
|
|
57
|
-
} .with-
|
|
59
|
+
} .with-suffix__readOnly_b4nsz {
|
|
58
60
|
color: var(--input-read-only-color);
|
|
59
61
|
}
|
package/index.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* hash:
|
|
1
|
+
/* hash: jgwhf */
|
|
2
2
|
:root {
|
|
3
3
|
} /* deprecated */ :root {
|
|
4
4
|
--color-light-text-secondary: rgba(60, 60, 67, 0.66); /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
/* display */
|
|
29
29
|
|
|
30
30
|
/* управляет видимостью иконки ошибки, если она стоит рядом с другой иконкой */
|
|
31
|
-
|
|
31
|
+
|
|
32
|
+
/* mobile */
|
|
33
|
+
} .with-suffix__suffixContainer_b4nsz {
|
|
32
34
|
font-size: 16px;
|
|
33
35
|
line-height: 20px;
|
|
34
36
|
font-weight: 400;
|
|
@@ -40,20 +42,20 @@
|
|
|
40
42
|
align-items: center;
|
|
41
43
|
display: none;
|
|
42
44
|
pointer-events: none;
|
|
43
|
-
} input:focus:not(:read-only) + .with-
|
|
44
|
-
.with-
|
|
45
|
+
} input:focus:not(:read-only) + .with-suffix__suffixContainer_b4nsz,
|
|
46
|
+
.with-suffix__suffixVisible_b4nsz .with-suffix__suffixContainer_b4nsz {
|
|
45
47
|
display: inline-flex;
|
|
46
|
-
} .with-
|
|
48
|
+
} .with-suffix__hasSuffix_b4nsz input:focus::placeholder {
|
|
47
49
|
color: transparent;
|
|
48
50
|
transition: none;
|
|
49
|
-
} .with-
|
|
51
|
+
} .with-suffix__spacer_b4nsz {
|
|
50
52
|
visibility: hidden;
|
|
51
53
|
flex-shrink: 0;
|
|
52
54
|
white-space: pre;
|
|
53
|
-
} .with-
|
|
55
|
+
} .with-suffix__suffix_b4nsz {
|
|
54
56
|
white-space: pre;
|
|
55
|
-
} .with-
|
|
57
|
+
} .with-suffix__disabled_b4nsz {
|
|
56
58
|
color: var(--input-disabled-color);
|
|
57
|
-
} .with-
|
|
59
|
+
} .with-suffix__readOnly_b4nsz {
|
|
58
60
|
color: var(--input-read-only-color);
|
|
59
61
|
}
|
package/modern/Component.d.ts
CHANGED
|
@@ -13,38 +13,9 @@ type withSuffixProps = InputProps & {
|
|
|
13
13
|
*/
|
|
14
14
|
suffixContainerClassName?: string;
|
|
15
15
|
};
|
|
16
|
-
declare const withSuffix: (Input: FC<InputProps & RefAttributes<HTMLInputElement>>) => React.ForwardRefExoticComponent<Omit<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
block?: boolean | undefined;
|
|
20
|
-
clear?: boolean | undefined;
|
|
21
|
-
size?: "s" | "m" | "l" | "xl" | undefined;
|
|
22
|
-
colors?: "default" | "inverted" | undefined;
|
|
23
|
-
error?: React.ReactNode;
|
|
24
|
-
success?: boolean | undefined;
|
|
25
|
-
hint?: React.ReactNode;
|
|
26
|
-
label?: React.ReactNode;
|
|
27
|
-
labelView?: "inner" | "outer" | undefined;
|
|
28
|
-
type?: "number" | "text" | "tel" | "email" | "card" | "money" | "password" | undefined;
|
|
29
|
-
wrapperRef?: React.Ref<HTMLDivElement> | undefined;
|
|
30
|
-
leftAddons?: React.ReactNode;
|
|
31
|
-
rightAddons?: React.ReactNode;
|
|
32
|
-
bottomAddons?: React.ReactNode;
|
|
33
|
-
className?: string | undefined;
|
|
34
|
-
fieldClassName?: string | undefined;
|
|
35
|
-
inputClassName?: string | undefined;
|
|
36
|
-
labelClassName?: string | undefined;
|
|
37
|
-
addonsClassName?: string | undefined;
|
|
38
|
-
focusedClassName?: string | undefined;
|
|
39
|
-
filledClassName?: string | undefined;
|
|
40
|
-
onChange?: ((event: React.ChangeEvent<HTMLInputElement>, payload: {
|
|
41
|
-
value: string;
|
|
42
|
-
}) => void) | undefined;
|
|
43
|
-
onClear?: ((event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void) | undefined;
|
|
44
|
-
onClick?: ((event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void) | undefined;
|
|
45
|
-
onMouseDown?: ((event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void) | undefined;
|
|
46
|
-
onMouseUp?: ((event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void) | undefined;
|
|
47
|
-
dataTestId?: string | undefined;
|
|
16
|
+
declare const withSuffix: (Input: FC<InputProps & RefAttributes<HTMLInputElement>>) => React.ForwardRefExoticComponent<Omit<import("packages/input/src/components/base-input").BaseInputProps, "FormControlComponent" | "colorStyles"> & {
|
|
17
|
+
breakpoint?: number | undefined;
|
|
18
|
+
defaultMatchMediaValue?: boolean | (() => boolean) | undefined;
|
|
48
19
|
} & {
|
|
49
20
|
/**
|
|
50
21
|
* Дополнительный закрепленный текст справа от основного значения.
|
package/modern/Component.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import React, { forwardRef,
|
|
1
|
+
import React, { forwardRef, useState, useCallback, Fragment } from 'react';
|
|
2
2
|
import mergeRefs from 'react-merge-refs';
|
|
3
3
|
import cn from 'classnames';
|
|
4
4
|
import { Portal } from '@alfalab/core-components-portal/modern';
|
|
5
5
|
|
|
6
|
-
const styles = {"suffixContainer":"with-
|
|
6
|
+
const styles = {"suffixContainer":"with-suffix__suffixContainer_b4nsz","suffixVisible":"with-suffix__suffixVisible_b4nsz","hasSuffix":"with-suffix__hasSuffix_b4nsz","spacer":"with-suffix__spacer_b4nsz","suffix":"with-suffix__suffix_b4nsz","disabled":"with-suffix__disabled_b4nsz","readOnly":"with-suffix__readOnly_b4nsz"};
|
|
7
7
|
require('./index.css')
|
|
8
8
|
|
|
9
9
|
const withSuffix = (Input) => forwardRef(({ value, defaultValue, onChange, onClear, suffix = '', placeholder, className, disabled, readOnly, suffixContainerClassName, ...restProps }, ref) => {
|
|
10
10
|
const uncontrolled = value === undefined;
|
|
11
|
-
const
|
|
11
|
+
const [inputNode, setInputNode] = useState(null);
|
|
12
12
|
const [stateValue, setStateValue] = useState(defaultValue || '');
|
|
13
13
|
const handleInputChange = useCallback((event, payload) => {
|
|
14
14
|
if (onChange) {
|
|
@@ -28,10 +28,10 @@ const withSuffix = (Input) => forwardRef(({ value, defaultValue, onChange, onCle
|
|
|
28
28
|
}, [onClear, uncontrolled]);
|
|
29
29
|
const getPortalContainer = useCallback(
|
|
30
30
|
// TODO: Изменить сигнатуру getPortalContainer в Portal
|
|
31
|
-
() =>
|
|
31
|
+
() => inputNode?.parentElement, [inputNode]);
|
|
32
32
|
const visibleValue = uncontrolled ? stateValue : value;
|
|
33
33
|
return (React.createElement(Fragment, null,
|
|
34
|
-
React.createElement(Input, { ref: mergeRefs([ref,
|
|
34
|
+
React.createElement(Input, { ref: mergeRefs([ref, setInputNode]), value: visibleValue, disabled: disabled, readOnly: readOnly, onChange: handleInputChange, onClear: handleClear, placeholder: placeholder, className: cn(className, {
|
|
35
35
|
[styles.suffixVisible]: Boolean(visibleValue),
|
|
36
36
|
[styles.hasSuffix]: suffix,
|
|
37
37
|
}), ...restProps }),
|
package/modern/index.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* hash:
|
|
1
|
+
/* hash: jgwhf */
|
|
2
2
|
:root {
|
|
3
3
|
} /* deprecated */ :root {
|
|
4
4
|
--color-light-text-secondary: rgba(60, 60, 67, 0.66); /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
/* display */
|
|
29
29
|
|
|
30
30
|
/* управляет видимостью иконки ошибки, если она стоит рядом с другой иконкой */
|
|
31
|
-
|
|
31
|
+
|
|
32
|
+
/* mobile */
|
|
33
|
+
} .with-suffix__suffixContainer_b4nsz {
|
|
32
34
|
font-size: 16px;
|
|
33
35
|
line-height: 20px;
|
|
34
36
|
font-weight: 400;
|
|
@@ -40,20 +42,20 @@
|
|
|
40
42
|
align-items: center;
|
|
41
43
|
display: none;
|
|
42
44
|
pointer-events: none;
|
|
43
|
-
} input:focus:not(:read-only) + .with-
|
|
44
|
-
.with-
|
|
45
|
+
} input:focus:not(:read-only) + .with-suffix__suffixContainer_b4nsz,
|
|
46
|
+
.with-suffix__suffixVisible_b4nsz .with-suffix__suffixContainer_b4nsz {
|
|
45
47
|
display: inline-flex;
|
|
46
|
-
} .with-
|
|
48
|
+
} .with-suffix__hasSuffix_b4nsz input:focus::placeholder {
|
|
47
49
|
color: transparent;
|
|
48
50
|
transition: none;
|
|
49
|
-
} .with-
|
|
51
|
+
} .with-suffix__spacer_b4nsz {
|
|
50
52
|
visibility: hidden;
|
|
51
53
|
flex-shrink: 0;
|
|
52
54
|
white-space: pre;
|
|
53
|
-
} .with-
|
|
55
|
+
} .with-suffix__suffix_b4nsz {
|
|
54
56
|
white-space: pre;
|
|
55
|
-
} .with-
|
|
57
|
+
} .with-suffix__disabled_b4nsz {
|
|
56
58
|
color: var(--input-disabled-color);
|
|
57
|
-
} .with-
|
|
59
|
+
} .with-suffix__readOnly_b4nsz {
|
|
58
60
|
color: var(--input-read-only-color);
|
|
59
61
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alfalab/core-components-with-suffix",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"react": "^16.9.0 || ^17.0.1 || ^18.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@alfalab/core-components-input": "^
|
|
18
|
-
"@alfalab/core-components-portal": "^3.
|
|
17
|
+
"@alfalab/core-components-input": "^12.0.0",
|
|
18
|
+
"@alfalab/core-components-portal": "^3.2.0",
|
|
19
19
|
"classnames": "^2.3.1",
|
|
20
20
|
"react-merge-refs": "^1.1.0",
|
|
21
21
|
"tslib": "^2.4.0"
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
FC,
|
|
3
|
+
forwardRef,
|
|
4
|
+
Fragment,
|
|
5
|
+
ReactNode,
|
|
6
|
+
RefAttributes,
|
|
7
|
+
useCallback,
|
|
8
|
+
useState,
|
|
9
|
+
} from 'react';
|
|
10
|
+
import mergeRefs from 'react-merge-refs';
|
|
11
|
+
import cn from 'classnames';
|
|
12
|
+
|
|
13
|
+
import { InputProps } from '@alfalab/core-components-input';
|
|
14
|
+
import { Portal } from '@alfalab/core-components-portal';
|
|
15
|
+
|
|
16
|
+
import styles from './index.module.css';
|
|
17
|
+
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
19
|
+
export type withSuffixProps = InputProps & {
|
|
20
|
+
/**
|
|
21
|
+
* Дополнительный закрепленный текст справа от основного значения.
|
|
22
|
+
* Например: value='85' suffix=' мес' -> 85 мес
|
|
23
|
+
*/
|
|
24
|
+
suffix?: ReactNode;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Дополнительный класс для контейнера с суффиксом
|
|
28
|
+
*/
|
|
29
|
+
suffixContainerClassName?: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const withSuffix = (Input: FC<InputProps & RefAttributes<HTMLInputElement>>) =>
|
|
33
|
+
forwardRef<HTMLInputElement, withSuffixProps>(
|
|
34
|
+
(
|
|
35
|
+
{
|
|
36
|
+
value,
|
|
37
|
+
defaultValue,
|
|
38
|
+
onChange,
|
|
39
|
+
onClear,
|
|
40
|
+
suffix = '',
|
|
41
|
+
placeholder,
|
|
42
|
+
className,
|
|
43
|
+
disabled,
|
|
44
|
+
readOnly,
|
|
45
|
+
suffixContainerClassName,
|
|
46
|
+
...restProps
|
|
47
|
+
},
|
|
48
|
+
ref,
|
|
49
|
+
) => {
|
|
50
|
+
const uncontrolled = value === undefined;
|
|
51
|
+
|
|
52
|
+
const [inputNode, setInputNode] = useState<HTMLInputElement | null>(null);
|
|
53
|
+
|
|
54
|
+
const [stateValue, setStateValue] = useState(defaultValue || '');
|
|
55
|
+
|
|
56
|
+
const handleInputChange = useCallback<Required<InputProps>['onChange']>(
|
|
57
|
+
(event, payload) => {
|
|
58
|
+
if (onChange) {
|
|
59
|
+
onChange(event, payload);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (uncontrolled) {
|
|
63
|
+
setStateValue(payload.value);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
[onChange, uncontrolled],
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const handleClear = useCallback<Required<InputProps>['onClear']>(
|
|
70
|
+
(event) => {
|
|
71
|
+
if (uncontrolled) {
|
|
72
|
+
setStateValue('');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (onClear) {
|
|
76
|
+
onClear(event);
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
[onClear, uncontrolled],
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const getPortalContainer = useCallback(
|
|
83
|
+
// TODO: Изменить сигнатуру getPortalContainer в Portal
|
|
84
|
+
() => inputNode?.parentElement as HTMLElement,
|
|
85
|
+
[inputNode],
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const visibleValue = uncontrolled ? stateValue : value;
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<Fragment>
|
|
92
|
+
<Input
|
|
93
|
+
ref={mergeRefs([ref, setInputNode])}
|
|
94
|
+
value={visibleValue}
|
|
95
|
+
disabled={disabled}
|
|
96
|
+
readOnly={readOnly}
|
|
97
|
+
onChange={handleInputChange}
|
|
98
|
+
onClear={handleClear}
|
|
99
|
+
placeholder={placeholder}
|
|
100
|
+
className={cn(className, {
|
|
101
|
+
[styles.suffixVisible]: Boolean(visibleValue),
|
|
102
|
+
[styles.hasSuffix]: suffix,
|
|
103
|
+
})}
|
|
104
|
+
{...restProps}
|
|
105
|
+
/>
|
|
106
|
+
<Portal getPortalContainer={getPortalContainer}>
|
|
107
|
+
<div className={cn(styles.suffixContainer, suffixContainerClassName)}>
|
|
108
|
+
<span className={styles.spacer}>{visibleValue}</span>
|
|
109
|
+
{suffix && (
|
|
110
|
+
<div
|
|
111
|
+
className={cn(styles.suffix, {
|
|
112
|
+
[styles.disabled]: disabled,
|
|
113
|
+
[styles.readOnly]: readOnly,
|
|
114
|
+
})}
|
|
115
|
+
>
|
|
116
|
+
{suffix}
|
|
117
|
+
</div>
|
|
118
|
+
)}
|
|
119
|
+
</div>
|
|
120
|
+
</Portal>
|
|
121
|
+
</Fragment>
|
|
122
|
+
);
|
|
123
|
+
},
|
|
124
|
+
);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
@import '@alfalab/core-components-themes/src/default.css';
|
|
2
|
+
@import '@alfalab/core-components-input/src/vars.css';
|
|
3
|
+
|
|
4
|
+
.suffixContainer {
|
|
5
|
+
@mixin paragraph_component;
|
|
6
|
+
|
|
7
|
+
position: absolute;
|
|
8
|
+
left: 0;
|
|
9
|
+
top: 0;
|
|
10
|
+
bottom: 0;
|
|
11
|
+
align-items: center;
|
|
12
|
+
display: none;
|
|
13
|
+
pointer-events: none;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
input:focus:not(:read-only) + .suffixContainer,
|
|
17
|
+
.suffixVisible .suffixContainer {
|
|
18
|
+
display: inline-flex;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.hasSuffix input:focus::placeholder {
|
|
22
|
+
color: transparent;
|
|
23
|
+
transition: none;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.spacer {
|
|
27
|
+
visibility: hidden;
|
|
28
|
+
flex-shrink: 0;
|
|
29
|
+
white-space: pre;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.suffix {
|
|
33
|
+
white-space: pre;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.disabled {
|
|
37
|
+
color: var(--input-disabled-color);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.readOnly {
|
|
41
|
+
color: var(--input-read-only-color);
|
|
42
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Component';
|