@homecode/ui 4.20.0-beta-6 → 4.20.0-beta-8
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.
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { forwardRef, useRef, useState, useMemo, useEffect, createElement } from 'react';
|
|
3
3
|
import cn from 'classnames';
|
|
4
|
-
import omit from 'lodash.omit';
|
|
5
4
|
import { Label } from '../Label/Label.js';
|
|
6
5
|
import { RequiredStar } from '../RequiredStar/RequiredStar.js';
|
|
7
6
|
import { AssistiveText } from '../AssistiveText/AssistiveText.js';
|
|
@@ -26,6 +25,7 @@ import '../Paranja/Paranja.styl.js';
|
|
|
26
25
|
import '../Popup/Popup.styl.js';
|
|
27
26
|
import '../Select/Select.styl.js';
|
|
28
27
|
import 'justorm/react';
|
|
28
|
+
import 'lodash.omit';
|
|
29
29
|
import '../Checkbox/Checkbox.styl.js';
|
|
30
30
|
import '../Container/Container.styl.js';
|
|
31
31
|
import '../DatePicker/DatePicker.styl.js';
|
|
@@ -61,8 +61,17 @@ const TEXTAREA_SCROLL_TOP_OFFSET = {
|
|
|
61
61
|
l: 50,
|
|
62
62
|
};
|
|
63
63
|
const Input = forwardRef((props, ref) => {
|
|
64
|
-
const { type = 'text', size = 'm', variant = 'default', value, defaultValue = '', onChange, onFocus, onBlur, onClear, onInput, changeOnEnd, checkAutofill, hasClear, required, hideRequiredStar, disabled, error, label, placeholder, addonLeft, addonRight, forceLabelOnTop, scrollProps, step = 1, round, className, } = props;
|
|
65
64
|
const inputRef = useRef(null);
|
|
65
|
+
const setRef = (element) => {
|
|
66
|
+
inputRef.current = element;
|
|
67
|
+
if (typeof ref === 'function') {
|
|
68
|
+
ref(element);
|
|
69
|
+
}
|
|
70
|
+
else if (ref) {
|
|
71
|
+
ref.current = element;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const { type = 'text', size = 'm', variant = 'default', value, defaultValue = '', onChange, onFocus, onBlur, onClear, onInput, changeOnEnd, checkAutofill, hasClear, required, hideRequiredStar, disabled, error, label, placeholder, addonLeft, addonRight, forceLabelOnTop, scrollProps, step = 1, round, className, } = props;
|
|
66
75
|
const updateAutoComplete = () => {
|
|
67
76
|
const form = inputRef.current?.closest('form');
|
|
68
77
|
const val = form?.getAttribute('autocomplete');
|
|
@@ -202,23 +211,11 @@ const Input = forwardRef((props, ref) => {
|
|
|
202
211
|
};
|
|
203
212
|
const controlProps = useMemo(() => {
|
|
204
213
|
const controlProps = {
|
|
205
|
-
|
|
206
|
-
'className',
|
|
207
|
-
'clear',
|
|
208
|
-
'onClear',
|
|
209
|
-
'hasClear',
|
|
210
|
-
'placeholder',
|
|
211
|
-
'hideRequiredStar',
|
|
212
|
-
'size',
|
|
213
|
-
'error',
|
|
214
|
-
'checkAutofill',
|
|
215
|
-
'addonLeft',
|
|
216
|
-
'addonRight',
|
|
217
|
-
'forceLabelOnTop',
|
|
218
|
-
'changeOnEnd',
|
|
219
|
-
'scrollProps',
|
|
220
|
-
]),
|
|
214
|
+
type,
|
|
221
215
|
value: inputValue,
|
|
216
|
+
step,
|
|
217
|
+
required,
|
|
218
|
+
disabled,
|
|
222
219
|
...props.controlProps,
|
|
223
220
|
onChange: handleChange,
|
|
224
221
|
onFocus: handleFocus,
|
|
@@ -239,7 +236,27 @@ const Input = forwardRef((props, ref) => {
|
|
|
239
236
|
if (controlProps.value === undefined)
|
|
240
237
|
controlProps.value = ' ';
|
|
241
238
|
return controlProps;
|
|
242
|
-
}, [
|
|
239
|
+
}, [
|
|
240
|
+
type,
|
|
241
|
+
size,
|
|
242
|
+
variant,
|
|
243
|
+
inputValue,
|
|
244
|
+
defaultValue,
|
|
245
|
+
step,
|
|
246
|
+
required,
|
|
247
|
+
disabled,
|
|
248
|
+
props.controlProps,
|
|
249
|
+
handleChange,
|
|
250
|
+
onFocus,
|
|
251
|
+
onBlur,
|
|
252
|
+
isTextArea,
|
|
253
|
+
onTextAreaInput,
|
|
254
|
+
placeholder,
|
|
255
|
+
label,
|
|
256
|
+
isLabelOnTop,
|
|
257
|
+
autoComplete,
|
|
258
|
+
uid,
|
|
259
|
+
]);
|
|
243
260
|
const wrapControl = control => {
|
|
244
261
|
if (isTextArea) {
|
|
245
262
|
const { size } = props;
|
|
@@ -292,7 +309,9 @@ const Input = forwardRef((props, ref) => {
|
|
|
292
309
|
}, []);
|
|
293
310
|
const Control = isTextArea ? 'span' : 'input';
|
|
294
311
|
const classes = cn(S.root, isTextArea && S.isTextArea, S[`size-${size}`], S[`variant-${variant}`], isFocused && S.isFocused, error && S.hasError, hasClear && S.hasClear, disabled && S.isDisabled, round && S.round, className);
|
|
295
|
-
return (jsxs("div", { className: classes, title: String(value), children: [jsxs("label", { className: S.main, children: [jsx("div", { className: S.border, suppressHydrationWarning: true, style: { clipPath: labelClipPath } }, "border"), renderAddon('left'), wrapControl(jsxs(Fragment, { children: [createElement(Control, { ...controlProps, className: cn(S.control, controlProps?.className), ref:
|
|
312
|
+
return (jsxs("div", { className: classes, title: String(value), children: [jsxs("label", { className: S.main, children: [jsx("div", { className: S.border, suppressHydrationWarning: true, style: { clipPath: labelClipPath } }, "border"), renderAddon('left'), wrapControl(jsxs(Fragment, { children: [createElement(Control, { ...controlProps, className: cn(S.control, controlProps?.className), ref: setRef, key: "control" }), isTextArea &&
|
|
313
|
+
controlProps.placeholder &&
|
|
314
|
+
!controlProps.value && (jsx("span", { className: S.placeholder, spellCheck: false, children: controlProps.placeholder }))] })), isNumber && (jsxs("div", { className: S.numberArrows, children: [jsx(Button, { variant: "clear", onClick: () => onNumberWheel(1), tabIndex: -1, children: jsx(Icon, { type: "chevronUp", size: size }) }), jsx(Button, { variant: "clear", onClick: () => onNumberWheel(-1), tabIndex: -1, children: jsx(Icon, { type: "chevronDown", size: size }) })] })), jsx(Label, { className: cn(S.label, addonRight && S.hasAddonRight), size: size, isOnTop: isLabelOnTop, isError: Boolean(error), onClipPathChange: onLabelClipPathChange, children: label }, "label"), renderAddon('right'), required && !hideRequiredStar && (jsx(RequiredStar, { size: size }, "required-star"))] }, "main"), hasClear && !disabled && hasValue && (jsx(Button, { className: S.clearButton, variant: "clear", size: size, square: true, onClick: onClearPress, title: "", children: jsx(Icon, { className: S.clearIcon, size: size, type: "close" }) }, "clear")), !disabled && typeof error === 'string' && (jsx(AssistiveText, { variant: "danger", size: size, children: error }, "assistive-text"))] }));
|
|
296
315
|
});
|
|
297
316
|
|
|
298
317
|
export { Input };
|
|
@@ -28,6 +28,7 @@ class Select extends Component {
|
|
|
28
28
|
scrollInnerElem;
|
|
29
29
|
onScrollInnerRef = elem => (this.scrollInnerElem = elem);
|
|
30
30
|
focusedElem;
|
|
31
|
+
selectedElem;
|
|
31
32
|
items = [];
|
|
32
33
|
maxIndex = -1;
|
|
33
34
|
isFirstSelectedMeet = false;
|
|
@@ -157,6 +158,9 @@ class Select extends Component {
|
|
|
157
158
|
}
|
|
158
159
|
}
|
|
159
160
|
};
|
|
161
|
+
onSelectedElemRef = elem => {
|
|
162
|
+
this.selectedElem = elem;
|
|
163
|
+
};
|
|
160
164
|
onDocumentClick = e => {
|
|
161
165
|
if (!this.isClickedInside(e.target)) {
|
|
162
166
|
this.store.isOpen = false;
|
|
@@ -524,8 +528,8 @@ class Select extends Component {
|
|
|
524
528
|
onPointerUp: () => this.onItemToggle(id),
|
|
525
529
|
onPointerEnter: () => this.onOptionHover(id),
|
|
526
530
|
};
|
|
527
|
-
|
|
528
|
-
|
|
531
|
+
// @ts-ignore
|
|
532
|
+
if (isFocused || isSelected)
|
|
529
533
|
props.ref = this.onFocusedElemRef;
|
|
530
534
|
if (isIndeterminate || (isSelected && !this.isFirstSelectedMeet)) {
|
|
531
535
|
this.isFirstSelectedMeet = true;
|
|
@@ -587,7 +591,7 @@ class Select extends Component {
|
|
|
587
591
|
const { className, popupProps, size, error, blur, disabled } = this.props;
|
|
588
592
|
const { isOpen, isFocused } = this.store;
|
|
589
593
|
const classes = cn(S.root, className, S[`size-${size}`]);
|
|
590
|
-
return (jsxs(Fragment, { children: [jsx(Popup, { className: classes, direction: "bottom", size: size, focusControl: true, hoverControl: isFocused, blur: blur, isOpen: isOpen, disabled: disabled, ...popupProps, onOpen: this.onPopupOpen,
|
|
594
|
+
return (jsxs(Fragment, { children: [jsx(Popup, { className: classes, direction: "bottom", size: size, focusControl: true, hoverControl: isFocused, blur: blur, isOpen: isOpen, disabled: disabled, ...popupProps, onOpen: this.onPopupOpen, onAfterClose: this.onPopupClose, trigger: this.renderTrigger(), triggerProps: {
|
|
591
595
|
onFocus: this.onFocus,
|
|
592
596
|
onBlur: this.onBlur,
|
|
593
597
|
}, content: this.renderOptionsList() }), this.isErrorVisible() && (jsx(AssistiveText, { variant: "danger", size: size, children: error }))] }));
|
|
@@ -4,12 +4,33 @@ import { Component, ReactNode } from 'react';
|
|
|
4
4
|
export declare const SelectHelpers: typeof H;
|
|
5
5
|
export declare class Select extends Component<T.Props, T.State> {
|
|
6
6
|
store: any;
|
|
7
|
-
inputRef: import("react").RefObject<(
|
|
7
|
+
inputRef: import("react").RefObject<import("react").ForwardRefExoticComponent<Omit<import("react").InputHTMLAttributes<HTMLInputElement>, "onChange"> & Omit<import("../Input/Input.types").ControlProps, "onChange" | "ref"> & import("../../types").FormControl<import("../Input/Input.types").Value, HTMLInputElement> & {
|
|
8
|
+
name?: string;
|
|
9
|
+
step?: number;
|
|
10
|
+
size?: import("../../types").Size;
|
|
11
|
+
label?: string;
|
|
12
|
+
variant?: import("../../types").Variant;
|
|
13
|
+
round?: boolean;
|
|
14
|
+
hideRequiredStar?: boolean;
|
|
15
|
+
forceLabelOnTop?: boolean;
|
|
16
|
+
error?: string | boolean;
|
|
17
|
+
hasClear?: boolean;
|
|
18
|
+
changeOnEnd?: boolean;
|
|
19
|
+
addonLeft?: ReactNode;
|
|
20
|
+
addonLeftClassName?: string;
|
|
21
|
+
addonRight?: ReactNode;
|
|
22
|
+
addonRightClassName?: string;
|
|
23
|
+
onClear?: () => void;
|
|
24
|
+
controlProps?: import("../Input/Input.types").ControlProps & import("../../types").ComponentType;
|
|
25
|
+
checkAutofill?: boolean;
|
|
26
|
+
scrollProps?: Partial<import("../Scroll/Scroll.types").Props>;
|
|
27
|
+
} & import("react").RefAttributes<HTMLInputElement>>>;
|
|
8
28
|
triggerInputRef: import("react").RefObject<HTMLDivElement>;
|
|
9
29
|
contentRef: import("react").RefObject<HTMLDivElement>;
|
|
10
30
|
scrollInnerElem: HTMLDivElement;
|
|
11
31
|
onScrollInnerRef: (elem: any) => any;
|
|
12
32
|
focusedElem: HTMLDivElement;
|
|
33
|
+
selectedElem: HTMLDivElement;
|
|
13
34
|
items: any[];
|
|
14
35
|
maxIndex: number;
|
|
15
36
|
isFirstSelectedMeet: boolean;
|
|
@@ -35,6 +56,7 @@ export declare class Select extends Component<T.Props, T.State> {
|
|
|
35
56
|
getDefaultSelected(): any;
|
|
36
57
|
isClickedInside: (elem: any) => any;
|
|
37
58
|
onFocusedElemRef: (elem: any) => void;
|
|
59
|
+
onSelectedElemRef: (elem: any) => void;
|
|
38
60
|
onDocumentClick: (e: any) => void;
|
|
39
61
|
onDocumentKeyDown: (e: any) => void;
|
|
40
62
|
onDocumentKeyUp: (e: any) => void;
|