@homecode/ui 4.20.0-beta-6 → 4.20.0-beta-7
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.
|
@@ -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');
|
|
@@ -292,7 +301,9 @@ const Input = forwardRef((props, ref) => {
|
|
|
292
301
|
}, []);
|
|
293
302
|
const Control = isTextArea ? 'span' : 'input';
|
|
294
303
|
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:
|
|
304
|
+
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 &&
|
|
305
|
+
controlProps.placeholder &&
|
|
306
|
+
!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
307
|
});
|
|
297
308
|
|
|
298
309
|
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;
|