@ozen-ui/kit 0.12.0 → 0.13.1
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/__inner__/cjs/components/DataList/DataList.css +55 -28
- package/__inner__/cjs/components/DataList/DataList.d.ts +2 -2
- package/__inner__/cjs/components/DataList/DataList.js +62 -24
- package/__inner__/cjs/components/DataList/DataListProvider.d.ts +8 -10
- package/__inner__/cjs/components/DataList/DataListProvider.js +0 -2
- package/__inner__/cjs/components/DataList/components/DataListOption.d.ts +5 -18
- package/__inner__/cjs/components/DataList/components/DataListOption.js +14 -22
- package/__inner__/cjs/components/DataList/types.d.ts +19 -12
- package/__inner__/cjs/components/DataList/types.js +5 -0
- package/__inner__/cjs/components/DataList/useDataListNavigation.d.ts +15 -6
- package/__inner__/cjs/components/DataList/useDataListNavigation.js +68 -21
- package/__inner__/cjs/components/FieldControl/FieldControl.css +0 -15
- package/__inner__/cjs/components/Input/Input.css +0 -7
- package/__inner__/cjs/components/Input/Input.js +5 -5
- package/__inner__/cjs/components/Input/types.d.ts +3 -3
- package/__inner__/cjs/components/InputNumber/InputNumber.js +10 -10
- package/__inner__/cjs/components/InputNumber/types.d.ts +2 -0
- package/__inner__/cjs/components/Textarea/types.d.ts +1 -3
- package/__inner__/cjs/hooks/useControlled/useControlled.js +3 -3
- package/__inner__/esm/components/DataList/DataList.css +55 -28
- package/__inner__/esm/components/DataList/DataList.d.ts +2 -2
- package/__inner__/esm/components/DataList/DataList.js +63 -25
- package/__inner__/esm/components/DataList/DataListProvider.d.ts +8 -10
- package/__inner__/esm/components/DataList/DataListProvider.js +0 -2
- package/__inner__/esm/components/DataList/components/DataListOption.d.ts +5 -18
- package/__inner__/esm/components/DataList/components/DataListOption.js +16 -23
- package/__inner__/esm/components/DataList/types.d.ts +19 -12
- package/__inner__/esm/components/DataList/types.js +2 -1
- package/__inner__/esm/components/DataList/useDataListNavigation.d.ts +15 -6
- package/__inner__/esm/components/DataList/useDataListNavigation.js +69 -22
- package/__inner__/esm/components/FieldControl/FieldControl.css +0 -15
- package/__inner__/esm/components/Input/Input.css +0 -7
- package/__inner__/esm/components/Input/Input.js +5 -5
- package/__inner__/esm/components/Input/types.d.ts +3 -3
- package/__inner__/esm/components/InputNumber/InputNumber.js +10 -10
- package/__inner__/esm/components/InputNumber/types.d.ts +2 -0
- package/__inner__/esm/components/Textarea/types.d.ts +1 -3
- package/__inner__/esm/hooks/useControlled/useControlled.js +3 -3
- package/package.json +1 -1
|
@@ -1,33 +1,40 @@
|
|
|
1
|
-
import type { ReactNode,
|
|
1
|
+
import type { ReactNode, ElementType } from 'react';
|
|
2
2
|
import type React from 'react';
|
|
3
3
|
import type { FormElementSizeVariant } from '../../types/FormElementSizeVariant';
|
|
4
|
-
import type { PolymorphicComponentPropsWithRef } from '../../utils/polymorphicComponentWithRef';
|
|
4
|
+
import type { PolymorphicComponentPropsWithRef, PolymorphicComponentRef } from '../../utils/polymorphicComponentWithRef';
|
|
5
5
|
import type { ListProps } from '../List';
|
|
6
6
|
import type { PopoverBaseProps } from '../Popover';
|
|
7
7
|
import type { DATA_LIST_DEFAULT_TAG } from './constants';
|
|
8
|
-
export type DataListPayload = {
|
|
8
|
+
export type DataListPayload<MULTIPLE extends boolean> = {
|
|
9
9
|
name?: string;
|
|
10
|
-
value: string;
|
|
10
|
+
value: MULTIPLE extends true ? string[] : string;
|
|
11
11
|
};
|
|
12
|
-
export type
|
|
12
|
+
export type DataListSelected<MULTIPLE extends boolean> = (MULTIPLE extends true ? string[] : string) | undefined;
|
|
13
|
+
export type DataListOnSelect<MULTIPLE extends boolean> = (event: React.SyntheticEvent | KeyboardEvent, payload: DataListPayload<MULTIPLE>) => void;
|
|
14
|
+
export type DataListBaseProps<MULTIPLE extends boolean = false> = {
|
|
13
15
|
/** Имя списка */
|
|
14
16
|
name?: string;
|
|
15
17
|
/** Признак по которому компонент будет представлен */
|
|
16
18
|
open?: boolean;
|
|
17
19
|
/** Содержимое компонента */
|
|
18
20
|
children: ReactNode;
|
|
21
|
+
/** Если {true} из списка можно выбрать несколько вариантов */
|
|
22
|
+
multiple?: MULTIPLE;
|
|
19
23
|
/** Дополнительные CSS-классы */
|
|
20
24
|
className?: string;
|
|
21
25
|
/** Размер компонента */
|
|
22
26
|
size?: FormElementSizeVariant;
|
|
23
|
-
/** Выбранная
|
|
24
|
-
selected?:
|
|
27
|
+
/** Выбранная или выбранные опции */
|
|
28
|
+
selected?: DataListSelected<MULTIPLE>;
|
|
25
29
|
/** Выбранная опция по умолчанию */
|
|
26
|
-
defaultSelected?:
|
|
30
|
+
defaultSelected?: DataListSelected<MULTIPLE>;
|
|
27
31
|
/** Функция обратного вызова для выбора значения */
|
|
28
|
-
onSelect?:
|
|
32
|
+
onSelect?: DataListOnSelect<MULTIPLE>;
|
|
29
33
|
/** Свойства компонента List */
|
|
30
34
|
listProps?: ListProps;
|
|
31
|
-
}
|
|
32
|
-
export
|
|
33
|
-
export
|
|
35
|
+
} & Omit<PopoverBaseProps, 'onSelect'>;
|
|
36
|
+
export declare const isMultipleParams: (params: DataListBaseProps<boolean>) => params is DataListBaseProps<true>;
|
|
37
|
+
export declare const isNotMultipleParams: (params: DataListBaseProps<boolean>) => params is DataListBaseProps<false>;
|
|
38
|
+
export type DataListRef = PolymorphicComponentRef<typeof DATA_LIST_DEFAULT_TAG>;
|
|
39
|
+
export type DataListProps<As extends ElementType = typeof DATA_LIST_DEFAULT_TAG, MULTIPLE extends boolean = false> = PolymorphicComponentPropsWithRef<DataListBaseProps<MULTIPLE>, As>;
|
|
40
|
+
export type DataListComponent = <As extends ElementType = typeof DATA_LIST_DEFAULT_TAG, MULTIPLE extends boolean = false>(props: PolymorphicComponentPropsWithRef<DataListBaseProps<MULTIPLE>, As>) => React.ReactElement | null;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export var isMultipleParams = function (params) { return !!params.multiple; };
|
|
2
|
+
export var isNotMultipleParams = function (params) { return !params.multiple; };
|
|
@@ -1,14 +1,23 @@
|
|
|
1
|
+
import type React from 'react';
|
|
1
2
|
import type { MouseEvent, RefObject } from 'react';
|
|
3
|
+
type UserListItemValue = string | null;
|
|
2
4
|
export type UseListNavigationProps = {
|
|
3
5
|
name?: string;
|
|
4
|
-
|
|
6
|
+
ref?: RefObject<HTMLElement>;
|
|
7
|
+
selected?: UserListItemValue;
|
|
8
|
+
active?: boolean;
|
|
9
|
+
onSelect?: (e: React.SyntheticEvent | KeyboardEvent, selectedItem: string) => void;
|
|
5
10
|
};
|
|
6
11
|
export type UseListNavigationValue = {
|
|
7
12
|
'data-list': string;
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
focused?: UserListItemValue;
|
|
14
|
+
highlighted?: UserListItemValue;
|
|
15
|
+
ref?: RefObject<HTMLElement>;
|
|
10
16
|
onKeyDown: (event: KeyboardEvent) => void;
|
|
11
|
-
onMouseMove: (event: MouseEvent<
|
|
12
|
-
onMouseLeave: (event: MouseEvent<
|
|
17
|
+
onMouseMove: (event: MouseEvent<HTMLElement>) => void;
|
|
18
|
+
onMouseLeave: (event: MouseEvent<HTMLElement>) => void;
|
|
19
|
+
onClick: (event: React.MouseEvent<HTMLElement>) => void;
|
|
13
20
|
};
|
|
14
|
-
|
|
21
|
+
/** Навигация по элементам списка без перехвата фокуса с элемента контроля */
|
|
22
|
+
export declare function useDataListNavigation({ name: nameProp, selected, active, onSelect, }?: UseListNavigationProps): UseListNavigationValue;
|
|
23
|
+
export {};
|
|
@@ -1,54 +1,101 @@
|
|
|
1
1
|
import { __read } from "tslib";
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
import { useBoolean } from '../../hooks/useBoolean';
|
|
2
|
+
import { useEffect, useState, useCallback, useRef } from 'react';
|
|
4
3
|
import { useUniqueId } from '../../hooks/useUniqueId';
|
|
5
4
|
import { getNextIndex } from '../../utils/getNextIndex';
|
|
6
5
|
import { getPrevIndex } from '../../utils/getPrevIndex';
|
|
7
6
|
import { isKey } from '../../utils/isKey';
|
|
8
7
|
import { scrollContainerToElement } from '../../utils/scrollContainerToElement';
|
|
8
|
+
var getData = function (el, attr) {
|
|
9
|
+
if (!el) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
if ('currentTarget' in el)
|
|
13
|
+
return el.currentTarget.getAttribute("data-list-".concat(attr));
|
|
14
|
+
return el.getAttribute("data-list-".concat(attr));
|
|
15
|
+
};
|
|
16
|
+
/** Навигация по элементам списка без перехвата фокуса с элемента контроля */
|
|
9
17
|
export function useDataListNavigation(_a) {
|
|
10
|
-
var _b = _a === void 0 ? {} : _a, nameProp = _b.name,
|
|
18
|
+
var _b = _a === void 0 ? {} : _a, nameProp = _b.name, selected = _b.selected, _c = _b.active, active = _c === void 0 ? false : _c, onSelect = _b.onSelect;
|
|
11
19
|
var name = useUniqueId(nameProp);
|
|
12
|
-
var
|
|
13
|
-
var _d = __read(
|
|
14
|
-
var
|
|
20
|
+
var ref = useRef(null);
|
|
21
|
+
var _d = __read(useState(null), 2), current = _d[0], setCurrent = _d[1];
|
|
22
|
+
var _e = __read(useState(), 2), focused = _e[0], serFocused = _e[1];
|
|
23
|
+
var _f = __read(useState(), 2), highlighted = _f[0], setHighlighted = _f[1];
|
|
24
|
+
var currentValue = current || selected;
|
|
25
|
+
var getItemsData = useCallback(function () {
|
|
15
26
|
var _a;
|
|
27
|
+
var items = Array.from(((_a = ref === null || ref === void 0 ? void 0 : ref.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll("[data-list=\"".concat(name, "\"]"))) || []).filter(function (item) { return getData(item, 'disabled') !== 'true'; });
|
|
28
|
+
return [
|
|
29
|
+
items,
|
|
30
|
+
items.find(function (item) { return getData(item, 'value') === currentValue; }),
|
|
31
|
+
];
|
|
32
|
+
}, [name, currentValue]);
|
|
33
|
+
useEffect(function () {
|
|
34
|
+
if (!active) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
var _a = __read(getItemsData(), 2), selectedItem = _a[1];
|
|
38
|
+
if (ref === null || ref === void 0 ? void 0 : ref.current) {
|
|
39
|
+
scrollContainerToElement({
|
|
40
|
+
container: ref.current,
|
|
41
|
+
element: selectedItem,
|
|
42
|
+
});
|
|
43
|
+
setCurrent(getData(selectedItem, 'value') || '');
|
|
44
|
+
}
|
|
45
|
+
return function () {
|
|
46
|
+
setCurrent(null);
|
|
47
|
+
serFocused(null);
|
|
48
|
+
setHighlighted(null);
|
|
49
|
+
};
|
|
50
|
+
}, [active]);
|
|
51
|
+
var onClick = function (event) {
|
|
52
|
+
if (getData(event, 'disabled') === 'true') {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
serFocused(null);
|
|
56
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect(event, currentValue || '');
|
|
57
|
+
};
|
|
58
|
+
var onKeyDown = function (event) {
|
|
59
|
+
if (isKey(event, 'Enter')) {
|
|
60
|
+
event.preventDefault();
|
|
61
|
+
if (currentValue)
|
|
62
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect(event, currentValue);
|
|
63
|
+
}
|
|
16
64
|
if (!isKey(event, 'ArrowUp') && !isKey(event, 'ArrowDown')) {
|
|
17
65
|
return;
|
|
18
66
|
}
|
|
19
67
|
event.preventDefault();
|
|
20
|
-
var
|
|
21
|
-
var currentIndex = currentItem
|
|
68
|
+
var _a = __read(getItemsData(), 2), items = _a[0], currentItem = _a[1];
|
|
69
|
+
var currentIndex = !currentItem ? null : items.indexOf(currentItem);
|
|
22
70
|
var isArrowUp = isKey(event, 'ArrowUp');
|
|
23
71
|
var newIndex = isArrowUp
|
|
24
72
|
? getPrevIndex(currentIndex !== null && currentIndex !== void 0 ? currentIndex : 0, items.length)
|
|
25
73
|
: getNextIndex(currentIndex !== null && currentIndex !== void 0 ? currentIndex : -1, items.length);
|
|
26
74
|
var item = items[newIndex];
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
75
|
+
var newValue = getData(item, 'value');
|
|
76
|
+
setCurrent(newValue);
|
|
77
|
+
serFocused(newValue);
|
|
78
|
+
if (ref === null || ref === void 0 ? void 0 : ref.current) {
|
|
30
79
|
scrollContainerToElement({
|
|
31
|
-
container:
|
|
80
|
+
container: ref.current,
|
|
32
81
|
element: item,
|
|
33
82
|
});
|
|
34
83
|
}
|
|
35
84
|
};
|
|
36
85
|
var onMouseMove = function (event) {
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
hideKeyboardHighlight();
|
|
86
|
+
if (getData(event, 'disabled') !== 'true')
|
|
87
|
+
setCurrent(getData(event, 'value'));
|
|
88
|
+
setHighlighted(getData(event, 'value'));
|
|
41
89
|
};
|
|
42
90
|
var onMouseLeave = function () {
|
|
43
|
-
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
setCurrentItem(null);
|
|
91
|
+
setHighlighted(null);
|
|
47
92
|
};
|
|
48
93
|
return {
|
|
49
94
|
'data-list': name,
|
|
50
|
-
|
|
51
|
-
|
|
95
|
+
ref: ref,
|
|
96
|
+
focused: focused,
|
|
97
|
+
highlighted: highlighted,
|
|
98
|
+
onClick: onClick,
|
|
52
99
|
onKeyDown: onKeyDown,
|
|
53
100
|
onMouseMove: onMouseMove,
|
|
54
101
|
onMouseLeave: onMouseLeave,
|
|
@@ -24,9 +24,6 @@
|
|
|
24
24
|
|
|
25
25
|
text-transform: var(--typography-text-2xs-text_transform, none);
|
|
26
26
|
}
|
|
27
|
-
.FieldControl_size_2xs .FieldInput::-webkit-calendar-picker-indicator {
|
|
28
|
-
inset-inline-end: -25px;
|
|
29
|
-
}
|
|
30
27
|
.FieldControl_size_xs {
|
|
31
28
|
--textfield-gutter-x: 12px;
|
|
32
29
|
--textfield-input-height: 40px;
|
|
@@ -39,9 +36,6 @@
|
|
|
39
36
|
|
|
40
37
|
text-transform: var(--typography-text-xs-text_transform, none);
|
|
41
38
|
}
|
|
42
|
-
.FieldControl_size_xs .FieldInput::-webkit-calendar-picker-indicator {
|
|
43
|
-
inset-inline-end: -25px;
|
|
44
|
-
}
|
|
45
39
|
.FieldControl_size_s {
|
|
46
40
|
--textfield-gutter-x: 16px;
|
|
47
41
|
--textfield-input-height: 48px;
|
|
@@ -54,9 +48,6 @@
|
|
|
54
48
|
|
|
55
49
|
text-transform: var(--typography-text-s-text_transform, none);
|
|
56
50
|
}
|
|
57
|
-
.FieldControl_size_s .FieldInput::-webkit-calendar-picker-indicator {
|
|
58
|
-
inset-inline-end: -30px;
|
|
59
|
-
}
|
|
60
51
|
.FieldControl_size_m {
|
|
61
52
|
--textfield-gutter-x: 20px;
|
|
62
53
|
--textfield-input-height: 56px;
|
|
@@ -69,9 +60,6 @@
|
|
|
69
60
|
|
|
70
61
|
text-transform: var(--typography-text-m-text_transform, none);
|
|
71
62
|
}
|
|
72
|
-
.FieldControl_size_m .FieldInput::-webkit-calendar-picker-indicator {
|
|
73
|
-
inset-inline-end: -34px;
|
|
74
|
-
}
|
|
75
63
|
.FieldControl_size_l {
|
|
76
64
|
--textfield-gutter-x: 24px;
|
|
77
65
|
--textfield-input-height: 64px;
|
|
@@ -84,9 +72,6 @@
|
|
|
84
72
|
|
|
85
73
|
text-transform: var(--typography-text-l-text_transform, none);
|
|
86
74
|
}
|
|
87
|
-
.FieldControl_size_l .FieldInput::-webkit-calendar-picker-indicator {
|
|
88
|
-
inset-inline-end: -39px;
|
|
89
|
-
}
|
|
90
75
|
.FieldControl_hasLabel.FieldControl_size_2xs {
|
|
91
76
|
--textfield-input-padding: 8px 0 8px;
|
|
92
77
|
}
|
|
@@ -44,13 +44,6 @@
|
|
|
44
44
|
appearance: none;
|
|
45
45
|
margin: 0;
|
|
46
46
|
}
|
|
47
|
-
.Input-Field::-webkit-calendar-picker-indicator {
|
|
48
|
-
opacity: 0;
|
|
49
|
-
position: absolute;
|
|
50
|
-
inset-block-start: 50%;
|
|
51
|
-
transform: translateY(-50%);
|
|
52
|
-
cursor: pointer;
|
|
53
|
-
}
|
|
54
47
|
.Input-Field[type='number'] {
|
|
55
48
|
-webkit-appearance: textfield;
|
|
56
49
|
-moz-appearance: textfield;
|
|
@@ -18,16 +18,16 @@ export var Input = forwardRef(function (inProps, ref) {
|
|
|
18
18
|
props: inProps,
|
|
19
19
|
name: 'Input',
|
|
20
20
|
});
|
|
21
|
-
var _a = props.size, size = _a === void 0 ? INPUT_DEFAULT_SIZE : _a, label = props.label, error = props.error, autoFocus = props.autoFocus, placeholder = props.placeholder, id = props.id, name = props.name, type = props.type, renderLeft = props.renderLeft, renderRight = props.renderRight, inputRef = props.inputRef, fullWidth = props.fullWidth, disabled = props.disabled, hint = props.hint, required = props.required, className = props.className, inputProps = props.inputProps, value = props.value, defaultValue = props.defaultValue, onChange = props.onChange, labelProps = props.labelProps, labelRef = props.labelRef, other = __rest(props, ["size", "label", "error", "autoFocus", "placeholder", "id", "name", "type", "renderLeft", "renderRight", "inputRef", "fullWidth", "disabled", "hint", "required", "className", "inputProps", "value", "defaultValue", "onChange", "labelProps", "labelRef"]);
|
|
22
|
-
var
|
|
21
|
+
var _a = props.size, size = _a === void 0 ? INPUT_DEFAULT_SIZE : _a, label = props.label, error = props.error, autoFocus = props.autoFocus, placeholder = props.placeholder, id = props.id, name = props.name, type = props.type, renderLeft = props.renderLeft, renderRight = props.renderRight, inputRef = props.inputRef, fullWidth = props.fullWidth, disabled = props.disabled, hint = props.hint, required = props.required, className = props.className, inputProps = props.inputProps, value = props.value, defaultValue = props.defaultValue, onChange = props.onChange, labelProps = props.labelProps, labelRef = props.labelRef, bodyProps = props.bodyProps, other = __rest(props, ["size", "label", "error", "autoFocus", "placeholder", "id", "name", "type", "renderLeft", "renderRight", "inputRef", "fullWidth", "disabled", "hint", "required", "className", "inputProps", "value", "defaultValue", "onChange", "labelProps", "labelRef", "bodyProps"]);
|
|
22
|
+
var bodyInnerRef = useRef(null);
|
|
23
23
|
var fieldInnerRef = useRef(null);
|
|
24
24
|
/* Хук useEventListener необходим для того, чтобы при нажатии на кнопку мыши
|
|
25
|
-
* внутри HTML-элемента label
|
|
25
|
+
* внутри HTML-элемента label – фокус не переходил на body или на цель нажатия кнопки мыши.
|
|
26
26
|
* Если же нажатие кнопки происходит на самом HTML-элементе input, то мы ничего не делаем,
|
|
27
27
|
* так как в противном случае мы сломаем возможность выделять текст для копирования.
|
|
28
28
|
*/
|
|
29
29
|
useEventListener({
|
|
30
|
-
element:
|
|
30
|
+
element: bodyInnerRef,
|
|
31
31
|
eventName: 'mousedown',
|
|
32
32
|
handler: function (e) {
|
|
33
33
|
var _a;
|
|
@@ -38,7 +38,7 @@ export var Input = forwardRef(function (inProps, ref) {
|
|
|
38
38
|
},
|
|
39
39
|
});
|
|
40
40
|
return (React.createElement(FieldControl, __assign({ size: size, error: error, disabled: disabled, required: required, fullWidth: fullWidth }, other, { ref: ref, className: cnInput({}, [className]) }),
|
|
41
|
-
React.createElement("label", { className: cnInput('Body'), ref:
|
|
41
|
+
React.createElement("label", __assign({}, bodyProps, { className: cnInput('Body'), ref: useMultiRef([bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.ref, bodyInnerRef]) }),
|
|
42
42
|
React.createElement(FieldIcon, { icon: renderLeft }),
|
|
43
43
|
React.createElement("div", { className: cnInput('FieldContainer') },
|
|
44
44
|
React.createElement(FieldLabel, __assign({}, labelProps, { ref: labelRef || (labelProps === null || labelProps === void 0 ? void 0 : labelProps.ref), className: labelProps === null || labelProps === void 0 ? void 0 : labelProps.className }), label),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ComponentPropsWithRef,
|
|
1
|
+
import type { ComponentPropsWithRef, Ref } from 'react';
|
|
2
2
|
import type { FormElementSizeVariant } from '../../types/FormElementSizeVariant';
|
|
3
3
|
import type { FIELD_CONTROL_DEFAULT_TAG } from '../FieldControl';
|
|
4
4
|
import type { FieldIconProps } from '../FieldIcon';
|
|
@@ -63,8 +63,8 @@ export type InputProps = Omit<ComponentPropsWithRef<typeof FIELD_CONTROL_DEFAULT
|
|
|
63
63
|
};
|
|
64
64
|
/** Свойства FieldLabel */
|
|
65
65
|
labelProps?: FieldLabelProps;
|
|
66
|
-
/**
|
|
67
|
-
|
|
66
|
+
/** Cвойства Body */
|
|
67
|
+
bodyProps?: ComponentPropsWithRef<'label'>;
|
|
68
68
|
/** data-атрибут для тестирования */
|
|
69
69
|
'data-testid'?: string;
|
|
70
70
|
} & InputPropsDeprecated;
|
|
@@ -21,7 +21,7 @@ export var InputNumber = forwardRef(function (inProps, ref) {
|
|
|
21
21
|
props: inProps,
|
|
22
22
|
name: 'InputNumber',
|
|
23
23
|
});
|
|
24
|
-
var _a = props.size, size = _a === void 0 ? INPUT_NUMBER_DEFAULT_SIZE : _a, _b = props.step, step = _b === void 0 ? INPUT_NUMBER_DEFAULT_STEP : _b, _c = props.autoFocus, autoFocus = _c === void 0 ? INPUT_NUMBER_DEFAULT_AUTO_FOCUS : _c, _d = props.error, error = _d === void 0 ? INPUT_NUMBER_DEFAULT_ERROR : _d, _e = props.required, required = _e === void 0 ? INPUT_NUMBER_DEFAULT_REQUIRED : _e, _f = props.disabled, disabled = _f === void 0 ? INPUT_NUMBER_DEFAULT_DISABLED : _f, _g = props.fullWidth, fullWidth = _g === void 0 ? INPUT_NUMBER_DEFAULT_FULL_WIDTH : _g, _h = props.defaultValue, defaultValue = _h === void 0 ? INPUT_NUMBER_DEFAULT_VALUE : _h, _j = props.min, min = _j === void 0 ? INPUT_NUMBER_DEFAULT_MIN : _j, _k = props.max, max = _k === void 0 ? INPUT_NUMBER_DEFAULT_MAX : _k, label = props.label, placeholder = props.placeholder, id = props.id, name = props.name, renderLeft = props.renderLeft, renderRight = props.renderRight, hint = props.hint, className = props.className, inputProps = props.inputProps, valueProp = props.value, onChange = props.onChange, labelRef = props.labelRef, labelProps = props.labelProps, other = __rest(props, ["size", "step", "autoFocus", "error", "required", "disabled", "fullWidth", "defaultValue", "min", "max", "label", "placeholder", "id", "name", "renderLeft", "renderRight", "hint", "className", "inputProps", "value", "onChange", "labelRef", "labelProps"]);
|
|
24
|
+
var _a = props.size, size = _a === void 0 ? INPUT_NUMBER_DEFAULT_SIZE : _a, _b = props.step, step = _b === void 0 ? INPUT_NUMBER_DEFAULT_STEP : _b, _c = props.autoFocus, autoFocus = _c === void 0 ? INPUT_NUMBER_DEFAULT_AUTO_FOCUS : _c, _d = props.error, error = _d === void 0 ? INPUT_NUMBER_DEFAULT_ERROR : _d, _e = props.required, required = _e === void 0 ? INPUT_NUMBER_DEFAULT_REQUIRED : _e, _f = props.disabled, disabled = _f === void 0 ? INPUT_NUMBER_DEFAULT_DISABLED : _f, _g = props.fullWidth, fullWidth = _g === void 0 ? INPUT_NUMBER_DEFAULT_FULL_WIDTH : _g, _h = props.defaultValue, defaultValue = _h === void 0 ? INPUT_NUMBER_DEFAULT_VALUE : _h, _j = props.min, min = _j === void 0 ? INPUT_NUMBER_DEFAULT_MIN : _j, _k = props.max, max = _k === void 0 ? INPUT_NUMBER_DEFAULT_MAX : _k, label = props.label, placeholder = props.placeholder, id = props.id, name = props.name, renderLeft = props.renderLeft, renderRight = props.renderRight, hint = props.hint, className = props.className, inputProps = props.inputProps, valueProp = props.value, onChange = props.onChange, labelRef = props.labelRef, labelProps = props.labelProps, bodyProps = props.bodyProps, other = __rest(props, ["size", "step", "autoFocus", "error", "required", "disabled", "fullWidth", "defaultValue", "min", "max", "label", "placeholder", "id", "name", "renderLeft", "renderRight", "hint", "className", "inputProps", "value", "onChange", "labelRef", "labelProps", "bodyProps"]);
|
|
25
25
|
var _l = __read(useState(false), 2), focused = _l[0], setFocused = _l[1];
|
|
26
26
|
var _m = __read(useState(null), 2), timeoutId = _m[0], setTimeoutId = _m[1];
|
|
27
27
|
var _o = __read(useState(null), 2), countDirection = _o[0], setCountDirection = _o[1];
|
|
@@ -31,8 +31,8 @@ export var InputNumber = forwardRef(function (inProps, ref) {
|
|
|
31
31
|
state: 'value',
|
|
32
32
|
defaultValue: defaultValue,
|
|
33
33
|
}), 2), valueState = _p[0], setValueState = _p[1];
|
|
34
|
-
var
|
|
35
|
-
var
|
|
34
|
+
var bodyInnerRef = useRef(null);
|
|
35
|
+
var fieldInnerRef = useRef(null);
|
|
36
36
|
var filled = isValidValue(valueState);
|
|
37
37
|
var handleChange = function (event) {
|
|
38
38
|
if (disabled)
|
|
@@ -90,18 +90,18 @@ export var InputNumber = forwardRef(function (inProps, ref) {
|
|
|
90
90
|
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(inputProps, event);
|
|
91
91
|
};
|
|
92
92
|
/* Хук useEventListener необходим для того, чтобы при нажатии на кнопку мыши
|
|
93
|
-
* внутри HTML-элемента label
|
|
93
|
+
* внутри HTML-элемента label – фокус не переходил на body или на цель нажатия кнопки мыши.
|
|
94
94
|
* Если же нажатие кнопки происходит на самом HTML-элементе input, то мы ничего не делаем,
|
|
95
95
|
* так как в противном случае мы сломаем возможность выделять текст для копирования.
|
|
96
96
|
*/
|
|
97
97
|
useEventListener({
|
|
98
|
-
element:
|
|
98
|
+
element: bodyInnerRef,
|
|
99
99
|
eventName: 'mousedown',
|
|
100
100
|
handler: function (e) {
|
|
101
101
|
var _a;
|
|
102
|
-
if (e.target !==
|
|
102
|
+
if (e.target !== fieldInnerRef.current) {
|
|
103
103
|
e.preventDefault();
|
|
104
|
-
(_a =
|
|
104
|
+
(_a = fieldInnerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
105
105
|
}
|
|
106
106
|
},
|
|
107
107
|
});
|
|
@@ -132,13 +132,13 @@ export var InputNumber = forwardRef(function (inProps, ref) {
|
|
|
132
132
|
hasLabel: !!label,
|
|
133
133
|
focused: focused,
|
|
134
134
|
}, [className]) }),
|
|
135
|
-
React.createElement("label", {
|
|
135
|
+
React.createElement("label", __assign({}, bodyProps, { className: cnInputNumber('Body'), ref: useMultiRef([bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.ref, bodyInnerRef]) }),
|
|
136
136
|
React.createElement(FieldIcon, { className: cnInputNumber('RenderLeft'), icon: renderLeft, size: size }),
|
|
137
137
|
React.createElement("div", { className: cnInputNumber('FieldContainer') },
|
|
138
|
-
|
|
138
|
+
React.createElement(FieldLabel, __assign({ filled: filled, focused: focused, required: required, disabled: disabled, size: size }, labelProps, { className: cnInputNumber('Label', [labelProps === null || labelProps === void 0 ? void 0 : labelProps.className]), ref: labelRef }), label),
|
|
139
139
|
React.createElement("input", __assign({ id: id, name: name, autoFocus: autoFocus, disabled: disabled, value: valueState, required: required, placeholder: placeholder, className: cnInputNumber('Field', { filled: filled }, [
|
|
140
140
|
inputProps === null || inputProps === void 0 ? void 0 : inputProps.className,
|
|
141
|
-
]), min: min, max: max, step: step }, inputProps, { type: "number", onFocus: handleFocus, onBlur: handleBlur, onChange: handleChange, onKeyDown: handleKeyDown, ref: useMultiRef([inputProps === null || inputProps === void 0 ? void 0 : inputProps.ref,
|
|
141
|
+
]), min: min, max: max, step: step }, inputProps, { type: "number", onFocus: handleFocus, onBlur: handleBlur, onChange: handleChange, onKeyDown: handleKeyDown, ref: useMultiRef([inputProps === null || inputProps === void 0 ? void 0 : inputProps.ref, fieldInnerRef]) }))),
|
|
142
142
|
React.createElement(FieldIcon, { className: cnInputNumber('RenderRight'), icon: renderRight, size: size }),
|
|
143
143
|
React.createElement("span", { className: cnInputNumber('Controls') },
|
|
144
144
|
React.createElement(IconButton, { tabIndex: -1, size: size, className: cnInputNumber('Increment'), icon: SortUpIcon, onMouseDown: handleMouseDown('increment'), disabled: disabled, "aria-label": "increment", type: "button", variant: "ghost" }),
|
|
@@ -52,6 +52,8 @@ export type InputNumberProps = {
|
|
|
52
52
|
labelRef?: FieldLabelProps['ref'];
|
|
53
53
|
/** Свойства FieldLabel */
|
|
54
54
|
labelProps?: FieldLabelProps;
|
|
55
|
+
/** Cвойства Body */
|
|
56
|
+
bodyProps?: ComponentPropsWithRef<'label'>;
|
|
55
57
|
/** Шаг инкремента/декремента */
|
|
56
58
|
step?: number;
|
|
57
59
|
/** Минимально допустимое значение */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Ref, ComponentPropsWithRef
|
|
1
|
+
import type { Ref, ComponentPropsWithRef } from 'react';
|
|
2
2
|
import type { FormElementSizeVariant } from '../../types/FormElementSizeVariant';
|
|
3
3
|
import type { FIELD_CONTROL_DEFAULT_TAG } from '../FieldControl';
|
|
4
4
|
import type { FieldLabelProps } from '../FieldLabel';
|
|
@@ -61,8 +61,6 @@ export type TextareaProps = Omit<ComponentPropsWithRef<typeof FIELD_CONTROL_DEFA
|
|
|
61
61
|
};
|
|
62
62
|
/** Свойства FieldLabel */
|
|
63
63
|
labelProps?: FieldLabelProps;
|
|
64
|
-
/** Ссылка на корневой DOM-элемент компонента */
|
|
65
|
-
ref?: ComponentRef<typeof FIELD_CONTROL_DEFAULT_TAG>;
|
|
66
64
|
/** data-атрибут для тестирования */
|
|
67
65
|
'data-testid'?: string;
|
|
68
66
|
} & TextareaPropsDeprecated;
|
|
@@ -22,7 +22,7 @@ export var useControlled = function (_a) {
|
|
|
22
22
|
console.error([
|
|
23
23
|
"\u00D6zen-UI: \u041F\u043E\u0432\u0435\u0434\u0435\u043D\u0438\u0435 \u0441\u0432\u043E\u0439\u0441\u0442\u0432\u0430 '".concat(state, "' \u0443 \u043A\u043E\u043C\u043F\u043E\u043D\u0435\u043D\u0442\u0430 ").concat(name, " \u043F\u043E\u043C\u0435\u043D\u044F\u043B\u043E\u0441\u044C \u0441 ").concat(isControlled ? '' : 'не', "\u043A\u043E\u043D\u0442\u0440\u043E\u043B\u0438\u0440\u0443\u0435\u043C\u043E\u0433\u043E \u043D\u0430 ").concat(isControlled ? 'не' : '', "\u043A\u043E\u043D\u0442\u0440\u043E\u043B\u0438\u0440\u0443\u0435\u043C\u043E\u0435."),
|
|
24
24
|
'Компоненты не должны переключаться с неконтролируемого поведения в контролируемое, или наоборот.',
|
|
25
|
-
'Поведение определяется после первого рендера и является контролируемым, если значение не
|
|
25
|
+
'Поведение определяется после первого рендера и является контролируемым, если значение не «undefined».',
|
|
26
26
|
].join('\n'));
|
|
27
27
|
}
|
|
28
28
|
}, [state, name, valueProp]);
|
|
@@ -30,8 +30,8 @@ export var useControlled = function (_a) {
|
|
|
30
30
|
useEffect(function () {
|
|
31
31
|
if (!isControlled && defaultValue_1 !== defaultProp) {
|
|
32
32
|
console.error([
|
|
33
|
-
"\u00D6zen-UI: \u041D\u0435\u043A\u043E\u043D\u0442\u0440\u043E\u043B\u0438\u0440\u0443\u0435\u043C\u044B\u0439 \u043A\u043E\u043C\u043F\u043E\u043D\u0435\u043D\u0442 ".concat(name, " \u0441\u043C\u0435\u043D\u0438\u043B default ").concat(state, " \u043F\u043E\u0441\u043B\u0435 \u043F\u0435\u0440\u0432\u043E\u0439 \u0438\u043D\u0438\u0446\u0438\u0430\u043B\u0438\u0437\u0430\u0446\u0438\u0438 ").concat(name)
|
|
34
|
-
|
|
33
|
+
"\u00D6zen-UI: \u041D\u0435\u043A\u043E\u043D\u0442\u0440\u043E\u043B\u0438\u0440\u0443\u0435\u043C\u044B\u0439 \u043A\u043E\u043C\u043F\u043E\u043D\u0435\u043D\u0442 ".concat(name, " \u0441\u043C\u0435\u043D\u0438\u043B default ").concat(state, " \u043F\u043E\u0441\u043B\u0435 \u043F\u0435\u0440\u0432\u043E\u0439 \u0438\u043D\u0438\u0446\u0438\u0430\u043B\u0438\u0437\u0430\u0446\u0438\u0438 ").concat(name, "."),
|
|
34
|
+
"\u0415\u0441\u043B\u0438 \u043D\u0435\u043E\u0431\u0445\u043E\u0434\u0438\u043C\u043E \u043C\u0435\u043D\u044F\u0442\u044C \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u0432\u043E\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435\u0441\u044C \u043A\u043E\u043D\u0442\u0440\u043E\u043B\u0438\u0440\u0443\u0435\u043C\u044B\u043C \u043F\u043E\u0432\u0435\u0434\u0435\u043D\u0438\u0435\u043C.",
|
|
35
35
|
].join('\n'));
|
|
36
36
|
}
|
|
37
37
|
}, [JSON.stringify(defaultProp)]);
|